On Tue, Aug 25, 2009 at 6:36 PM, Michael Caisse <boost@objectmodelingdesigns.com> wrote:
Robert Dailey wrote:
When reading information from a serial_port, it seems like I'm required to poll the port for data. Is it possible to receive asynchronous events when data is available, kind of like how TCP/IP works?

---------
Robert Dailey

Robert -

Just use the serial_port like you would a TCP/IP socket. For example,
I do this in one of my classes reading streams from hardware:


 serial_port.async_read_some( boost::asio::buffer( in_message, MAX_MESSAGE_SIZE ),
                              boost::bind( &SerialClient::read_done,
                                           shared_from_this(),
                                           boost::asio::placeholders::error,
                                           boost::asio::placeholders::bytes_transferred ) );

Why are you having to poll?

What I'm really asking is: How do you know when to call async_read_some()? Ideally I only want to call into the socket to read information when I get a callback saying that there is actually something in the read buffer to get. A short sequence of what I want to happen:

  1. Send a message over the COM port
  2. Wait for the device to reply (The device would send a message back)
  3. Receive a callback saying that a new message (new data) is available and ready to be read
  4. Call async_read() to obtain that data.