I cannot find a way to make what seems to be one of the simplest thing with the boost asio library :
Read all the data available in a serial port
For example in Qt there is a readAll() method from QextSerialPort.
Actually, all the examples I found are about reading a certain amount of data, or multi threaded.
In my case I need it to read the data from a GSM controller. The response size depends on the sent command and the controller context so I can't specify it.
Try this:
boost::asio::read(
sock,
boost::asio::buffer(buf),
boost::asio::transfer_at_least(1),
ec
);
You want the transfer_all() completion condition combined with the read() or async_read() free functions:
boost::array<char, 128> buf;
boost::system::error_code ec;
std::size_t n = boost::asio::read(
sock, boost::asio::buffer(buf),
boost::asio::transfer_all(), ec);
if (ec)
{
// An error occurred.
}
else
{
// n == 128
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With