I want to write to a serial device. After each write I read from the device. I want to have a timeout for the read operation, if the device doesn’t respond.
I’ve found a quite elegant solution here on SO. However, in my application, the port and the io_service are member variables, but when I try to instatiate the deadline_timer with the io_service member I get an access violation.
There should be no problem creating a deadline_timer with an io_service that is a member variable.
If the deadline_timer is a member in the same class as the io_service, you must make sure that the deadline_timer is declared after the io_service so that the io_service has been constructed when the time comes to construct the deadline_timer.