Project

General

Profile

Serial Scol plugin

#include <AsyncSerial.h>

Inheritance diagram for AsyncSerial:
BufferedAsyncSerial CallbackAsyncSerial

Public Member Functions

 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 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))
 
bool isOpen () const
 
bool errorStatus () const
 
void close ()
 
void write (const char *data, size_t size)
 
void write (const std::vector< char > &data)
 
void writeString (const std::string &s)
 

Static Public Attributes

static const int readBufferSize = 512
 

Protected Member Functions

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

Detailed Description

Asyncronous serial class. Intended to be a base class.

Definition at line 28 of file AsyncSerial.h.

Constructor & Destructor Documentation

◆ AsyncSerial() [1/2]

AsyncSerial::AsyncSerial ( )

Definition at line 67 of file AsyncSerial.cpp.

◆ AsyncSerial() [2/2]

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

Definition at line 93 of file AsyncSerial.cpp.

◆ ~AsyncSerial()

AsyncSerial::~AsyncSerial ( )
virtual

Definition at line 283 of file AsyncSerial.cpp.

Member Function Documentation

◆ clearReadCallback()

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 395 of file AsyncSerial.cpp.

◆ close()

void AsyncSerial::close ( )

Close the serial device

Exceptions
boost::system::system_errorif any error

Definition at line 227 of file AsyncSerial.cpp.

◆ errorStatus()

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

Definition at line 209 of file AsyncSerial.cpp.

◆ isOpen()

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

Definition at line 204 of file AsyncSerial.cpp.

◆ open()

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 111 of file AsyncSerial.cpp.

◆ retry()

void AsyncSerial::retry ( )
protected

try to reconnect

Definition at line 135 of file AsyncSerial.cpp.

◆ setErrorStatus()

void AsyncSerial::setErrorStatus ( bool  e)
protected

To allow derived classes to report errors

Parameters
eerror status

Definition at line 384 of file AsyncSerial.cpp.

◆ setReadCallback()

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 390 of file AsyncSerial.cpp.

◆ write() [1/2]

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 246 of file AsyncSerial.cpp.

◆ write() [2/2]

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

Write data asynchronously. Returns immediately.

Parameters
datato be sent through the serial device

Definition at line 258 of file AsyncSerial.cpp.

◆ writeString()

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 271 of file AsyncSerial.cpp.

Member Data Documentation

◆ readBufferSize

const int AsyncSerial::readBufferSize = 512
static

Read buffer maximum size

Definition at line 131 of file AsyncSerial.h.


The documentation for this class was generated from the following files:
  • G:/work/subversion/scol-technologies/trunk/scol/plugins/serialio/include/AsyncSerial.h
  • G:/work/subversion/scol-technologies/trunk/scol/plugins/serialio/src/AsyncSerial.cpp