QModbusPdu Class

QModbusPduはModbus ADU内部に格納されるファンクション・コードとペイロードを含む抽象コンテナ・クラスです。詳細...

ヘッダー #include <QModbusPdu>
CMake: find_package(Qt6 REQUIRED COMPONENTS SerialBus)
target_link_libraries(mytarget PRIVATE Qt6::SerialBus)
qmake: QT += serialbus
によって継承される:

QModbusRequest そしてQModbusResponse

パブリックな型

enum ExceptionCode { IllegalFunction, IllegalDataAddress, IllegalDataValue, ServerDeviceFailure, Acknowledge, …, ExtendedException }
enum FunctionCode { Invalid, ReadCoils, ReadDiscreteInputs, ReadHoldingRegisters, ReadInputRegisters, …, UndefinedFunctionCode }

パブリック関数

QModbusPdu()
virtual ~QModbusPdu()
QByteArray data() const
qint16 dataSize() const
void decodeData(Args &&... data) const
void encodeData(Args... data)
QModbusPdu::ExceptionCode exceptionCode() const
QModbusPdu::FunctionCode functionCode() const
bool isException() const
bool isValid() const
void setData(const QByteArray &data)
virtual void setFunctionCode(QModbusPdu::FunctionCode code)
qint16 size() const

静的パブリックメンバ

const quint8 ExceptionByte

保護された関数

QModbusPdu(QModbusPdu::FunctionCode code, const QByteArray &data)
QModbusPdu(const QModbusPdu &other)
QModbusPdu &operator=(const QModbusPdu &other)
QDataStream &operator<<(QDataStream &stream, const QModbusPdu &pdu)
QDebug operator<<(QDebug debug, const QModbusPdu &pdu)

詳細説明

このクラスは Modbus Application Protocol Specification 1.1b で定義されている生の Modbus プロトコル・パケットへのアクセスを提供します。

メンバ・タイプ・ドキュメント

enum QModbusPdu::ExceptionCode

この enum は Modbus Exception Codes で定義されたすべての可能なエラー状態を記述します。これらは、リクエストへのリプライで適切なエラー条件をチェックした後、サーバによって設定され、例外コードを操作するためにクライアントによってデコードされなければなりません。

定数説明
QModbusPdu::IllegalFunction0x01ファンクション・コードはデバイスによってサポートされていません。
QModbusPdu::IllegalDataAddress0x02クエリの受信データ・アドレスが Modbus サーバーに許容されるアドレスではありません。
QModbusPdu::IllegalDataValue0x03リクエスト・データ・フィールドに含まれる値が Modbus サーバーに許容される値ではありません。
QModbusPdu::ServerDeviceFailure0x04サーバーが要求されたアクションを実行しようとしている間に回復不可能なエラーが発生しました。
QModbusPdu::Acknowledge0x05プログラミング・コマンドと組み合わせた特殊な使用。
QModbusPdu::ServerDeviceBusy0x06サーバは長時間のプログラム・コマンドを処理中です。
QModbusPdu::NegativeAcknowledge0x07サーバーは問い合わせで受け取ったプログラム機能を実行できない。このコードは、プログラミング要求に失敗した場合に返される。クライアントはサーバーに診断情報またはエラー情報を要求する必要があります。
QModbusPdu::MemoryParityError0x08拡張ファイル領域が整合性チェックに失敗したことを示します。ファンクションコード20および21と組み合わせて使用する。この例外コードは、伝送路のパリティ設定を参照するものではなく、ファイルレコードのサーバー内部メモリのみを参照するものである。
QModbusPdu::GatewayPathUnavailable0x0Aゲートウェイが、リクエストを処理するための入力ポートから出力ポートへの内部通信経路を確保できなかったことを示す。
QModbusPdu::GatewayTargetDeviceFailedToRespond0x0Bゲートウェイの背後にあるターゲット・デバイスから応答が得られなかったことを示す。通常これは、ターゲット・デバイスがネットワーク上でオンラインでないことを意味する。
QModbusPdu::ExtendedException0xFFこれは Modbus 仕様による拡張例外です。一般にこのコードは、他にさらに記述されている例外を記述するために使用されます。

enum QModbusPdu::FunctionCode

ファンクション・コードとサーバに要求される暗黙のアクション・タイプを定義します。すべての Modbus デバイスが同じファンクション・コードを扱えるわけではありません。

