Async 1.8.0
|
A class for using asyncronous serial communications. More...
#include <AsyncSerial.h>
Public Types | |
enum | Parity { PARITY_NONE , PARITY_EVEN , PARITY_ODD } |
A type that defines the possible choices for parity. More... | |
enum | Flow { FLOW_NONE , FLOW_HW , FLOW_XONOFF } |
A type that defines the possible choices for flow control. More... | |
enum | Pin { PIN_NONE , PIN_RTS , PIN_DTR , PIN_CTS , PIN_DSR , PIN_DCD , PIN_RI } |
A type that defines the read/write pins in the serial port. More... | |
Public Member Functions | |
Serial (const std::string &serial_port) | |
Constuctor. | |
~Serial (void) | |
Destructor. | |
bool | setParams (int speed, Parity parity, int bits, int stop_bits, Flow flow) |
Setup the serial port communications parameters. | |
bool | open (bool flush=false) |
Open the serial port. | |
bool | close (void) |
Close a previously opened serial port. | |
int | write (const char *buf, size_t count) |
Write data to the serial port. | |
bool | setCanonical (bool canonical) |
Set or clear canonical mode. | |
bool | stopInput (bool stop) |
Stop/start input of data. | |
bool | setPin (Pin pin, bool set) |
Set the state of one of the output pins in the serial port. | |
bool | getPin (Pin pin, bool &is_set) |
Get the state of one of the input pins in the serial port. | |
Public Attributes | |
sigc::signal< void, char *, int > | charactersReceived |
A signal that is emitted when there is data to read. | |
Static Public Attributes | |
static const int | READ_BUFSIZE = 1024 |
The maximum number of characters that can be read at once. | |
A class for using asyncronous serial communications.
This class is used to communicate over an asynchronous serial link (e.g. RS-232 port). An example of how to use it is shown below.
Definition at line 129 of file AsyncSerial.h.
enum Async::Serial::Flow |
A type that defines the possible choices for flow control.
Enumerator | |
---|---|
FLOW_NONE | No flow control in use. |
FLOW_HW | Use hardware flow control. |
FLOW_XONOFF | Use software (XON/XOFF) flow control. |
Definition at line 145 of file AsyncSerial.h.
A type that defines the possible choices for parity.
Enumerator | |
---|---|
PARITY_NONE | Parity not used. |
PARITY_EVEN | Use even parity. |
PARITY_ODD | Use odd parity. |
Definition at line 135 of file AsyncSerial.h.
enum Async::Serial::Pin |
A type that defines the read/write pins in the serial port.
Definition at line 155 of file AsyncSerial.h.
|
explicit |
Constuctor.
serial_port | The device name of the serial port to use |
This is the constructor for the serial port class. It is possible to create multiple instances connected to the same serial port. For this to work, the given device name string must be exactly the same in all instances.
Async::Serial::~Serial | ( | void | ) |
Destructor.
bool Async::Serial::close | ( | void | ) |
Close a previously opened serial port.
Use this method to close a previously opened serial port. If the port is already closed, true is returned and nothing is done. If the port has been opened by multiple instances, it will not be closed until the last instance has closed it.
bool Async::Serial::getPin | ( | Pin | pin, |
bool & | is_set ) |
Get the state of one of the input pins in the serial port.
pin | The pin to get the state of. See Serial::Pin. |
is_set | The result will be returned in this variable. |
Use this function to read the state of one of the input pins in the serial port. For a list of available pins see Serial::Pin.
bool Async::Serial::open | ( | bool | flush = false | ) |
Open the serial port.
flush | Flush (discard) pending RX/TX data on open |
Call this method to open the serial port. No special setup of the port is done during the open call. The old setup is saved and restored when the port is closed. To setup the port operating parameters, use the setParams method after calling open. If the open method is called when the port is already opened, it just returns true without doing anything.
bool Async::Serial::setCanonical | ( | bool | canonical | ) |
Set or clear canonical mode.
Call this method to configure the serial port for canonical mode. In this mode, a couple of control characters are parsed by the kernel driver and interpreted in special ways. Most notably, only whole lines of text are sent up to the application. Don't use canonical mode when the serial stream is not readable text that is split into lines with a line feed character.
This function may be called both before or after the port has been opened and the setting is remembered after a close.
Setup the serial port communications parameters.
speed | The serial speed to use |
parity | The parity to use (see Serial::Parity) |
bits | The number of bits in each serial word |
stop_bits | The number of stop bits to use |
flow | The type of flow control to use (see Serial::Flow) |
This function is used to setup the serial communications parameters for the serial port. This must be done after calling the open function.
bool Async::Serial::setPin | ( | Pin | pin, |
bool | set ) |
Set the state of one of the output pins in the serial port.
pin | The pin to set. See Serial::Pin. |
set | If true the pin is set, if false the pin is cleared |
Use this function to control one of the output pins in the serial port. For a list of available pins see Serial::Pin.
bool Async::Serial::stopInput | ( | bool | stop | ) |
Stop/start input of data.
stop | Stop input if true or start input if false |
Use this function to start/stop input of data when the flow control has been enabled.
|
inline |
Write data to the serial port.
buf | A buffer containing the data to write |
count | The number of bytes to write |
Definition at line 244 of file AsyncSerial.h.
sigc::signal<void, char*, int> Async::Serial::charactersReceived |
A signal that is emitted when there is data to read.
buf | A buffer containing the data that has been read |
count | The number of bytes that was read |
This signal is emitted whenever one or more characters has been received on the serial port. The buffer is always null-terminated but the null is not included in the count.
Definition at line 315 of file AsyncSerial.h.
|
static |
The maximum number of characters that can be read at once.
Definition at line 169 of file AsyncSerial.h.