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 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 as QtOpcUa
MyClass {
    id: myclass
}
QtOpcUa.Connection {
    connection: myclass.connection
 }
					

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.


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.


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.


信号文档编制

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 readResults parameter is an array of ReadResult entries, containing 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 .

另请参阅 readNodeAttributes () 和 ReadResult .


writeNodeAttributesFinished ( writeResults )

Emitted when the write request started using writeNodeAttributes () is finished. The writeResults parameter is an array of WriteResult entries, containing 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 .

另请参阅 writeNodeAttributes () 和 WriteResult .


方法文档编制

connectToEndpoint ( endpointDescription )

Connects to the endpoint specified with endpointDescription .

另请参阅 EndpointDescription .


disconnectFromEndpoint ()

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 valuesToBeRead parameter must be a 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 () 和 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 valuesToBeWritten parameter must be a 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 () 和 WriteItem .