Reputation: 10082
I'm using JavaComm, and getting the inputStream from the serial port object. I have a problem in that sometimes when the system starts up there are noise characters in the buffer that I do not want. I want to initialize the serial port then somehow flush the input of all data before I begin my processing.
Is there any way to do that?
TY Fred
Upvotes: 3
Views: 7218
Reputation: 86774
How would a "flush()" method know what is garbage and what is real data? Only you know, and your program should be prepared to ignore leading garbage.
EDIT: If you can be absolutely certain that all data in the input buffer prior to sending the request is garbage, then just read until there is no more input data -- i.e. flush it yourself.
Upvotes: 5
Reputation: 143154
Before sending any requests to your device read all that you can. Once there's nothing left to read you can start sending requests.
Upvotes: 2