ark::serial::SerialPort

Defined in header “ark/serial/serial_port.hh”.


This class is a convenience wrapper for reading data from a serial port. It allows you to open a port, configure it, and then read or write bytes.

This is non-blocking.

Methods

  • SerialPort(SerialPortConfiguration config)
    Constructor. Initializes the serial port with the given configuration.

  • ~SerialPort()
    Destructor. Cleans up any open file handles.

  • size_t read(void * destination, size_t size)
    Reads at most ‘size’ bytes into the given buffer. Returns the number of bytes actually read, or throws if there was an error.

  • bool wait_for(std::chrono::nanoseconds duration)
    Waits for at least one byte to be read for reading. Sleeps for at most the given duration. Returns true if data is waiting, or false otherwise.

  • void write(const void * data, size_t size)
    Writes data to the device. Throws if there was an error or all of the bytes were not written.