Public Member Functions | Static Public Attributes | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
AsyncSerial Class Referenceabstract

Asyncronous serial class Asyncronous serial class. Intended to be a base class. More...

#include <AsyncSerial.h>

Inheritance diagram for AsyncSerial:
Inheritance graph
[legend]

Public Member Functions

 AsyncSerial ()
 
 AsyncSerial (const std::string &devname, unsigned int baud_rate, boost::asio::serial_port_base::parity opt_parity=boost::asio::serial_port_base::parity(boost::asio::serial_port_base::parity::none), boost::asio::serial_port_base::character_size opt_csize=boost::asio::serial_port_base::character_size(8), boost::asio::serial_port_base::flow_control opt_flow=boost::asio::serial_port_base::flow_control(boost::asio::serial_port_base::flow_control::none), boost::asio::serial_port_base::stop_bits opt_stop=boost::asio::serial_port_base::stop_bits(boost::asio::serial_port_base::stop_bits::one))
 
void close ()
 
bool errorStatus () const
 
bool isOpen () const
 
void open (const std::string &devname, unsigned int baud_rate, boost::asio::serial_port_base::parity opt_parity=boost::asio::serial_port_base::parity(boost::asio::serial_port_base::parity::none), boost::asio::serial_port_base::character_size opt_csize=boost::asio::serial_port_base::character_size(8), boost::asio::serial_port_base::flow_control opt_flow=boost::asio::serial_port_base::flow_control(boost::asio::serial_port_base::flow_control::none), boost::asio::serial_port_base::stop_bits opt_stop=boost::asio::serial_port_base::stop_bits(boost::asio::serial_port_base::stop_bits::one))
 
void write (const char *data, size_t size)
 
void write (const std::vector< char > &data)
 
void writeString (const std::string &s)
 
virtual ~AsyncSerial ()=0
 

Static Public Attributes

static const int readBufferSize = 512
 

Protected Member Functions

void clearReadCallback ()
 
void setErrorStatus (bool e)
 
void setReadCallback (const boost::function< void(const char *, size_t) > &callback)
 

Private Member Functions

void doClose ()
 
void doRead ()
 
void doWrite ()
 
void readEnd (const boost::system::error_code &error, size_t bytes_transferred)
 
void writeEnd (const boost::system::error_code &error)
 

Private Attributes

boost::shared_ptr
< AsyncSerialImpl
pimpl
 

Detailed Description

Asyncronous serial class Asyncronous serial class. Intended to be a base class.

Definition at line 66 of file AsyncSerial.h.

Constructor & Destructor Documentation

AsyncSerial::AsyncSerial ( )

Definition at line 139 of file AsyncSerial.cpp.

AsyncSerial::AsyncSerial ( const std::string &  devname,
unsigned int  baud_rate,
boost::asio::serial_port_base::parity  opt_parity = boost::asio::serial_port_base::parity(boost::asio::serial_port_base::parity::none),
boost::asio::serial_port_base::character_size  opt_csize = boost::asio::serial_port_base::character_size(8),
boost::asio::serial_port_base::flow_control  opt_flow = boost::asio::serial_port_base::flow_control(boost::asio::serial_port_base::flow_control::none),
boost::asio::serial_port_base::stop_bits  opt_stop = boost::asio::serial_port_base::stop_bits(boost::asio::serial_port_base::stop_bits::one) 
)

Constructor. Creates and opens a serial device.

Parameters
devnameserial device name, example "/dev/ttyS0" or "COM1"
baud_rateserial baud rate
opt_parityserial parity, default none
opt_csizeserial character size, default 8bit
opt_flowserial flow control, default none
opt_stopserial stop bits, default 1
Exceptions
boost::system::system_errorif cannot open the serial device
AsyncSerial::~AsyncSerial ( )
pure virtual

Definition at line 250 of file AsyncSerial.cpp.

Member Function Documentation

void AsyncSerial::clearReadCallback ( )
protected

To unregister the read callback in the derived class destructor so it does not get called after the derived class destructor but before the base class destructor

Definition at line 381 of file AsyncSerial.cpp.

void AsyncSerial::close ( )

Close the serial device

