Public Types | Public Member Functions | Public Attributes | Private Member Functions | List of all members
swri_serial_util::SerialPort Class Reference

#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 ()
 

Detailed Description

Definition at line 82 of file serial_port.h.

Member Enumeration Documentation

Enumerator
SUCCESS 
TIMEOUT 
INTERRUPTED 
ERROR 

Definition at line 86 of file serial_port.h.

Constructor & Destructor Documentation

swri_serial_util::SerialPort::SerialPort ( )

Constructor.

Definition at line 74 of file serial_port.cpp.

swri_serial_util::SerialPort::~SerialPort ( )

Destructor.

Closes serial port if open.

Definition at line 80 of file serial_port.cpp.

Member Function Documentation

void swri_serial_util::SerialPort::Close ( )

Close the serial port.

Definition at line 85 of file serial_port.cpp.

std::string swri_serial_util::SerialPort::ErrorMsg ( ) const
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

Parameters
[in]deviceThe OS path of the device.
[in]configThe port configuration settings.

Definition at line 94 of file serial_port.cpp.

int32_t swri_serial_util::SerialPort::ParseBaudRate ( int32_t  baud)
private

Parses integer and enumerated baud rates into enumerated baud rates.

Parameters
[in]baudThe baud rate (either integer or enumerated)
Returns
The enumerated baud rate or -1 if invalid.

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.

Parameters
[out]outputThe output buffer for bytes read in.
[in]max_bytesThe maximum number of bytes to read. If set to 0, all available bytes are read.
[in]timeoutThe maximum time to block in milliseconds
Returns
Read result (SUCCESS, TIMEOUT, INTERRUPTED, or ERROR).

Definition at line 352 of file serial_port.cpp.

bool swri_serial_util::SerialPort::SetLowLatencyMode ( )
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.

Member Data Documentation

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.


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


swri_serial_util
Author(s): Marc Alban
autogenerated on Fri Jun 7 2019 22:06:02