CppLinuxSerial
CppLinuxSerial copied to clipboard
Flush write buffer
Hi, First of all, thank you for providing this library, it has really helped during my current project. At this point if my application uses Ser.Write("my string"), it will stay in the write buffer until it is read by the connected device.
If for some reason, it isn't read, the buffer will keep older messages, resulting in unexpected messages when it is read at a later point, or even resulting in a segmentation fault when a buffer overflow occurs.
How can I flush the write buffer before calling Ser.Write("my string")?
Hi @SanderEveraers , I did some quick Googling and think that tcflush() and tcdrain() might help? (see https://linux.die.net/man/3/tcdrain). tcflush seems to drop any data that is ready to be transmitted but not sent, whilst tcdrain() doesn't return until all pending data to be sent has been sent.