DUNE: Uniform Navigational Environment
2019.02.0
|
The SerialPort class encapsulates serial port access.
Classes | |
class | Error |
Public Types | |
enum | Parity { SP_PARITY_NONE, SP_PARITY_EVEN, SP_PARITY_ODD } |
enum | StopBits { SP_STOPBITS_1, SP_STOPBITS_1_5, SP_STOPBITS_2 } |
enum | DataBits { SP_DATABITS_5, SP_DATABITS_6, SP_DATABITS_7, SP_DATABITS_8 } |
Public Member Functions | |
SerialPort (const std::string &device, int baudrate=38400, Parity parity=SP_PARITY_NONE, StopBits stopbits=SP_STOPBITS_1, DataBits databits=SP_DATABITS_8, bool block=false) | |
~SerialPort (void) | |
void | setMinimumRead (int value) |
void | setBaudRate (int baudrate) |
void | setParity (Parity parity) |
void | setDataBits (DataBits databits) |
void | setStopBits (StopBits sbits) |
void | setCanonicalInput (bool enable) |
void | setCanonicalInputTerminator (char terminator) |
void | setNonBlocking (void) |
void | sendBreak (int duration) |
void | setXONXOFF (bool enabled) |
void | setCTSRTS (bool enabled) |
Public Member Functions inherited from DUNE::IO::Handle | |
virtual | ~Handle (void) |
size_t | write (const uint8_t *data, size_t length) |
size_t | write (const char *data, size_t length) |
size_t | writeString (const char *cstr) |
size_t | read (uint8_t *data, size_t length) |
size_t | read (char *data, size_t length) |
size_t | readString (char *bfr, size_t length) |
void | flush (void) |
void | flushInput (void) |
void | flushOutput (void) |
NativeHandle | getNative (void) const |
Static Public Member Functions | |
static std::vector< std::string > | enumerate (void) |
Additional Inherited Members |
The optional parity bit is a simple sum of the data bits indicating whether or not the data contains an even or odd number of 1 bits.
With even parity, the parity bit is 0 if there is an even number of 1's in the character. With odd parity, the parity bit is 0 if there is an odd number of 1's in the data. No parity means that no parity bit is present or transmitted.
Enumerator | |
---|---|
SP_PARITY_NONE |
No parity. |
SP_PARITY_EVEN |
Even parity. |
SP_PARITY_ODD |
Odd parity. |
There can be 1, 1.5, or 2 stop bits between characters and they always have a value of 1.
Stop bits traditionally were used to give the computer time to process the previous character, but now only serve to synchronize the receiving computer to the incoming characters.
Enumerator | |
---|---|
SP_STOPBITS_1 |
One stop bit. |
SP_STOPBITS_1_5 |
One and half stop bits. |
SP_STOPBITS_2 |
Two stop bits. |
DUNE::Hardware::SerialPort::SerialPort | ( | const std::string & | device, |
int | baudrate = 38400 , |
||
Parity | parity = SP_PARITY_NONE , |
||
StopBits | stopbits = SP_STOPBITS_1 , |
||
DataBits | databits = SP_DATABITS_8 , |
||
bool | block = false |
||
) |
Serial port constructor.
device | serial port device. |
baudrate | I/O baud rate. |
parity | parity checking type. |
stopbits | number of stop bits. |
databits | number of data bits. |
block | false enable non-blocking I/O. |
SerialPortError. |
References DUNE::System::Error::getLastMessage(), setBaudRate(), setCanonicalInput(), setCTSRTS(), setDataBits(), setMinimumRead(), setNonBlocking(), setParity(), setStopBits(), and setXONXOFF().
DUNE::Hardware::SerialPort::~SerialPort | ( | void | ) |
Serial port destructor.
References DUNE::IO::Handle::flush().
|
static |
Enumerate available serial ports.
The names returned are dependent on the operating system.
References DUNE::Utils::String::format(), and DUNE::FileSystem::Path.
void DUNE::Hardware::SerialPort::sendBreak | ( | int | duration | ) |
References DUNE::Time::Delay::wait().
void DUNE::Hardware::SerialPort::setBaudRate | ( | int | baudrate | ) |
Set the baud rate of the serial port.
baudrate | baud rate value. |
References DUNE::System::Error::getLastMessage().
Referenced by SerialPort().
void DUNE::Hardware::SerialPort::setCanonicalInput | ( | bool | enable | ) |
Enable canonical input.
Canonical input is line-oriented. Input characters are put into a buffer which can be edited interactively by the user until a CR (carriage return) or LF (line feed) character is received.
enable | enable / disable canonical input. |
References DUNE::System::Error::getLastMessage().
Referenced by SerialPort().
void DUNE::Hardware::SerialPort::setCanonicalInputTerminator | ( | char | terminator | ) |
References DUNE::System::Error::getLastMessage().
void DUNE::Hardware::SerialPort::setCTSRTS | ( | bool | enabled | ) |
Enable hardware flow control (CTSRTS).
enabled | enable / disable hardware flow control |
References DUNE::System::Error::getLastMessage().
Referenced by SerialPort().
void DUNE::Hardware::SerialPort::setDataBits | ( | DataBits | databits | ) |
Set the number of data bits of the serial port.
databits | number of data bits. |
References DUNE::System::Error::getLastMessage(), SP_DATABITS_5, SP_DATABITS_6, SP_DATABITS_7, and SP_DATABITS_8.
Referenced by SerialPort().
void DUNE::Hardware::SerialPort::setMinimumRead | ( | int | value | ) |
References DUNE::System::Error::getLastMessage().
Referenced by SerialPort().
void DUNE::Hardware::SerialPort::setNonBlocking | ( | void | ) |
References DUNE::System::Error::getLastMessage().
Referenced by SerialPort().
void DUNE::Hardware::SerialPort::setParity | ( | Parity | parity | ) |
Set the parity of the serial port.
parity | parity value. |
References DUNE::System::Error::getLastMessage(), SP_PARITY_EVEN, SP_PARITY_NONE, and SP_PARITY_ODD.
Referenced by SerialPort().
void DUNE::Hardware::SerialPort::setStopBits | ( | StopBits | sbits | ) |
Set the number of stop bits of the serial port.
sbits | number of stop bits. |
References DUNE::System::Error::getLastMessage(), SP_STOPBITS_1, SP_STOPBITS_1_5, and SP_STOPBITS_2.
Referenced by SerialPort().
void DUNE::Hardware::SerialPort::setXONXOFF | ( | bool | enabled | ) |
Enable software flow control (XON/XOFF/XANY).
enabled | enable / disable software flow control |
References DUNE::System::Error::getLastMessage().
Referenced by SerialPort().