[prev in list] [next in list] [prev in thread] [next in thread] 

List:       boost-users
Subject:    Re: [Boost-users] Can someone provide an Asio Serial Port example?
From:       Jeff Dunlap <jeff_j_dunlap () yahoo ! com>
Date:       2010-01-30 21:45:07
Message-ID: loom.20100130T224352-377 () post ! gmane ! org
[Download RAW message or body]

Michael Caisse <boost <at> objectmodelingdesigns.com> writes:

>  
> Using the asio serial port is just like using the socket after you
> have one opened and going.
> 
> To get things going:
> 
> Construct the serial port with the associated io_service as
> with other ASIO services...
> 
>    asio::serial_port port( io_service );
> 
> Next, open the device and setup various options. I have found
> that the defaults among various OS's for the asio serial port
> differ. It can create real headaches so I initialize everything
> that I like:
> 
>    port.open( "/dev/ttyUSB0" );   // or whatever the device might be
> 
>    if( !port.is_open() ){ // do something clever if the open failed }
> 
>    typedef boost::asio::serial_port_base asio_serial;
> 
>    port.set_option( asio_serial::baud_rate( baud ) );
>    port.set_option( asio_serial::flow_control( 
asio_serial::flow_control::none ) );
>    port.set_option( asio_serial::parity( asio_serial::parity::none ) );
>    port.set_option( asio_serial::stop_bits( asio_serial::stop_bits::one ) );
>    port.set_option( asio_serial::character_size( 8 ) );
> 
> Then just use the port as you would a socket. For example,
> 
>    port.async_read_some( asio::buffer( in_message, MAX_MESSAGE_SIZE ),
>                          boost::bind( &my_client::read_done,
>                                       shared_from_this(),
>                                       asio::placeholders::error,
>                                       
asio::placeholders::bytes_transferred ) );
> 
> HTH,
> michael
> 

I'd really like to thank Jeff Gray for his serial example as well as Markus and 
Michael for the guidance to get me started.  

I used Mr. Gray's example which at first didn't work in my particular case 
because of some configuration options that are missing but then I configured 
the port as suggested by Michael and next thing I knew I was reading from and 
writing to a hobby microcontroller that I was given.  I still have quite a bit 
to learn though.

Thank you

_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic