0

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.

Community
  • 1
  • 1
Simon
  • 1,616
  • 2
  • 17
  • 39

1 Answers1

0

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.

janm
  • 17,976
  • 1
  • 43
  • 61
  • Construction in the correct order did solve this problem, but the next access violation occurred, when calling async_read() with bind() – Simon Jul 19 '12 at 09:53
  • 2nd access violation was caused, because io_service was not the first member variable. – Simon Jul 19 '12 at 12:39