Class Serial
Defined in File serial.hpp
Inheritance Relationships
Derived Type
public robotiq_driver::DefaultSerial
(Class DefaultSerial)
Class Documentation
-
class Serial
The driver talks to the hardware through an implementation of the serial interface. We can mock the serial connection to check that a high level command (e.g activate) is converted into the correct sequence of bytes including CRC.
Subclassed by robotiq_driver::DefaultSerial
Public Functions
-
virtual ~Serial() = default
-
virtual void open() = 0
Opens the serial port as long as the port is set and the port isn’t already open.
-
virtual bool is_open() const = 0
Gets the open status of the serial port.
- Returns:
Returns true if the port is open, false otherwise.
-
virtual void close() = 0
Closes the serial port.
-
virtual std::vector<uint8_t> read(size_t size) = 0
Read a given amount of bytes from the serial port.
- Parameters:
size – The number of bytes to read.
- Throws:
serial::PortNotOpenedException –
serial::SerialException –
- Returns:
The sequence of bytes.
-
virtual void write(const std::vector<uint8_t> &data) = 0
Write a sequence of bytes to the serial port.
- Parameters:
data – A vector containing data to be written to the serial port.
- Throws:
serial::PortNotOpenedException –
serial::SerialException –
serial::IOException –
-
virtual void set_port(const std::string &port) = 0
Sets the serial port identifier.
- Parameters:
port – A const std::string reference containing the address of the serial port, which would be something like “COM1” on Windows and “/dev/ttyS0” on Linux.
- Throws:
std::invalid_argument –
-
virtual std::string get_port() const = 0
Gets the serial port identifier.
See also
SerialInterface::setPort
- Throws:
std::invalid_argument –
-
virtual void set_timeout(const std::chrono::milliseconds timeout) = 0
Set read timeout in milliseconds.
- Parameters:
timeout – Read timeout in milliseconds.
-
virtual std::chrono::milliseconds get_timeout() const = 0
Get read timeout in milliseconds.
- Returns:
Read timeout in milliseconds.
-
virtual void set_baudrate(uint32_t baudrate) = 0
Sets the baudrate for the serial port.
- Parameters:
baudrate – An integer that sets the baud rate for the serial port.
-
virtual uint32_t get_baudrate() const = 0
Gets the baudrate for the serial port.
- Returns:
An integer that sets the baud rate for the serial port.
-
virtual ~Serial() = default