Base Framework
|
Serial port. More...
#include <base/communication/SerialPort.h>
Inherits CommunicationsPort, and AsynchronousInputStream.
Classes | |
class | Parity |
class | StopBits |
Public Types | |
enum | Event { BREAK, CD, CTS, DSR, ERROR, RING, RLSD, INPUT_AVAILABLE, OUTPUT_EMPTY } |
Public Member Functions | |
SerialPort (const String &name) | |
String | getName () const noexcept |
unsigned int | getBaudRate () const |
unsigned int | getDataBits () const |
unsigned int | getFlowControlMode () const |
unsigned int | getParity () const |
unsigned int | getStopBits () const |
void | setParameters (unsigned int baudRate, unsigned int dataBits, unsigned int parity, unsigned int stopBits) |
void | setFlowControlMode (unsigned int flowMode) |
bool | isCD () const |
bool | isCTS () const |
bool | isDSR () const |
bool | isDTR () const |
bool | isRI () const |
bool | isRTS () const |
void | close () |
void | sendBreak (unsigned int milliseconds) |
void | setDTR (bool state) |
void | setRTS (bool state) |
bool | isReadTimeoutSupported () const |
bool | isWriteTimeoutSupported () const |
unsigned int | getReadTimeout () const |
unsigned int | getWriteTimeout () const |
void | setReadTimeout (unsigned int milliseconds) |
void | setWriteTimeout (unsigned int milliseconds) |
void | setInputBufferSize (unsigned int size) |
unsigned int | getInputBufferSize () const |
void | setOutputBufferSize (unsigned int size) |
unsigned int | getOutputBufferSize () const |
unsigned int | read (uint8 *buffer, unsigned int bytesToRead, bool nonblocking) |
unsigned int | write (const uint8 *buffer, unsigned int bytesToWrite, bool nonblocking) |
void | asyncCancel () |
AsynchronousReadOperation | read (uint8 *buffer, unsigned int bytesToRead, AsynchronousReadEventListener *listener) |
AsynchronousWriteOperation | write (const uint8 *buffer, unsigned int bytesToWrite, AsynchronousWriteEventListener *listener) |
virtual | ~SerialPort () |
![]() | |
virtual | ~AsynchronousStream () noexcept(false) |
Static Public Member Functions | |
static List< String > | getPorts () noexcept |
![]() | |
static bool | asyncTest () noexcept |
Serial port.
An RS-232 serial communications port. SerialPort describes the low-level interface to a serial communications port made available by the underlying system. SerialPort defines the minimum required functionality for serial communications ports.
enum SerialPort::Event |
Enumerator | |
---|---|
BREAK | Break event. |
CD | Carrier Detect (CD) event. |
CTS | Clear To Send (CTS) event. |
DSR | Data Set Ready (DSR) event. |
ERROR | Error event. |
RING | Ring Indicator (RI) event. |
RLSD | Received Line Signal Detector (RLSD) event. |
INPUT_AVAILABLE | Input data is available event. |
OUTPUT_EMPTY | Output buffer is empty event. |
SerialPort::SerialPort | ( | const String & | name | ) |
Initializes the serial communication port.
name | The name of the serial port (e.g. "com1" under Windows). |
|
virtual |
Destroys the serial port object.
void SerialPort::close | ( | ) |
Closes the communications port.
unsigned int SerialPort::getBaudRate | ( | ) | const |
Registers a SerialPortEventListener object to listen for SerialEvents. Returns the currently configured baud rate.
unsigned int SerialPort::getDataBits | ( | ) | const |
Returns the currently configured number of data bits.
unsigned int SerialPort::getFlowControlMode | ( | ) | const |
Returns the currently configured flow control mode.
unsigned int SerialPort::getInputBufferSize | ( | ) | const |
Returns the input buffer size.
|
noexcept |
Returns the name of the communications port.
unsigned int SerialPort::getOutputBufferSize | ( | ) | const |
Returns the output buffer size.
unsigned int SerialPort::getParity | ( | ) | const |
Returns the currently configured parity setting.
unsigned int SerialPort::getReadTimeout | ( | ) | const |
Returns the maximum read timeout period.
unsigned int SerialPort::getStopBits | ( | ) | const |
Returns the currently configured stop bits.
unsigned int SerialPort::getWriteTimeout | ( | ) | const |
Returns the maximum write timeout period.
bool SerialPort::isCD | ( | ) | const |
Returns the state of the CD (Carrier Detect) bit in the UART, if supported by the underlying implementation.
bool SerialPort::isCTS | ( | ) | const |
Returns the state of the CTS (Clear To Send) bit in the UART, if supported by the underlying implementation.
bool SerialPort::isDSR | ( | ) | const |
Returns the state of the DSR (Data Set Ready) bit in the UART, if supported by the underlying implementation.
bool SerialPort::isDTR | ( | ) | const |
Returns the state of the DTR (Data Terminal Ready) bit in the UART, if supported by the underlying implementation.
bool SerialPort::isReadTimeoutSupported | ( | ) | const |
Returns true if read timeout is supported.
bool SerialPort::isRI | ( | ) | const |
Returns the state of the RI (Ring Indicator) bit in the UART, if supported by the underlying implementation.
bool SerialPort::isRTS | ( | ) | const |
Returns the state of the RTS (Request To Send) bit in the UART, if supported by the underlying implementation.
bool SerialPort::isWriteTimeoutSupported | ( | ) | const |
Returns true if write timeout is supported.
|
virtual |
Requests and asynchronous read operation.
buffer | The bytes to be read. |
bytesToRead | The number of bytes to be read. |
listener | The listener to be notified on completion. |
Implements AsynchronousInputStream.
void SerialPort::sendBreak | ( | unsigned int | milliseconds | ) |
Sends a break of the specified duration.
milliseconds | The duration of the break in milliseconds. |
void SerialPort::setDTR | ( | bool | state | ) |
Sets or clears the Data Terminal Ready (DTR) signal.
void SerialPort::setFlowControlMode | ( | unsigned int | flowMode | ) |
Sets the flow control mode.
void SerialPort::setInputBufferSize | ( | unsigned int | size | ) |
Sets the input buffer size.
void SerialPort::setOutputBufferSize | ( | unsigned int | size | ) |
Sets the output buffer size.
void SerialPort::setParameters | ( | unsigned int | baudRate, |
unsigned int | dataBits, | ||
unsigned int | parity, | ||
unsigned int | stopBits | ||
) |
Sets the serial port parameters.
void SerialPort::setReadTimeout | ( | unsigned int | milliseconds | ) |
Sets the maximum read timeout period.
void SerialPort::setRTS | ( | bool | state | ) |
Sets or clears the Request To Send (RTS) signal.
void SerialPort::setWriteTimeout | ( | unsigned int | milliseconds | ) |
Sets the maximum write timeout period.