lcd.java,,,主程序,,即可以读取串口数据,也可以发送串口数据但在读取串口数据的时候,,总是不稳定..数据不是多了就是少了,,,不知道是怎么回事..比如我测试发送数据:789  主程序.lcd.java有时候会收到78978978 有时候则正常..请问怎么解决贴出代码如下:
public void serialEvent(SerialPortEvent event) {

try{ 

serialPort.setSerialPortParams(bit, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); 

}catch (UnsupportedCommOperationException e) {




byte[] readBuffer = new byte[20]; 

try { 

inputStream = serialPort.getInputStream(); 

catch (IOException e) {} 
try {  while (inputStream.available() > 0) { 
int numBytes = inputStream.read(readBuffer); 

String str=new String(readBuffer);  a1.setText(str);

System.out.println(str);


catch (IOException e) { } 

}