做串口发送和接受数据是遇到了问题,希望各位前辈帮忙
代码片断
public void serialEvent(SerialPortEvent event)//实现串口监听中的方法
{
switch(event.getEventType())
{
case SerialPortEvent.BI:
case SerialPortEvent.OE:
case SerialPortEvent.FE:
case SerialPortEvent.PE:
case SerialPortEvent.CD:
case SerialPortEvent.CTS:
case SerialPortEvent.DSR:
case SerialPortEvent.RI:
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
break;
case SerialPortEvent.DATA_AVAILABLE:
byte[] readBuffer=new byte[1];
System.out.println("为什么只执行一遍?");
try
{
while(inputStream.available()!=-1)
{
int numBytes=inputStream.read(readBuffer);
area.append(new String(readBuffer));
}
System.out.println("为什么不执行这一句呢?");
}
catch(Exception e){}
break;
}
}
[求助]串口问题