Class SerialPort

Class Documentation

class SerialPort

Public Functions

SerialPort(const IoContext &ctx, const std::string &device_name, const SerialPortConfig serial_port_config)

Default constructor.

Parameters:
  • ctx[in] An IoContext object to handle threads

  • device_name[in] The name of the serial device in the OS

  • serial_port_config[in] Configuration options for the serial port

~SerialPort()
SerialPort(const SerialPort&) = delete
SerialPort &operator=(const SerialPort&) = delete
std::string device_name() const

Function to return the stored device name.

Returns:

Device name as a string

SerialPortConfig serial_port_config() const

Function to return the stored serial port configuration.

Returns:

SerialPortConfig object representing the stored serial port configuration

void open()

Function to open the serial port as-configured.

void close()

Function to close the serial port as-configured.

bool is_open() const

Function to check whether the port is already open.

Returns:

Bool indicating whether the port is currently open

size_t send(const std::vector<uint8_t> &buff)

Blocking send operation.

Parameters:

buff[in] A buffer containing the data to send

Returns:

The number of bytes sent

size_t receive(std::vector<uint8_t> &buff)

Bocking receive operation.

Parameters:

buff[out] A buffer to be populated with the read data

Returns:

The number of bytes read

void async_send(const std::vector<uint8_t> &buff)

Non-blocking send operation.

Parameters:

buff[in] A buffer containing the data to send

void async_receive(Functor func)

Non-blocking receive operation.

Parameters:

func[in] A function to be called when data are received

bool send_break()

Function to send a break sequence to the serial port Note: The port should be open first.

Returns:

True if the break was sent, False otherwise