Connection QML Type

サーバーに接続します。詳細...

Import Statement: import QtOpcUa
Since: QtOpcUa 5.12

プロパティ

信号

方法

詳細説明

メインAPIはバックエンドを使って接続を行う。接続を試みる前に、バックエンドを設定する必要があります。

import QtOpcUa as QtOpcUa

QtOpcUa.Connection {
    backend: "open62541"
}

Component.onCompleted: {
    connection.connectToEndpoint("opc.tcp://127.0.0.1:43344");
}

プロパティの説明

authenticationInformation : AuthenticationInformation

この接続に認証情報を設定する。認証情報は、connectToEndpoint をコールする前に設定しておく必要があります。認証情報が設定されていない場合は、匿名モードが使用されます。これは現在の接続には影響しない。クライアントが切断され、その後再接続されると、新しい認証情報が使用される。backend が設定される前にこのプロパティを読み書きすると、書き込みは無視され、読み込みは無効なAuthenticationInformation を返します。


availableBackends : stringlist [read-only]

利用可能なすべてのバックエンド名をリストとして返します。これらは、接続時にバックエンドを選択するために使用されます。

Connection::backendも参照ください


backend : string

サーバへの接続に使用するバックエンドを設定します。接続を試みる前に設定する必要があります。

Connection::availableBackends参照


connected : bool [read-only]

接続の状態。接続がある場合はtrue 、そうでない場合はfalse


connection : QOpcUaClient

このプロパティは、C++ から接続を注入するためだけに使用されます。接続の設定が複雑な場合は、C++ を使用してすべての詳細を処理できます。接続が確立した後、このプロパティを使って QML に接続を渡すことができます。クライアントの所有権はQMLに移ります。

class MyClass : public QObject {
    Q_OBJECT
    Q_PROPERTY(QOpcUaClient* connection READ connection NOTIFY connectionChanged)

public:
    MyClass (QObject* parent = nullptr);
    QOpcUaClient *connection() const;

signals:
    void connectionChanged(QOpcUaClient *);

クライアントのセットアップが完了するとconnectionChanged というシグナルを発し、以下の QML コードがその接続を使用します。

import QtOpcUa as QtOpcUa

MyClass {
    id: myclass
}

QtOpcUa.Connection {
    connection: myclass.connection
 }

currentEndpoint : QOpcUaEndpointDescription

接続先サーバのエンドポイント記述。接続が確立していない場合は、空のエンドポイント記述が返されます。


defaultConnection : bool

これをデフォルトの接続とします。通常は、各ノードに使用する接続を指定する必要があります。このプロパティをtrue に設定すると、ノードに接続が設定されていない場合はすべて、この接続が使用されます。すでに確立されている接続は影響を受けません。複数の接続でdefaultConnectiontrue に設定すると、最後の接続が使用されます。

QtOpcUa.Connection {
    ...
    defaultConnection: true
    ...
}

Nodeも参照してください


namespaces : stringlist [read-only]

接続サーバに登録されているすべての名前空間 URI の文字列のリスト。


supportedSecurityPolicies : stringlist

サポートされているセキュリティ・ポリシーを含む文字列のリスト。

このプロパティは現在技術プレビューとして提供されているため、提供される API や機能は事前の通知なしにいつでも変更される可能性があります。


supportedUserTokenTypes : array[tokenTypes]

サポートされるすべてのユーザートークンタイプのユーザートークンポリシータイプの配列。

このプロパティは、現在技術プレビューとして利用可能です。したがって、提供される API および機能は、事前の通知なしにいつでも変更される可能性があります。


シグナル・ドキュメント

nodeChanged()

基礎となるノードが変更されたときに発行されます。これは、NodeId の名前空間または識別子が変更されたときに発生します。

注: 対応するハンドラはonNodeChanged


readNodeAttributesFinished(readResults)

readNodeAttributes() を使用して開始された読み取り要求が終了したときに発行される。readResults パラメータは、サーバーから要求された値を含むReadResult エントリの配列である。

connection.onReadNodeAttributesFinished(results) {
    for (var i = 0; results.length; i++) {
        if (results[i].status.isGood) {
            console.log(results[i].value);
        } else {
            // handle error
        }
    }
}

注: 対応するハンドラはonReadNodeAttributesFinished である。

readNodeAttributes() およびReadResultも参照のこと


writeNodeAttributesFinished(writeResults)

writeNodeAttributes() を使用して開始した書き込み要求が終了したときに発行される。writeResults パラメータは、サーバーから要求された値を含む、WriteResult エントリの配列である。

for (var i = 0; i < writeResults.length; i++) {
    console.log(writeResults[i].nodeId);
    console.log(writeResults[i].namespaceName);
    console.log(writeResults[i].attribute);

    if (writeResults[i].status.isBad) {
        // value was not written
    }
}

注意: 対応するハンドラはonWriteNodeAttributesFinished

writeNodeAttributes() およびWriteResultも参照


メソッドのドキュメント

connectToEndpoint(endpointDescription)

endpointDescription で指定したエンドポイントに接続します。

EndpointDescriptionも参照


disconnectFromEndpoint()

確立された接続を切断します。


readNodeAttributes(valuesToBeRead)

この関数は、サーバから複数の値を一度に読み込むために使用します。読み込み要求が正常にディスパッチされた場合はtrue を返します。

valuesToBeRead パラメータは、ReadItem エントリの JavaScript 配列でなければなりません。

// List of items to read
var readItemList = [];
// Item to be added to the list of items to be read
var readItem;

// Prepare an item to be read

// Create a new read item and fill properties
readItem = QtOpcUa.ReadItem.create();
readItem.ns = "http://qt-project.org";
readItem.nodeId = "s=Demo.Static.Scalar.Double";
readItem.attribute = QtOpcUa.Constants.NodeAttribute.DisplayName;

// Add the prepared item to the list of items to be read
readItemList.push(readItem);

// Add further items
[...]

if (!connection.readNodeAttributes(readItemList)) {
    // handle error
}

読み込みリクエストの結果は、シグナルreadNodeAttributesFinished() で提供されます。

readNodeAttributesFinished() およびReadItemも参照


writeNodeAttributes(valuesToBeWritten)

この関数は、複数の値を一度にサーバに書き込むために使用される。書き込み要求が正常にディスパッチされた場合、true を返します。

valuesToBeWritten パラメータは、WriteItem エントリの JavaScript 配列でなければならない。

// List of items to write
var writeItemList = [];
// Item to be added to the list of items to be written
var writeItem;

// Prepare an item to be written

// Create a new write item and fill properties
writeItem = QtOpcUa.WriteItem.create();
writeItem.ns = "http://qt-project.org";
writeItem.nodeId = "s=Demo.Static.Scalar.Double";
writeItem.attribute = QtOpcUa.Constants.NodeAttribute.Value;
writeItem.value = 32.1;
writeItem.valueType = QtOpcUa.Constants.Double;

// Add the prepared item to the list of items to be written
writeItemList.push(writeItem);

// Add further items
[...]

if (!connection.writeNodeAttributes(writeItemList)) {
    // handle error
}

書き込みリクエストの結果は、シグナルConnection::writeNodeAttributesFinished() によって提供される。

Connection::writeNodeAttributesFinished() およびWriteItemも参照のこと


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