Connection QML Type

Connects to a server. 更多...

import 語句: import QtOpcUa.
Since: QtOpcUa 5.12

特性

信號

方法

詳細描述

The main API uses backends to make connections. You have to set the backend before any connection attempt.

import QtOpcUa 5.13 as QtOpcUa
QtOpcUa.Connection {
    backend: "open62541"
}
Component.onCompleted: {
    connection.connectToEndpoint("opc.tcp://127.0.0.1:43344");
}
					

特性文檔編製

authenticationInformation : AuthenticationInformation

Set the authentication information to this connection. The authentication information has to be set before calling connectToEndpoint . If no authentication information is set, the anonymous mode will be used. It has no effect on the current connection. If the client is disconnected and then reconnected, the new credentials are used. Reading and writing this property before a backend is set, writes are ignored and reads return and invalid AuthenticationInformation .

[read-only] availableBackends : stringlist

Returns the names of all available backends as a list. These are used to select a backend when connecting.

另請參閱 Connection::backend .

backend : string

Set the backend to use for a connection to the server. Has to be set before any connection attempt.

另請參閱 Connection::availableBackends .

[read-only] connected : bool

Status of the connection. true when there is a connection, otherwise false .

connection : QOpcUaClient

This property is used only to inject a connection from C++. In case of complex setup of a connection you can use C++ to handle all the details. After the connection is established it can be handed to QML using this property. Ownership of the client is transferred to 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 *);
					

Emitting the signal connectionChanged when the client setup is completed, the QML code below will use the connection.

import QtOpcUa 5.13 as QtOpcUa
MyClass {
    id: myclass
}
QtOpcUa.Connection {
    connection: myclass.connection
 }
					

該特性在 Qt 5.13 引入。

currentEndpoint : QOpcUaEndpointDescription

An endpoint description of the server to which the connection is connected to. When the connection is not established, an empty endpoint description is returned.

該特性在 Qt 5.13 引入。

defaultConnection : bool

Makes this the default connection. Usually each node needs to be given a connection to use. If this property is set to true , this connection will be used in all cases where a node has no connection set. Already established connections are not affected. If defaultConnection 被設為 true on multiple connection the last one is used.

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

另請參閱 Node .

[read-only] namespaces : stringlist

List of strings of all namespace URIs registered on the connected server.

supportedSecurityPolicies : stringlist

A list of strings containing the supported security policies

This property is currently available as a Technology Preview, and therefore the API and functionality provided may be subject to change at any time without prior notice.

該特性在 Qt 5.13 引入。

supportedUserTokenTypes : array [ tokenTypes ]

An array of user token policy types of all supported user token types.

This property is currently available as a Technology Preview, and therefore the API and functionality provided may be subject to change at any time without prior notice.

該特性在 Qt 5.13 引入。

信號文檔編製

nodeChanged ()

Emitted when the underlying node has changed. This happens when the namespace or identifier of the NodeId 改變。

注意: 相應處理程序是 onNodeChanged .

readNodeAttributesFinished ( readResults )

Emitted when the read request, started using readNodeAttributes() , is finished. The parameter of this signal is an array of ReadResult , which contains the values requested from the server.

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

注意: 相應處理程序是 onReadNodeAttributesFinished .

This signal was introduced in Qt 5.13.

另請參閱 readNodeAttributes() and ReadResult .

writeNodeAttributesFinished ( writeResults )

Emitted when the write request started using writeNodeAttributes() is finished. The parameter of this signal is an array of WriteResult , which contains the values requested from the server.

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 .

This signal was introduced in Qt 5.13.

另請參閱 writeNodeAttributes() and WriteResult .

方法文檔編製

connectToEndpoint ( endpointDescription )

Connects to the given endpoint.

另請參閱 EndpointDescription .

disconnectFromEndpoint ( url )

Disconnects an established connection.

readNodeAttributes ( valuesToBeRead )

This function is used to read multiple values from a server in one go. Returns true if the read request was dispatched successfully.

The values to be read have to be passed as JavaScript array of ReadItem .

// 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
}
					

The result of the read request are provided by the signal readNodeAttributesFinished() .

另請參閱 readNodeAttributesFinished() and ReadItem .

writeNodeAttributes ( valuesToBeWritten )

This function is used to write multiple values to a server in one go. Returns true if the write request was dispatched successfully.

The values to be written have to be passed as JavaScript array of WriteItem .

// 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
}
					

The result of the write request are provided by the signal Connection::writeNodeAttributesFinished() .

另請參閱 Connection::writeNodeAttributesFinished() and WriteItem .