Class DefaultSerial

Inheritance Relationships

Base Type

Class Documentation

class DefaultSerial : public robotiq_driver::Serial

Public Functions

DefaultSerial()

Creates a Serial object to send and receive bytes to and from the serial port.

virtual void open() override

Opens the serial port as long as the port is set and the port isn’t already open.

virtual bool is_open() const override

Gets the open status of the serial port.

Returns:

Returns true if the port is open, false otherwise.

virtual void close() override

Closes the serial port.

virtual std::vector<uint8_t> read(size_t size = 1) override

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) override

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) override

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 override

Gets the serial port identifier.

See also

SerialInterface::setPort

Throws:

std::invalid_argument

virtual void set_timeout(std::chrono::milliseconds timeout_ms) override

Set read timeout in milliseconds.

Parameters:

timeout – Read timeout in milliseconds.

virtual std::chrono::milliseconds get_timeout() const override

Get read timeout in milliseconds.

Returns:

Read timeout in milliseconds.

virtual void set_baudrate(uint32_t baudrate) override

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 override

Gets the baudrate for the serial port.

Returns:

An integer that sets the baud rate for the serial port.