Class SerialPort

Class Documentation

class SerialPort

Public Types

enum Result

Values:

enumerator SUCCESS
enumerator TIMEOUT
enumerator INTERRUPTED
enumerator ERROR

Public Functions

SerialPort()

Constructor.

~SerialPort()

Destructor.

Closes serial port if open.

virtual bool 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:
  • device[in] The OS path of the device.

  • config[in] The port configuration settings.

virtual void Close()

Close the serial port.

virtual Result 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:
  • output[out] The output buffer for bytes read in.

  • max_bytes[in] The maximum number of bytes to read. If set to 0, all available bytes are read.

  • timeout[in] The maximum time to block in milliseconds

Returns:

Read result (SUCCESS, TIMEOUT, INTERRUPTED, or ERROR).

virtual int32_t Write(const std::vector<uint8_t> &input)
inline std::string ErrorMsg() const

Get the most recent error message.

Public Members

int fd_
std::string error_msg_