inputstream.available() is 0 always

后端 未结 3 692
感动是毒
感动是毒 2020-12-11 16:17

I have no idea of what is happening to my code. i am getting no errors and no response as well. I am writing the data to the serialport and waiting for the response by activ

3条回答
  •  悲哀的现实
    2020-12-11 16:48

    .available() can not be used in inter-process communication (serial included), since it only checks if there is data available (in input buffers) in current process.

    In serial communication, when you send a messaga and then immediately call available() you will mostly get 0 as serial port did not yet reply with any data.

    The solution is to use blocking read() in a separate thread (with interrupt() to end it):

    Thread interrupt not ending blocking call on input stream read

提交回复
热议问题