SerialTransport¶
class nmeasim::io::SerialTransport · Library API
Writes lines to a serial port.
#include <nmeasim/io/transports/serial_transport.hpp>
Inherits nmeasim::io::Transport
Declared in src/io/include/nmeasim/io/transports/serial_transport.hpp (line 53)
The port is opened write-only. An unplugged device closes the port and moves the transport to State::Failed with the message Serial port <name> was disconnected; it does not reopen by itself. Other runtime errors of the port are reported through error_occurred and leave the transport open.
Summary¶
Public member functions
| Name | Description |
|---|---|
SerialTransport() |
Creates a closed transport for the port described by config; nothing is opened until open. |
~SerialTransport() |
Destroys the transport, closing the port first. |
description() |
Returns the port name and baud rate. |
open() |
Opens the port write-only and applies the line settings of config. |
close() |
Closes the port and moves to State::Closed. |
write() |
Queues line for transmission on the port. |
config() |
Returns the settings the transport was created with. |
Private data members
| Name | Description |
|---|---|
port_ |
The port device. |
config_ |
Port name and line settings, fixed at construction. |
opening_ |
True while open opens and configures the port, so that errors raised by the port during that time are reported once by open rather than also as runtime errors. |
Public member functions¶
SerialTransport()¶
explicit SerialTransport(SerialConfig config, QObject* parent = nullptr)
Creates a closed transport for the port described by config; nothing is opened until open.
Parameters
| Name | Type | Description |
|---|---|---|
config |
SerialConfig |
Port name and line settings, copied into the transport. |
parent |
QObject* |
Qt parent that owns the transport; null leaves ownership to the caller. |
Declared in src/io/include/nmeasim/io/transports/serial_transport.hpp:62 · defined in src/io/src/transports/serial_transport.cpp:10
~SerialTransport()¶
~SerialTransport() override
Destroys the transport, closing the port first.
Declared in src/io/include/nmeasim/io/transports/serial_transport.hpp:64 · defined in src/io/src/transports/serial_transport.cpp:28
description()¶
QString description() const override
Returns the port name and baud rate.
Returns QString: For example Serial port /dev/ttyUSB0 at 4800 baud.
Overrides description · Declared in src/io/include/nmeasim/io/transports/serial_transport.hpp:69 · defined in src/io/src/transports/serial_transport.cpp:32
open()¶
bool open() override
Opens the port write-only and applies the line settings of config.
Returns true at once when already open. Fails when the device is missing, busy or not accessible, and when the driver rejects a setting, in which case the port is closed again. last_error then names the port, the failed step and the reason reported by the port.
Returns bool: True when the port is open and configured, false when either step failed.
Overrides open · Declared in src/io/include/nmeasim/io/transports/serial_transport.hpp:78 · defined in src/io/src/transports/serial_transport.cpp:38
close()¶
void close() override
Closes the port and moves to State::Closed.
Overrides close · Declared in src/io/include/nmeasim/io/transports/serial_transport.hpp:80 · defined in src/io/src/transports/serial_transport.cpp:66
write()¶
void write(const QByteArray& line) override
Queues line for transmission on the port.
The port sends it asynchronously at the configured baud rate; the transport sets no limit on how much can be queued when lines are produced faster than the line speed allows.
Parameters
| Name | Type | Description |
|---|---|---|
line |
const QByteArray& |
One complete line, terminator included. |
Overrides write · Declared in src/io/include/nmeasim/io/transports/serial_transport.hpp:88 · defined in src/io/src/transports/serial_transport.cpp:73
config()¶
const SerialConfig& config() const noexcept
Returns the settings the transport was created with.
Returns const SerialConfig&: A reference valid for the lifetime of the transport.
Declared in src/io/include/nmeasim/io/transports/serial_transport.hpp:93
Private data members¶
port_¶
QSerialPort port_
The port device.
Declared in src/io/include/nmeasim/io/transports/serial_transport.hpp:97
config_¶
SerialConfig config_
Port name and line settings, fixed at construction.
Declared in src/io/include/nmeasim/io/transports/serial_transport.hpp:99
opening_¶
bool opening_{false}
True while open opens and configures the port, so that errors raised by the port during that time are reported once by open rather than also as runtime errors.
Declared in src/io/include/nmeasim/io/transports/serial_transport.hpp:102
Inherited members¶
From nmeasim::io::SerialTransport: bytes_written(), client_count(), client_count_changed(), count_bytes(), error_occurred(), fail(), is_open(), last_error(), set_state(), State, state(), state_changed(), Transport()