我已经使用RXTX comm编写了一个串行通信代码。当我在端口上写入13000字节时,没有写入任何内容但是当我写入115200或更少的字节时,它就像一个魅力。更多的事情只发生在一些系统上。
更新: 下面是我在端口上写字节的代码:
public String portWriter(byte[] messageString) throws NoSuchPortException {
if (Processing.serialPort == null) {
System.out.println("serial port is null");
Processing.portId = CommPortIdentifier.getPortIdentifier(Processing.portText);
try {
Processing.serialPort = (SerialPort) Processing.portId.open("SimpleWriteApp", 2000);
} catch (PortInUseException e) {
return "Port in use by another application.";
}
try {
Processing.serialPort.setSerialPortParams(Processing.speed,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {
return "Unsupported comm operation.";
}
}
try {
outputStream = Processing.serialPort.getOutputStream();
outputStream.flush();
} catch (IOException e) {
return "Unable to write on port.";
}
try {
//System.out.println("write " + new BigInteger(1, messageString).toString(16));
outputStream.write(messageString);
} catch (IOException e) {
return "Unable to write on port.";
}
return null;
}