Exceptions
boost::system::system_errorif any error

Definition at line 203 of file AsyncSerial.cpp.

void AsyncSerial::doClose ( )
private

Callback to close serial port

Definition at line 355 of file AsyncSerial.cpp.

void AsyncSerial::doRead ( )
private

Callback called to start an Asynchronous read operation. This callback is called by the io_service in the spawned thread.

Definition at line 266 of file AsyncSerial.cpp.

void AsyncSerial::doWrite ( )
private

Callback called to start an Asynchronous write operation. If it is already in progress, does nothing. This callback is called by the io_service in the spawned thread.

Definition at line 306 of file AsyncSerial.cpp.

bool AsyncSerial::errorStatus ( ) const
Returns
true if error were found

Definition at line 196 of file AsyncSerial.cpp.

bool AsyncSerial::isOpen ( ) const
Returns
true if serial device is open

Definition at line 191 of file AsyncSerial.cpp.

void AsyncSerial::open ( const std::string &  devname,
unsigned int  baud_rate,
boost::asio::serial_port_base::parity  opt_parity = boost::asio::serial_port_base::parity ( boost::asio::serial_port_base::                                                     parity::none ),
boost::asio::serial_port_base::character_size  opt_csize = boost::asio::serial_port_base::character_size ( 8 ),
boost::asio::serial_port_base::flow_control  opt_flow = boost::asio::serial_port_base::flow_control ( boost::asio::                                                           serial_port_base::flow_control::                                                           none ),
boost::asio::serial_port_base::stop_bits  opt_stop = boost::asio::serial_port_base::stop_bits ( boost::asio::                                                        serial_port_base::stop_bits::                                                        one ) 
)

Opens a serial device.

Parameters
devnameserial device name, example "/dev/ttyS0" or "COM1"
baud_rateserial baud rate
opt_parityserial parity, default none
opt_csizeserial character size, default 8bit
opt_flowserial flow control, default none
opt_stopserial stop bits, default 1
Exceptions
boost::system::system_errorif cannot open the serial device

Definition at line 164 of file AsyncSerial.cpp.

void AsyncSerial::readEnd ( const boost::system::error_code &  error,
size_t  bytes_transferred 
)
private

Callback called at the end of the Asynchronous operation. This callback is called by the io_service in the spawned thread.

Definition at line 276 of file AsyncSerial.cpp.

void AsyncSerial::setErrorStatus ( bool  e)
protected

To allow derived classes to report errors

Parameters
eerror status

Definition at line 367 of file AsyncSerial.cpp.

void AsyncSerial::setReadCallback ( const boost::function< void(const char *, size_t) > &  callback)
protected

To allow derived classes to set a read callback

Definition at line 374 of file AsyncSerial.cpp.

void AsyncSerial::write ( const char *  data,
size_t  size 
)

Write data asynchronously. Returns immediately.

Parameters
dataarray of char to be sent through the serial device
sizearray size

Definition at line 220 of file AsyncSerial.cpp.

void AsyncSerial::write ( const std::vector< char > &  data)

Write data asynchronously. Returns immediately.

Parameters
datato be sent through the serial device

Definition at line 230 of file AsyncSerial.cpp.

void AsyncSerial::writeEnd ( const boost::system::error_code &  error)
private

Callback called at the end of an asynchronuous write operation, if there is more data to write, restarts a new write operation. This callback is called by the io_service in the spawned thread.

Definition at line 326 of file AsyncSerial.cpp.

void AsyncSerial::writeString ( const std::string &  s)

Write a string asynchronously. Returns immediately. Can be used to send ASCII data to the serial device. To send binary data, use write()

Parameters
sstring to send

Definition at line 241 of file AsyncSerial.cpp.

Member Data Documentation

boost::shared_ptr< AsyncSerialImpl > AsyncSerial::pimpl
private

Definition at line 217 of file AsyncSerial.h.

const int AsyncSerial::readBufferSize = 512
static

Read buffer maximum size

Definition at line 176 of file AsyncSerial.h.


The documentation for this class was generated from the following files:


pressure_cells
Author(s): Emilio Estrelinha
autogenerated on Mon Mar 2 2015 01:32:47