Reputation: 121
My device send to serial port every 5 seconds. So, I have two situations for using.
The first one, port is open-close every 5 secs, after send data.
And open once time, and use it persistence (Try to check port is opened before using).
Which use-case is better?
Upvotes: 0
Views: 98
Reputation: 3016
You should not open / close your serial device every n seconds, because time drifting might make you loose data written to your serial port.
In order to keep your program running smootly, why don't you create a new thread which opens the serial port and keeps reading in a while loop ?
Upvotes: 1