cornelluniversity::vetserial::asynch_serial Class Reference

An asynchronous serial object based on the boost::asio library utilizing asynch reads. More...

#include <asserial.h>

List of all members.

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.
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.
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 &).


Detailed Description

An asynchronous serial object based on the boost::asio library utilizing asynch reads.

This implementation is specifically intended for multi-threaded environments.

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 assumptions regarding the use of the data, it is simply passed on as it is collected.

Definition at line 91 of file asserial.h.


Constructor & Destructor Documentation

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.

Parameters:
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)
Exceptions:
cornelluniversity::vetsim_serial if the boost::asio::serial_port fails is_open()


Member Function Documentation

bool cornelluniversity::vetserial::asynch_serial::active (  )  const [inline]

return true if the socket is still active

Returns:
bool - true is the current connection is still active

Definition at line 131 of file asserial.h.

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.

Parameters:
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)
Exceptions:
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 &).

Parameters:
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

Definition at line 150 of file asserial.h.

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.

Parameters:
msg - character to be queued for transmission.

Definition at line 143 of file asserial.h.


The documentation for this class was generated from the following file:
Generated on Thu Sep 27 11:11:48 2012 for VetSim by  doxygen 1.4.7