#include <serial_port.h>
Public Types | |
enum | Result { SUCCESS, TIMEOUT, INTERRUPTED, ERROR } |
Public Member Functions | |
void | Close () |
std::string | ErrorMsg () const |
bool | Open (const std::string &device, SerialConfig config=SerialConfig()) |
Result | ReadBytes (std::vector< uint8_t > &output, size_t max_bytes, int32_t timeout) |
SerialPort () | |
int32_t | Write (const std::vector< uint8_t > &input) |
~SerialPort () | |
Public Attributes | |
std::string | error_msg_ |
int | fd_ |
Private Member Functions | |
int32_t | ParseBaudRate (int32_t baud) |
bool | SetLowLatencyMode () |
Definition at line 82 of file serial_port.h.
Enumerator | |
---|---|
SUCCESS | |
TIMEOUT | |
INTERRUPTED | |
ERROR |
Definition at line 86 of file serial_port.h.
swri_serial_util::SerialPort::SerialPort | ( | ) |
Constructor.
Definition at line 74 of file serial_port.cpp.
swri_serial_util::SerialPort::~SerialPort | ( | ) |
void swri_serial_util::SerialPort::Close | ( | ) |
Close the serial port.
Definition at line 85 of file serial_port.cpp.
|
inline |
Get the most recent error message.
Definition at line 150 of file serial_port.h.
bool swri_serial_util::SerialPort::Open | ( | const std::string & | device, |
SerialConfig | config = SerialConfig() |
||
) |
Open and configure the serial port.
The default configuration is: baud = 115200 parity = NO_PARITY flow control = false data bits = 8 stop bits = 1 low latency mode = false
[in] | device | The OS path of the device. |
[in] | config | The port configuration settings. |
Definition at line 94 of file serial_port.cpp.
|
private |
Parses integer and enumerated baud rates into enumerated baud rates.
[in] | baud | The baud rate (either integer or enumerated) |
Definition at line 228 of file serial_port.cpp.
SerialPort::Result swri_serial_util::SerialPort::ReadBytes | ( | std::vector< uint8_t > & | output, |
size_t | max_bytes, | ||
int32_t | timeout | ||
) |
Read bytes from the serial port.
Appends up to max_bytes into the provided vector. If max_bytes is 0, it reads all available bytes.
[out] | output | The output buffer for bytes read in. |
[in] | max_bytes | The maximum number of bytes to read. If set to 0, all available bytes are read. |
[in] | timeout | The maximum time to block in milliseconds |
Definition at line 352 of file serial_port.cpp.
|
private |
Attempts to put serial port in low latency mode.
Definition at line 201 of file serial_port.cpp.
int32_t swri_serial_util::SerialPort::Write | ( | const std::vector< uint8_t > & | input | ) |
Definition at line 433 of file serial_port.cpp.
std::string swri_serial_util::SerialPort::error_msg_ |
Definition at line 95 of file serial_port.h.
int swri_serial_util::SerialPort::fd_ |
Definition at line 94 of file serial_port.h.