Serial Scol plugin
Public Member Functions | List of all members
BufferedAsyncSerial Class Reference
Inheritance diagram for BufferedAsyncSerial:
AsyncSerial

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

Additional Inherited Members

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

Detailed Description

Definition at line 14 of file BufferedAsyncSerial.h.

Constructor & Destructor Documentation

◆ BufferedAsyncSerial() [1/2]

BufferedAsyncSerial::BufferedAsyncSerial ( )

Definition at line 24 of file BufferedAsyncSerial.cpp.

◆ BufferedAsyncSerial() [2/2]

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

◆ ~BufferedAsyncSerial()

BufferedAsyncSerial::~BufferedAsyncSerial ( )

Definition at line 113 of file BufferedAsyncSerial.cpp.

Member Function Documentation

◆ read() [1/2]

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

◆ read() [2/2]

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

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

◆ readString()

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

◆ readStringUntil()

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

Definition at line 66 of file BufferedAsyncSerial.cpp.


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