A ConnectionBackend that allows the software to interface with QSerialPort for communicating with SerialPort devices.
More...
|
|
TranslatedString | m_last_error |
| | The most recent error message from the serial port.
|
|
QSerialPort * | m_serial_port = nullptr |
| | The underlying Qt serial port instance.
|
|
LogPtr | m_log |
| | Log for diagnostic messages.
|
A ConnectionBackend that allows the software to interface with QSerialPort for communicating with SerialPort devices.
- See also
- Connection, BluetoothConnection, SocketConnection
Definition at line 25 of file SerialPortConnection.h.
◆ SerialPortConnection()
| SerialPortConnection::SerialPortConnection |
( |
LogPtr | log | ) |
|
◆ bytesAvailable()
| virtual uint04 SerialPortConnection::bytesAvailable |
( |
| ) |
const |
|
overridevirtual |
Returns the number of bytes available for reading from the serial port.
- Returns
- The number of bytes available.
Implements ConnectionBackend.
◆ CreateInfo() [1/2]
| ConnectionInfo SerialPortConnection::CreateInfo |
( |
const QSerialPort & | value | ) |
|
|
static |
Creates a ConnectionInfo from an existing QSerialPort.
- Parameters
-
| [in] | value | The serial port to convert. |
- Returns
- A ConnectionInfo populated with the serial port details.
◆ CreateInfo() [2/2]
| ConnectionInfo SerialPortConnection::CreateInfo |
( |
const QSerialPortInfo & | value | ) |
|
|
static |
Creates a ConnectionInfo from a QSerialPortInfo descriptor.
- Parameters
-
| [in] | value | The serial port info to convert. |
- Returns
- A ConnectionInfo populated with the serial port details.
◆ FromString()
| void SerialPortConnection::FromString |
( |
const String & | string, |
|
|
QSerialPort & | value ) |
|
static |
Deserializes a string representation into a QSerialPort configuration.
- Parameters
-
| [in] | string | The string to parse. |
| [in] | value | The QSerialPort to configure from the parsed data. |
◆ handleSerialPortError()
| void SerialPortConnection::handleSerialPortError |
( |
int | error, |
|
|
LogPtr | log ) |
Handles a QSerialPort error code and logs the corresponding message.
- Parameters
-
| [in] | error | The QSerialPort error code. |
| [in] | log | The log to write the error to. |
◆ isOpen()
| virtual bool SerialPortConnection::isOpen |
( |
| ) |
const |
|
overridevirtual |
Checks whether the serial port is currently open.
- Returns
- True if the port is open.
Implements ConnectionBackend.
◆ lastError()
Returns the last error message from the serial port.
- Returns
- A translated string describing the last error.
Implements ConnectionBackend.
◆ open()
| virtual bool SerialPortConnection::open |
( |
const ConnectionInfo & | request | ) |
|
|
overridevirtual |
Opens the serial port connection using the given connection information.
- Parameters
-
| [in] | request | The connection information describing the port to open. |
- Returns
- True if the connection was opened successfully.
Implements ConnectionBackend.
◆ peek()
| virtual uint04 SerialPortConnection::peek |
( |
char * | s, |
|
|
uint04 | size ) const |
|
overridevirtual |
Reads data from the serial port without consuming it.
- Parameters
-
| [in] | s | The buffer to store peeked data into. |
| [in] | size | The maximum number of bytes to peek. |
- Returns
- The number of bytes actually peeked.
Implements ConnectionBackend.
◆ rx()
Receives data from the serial port.
- Parameters
-
| [in] | s | The buffer to store received data into. |
| [in] | size | The maximum number of bytes to receive. |
- Returns
- The number of bytes actually received.
Implements ConnectionBackend.
◆ setSerialPort()
Sets the underlying QSerialPort and configures it with the given open type.
- Parameters
-
| [in] | serial_port | The QSerialPort to use. This object takes ownership. |
| [in] | connection_type | The mode to open the port in (read, write, or read/write). |
| [in] | log | The log to use for diagnostic messages. |
- Returns
- True if the serial port was set and opened successfully.
References e_read_write.
◆ threadID()
| String SerialPortConnection::threadID |
( |
| ) |
const |
|
overridevirtual |
Returns a string identifying the thread this connection operates on.
- Returns
- The thread identifier string.
Reimplemented from ConnectionBackend.
◆ ToString()
| void SerialPortConnection::ToString |
( |
const QSerialPort & | value, |
|
|
String & | string ) |
|
static |
Serializes a QSerialPort configuration to a string representation.
- Parameters
-
| [in] | value | The QSerialPort to serialize. |
| [in] | string | The output string to write the serialized data into. |
◆ tx()
| virtual void SerialPortConnection::tx |
( |
const StringView & | command | ) |
|
|
overridevirtual |
Transmits a command over the serial port.
- Parameters
-
| [in] | command | The data to transmit. |
Implements ConnectionBackend.
◆ txInThread()
| void SerialPortConnection::txInThread |
( |
const StringView & | command | ) |
|
Transmits a command over the serial port from within the connection thread.
- Parameters
-
| [in] | command | The data to transmit. |
◆ waitForReadyRead()
| virtual bool SerialPortConnection::waitForReadyRead |
( |
const TimeSpan & | span | ) |
|
|
overridevirtual |
Blocks until data is ready to read or the timeout expires.
- Parameters
-
| [in] | span | The maximum time to wait. |
- Returns
- True if data became available before the timeout.
Implements ConnectionBackend.
The documentation for this class was generated from the following file: