I have some code that needs to read from a serial device. It is a polled function that is called by a rate r
.
The device spits data out in lines separated by \r\n
and its fast, at around 100Hz. Whenever I poll, I want to read the entirety of the serial buffer. I am finding this hard to do with boost::asio because it doesn't seem to provide an available()
function for me.
One of the methods I tried was to use read_until()
but it does not solve my issue because there may be newer data in the buffer after the \r\n
that read_until()
stops at.
I tried consume()
on the buffer after I read it, but that is still a hack job until I know that I have read the latest data from the device.
Anyone has advice on this issue?
\r\n
is all that special. Use a buffer. – Hans Passant