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个包

问题是:

  • 当我使用
    javax.comm时,read()
    方法返回字节数组readBytes,其中省略了值为0的字节。read()方法不读取零
  • 当我使用
    RXTX时,numBytes
    具有正确的值(读取整个包),但只有在readBytes[0]中才有值
所以,我完全陷入困境,不知道发生了什么,也不知道在哪里找到解决方案

谁能至少给我一个解决这个问题的提示吗