最近做毕业设计,一个基于短信的XXX系统,处理串口数据时卡住了~请各位高手帮忙看看~
以下是程序的部分代码,按我的理解在inputstream读完以后应该是返回-1并以此为结束判断的,但运行的时候程序好像卡在最后一个字符那了~~
case SerialPortEvent.DATA_AVAILABLE :
System.out.println("DATA_AVAILABLE event occured.");
int ch = 0;
StringBuffer buf = new StringBuffer();
 
try {
while (ch != -1) 
{
ch = input.read();
System.out.print(ch);
if(ch == -1)
break;
buf.append((char)ch);
}
System.out.print(buf);
 
} catch (IOException e) {
System.out.print(buf);
e.printStackTrace();
}
 
break;