NDEVR
API Documentation
SerialPortConnection

A ConnectionBackend that allows the software to interface with QSerialPort for communicating with SerialPort devices. More...

Inheritance diagram for SerialPortConnection:
[legend]
Collaboration diagram for SerialPortConnection:
[legend]

Public Member Functions

 SerialPortConnection (LogPtr log)
 Constructs a SerialPortConnection with the given log.
virtual uint04 bytesAvailable () const override
 Returns the number of bytes available for reading from the serial port.
virtual void close () override
 Closes the serial port connection.
void handleSerialPortError (int error, LogPtr log)
 Handles a QSerialPort error code and logs the corresponding message.
virtual bool isOpen () const override
 Checks whether the serial port is currently open.
virtual TranslatedString lastError () const override
 Returns the last error message from the serial port.
virtual bool open (const ConnectionInfo &request) override
 Opens the serial port connection using the given connection information.
virtual uint04 peek (char *s, uint04 size) const override
 Reads data from the serial port without consuming it.
virtual uint04 rx (char *s, uint04 size=Constant< uint04 >::Max) override
 Receives data from the serial port.
bool setSerialPort (QSerialPort *serial_port, ConnectionOpenType connection_type=ConnectionOpenType::e_read_write, LogPtr log=LogPtr())
 Sets the underlying QSerialPort and configures it with the given open type.
String threadID () const override
 Returns a string identifying the thread this connection operates on.
virtual void tx (const StringView &command) override
 Transmits a command over the serial port.
void txInThread (const StringView &command)
 Transmits a command over the serial port from within the connection thread.
virtual bool waitForReadyRead (const TimeSpan &span) override
 Blocks until data is ready to read or the timeout expires.
Public Member Functions inherited from ConnectionBackend
 ConnectionBackend (LogPtr log)
 Constructs a ConnectionBackend with the given log.
void connectionStateChangedSignal (ConnectionState state)
 Emitted when the connection state changes.
void dataAvailableSignal ()
 Emitted when data is available to be read from the connection.

Static Public Member Functions

static ConnectionInfo CreateInfo (const QSerialPort &value)
 Creates a ConnectionInfo from an existing QSerialPort.
static ConnectionInfo CreateInfo (const QSerialPortInfo &value)
 Creates a ConnectionInfo from a QSerialPortInfo descriptor.
static void FromString (const String &string, QSerialPort &value)
 Deserializes a string representation into a QSerialPort configuration.
static void ToString (const QSerialPort &value, String &string)
 Serializes a QSerialPort configuration to a string representation.

Protected Attributes

TranslatedString m_last_error
 The most recent error message from the serial port.
QSerialPort * m_serial_port = nullptr
 The underlying Qt serial port instance.
Protected Attributes inherited from ConnectionBackend
LogPtr m_log
 Log for diagnostic messages.

Detailed Description

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.

Constructor & Destructor Documentation

◆ SerialPortConnection()

SerialPortConnection::SerialPortConnection ( LogPtr log)

Constructs a SerialPortConnection with the given log.

Parameters
[in]logThe log to use for diagnostic messages.

References SerialPortConnection().

Referenced by SerialPortConnection().

Member Function Documentation

◆ 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]valueThe 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]valueThe 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]stringThe string to parse.
[in]valueThe 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]errorThe QSerialPort error code.
[in]logThe 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()

virtual TranslatedString SerialPortConnection::lastError ( ) const
overridevirtual

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]requestThe 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]sThe buffer to store peeked data into.
[in]sizeThe maximum number of bytes to peek.
Returns
The number of bytes actually peeked.

Implements ConnectionBackend.

◆ rx()

virtual uint04 SerialPortConnection::rx ( char * s,
uint04 size = Constantuint04 >::Max )
overridevirtual

Receives data from the serial port.

Parameters
[in]sThe buffer to store received data into.
[in]sizeThe maximum number of bytes to receive.
Returns
The number of bytes actually received.

Implements ConnectionBackend.

◆ setSerialPort()

bool SerialPortConnection::setSerialPort ( QSerialPort * serial_port,
ConnectionOpenType connection_type = ConnectionOpenType::e_read_write,
LogPtr log = LogPtr() )

Sets the underlying QSerialPort and configures it with the given open type.

Parameters
[in]serial_portThe QSerialPort to use. This object takes ownership.
[in]connection_typeThe mode to open the port in (read, write, or read/write).
[in]logThe 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]valueThe QSerialPort to serialize.
[in]stringThe 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]commandThe 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]commandThe 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]spanThe 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: