#include <asserial.h>
Public Member Functions | |
asynch_serial (boost::asio::io_service &ios) | |
constructor : The object MUST be initialized with an ASIO io_service. This instance creates a serial port but does not connect it. If you use this constructor, you must call open() and follow up with setopt() calls as nothing will be set for you. Finally, you'll need to manually start the reading process with start_reading(). | |
asynch_serial (boost::asio::io_service &io_service, unsigned int baud, const std::string &device) | |
constructor : The object must be initialized with an ASIO io_service. Upon successful initialization, a connection is opened and an asynch read is started that blocks forever. | |
boost::asio::io_service & | ioservice () |
accessor to the current serial port's I/O Service | |
virtual | ~asynch_serial (void) |
destructor | |
void | open (const std::string &device) |
Use to open an uninitialized or closed connection. Any open connections are closed before open() commences. This instance only opens the port, it does not set any of the ports vitals, you must call setopt() and start a reading thread manualll. | |
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 &). | |
template<typename SettableSerialPortOption> | |
void | setopt (const SettableSerialPortOption &opt) |
A wrapper of the boost::asio::serial_port set_option() call. | |
void | start_reading (void) |
A wrapper of the internal read_start() call. This is necessary for manual start-up operations (if you dont send all options to the constructor). If the port is not open or if there is a read thread already in operation, than this routine does nothing. |
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 & | ios | ) | [inline] |
constructor : The object MUST be initialized with an ASIO io_service. This instance creates a serial port but does not connect it. If you use this constructor, you must call open() and follow up with setopt() calls as nothing will be set for you. Finally, you'll need to manually start the reading process with start_reading().
io_service | - refrence to boost::asio::io_service |
void setopt(const SettableSerialPortOption & opt)
void start_reading(void)
cornelluniversity::vetserial::asynch_serial::asynch_serial | ( | boost::asio::io_service & | io_service, | |
unsigned int | baud, | |||
const std::string & | device | |||
) |
constructor : The object must be initialized with an ASIO io_service. Upon successful initialization, a connection is opened and 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.
boost::asio::io_service& cornelluniversity::vetserial::asynch_serial::ioservice | ( | ) | [inline] |
accessor to the current serial port's I/O Service
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() |
void cornelluniversity::vetserial::asynch_serial::open | ( | const std::string & | device | ) |
Use to open an uninitialized or closed connection. Any open connections are closed before open() commences. This instance only opens the port, it does not set any of the ports vitals, you must call setopt() and start a reading thread manualll.
device | - std::string value of the device point to connect to. |
cornelluniversity::vetsim_serial | if the boost::asio::serial_port fails is_open() |
void start_reading(void)
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::setopt | ( | const SettableSerialPortOption & | opt | ) | [inline] |
A wrapper of the boost::asio::serial_port set_option() call.
opt | - refrence to a boost::asio SettableSerialPortOption object |
boost::system::system_error | in the event that the option cannot be set for any reason. |
void cornelluniversity::vetserial::asynch_serial::start_reading | ( | void | ) | [inline] |
A wrapper of the internal read_start() call. This is necessary for manual start-up operations (if you dont send all options to the constructor). If the port is not open or if there is a read thread already in operation, than this routine does nothing.
opt | - refrence to a boost::asio SettableSerialPortOption object |
boost::system::system_error | in the event that the option cannot be set for any reason. |
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. |