QModbusRtuSerialServer Class

The QModbusRtuSerialServer class represents a Modbus server that uses a serial port for its communication with the Modbus client. More...

Header: #include <QModbusRtuSerialServer>
CMake: find_package(Qt6 REQUIRED COMPONENTS SerialBus)
target_link_libraries(mytarget PRIVATE Qt6::SerialBus)
qmake: QT += serialbus
Since: Qt 6.2
Inherits: QModbusServer

Public Functions

QModbusRtuSerialServer(QObject *parent = nullptr)
virtual ~QModbusRtuSerialServer()
int interFrameDelay() const
void setInterFrameDelay(int microseconds)

Reimplemented Public Functions

virtual bool processesBroadcast() const override

Reimplemented Protected Functions

virtual void close() override
virtual bool open() override
virtual QModbusResponse processRequest(const QModbusPdu &request) override

Detailed Description

Communication via Modbus requires the interaction between a single Modbus client instance and multiple Modbus server. This class provides the Modbus server implementation via a serial port.

Since multiple Modbus server instances can interact with a Modbus client at the same time (using a serial bus), servers are identified by their serverAddress().

Member Function Documentation

[explicit] QModbusRtuSerialServer::QModbusRtuSerialServer(QObject *parent = nullptr)

Constructs a QModbusRtuSerialServer with the specified parent. The serverAddress preset is 1.

[virtual noexcept] QModbusRtuSerialServer::~QModbusRtuSerialServer()

Destroys the QModbusRtuSerialServer instance.

[override virtual protected] void QModbusRtuSerialServer::close()

Reimplements: QModbusDevice::close().

[since 6.2] int QModbusRtuSerialServer::interFrameDelay() const

Returns the amount of microseconds for the silent interval between two consecutive Modbus messages.

This function was introduced in Qt 6.2.

See also setInterFrameDelay().

[override virtual protected] bool QModbusRtuSerialServer::open()

Reimplements: QModbusDevice::open().

Note: When calling this function, existing buffered data is removed from the serial port.

[override virtual protected] QModbusResponse QModbusRtuSerialServer::processRequest(const QModbusPdu &request)

Reimplements: QModbusServer::processRequest(const QModbusPdu &request).

Processes the Modbus client request specified by request and returns a Modbus response.

The Modbus function QModbusRequest::EncapsulatedInterfaceTransport with MEI Type 13 (0x0D) CANopen General Reference is filtered out because it is usually Modbus TCP or Modbus serial ASCII only.

A request to the RTU serial server will be answered with a Modbus exception response with the exception code QModbusExceptionResponse::IllegalFunction.

[override virtual] bool QModbusRtuSerialServer::processesBroadcast() const

Reimplements: QModbusServer::processesBroadcast() const.

[since 6.2] void QModbusRtuSerialServer::setInterFrameDelay(int microseconds)

Sets the amount of microseconds for the silent interval between two consecutive Modbus messages. By default, the class implementation will use a pre-calculated value according to the Modbus specification. A active or running connection is not affected by such delay changes.

Note: If microseconds is set to -1 or microseconds is less than the pre-calculated delay then this pre-calculated value is used as frame delay.

This function was introduced in Qt 6.2.

See also interFrameDelay().

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.