所以我發現如何將Arduino連接到我的java程序。但是,使用串行連接不會提供任何有用的數據,無論是以錯誤的格式還是將其作爲一個盒子發送。我已經看過在這裏發佈的相關問題,但沒有一個提示似乎有幫助。那麼有誰知道如何使用串口在Arduino和計算機之間發送數據?Arduino無法發回串行數據
這是我正在使用的代碼,由此人提供: http://silveiraneto.net/2009/03/01/arduino-and-java/
package serialtalk;
import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;
import java.io.InputStream;
import java.io.OutputStream;
import processing.app.Preferences;
public class Main {
static InputStream input;
static OutputStream output;
public static void main(String[] args) throws Exception{
Preferences.init();
System.out.println("Using port: " + Preferences.get("serial.port"));
CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier(
Preferences.get("serial.port"));
SerialPort port = (SerialPort)portId.open("serial talk", 4000);
input = port.getInputStream();
output = port.getOutputStream();
port.setSerialPortParams(Preferences.getInteger("serial.debug_rate"),
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
while(true){
while(input.available()>0) {
System.out.print((char)(input.read()));
}
}
}
}
的Arduino是這樣的: http://www.arduino.cc/en/Main/ArduinoBoardDuemilanove
的代碼簡單地接收的數,並且確定哪個讀取模擬它應該從我的Arduino發回來。
它是你的Java應用程序或其他東西的問題?你能用串口監視器發送文本到板子嗎? – 2010-04-30 14:40:00
當我寫「Hello World!」時,我可以從arduino發送數據到Netbeans IDE。當我運行我的java程序時,arduino IDE中的串行監視器似乎沒有收到任何東西 – 2010-05-01 09:28:58