Reading serial port in Java

前端 未结 3 1907
情歌与酒
情歌与酒 2020-12-06 02:36

I\'m beginner in Java. I\'m reading data from device through serial port. I\'m getting data for every one minute, but first reading is coming half, after that data is coming

3条回答
  •  独厮守ぢ
    2020-12-06 03:05

    Use the following:

    while (inputStream.available()>0) {
      int numBytes = inputStream.read(readBuffer);
      System.out.print(new String(readBuffer));
    }
    

    You are printing the result out of the while loop. However the code inside the loop may run more than once, so chunk of data will be lost.

提交回复
热议问题