tags:

views:

86

answers:

1

Hi,i'm reading data from serial port in java,but i'm not getting full data,it is splitting ten it will comes. example: if target device writes datas_ok but i'm getting datas_ at first read then ok second time.

case SerialPortEvent.DATA_AVAILABLE:

   try {
    while (inputStream.available() > 0) {
     numBytes = inputStream.available();
     readBufferArray = new byte[numBytes];
     // int readtheBytes = (int) inputStream.skip(2);
     int readBytes = inputStream.read(readBufferArray);

     one = new String(readBufferArray);
     System.out.println("readBytes " + one);

     handleFlashResponse(one);

    }
   } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }

plz help me thanks

+2  A: 

From the decription, it sounds like you're reading faster than the data is being sent. This is normal. If you read from the port and there's nothing there, then you need to keep trying (unless there's a call you can make for a blocking read).

jdigital