Asyncronous serial class Asyncronous serial class. Intended to be a base class.
More...
#include <AsyncSerial.h>
|
| 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 () |
|
|
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) |
|
Asyncronous serial class Asyncronous serial class. Intended to be a base class.
Definition at line 108 of file AsyncSerial.h.
AsyncSerial::AsyncSerial |
( |
| ) |
|
|
inline |
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 ) |
|
) |
| |
|
inline |
Constructor. Creates and opens a serial device.
- Parameters
-
devname | serial device name, example "/dev/ttyS0" or "COM1" |
baud_rate | serial baud rate |
opt_parity | serial parity, default none |
opt_csize | serial character size, default 8bit |
opt_flow | serial flow control, default none |
opt_stop | serial stop bits, default 1 |
- Exceptions
-
boost::system::system_error | if cannot open the serial device |
Definition at line 128 of file AsyncSerial.h.
virtual AsyncSerial::~AsyncSerial |
( |
| ) |
|
|
inlinevirtual |
void AsyncSerial::clearReadCallback |
( |
| ) |
|
|
inlineprotected |
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 437 of file AsyncSerial.h.
void AsyncSerial::close |
( |
| ) |
|
|
inline |
Close the serial device
- Exceptions
-
boost::system::system_error | if any error |
Definition at line 211 of file AsyncSerial.h.
void AsyncSerial::doClose |
( |
| ) |
|
|
inlineprivate |
void AsyncSerial::doRead |
( |
| ) |
|
|
inlineprivate |
Callback called to start an Asynchronous read operation. This callback is called by the io_service in the spawned thread.
Definition at line 296 of file AsyncSerial.h.
void AsyncSerial::doWrite |
( |
| ) |
|
|
inlineprivate |
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 343 of file AsyncSerial.h.
bool AsyncSerial::errorStatus |
( |
| ) |
const |
|
inline |
bool AsyncSerial::isOpen |
( |
| ) |
const |
|
inline |
- Returns
- true if serial device is open
Definition at line 193 of file AsyncSerial.h.
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 ) |
|
) |
| |
|
inline |
Opens a serial device.
- Parameters
-
devname | serial device name, example "/dev/ttyS0" or "COM1" |
baud_rate | serial baud rate |
opt_parity | serial parity, default none |
opt_csize | serial character size, default 8bit |
opt_flow | serial flow control, default none |
opt_stop | serial stop bits, default 1 |
- Exceptions
-
boost::system::system_error | if cannot open the serial device |
Definition at line 158 of file AsyncSerial.h.
void AsyncSerial::readEnd |
( |
const boost::system::error_code & |
error, |
|
|
size_t |
bytes_transferred |
|
) |
| |
|
inlineprivate |
Callback called at the end of the Asynchronous operation. This callback is called by the io_service in the spawned thread.
Definition at line 309 of file AsyncSerial.h.
void AsyncSerial::setErrorStatus |
( |
bool |
e | ) |
|
|
inlineprotected |
To allow derived classes to report errors
- Parameters
-
Definition at line 417 of file AsyncSerial.h.
void AsyncSerial::setReadCallback |
( |
const boost::function< void(const char *, size_t) > & |
callback | ) |
|
|
inlineprotected |
To allow derived classes to set a read callback
Definition at line 426 of file AsyncSerial.h.
void AsyncSerial::write |
( |
const char * |
data, |
|
|
size_t |
size |
|
) |
| |
|
inline |
Write data asynchronously. Returns immediately.
- Parameters
-
data | array of char to be sent through the serial device |
size | array size |
Definition at line 231 of file AsyncSerial.h.
void AsyncSerial::write |
( |
const std::vector< char > & |
data | ) |
|
|
inline |
Write data asynchronously. Returns immediately.
- Parameters
-
data | to be sent through the serial device |
Definition at line 245 of file AsyncSerial.h.
void AsyncSerial::writeEnd |
( |
const boost::system::error_code & |
error | ) |
|
|
inlineprivate |
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 367 of file AsyncSerial.h.
void AsyncSerial::writeString |
( |
const std::string & |
s | ) |
|
|
inline |
Write a string asynchronously. Returns immediately. Can be used to send ASCII data to the serial device. To send binary data, use write()
- Parameters
-
Definition at line 261 of file AsyncSerial.h.
const int AsyncSerial::readBufferSize = 512 |
|
static |
The documentation for this class was generated from the following file: