Issues receiving in RXTX

后端 未结 6 1778
慢半拍i
慢半拍i 2020-12-08 17:47

I\'ve been using RXTX for about a year now, without too many problems. I just started a new program to interact with a new piece of hardware, so I reused the connect() metho

6条回答
  •  無奈伤痛
    2020-12-08 18:38

    There is a simpler solution to this problem. This is what I did:

    BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String line;
    
        while (keepRunning) {
            try {
                while ((br.ready()) && (line = br.readLine()) != null) {
    ....
    }
    

    If you check that the buffer "is ready" before you read it there should be no problem.

提交回复
热议问题