Boost logo

Boost Users :

Subject: Re: [Boost-users] [asio] serial_port question
From: Michael Caisse (boost_at_[hidden])
Date: 2009-08-25 22:04:32


Whoops ... forgot to start the read again in the completion handler.
"Fixed" below.

Michael Caisse wrote:
>
>
>
> void my_message_maker::read_start()
> {
> serial_port.async_read_some( boost::asio::buffer( in_message,
> MAX_MESSAGE_SIZE ),
> boost::bind( &my_message_maker::read_done,
> this,
>
> boost::asio::placeholders::error,
>
> boost::asio::placeholders::bytes_transferred ) );
> }
>
>
> void my_message_maker::read_done( const boost::system::error_code& error,
> int bytes_transferred )
> {
> if( !error )
> {
> for( int i=0; i < bytes_transferred; ++i )
> {
> if( in_message[ i ] == STX )
> {
> my_message.clear();
> }
> else if( in_message[ i ] == ETX )
> {
> make_callback( my_message );
> }
> else
> {
> my_message += in_message[ i ];
> }
          read_start();
       }

> }
> else
> {
> close_port( error );
> }
> }
>
>

-- 
----------------------------------
Michael Caisse
Object Modeling Designs
www.objectmodelingdesigns.com

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