Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
BufferedAsyncSerial Class Reference

Asynchronous serial class w/ buffer Asynchronous serial class that sends data to buffer after reading it from the port. More...

#include <BufferedAsyncSerial.h>

Inheritance diagram for BufferedAsyncSerial:
Inheritance graph
[legend]

Public Member Functions

 BufferedAsyncSerial ()
 
 BufferedAsyncSerial (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))
 
size_t read (char *data, size_t size)
 
std::vector< char > read ()
 
std::string readString ()
 
std::string readStringUntil (const std::string delim="\n")
 
virtual ~BufferedAsyncSerial ()
 
- Public Member Functions inherited from AsyncSerial
 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 ()
 

Private Member Functions

void readCallback (const char *data, size_t len)
 

Static Private Member Functions

static std::vector< char >
::iterator 
findStringInVector (std::vector< char > &v, const std::string &s)
 

Private Attributes

std::vector< char > readQueue
 
boost::mutex readQueueMutex
 

Additional Inherited Members

- Static Public Attributes inherited from AsyncSerial
static const int readBufferSize = 512
 
- Protected Member Functions inherited from AsyncSerial
void clearReadCallback ()
 
void setErrorStatus (bool e)
 
void setReadCallback (const boost::function< void(const char *, size_t) > &callback)
 

Detailed Description

Asynchronous serial class w/ buffer Asynchronous serial class that sends data to buffer after reading it from the port.

Definition at line 53 of file BufferedAsyncSerial.h.

Constructor & Destructor Documentation

BufferedAsyncSerial::BufferedAsyncSerial ( )
inline

Definition at line 56 of file BufferedAsyncSerial.h.

BufferedAsyncSerial::BufferedAsyncSerial ( 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
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 73 of file BufferedAsyncSerial.h.

virtual BufferedAsyncSerial::~BufferedAsyncSerial ( )
inlinevirtual

Definition at line 161 of file BufferedAsyncSerial.h.

Member Function Documentation

static std::vector< char >::iterator BufferedAsyncSerial::findStringInVector ( std::vector< char > &  v,
const std::string &  s 
)
inlinestaticprivate

Finds a substring in a vector of char. Used to look for the delimiter.

Parameters
vvector where to find the string
sstring to find
Returns
the beginning of the place in the vector where the first occurrence of the string is, or v.end() if the string was not found

Definition at line 183 of file BufferedAsyncSerial.h.

size_t BufferedAsyncSerial::read ( char *  data,
size_t  size 
)
inline

Read some data asynchronously. Returns immediately.

Parameters
dataarray of char to be read through the serial device
sizearray size
Returns
numbr of character actually read 0<=return<=size

Definition at line 96 of file BufferedAsyncSerial.h.

std::vector< char > BufferedAsyncSerial::read ( )
inline

Read all available data asynchronously. Returns immediately.

Returns
the receive buffer. It iempty if no data is available

Definition at line 112 of file BufferedAsyncSerial.h.

void BufferedAsyncSerial::readCallback ( const char *  data,
size_t  len 
)
inlineprivate

Read callback, stores data in the buffer

Definition at line 171 of file BufferedAsyncSerial.h.

std::string BufferedAsyncSerial::readString ( )
inline

Read a string asynchronously. Returns immediately. Can only be used if the user is sure that the serial device will not send binary data. For binary data read, use read() The returned string is empty if no data has arrived

Returns
a string with the received data.

Definition at line 128 of file BufferedAsyncSerial.h.

std::string BufferedAsyncSerial::readStringUntil ( const std::string  delim = "\n")
inline

Read a line asynchronously. Returns immediately. Can only be used if the user is sure that the serial device will not send binary data. For binary data read, use read() The returned string is empty if the line delimiter has not yet arrived.

Parameters
delimiterline delimiter, default='
'
Returns
a string with the received data. The delimiter is removed from the string.

Definition at line 146 of file BufferedAsyncSerial.h.

Member Data Documentation

std::vector< char > BufferedAsyncSerial::readQueue
private

Definition at line 215 of file BufferedAsyncSerial.h.

boost::mutex BufferedAsyncSerial::readQueueMutex
private

Definition at line 216 of file BufferedAsyncSerial.h.


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


serialcom
Author(s): Ricardo Pascoal
autogenerated on Mon Mar 2 2015 01:32:52