|
Boost Users : |
Subject: Re: [Boost-users] [asio] serial_port question
From: Robert Dailey (rcdailey_at_[hidden])
Date: 2009-08-25 19:58:06
On Tue, Aug 25, 2009 at 6:36 PM, Michael Caisse <
boost_at_[hidden]> 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.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net