QOpcUaGenericStructHandler Class
サーバーのデータ型を読み込み、拡張オブジェクトから/拡張オブジェクトへの汎用構造体をデコード/エンコードします。詳細...
ヘッダー | #include <QOpcUaGenericStructHandler> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS OpcUa) target_link_libraries(mytarget PRIVATE Qt6::OpcUa) |
qmake: | QT += opcua |
以来: | Qt 6.7 |
継承: | QObject |
パブリックタイプ
enum class | DataTypeKind { Unknown, Struct, Enum, Other } |
パブリック関数
QOpcUaGenericStructHandler(QOpcUaClient *client, QObject *parent = nullptr) | |
bool | addCustomEnumDefinition(const QOpcUaEnumDefinition &definition, const QString &typeId, const QString &name, QOpcUa::IsAbstract isAbstract = QOpcUa::IsAbstract::NotAbstract) |
bool | addCustomStructureDefinition(const QOpcUaStructureDefinition &definition, const QString &typeId, const QString &name, QOpcUa::IsAbstract isAbstract = QOpcUa::IsAbstract::NotAbstract) |
QOpcUaGenericStructValue | createGenericStructValueForTypeId(const QString &typeId) |
QOpcUaGenericStructHandler::DataTypeKind | dataTypeKindForTypeId(const QString &id) const |
std::optional<QOpcUaGenericStructValue> | decode(const QOpcUaExtensionObject &extensionObject) const |
std::optional<QOpcUaExtensionObject> | encode(const QOpcUaGenericStructValue &value) |
QOpcUaEnumDefinition | enumDefinitionForTypeId(const QString &id) const |
bool | initialize() |
(since 6.7) bool | initialized() const |
bool | isAbstractTypeId(const QString &id) const |
QOpcUaStructureDefinition | structureDefinitionForBinaryEncodingId(const QString &id) const |
QOpcUaStructureDefinition | structureDefinitionForTypeId(const QString &id) const |
QString | typeIdForBinaryEncodingId(const QString &id) const |
QString | typeNameForBinaryEncodingId(const QString &id) const |
QString | typeNameForTypeId(const QString &id) const |
シグナル
void | initializedChanged(bool initialized) |
詳細説明
OPC UAで使用されているバイナリデータエンコーディングは、小さなメッセージサイズを念頭に設計されており、データの構造に関する情報を含んでいません。このため、デコーダはエンコードされたデータの構造を事前に知っていなければ、データバッファをデコードすることができません。
OPC UA 1.04以降、DataTypeノードクラスのノードは、構造化型のフィールドとenum値の名前へのマッピングに関する情報を含むDataTypeDefinition属性を持つことができます。組み込み型のデコード方法に関する知識と合わせて、これによりクライアントは外部の知識に頼ることなく、一般的なカスタム構造化型をデコードすることができます。
QOpcUaGenericStructHandler は、BaseDataType から始まる HasSubtype 参照をたどってサーバーの型階層を走査し、ノードの DataTypeDefinition 属性を読み取ります。
DataTypeDefinition属性にQOpcUaStructureDefinition 値が存在する構造化型については、それを含む拡張オブジェクトの自動デコードが可能です。組み込み型または C++ データ・クラスが存在する型を持つフィールドは、対応するQt OPC UA 型にデシリアライズされ、その他の汎用構造体はネストされたQOpcUaGenericStructValue にシリアライズされます。ネストされたジェネリック構造体の値はすべて、サーバー内にQOpcUaStructureDefinition がなければデコードに失敗します。
カスタム構造体をエンコードする場合も同じ条件が適用されます。
カスタム構造体のデコード例
QOpcUaGenericStructHandlerhandler(opcuaClient); handler.initialize();QObject::connect(&handler, &)QOpcUaGenericStructHandler::initializedChanged, [opcuaClient, &handler](boolinitialized) {if(!initialized)return;autonode= opcuaClient->node("ns=4;i=3003");// open62541-testserverのカスタム構造体のテストノード node->readValueAttribute(); QObject::connect(node, &)QOpcUaNode::attributeRead, [node, &handler](QOpcUa::NodeAttributes attr) {if(!attr.testFlag(QOpcUa::NodeAttribute::Value)|| node->valueAttributeError()!= QOpcUa::UaStatusCode::Good)return;autoextObj= node->valueAttribute().value<QOpcUaExtensionObject>(); qDebug() << "Got object of type" << handler.typeNameForBinaryEncodingId(extObj.encodingTypeId()); const autoresult=handler.decode(extObj);if(!result)return; qDebug() << *result; }); });
カスタム構造体をエンコードする例:
QOpcUaGenericStructHandler handler(opcuaClient); handler.initialize(); QObject::connect(&handler, &QOpcUaGenericStructHandler::initializedChanged, [opcuaClient, &handler](bool initialized) { if (!initialized) return; QOpcUaGenericStructValue value = handler.createGenericStructValueForTypeId("ns=4;i=3006"); value.fieldsRef()["MandatoryMember"] = 23.0; value.fieldsRef()["OptionalMember"] = 42.0; const auto ext = handler.encode(value); if (!ext) return; // Use the extension object to write a node's value attribute, in a method parameter, etc... });
メンバ型ドキュメント
enum class QOpcUaGenericStructHandler::DataTypeKind
この列挙型は、データ型ノードのデータ型の種類を指定する。
定数 | 値 | 説明 |
---|---|---|
QOpcUaGenericStructHandler::DataTypeKind::Unknown | 0 | 型ノード ID が不明。 |
QOpcUaGenericStructHandler::DataTypeKind::Struct | 1 | 型ノード ID は構造化型に属します。 |
QOpcUaGenericStructHandler::DataTypeKind::Enum | 2 | 型ノード ID は列挙型に属しています。 |
QOpcUaGenericStructHandler::DataTypeKind::Other | 3 | 型ノード ID が struct 型でも enum 型でもない型(他の組み込み型またはそのサブタイプ)に属している。 |
メンバ関数ドキュメント
[explicit]
QOpcUaGenericStructHandler::QOpcUaGenericStructHandler(QOpcUaClient *client, QObject *parent = nullptr)
client の汎用構造体ハンドラを構築する。
bool QOpcUaGenericStructHandler::addCustomEnumDefinition(const QOpcUaEnumDefinition &definition, const QString &typeId, const QString &name, QOpcUa::IsAbstract isAbstract = QOpcUa::IsAbstract::NotAbstract)
カスタム列挙型定義definition を既知の型に追加します。これは、サーバーがStructureDefinitionを公開していないカスタム構造をサポートするために使用できます。パラメータdefinition 、typeId 、name は、適切なデコードとエンコードに必要です。isAbstract がセットされていると、その型はエンコードもデコードもできません。
列挙型定義が正常に追加された場合はtrue
を返します。
bool QOpcUaGenericStructHandler::addCustomStructureDefinition(const QOpcUaStructureDefinition &definition, const QString &typeId, const QString &name, QOpcUa::IsAbstract isAbstract = QOpcUa::IsAbstract::NotAbstract)
カスタム構造定義definition を既知の型に追加します。これは、サーバーがStructureDefinitionを公開していないカスタム構造をサポートするために使用できます。パラメータdefinition 、typeId 、name は、適切なデコードとエンコードに必要です。isAbstract がセットされている場合、その型をエンコードおよびデコードすることはできません。
構造体定義が正常に追加された場合はtrue
を返します。
QOpcUaGenericStructValue QOpcUaGenericStructHandler::createGenericStructValueForTypeId(const QString &typeId)
typeId に対応する構造体定義、型 ID、および型名で事前入力された汎用構造体値を返します。すべての必須フィールドには、無効なプレースホルダQVariant が挿入されます。
QOpcUaGenericStructHandler::DataTypeKind QOpcUaGenericStructHandler::dataTypeKindForTypeId(const QString &id) const
型ノード IDid のデータ型の種類を返す。
std::optional<QOpcUaGenericStructValue> QOpcUaGenericStructHandler::decode(const QOpcUaExtensionObject &extensionObject) const
extensionObject QOpcUaGenericStructValueデコーダが失敗すると、std::nullopt
が返される。
std::optional<QOpcUaExtensionObject> QOpcUaGenericStructHandler::encode(const QOpcUaGenericStructValue &value)
QOpcUaExtensionObject としてエンコードされたvalue を返し、エンコードできなかった場合はstd::nullopt
を返す。
QOpcUaEnumDefinition QOpcUaGenericStructHandler::enumDefinitionForTypeId(const QString &id) const
型ノード IDid のQOpcUaEnumDefinition を返す。ノード ID が不明な場合、または列挙型に属さない場合は、デフォルトの構築値が返されます。
bool QOpcUaGenericStructHandler::initialize()
データ型の階層走査を開始する。成功または失敗はinitializedChanged シグナルで報告される。
操作を開始できない場合はfalse
を返す。
[since 6.7]
bool QOpcUaGenericStructHandler::initialized() const
ジェネリック構造体ハンドラが初期化されている場合、true
を返します。
この関数は Qt 6.7 で導入されました。
[signal]
void QOpcUaGenericStructHandler::initializedChanged(bool initialized)
このシグナルは、初期化処理が終了したときに発せられる。initialized は、初期化が成功したかどうかを示す。
bool QOpcUaGenericStructHandler::isAbstractTypeId(const QString &id) const
id で記述されたデータ型が抽象型であれば真を返す。
QOpcUaStructureDefinition QOpcUaGenericStructHandler::structureDefinitionForBinaryEncodingId(const QString &id) const
バイナリ符号化ノード IDid のQOpcUaStructureDefinition を返す。ノード ID が不明な場合、または構造体タイプに属さない場合は、デフォルトの構築された値が返されます。
QOpcUaStructureDefinition QOpcUaGenericStructHandler::structureDefinitionForTypeId(const QString &id) const
型ノード IDid のQOpcUaStructureDefinition を返す。ノード ID が不明な場合、または構造体タイプに属さない場合は、デフォルトの構築値が返されます。
QString QOpcUaGenericStructHandler::typeIdForBinaryEncodingId(const QString &id) const
バイナリエンコーディング IDid に関連付けられたタイプノード ID を返します。
QString QOpcUaGenericStructHandler::typeNameForBinaryEncodingId(const QString &id) const
バイナリ符号化ノード IDid に属する型名を返す。ノード ID が不明な場合、または構造体タイプに属さない場合は、空の文字列が返されます。
QString QOpcUaGenericStructHandler::typeNameForTypeId(const QString &id) const
型ノード IDid で識別されるデータ型ノードに属する型名を返す。ノード ID が不明な場合は、空の文字列が返されます。
© 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.