Class SerialTransport
Defined in File serial_transport.h
Inheritance Relationships
Base Type
public flir_ptu_driver::Transport(Class Transport)
Class Documentation
-
class SerialTransport : public flir_ptu_driver::Transport
Serial (TTY) implementation of the PTU Transport interface.
Opens a POSIX serial device in raw 8-N-1 mode at the requested baud rate and exposes the byte stream expected by PTU. The previous termios settings are saved on open() and restored on close().
Public Functions
-
SerialTransport(const std::string &port, int baud)
Construct a serial transport bound to a TTY device.
The device is not opened until open() is called.
- Parameters:
port – Path to the serial device, e.g. “/dev/ttyUSB0”.
baud – Symbol rate in bits per second (must be a value accepted by termios, e.g. 9600, 19200, 38400, 57600, 115200).
-
~SerialTransport() override
Closes the device if still open and restores the prior termios state.
-
virtual bool open() override
Open the serial device and apply raw 8-N-1 termios settings.
- Returns:
trueif the device was opened successfully.
-
virtual void close() override
Restore the prior termios state and close the file descriptor.
-
virtual bool isOpen() const override
- Returns:
truewhile the underlying file descriptor is open.
-
virtual void write(const std::string &data) override
Send raw bytes over the serial link.
- Parameters:
data – Bytes to write; sent as-is with no framing or escaping.
-
virtual std::string readline(size_t max_len = 255, char eol = '\n') override
Read a single line terminated by
eol.Blocks until a terminator is seen,
max_lenbytes have accumulated, or the device reports an error. The terminator is included in the returned string when one was received.
-
virtual std::string read(size_t size) override
Read exactly
sizebytes, blocking until satisfied or on error.
-
virtual size_t available() override
- Returns:
Number of bytes currently buffered and immediately readable.
-
virtual void flush() override
Discard any bytes pending in the receive buffer.
-
SerialTransport(const std::string &port, int baud)