我有一个arduino USB接口板,当它从USB端口收到“L”时,它已被编码为发光LED。我只想要一个java代码。 rxtx已经正确设置..测试文件运行成功。
这是我的代码:(我从互联网上获得帮助)
import gnu.io.CommPortIdentifier;
import gnu.io.PortInUseException;
import gnu.io.SerialPort;
import gnu.io.UnsupportedCommOperationException;
import java.io.*;
import java.util.*;
public class SimpleWrite {
@SuppressWarnings("rawtypes")
static Enumeration portList;
static CommPortIdentifier portId;
static String messageString = "L";
static SerialPort serialPort;
static OutputStream outputStream;
public static void main(String[] args) throws IOException{
portList = CommPortIdentifier.getPortIdentifiers();
int i;
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (portId.getName().equals("COM12")) {
// if (portId.getName().equals("/dev/term/a")) {
while(( i=System.in.read()) != 13)
messageString += (char)i;
try {
serialPort = (SerialPort)
portId.open("SimpleWriteApp", 2000);
} catch (PortInUseException e) {System.out.println(e);}
try {
outputStream = serialPort.getOutputStream();
} catch (IOException e) {System.out.println(e);}
try {
serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {System.out.println(e);}
try { System.out.println(messageString);
outputStream.write(messageString.getBytes());
} catch (IOException e) {System.out.println(e);}
}
}
}
}
}
没有警告没有在eclipse控制台中显示错误。但LED仍处于关闭阶段。 COM-PORT,BAUDRATE PARITY一切都由XCTU检查。
我哪里错了?