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]

List of all members.

Public Member Functions

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

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

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 (  ) 

Definition at line 59 of file BufferedAsyncSerial.cpp.

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

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
BufferedAsyncSerial::~BufferedAsyncSerial (  )  [virtual]

Definition at line 163 of file BufferedAsyncSerial.cpp.


Member Function Documentation

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

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

Parameters:
v vector where to find the string
s string 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 132 of file BufferedAsyncSerial.cpp.

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

Read all available data asynchronously. Returns immediately.

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

Definition at line 91 of file BufferedAsyncSerial.cpp.

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

Read some data asynchronously. Returns immediately.

Parameters:
data array of char to be read through the serial device
size array size
Returns:
numbr of character actually read 0<=return<=size

Definition at line 76 of file BufferedAsyncSerial.cpp.

void BufferedAsyncSerial::readCallback ( const char *  data,
size_t  len 
) [private]

Read callback, stores data in the buffer

Definition at line 125 of file BufferedAsyncSerial.cpp.

std::string BufferedAsyncSerial::readString (  ) 

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 100 of file BufferedAsyncSerial.cpp.

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

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:
delimiter line delimiter, default='
'
Returns:
a string with the received data. The delimiter is removed from the string.

Definition at line 109 of file BufferedAsyncSerial.cpp.


Member Data Documentation

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

Definition at line 137 of file BufferedAsyncSerial.h.

boost::mutex BufferedAsyncSerial::readQueueMutex [private]

Definition at line 138 of file BufferedAsyncSerial.h.


The documentation for this class was generated from the following files:
 All Classes Files Functions Variables


pressure_cells
Author(s): Emilio Estrelinha
autogenerated on Wed Jul 23 04:34:41 2014