定数説明
QModbusPdu::Invalid0x00デフォルトのコンストラクタによって設定されます。
QModbusPdu::ReadCoils0x01デバイスから 1 つ以上のコイルのステータスを要求します。
QModbusPdu::ReadDiscreteInputs0x02デバイスから 1 つ以上の入力レジスタのステータスを要求します。
QModbusPdu::ReadHoldingRegisters0x03デバイスから 1 つ以上の保持レジスタ値のステータスを要求します。
QModbusPdu::ReadInputRegisters0x04デバイスから 1 つ以上の入力レジスタ値のステータスを要求する。
QModbusPdu::WriteSingleCoil0x05デバイスに1つのコイルを書き込むよう要求する。
QModbusPdu::WriteSingleRegister0x06デバイスに1つの保持レジスタの書き込みを要求する。
QModbusPdu::ReadExceptionStatus0x07デバイス上の8つの例外ステータス出力のステータスを要求する。
QModbusPdu::Diagnostics0x08クライアント・サーバ通信システムをチェックするための一連のテストを提供するために使用される。
QModbusPdu::GetCommEventCounter0x0Bデバイスの通信イベント・カウンタからステータス・ワードとイベント・カウントを要求する。
QModbusPdu::GetCommEventLog0x0Cデバイスからステータス・ワード、イベント・カウント、メッセージ・カウント、およびイベント・バイトのフィールドを要求する。
QModbusPdu::WriteMultipleCoils0x0Fデバイス上の1つ以上のコイルの書き込みを要求する。
QModbusPdu::WriteMultipleRegisters0x10デバイスに1つ以上の保持レジスタの書き込みを要求する。
QModbusPdu::ReportServerId0x11デバイスに対して、タイプの説明、現在のステータス、その他の情報を要求する。
QModbusPdu::ReadFileRecord0x14ファイルレコードの読み取りを要求する。
QModbusPdu::WriteFileRecord0x15ファイルレコードの書き込みを要求する。
QModbusPdu::MaskWriteRegister0x16AND または OR マスクとレジスタの現在の内容の組合せを使用して、 指定された保持レジスタの内容を変更する要求。
QModbusPdu::ReadWriteMultipleRegisters0x171つ以上の保持レジスタの状態を要求し、同時にデバイス上の1つ以上の保持レジスタを書き込む。
QModbusPdu::ReadFifoQueue0x18リモート・デバイスのレジスタの先入れ先出し(FIFO)キューの内容の読み出しを要求する。
QModbusPdu::EncapsulatedInterfaceTransport0x2BModbus 仕様書の Annex A を参照してください。
QModbusPdu::UndefinedFunctionCode0x100使用しないでください。

メンバー関数ドキュメント

[constexpr noexcept] QModbusPdu::QModbusPdu()

無効な QModbusPdu を構築します。

[protected] QModbusPdu::QModbusPdu(QModbusPdu::FunctionCode code, const QByteArray &data)

ファンクションコードがcode に設定され、ペイロードがdata に設定された QModbusPdu を構築します。 データは既にビッグエンディアンのバイトオーダーで格納されていることが期待されます。

[noexcept protected] QModbusPdu::QModbusPdu(const QModbusPdu &other)

other のコピーである QModbusPdu を構築する。

[virtual noexcept] QModbusPdu::~QModbusPdu()

QModbusPdu を破壊する。

QByteArray QModbusPdu::data() const

PDU のペイロード(ファンクションコードを除く)を返す。ペイロードはビッグエンディアンバイトオーダーで格納される。

setData()も参照のこと

qint16 QModbusPdu::dataSize() const

ファンクションコードを除いたPDUのデータサイズを返す。

template <typename... Args> void QModbusPdu::decodeData(Args &&... data) const

ペイロードをホストのエンディアンに変換し、data に読み込む。データは可変長の引数リストにすることができる。

QModbusResponsePdu response(QModbusPdu::ReportServerId);
response.encodeData(quint8(0x02), quint8(0x01), quint8(0xff));
quint8 count, id, run;
response.decodeData(&count, &id, &run);

注意: 使用はquint8quint16 に限られる。これは、QDataStream ストリーム演算子は、生データだけでなく、複雑な型のサイズやカウントなども追加するためである。

template <typename... Args> void QModbusPdu::encodeData(Args... data)

ペイロードをdata に設定する。 データはビッグエンディアン・バイト順に変換され、格納される。

QModbusRequestPdu request(QModbusPdu::ReadCoils);
// starting address and quantity of coils
request.encodeData(quint16(0x0c), quint16(0x0a));

注意: 使用はquint8 およびquint16 に限られる。これは、QDataStream ストリーム演算子は、生データだけでなく、複雑な型のサイズやカウントなども追加するためです。

QModbusPdu::ExceptionCode QModbusPdu::exceptionCode() const

レスポンスの例外コードを返します。

QModbusPdu::FunctionCode QModbusPdu::functionCode() const

PDUのファンクションコードを返す。

setFunctionCode()も参照してください

bool QModbusPdu::isException() const

PDUに例外コードが含まれている場合はtrueを返し、そうでない場合はfalseを返す。

bool QModbusPdu::isValid() const

PDUが有効であればtrueを返し、そうでなければfalseを返す。

メッセージコードが10進数で1~255の範囲にあり、PDUの複合サイズ(ファンクションコード+データ)が253バイトを超えない場合、PDUは有効であるとみなされる。デフォルトで構築されたPDUは無効である。

void QModbusPdu::setData(const QByteArray &data)

PDUのファンクションペイロードをdata に設定する。 データは既にビッグエンディアンバイトオーダーで格納されていることが期待される。

data()も参照のこと

[virtual] void QModbusPdu::setFunctionCode(QModbusPdu::FunctionCode code)

PDU のファンクションコードをcode に設定する。

functionCode()も参照

qint16 QModbusPdu::size() const

ファンクションコードとデータサイズを含むPDUのフルサイズを返す。

[noexcept protected] QModbusPdu &QModbusPdu::operator=(const QModbusPdu &other)

other のコピーを作成し、このQModbusPdu オブジェクトに代入する。

メンバー変数ドキュメント

const quint8 QModbusPdu::ExceptionByte

この変数は0x80に初期化される。

例外は、定義されたパケット形式で報告される。元のファンクションコードと同じファンクションコードが、最上位ビットが設定されている ことを除いて、要求元のクライアントに返される。これは、元のファンクションコードの値に0x80を追加するのと同じである。

このフィールドは生の Modbus パケットのファンクション・フィールドの例外ビットをマスクするために使用されます。

関連する非会員

QDataStream &operator<<(QDataStream &stream, const QModbusPdu &pdu)

streampdu を書き込み、ストリームへの参照を返す。

QDebug operator<<(QDebug debug, const QModbusPdu &pdu)

Modbuspdudebug ストリームに書き込みます。

© 2025 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.