#include <asserial.h>
Public Member Functions | |
| asynch_serial (boost::asio::io_service &io_service, unsigned int baud=9600, const std::string &device=DFLT_DEVICE) | |
| constructor : The object must be initialized with an ASIO io_service. Upon successful initialization, an asynch read is started that blocks forever. | |
| virtual | ~asynch_serial (void) |
| destructor | |
| void | open (unsigned int baud=9600, const std::string &device=DFLT_DEVICE) |
| Use to open an uninitialized or closed connection. Any open connections are closed before open() commences. Upon successful initialization, an asynch read is started that blocks forever. | |
| void | close (void) |
| call the do_close function via the io service in the other thread. | |
| bool | active () const |
| return true if the socket is still active | |
| void | active (const bool on_off) |
| active flag toggle for environments where a degree of manual control are required. | |
| void | write (const char msg) |
| pass the write data to the do_write function via the io service in the other thread. | |
| boost::signals2::connection | register_reader (const ReaderSlotType &slot) |
| sends our Rx data to the user-defined routine of the prototype: void function(const std::string &). | |
There are a few shortcomings in this implementation. most obvious is in the lack of support for (re)defining byte-width, number of stop-bits, parity, or flowcontrol. While it'd be nice (read as: proper) to support these configurables, they really weren't needed for what we are doing (we default to 8N1). I'll add it in eventually, just didn't need it at the moment.
I used boost slots & signals to implement a pluggable read implementation. You define a routine for dealing with the data once it has been received [of the proto: void func( const std::string &)]. You then register that routine and read data will be delivered to it. I make no assumptions regarding the use of the data, it is simply passed on as it is collected.
| cornelluniversity::vetserial::asynch_serial::asynch_serial | ( | boost::asio::io_service & | io_service, | |
| unsigned int | baud = 9600, |
|||
| const std::string & | device = DFLT_DEVICE | |||
| ) |
constructor : The object must be initialized with an ASIO io_service. Upon successful initialization, an asynch read is started that blocks forever.
| io_service | - refrence to boost::asio::io_service | |
| baud | - unsigned int value of the baud rate to use [optional] (defaults to 9600) | |
| device | - std::string value of the device point to connect to [optional] (defaults to a reasonable OS-dependant value) |
| cornelluniversity::vetsim_serial | if the boost::asio::serial_port fails is_open() |
| virtual cornelluniversity::vetserial::asynch_serial::~asynch_serial | ( | void | ) | [inline, virtual] |
destructor
| void cornelluniversity::vetserial::asynch_serial::active | ( | const bool | on_off | ) | [inline] |
active flag toggle for environments where a degree of manual control are required.
| bool cornelluniversity::vetserial::asynch_serial::active | ( | ) | const [inline] |
return true if the socket is still active
| void cornelluniversity::vetserial::asynch_serial::close | ( | void | ) | [inline] |
call the do_close function via the io service in the other thread.
| void cornelluniversity::vetserial::asynch_serial::open | ( | unsigned int | baud = 9600, |
|
| const std::string & | device = DFLT_DEVICE | |||
| ) |
Use to open an uninitialized or closed connection. Any open connections are closed before open() commences. Upon successful initialization, an asynch read is started that blocks forever.
| baud | - unsigned int value of the baud rate to use [optional] (defaults to 9600) | |
| device | - std::string value of the device point to connect to [optional] (defaults to a reasonable OS-dependant value) |
| cornelluniversity::vetsim_serial | if the boost::asio::serial_port fails is_open() |
| boost::signals2::connection cornelluniversity::vetserial::asynch_serial::register_reader | ( | const ReaderSlotType & | slot | ) | [inline] |
sends our Rx data to the user-defined routine of the prototype: void function(const std::string &).
| slot | - ReaderSlotType (boost slot definition) of the routine you wish to have handel received data. returns boost::signals2::connection - handle to the signal/slot connection |
| void cornelluniversity::vetserial::asynch_serial::write | ( | const char | msg | ) | [inline] |
pass the write data to the do_write function via the io service in the other thread.
| msg | - character to be queued for transmission. |
1.4.7