我最近买了 Arduino Yún,我正在尝试将模拟引脚的数据与处理和广播与 OSC 一起用于其他应用程序。
我正在使用 Proccesing 论坛中的此代码(我没有收到答案),但我不知道如何在我的处理代码中使用此代码。
// jsch is an open source SSH client for Java.
// get it from <a href="http://www.jcraft.com/jsch/" target="_blank" rel="nofollow">http://www.jcraft.com/jsch/</a>
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
import java.io.*;
String user = "root";
String password = "<ARDUINO PASSWORD>";
String host = "arduino.local";
int port=22;
try
{
JSch jsch = new JSch();
Session session = jsch.getSession(user, host, port);
session.setPassword(password);
session.setConfig("StrictHostKeyChecking", "no"); // less than maximally secure
System.out.println("Establishing Connection...");
session.connect();
System.out.println("Connection established.");
Channel channel = session.openChannel("exec");
// this stream will be used to send data to the Yun
DataOutputStream dataOut = new DataOutputStream(channel.getOutputStream());
channel.setInputStream(null);
// this jsch member class provides remote execution of a shell command
((ChannelExec) channel).setCommand("telnet localhost 6571");
// see <a href="http://arduino.cc/en/Guide/ArduinoYun#toc17" target="_blank" rel="nofollow">http://arduino.cc/en/Guide/ArduinoYun#toc17</a> for why this command
((ChannelExec)channel).setErrStream(System.err);
InputStream in=channel.getInputStream();
// after configuring all channel parameters, we connect, causing the
// command to be executed. Results and further input will be handled
// by the streams
channel.connect();
byte[] tmp=new byte[1024];
// poll input stream forever
while (true) {
while (in.available ()>0) {
int i=in.read(tmp, 0, 1024);
if (i<0)break;
System.out.print(new String(tmp, 0, i));
}
if (channel.isClosed()) {
System.out.println("exit-status: "+channel.getExitStatus());
break;
}
try {
// if used with the Console example code, this will blink the LED
// in time with polling events
dataOut.writeBytes("L\n");
dataOut.flush();
Thread.sleep(1000);
dataOut.writeBytes("H\n");
dataOut.flush();
}
catch(Exception ee) {
System.err.print(ee);
}
}
System.out.println("disconnecting...\n");
channel.disconnect();
session.disconnect();
System.out.println("Finished.\n");
}
catch(Exception e) {
System.err.print(e);
}
任何人都可以给出一些使用 Arduino Yún 并在处理中操作他们的数据的说明吗?
谢谢!