Java InputStream-从串行端口读取数据
从串行端口读取数据时出现问题。我的代码是这样的:Java InputStream-从串行端口读取数据,java,serial-port,inputstream,Java,Serial Port,Inputstream,从串行端口读取数据时出现问题。我的代码是这样的: case SerialPortEvent.DATA_AVAILABLE: try { int numBytes = 0; while ((numBytes = inputStream.read(readBuffer)) >= 0){ //Some code to process data } } catc
case SerialPortEvent.DATA_AVAILABLE:
try {
int numBytes = 0;
while ((numBytes = inputStream.read(readBuffer)) >= 0){
//Some code to process data
}
} catch (IOException e){
System.out.println(e.getMessage());
}
break;
传入的包很小,大小不同-5、7、13字节。波特率为57600。在真实环境中,每秒有3-4个包
问题是:
- 当我使用
方法返回字节数组readBytes,其中省略了值为0的字节。read()方法不读取零李>javax.comm时,read()
- 当我使用
具有正确的值(读取整个包),但只有在readBytes[0]中才有值RXTX时,numBytes