How to refresh Java serial InputStream?
•
Java
I'm using javacomm and getting InputStream from the serial object I have a problem. Sometimes when the system starts, there are noise characters in the buffer that I don't want I want to initialize the serial port and refresh all data input in some way before starting processing
Is there any way to do this?
Ty Fred
Solution
How does the "flush()" method know what is garbage and what is real data? Only you know that your program should be ready to ignore leading garbage
Edit: if you can be absolutely sure that all data in the input buffer is garbage before sending the request, just read until there is no more input data - that is, flush it yourself
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码