用于串行连接的Java InputStream文件结尾

用于串行连接的Java InputStream文件结尾,java,serial-port,inputstream,eof,Java,Serial Port,Inputstream,Eof,我正在用串行端口和Java InputStream处理EOF 我的串行设备以100Hz的频率连续发送16个字节。我的接收程序与此类似 private static final int MESSAGE_SIZE = 20; public byte[] read() throws IOException { final byte[] buffer = new byte[MESSAGE_SIZE]; int total = 0; int read = 0; while (total

我正在用串行端口和Java InputStream处理EOF

我的串行设备以100Hz的频率连续发送16个字节。我的接收程序与此类似

private static final int MESSAGE_SIZE = 20;

public byte[] read() throws IOException {
  final byte[] buffer = new byte[MESSAGE_SIZE];
  int total = 0;
  int read = 0;
  while (total < MESSAGE_SIZE
            && (read = in.read(buffer, total, MESSAGE_SIZE - total)) >= 0) {
    total += read;
  }
  return buffer;
}
张贴和证明

结果,我得到了16字节数据包和EOF的混合

串行端口上怎么会发生EOF?

可能的重复实际上更像是无法撤消手机的关闭它看起来可能是重复的