QModbusTcpServer Class
QModbusTcpServer クラスは、Modbus クライアントとの通信に TCP サーバーを使用する Modbus サーバーを表します。詳細...
| ヘッダー: | #include <QModbusTcpServer> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS SerialBus) target_link_libraries(mytarget PRIVATE Qt6::SerialBus) |
| qmake: | QT += serialbus |
| 継承元: | QModbusServer |
パブリック関数
| QModbusTcpServer(QObject *parent = nullptr) | |
| virtual | ~QModbusTcpServer() |
| void | installConnectionObserver(QModbusTcpConnectionObserver *observer) |
シグナル
| void | modbusClientDisconnected(QTcpSocket *modbusClient) |
再実装された保護関数
| virtual void | close() override |
| virtual bool | open() override |
| virtual QModbusResponse | processRequest(const QModbusPdu &request) override |
詳細な説明
Modbus による通信には、単一の Modbus クライアントインスタンスと単一の Modbus サーバー間のやり取りが必要です。このクラスは、TCP サーバーを介して Modbus サーバーの実装を提供します。
Modbus TCP ネットワークには複数のサーバーが存在する場合があります。サーバーへの読み取り・書き込みは、QModbusTcpClient で表されるクライアントデバイスによって行われます。
メンバ関数のドキュメント
[explicit] QModbusTcpServer::QModbusTcpServer(QObject *parent = nullptr)
指定されたparent を使用して、QModbusTcpServerを構築します。serverAddress のデフォルト値は255 です。
[virtual noexcept] QModbusTcpServer::~QModbusTcpServer()
QModbusTcpServer インスタンスを破棄します。
[override virtual protected] void QModbusTcpServer::close()
QModbusDevice::close() を再実装します。
void QModbusTcpServer::installConnectionObserver(QModbusTcpConnectionObserver *observer)
このサーバーインスタンスに新しいTCPクライアントが接続した際に通知を受け取るために使用できるobserver をインストールします。さらに、observer を使用することで、着信TCP接続を拒否することができます。
QModbusTcpServer 指定されたobserver の所有権を取得します。以前に設定されていたオブザーバーはすべて削除されます。この関数をnullptr をパラメータとして呼び出すことで、オブザーバーをアンインストールできます。
QModbusTcpConnectionObserverも参照してください 。
[signal] void QModbusTcpServer::modbusClientDisconnected(QTcpSocket *modbusClient)
このシグナルは、現在接続中のTCPベースのmodbusClient がこのModbus TCPサーバーから切断されたときに発信されます。なお、同時に複数のTCPクライアントが接続されている場合があることに注意してください。
installConnectionObserver() を通じてQModbusTcpConnectionObserver をインストールすることで、新しい接続の着信通知を受け取ることができます。
installConnectionObserverも参照してください 。
[override virtual protected] bool QModbusTcpServer::open()
QModbusDevice::open() を再実装します。
[override virtual protected] QModbusResponse QModbusTcpServer::processRequest(const QModbusPdu &request)
QModbusServer::processRequest(const QModbusPdu &request) を再実装します。
request で指定された Modbus クライアント要求を処理し、Modbus 応答を返します。
Modbus アプリケーションプロトコル仕様 1.1b に基づき、以下の Modbus 機能コードはシリアル回線専用であるため除外されます:
- QModbusRequest::ReadExceptionStatus
- QModbusRequest::Diagnostics
- QModbusRequest::GetCommEventCounter
- QModbusRequest::GetCommEventLog
- QModbusRequest::ReportServerId
TCP サーバーへのリクエストに対しては、例外コード QModbusExceptionResponse::IllegalFunction を含む Modbus 例外レスポンスが返されます。
© 2026 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.