I need to know how to read (sync or async doesn't matters) with a timeout. I want to check if a device is connected with a serial port or not.
For that I use asio::write
and then I wait for the response of the device.
If a device is connected asio::read(serial, boost::asio::buffer(&r,1))
works fine but if there is no device the program stops, which is is why I need the timeout
I know that I need a deadline_timer
but I have no idea how to use it in the async_read
function.
An example of how it works would be really helpful.
I know that there are many similar threads and I read lot of them but I can't find a solution that helps me solving my problem!
See Question&Answers more detail:os