QOpcUaClient allows interaction with an OPC UA server. 更多...
头: | #include <QOpcUaClient> |
qmake: | QT += opcua |
继承: | QObject |
enum | ClientError { NoError, InvalidUrl, AccessDenied, ConnectionError, UnknownError, UnsupportedAuthenticationInformation } |
enum | ClientState { Disconnected, Connecting, Connected, Closing } |
virtual | ~QOpcUaClient () |
bool | addNode (const QOpcUaAddNodeItem & nodeToAdd ) |
bool | addReference (const QOpcUaAddReferenceItem & referenceToAdd ) |
QOpcUaApplicationIdentity | applicationIdentity () const |
const QOpcUaAuthenticationInformation & | authenticationInformation () const |
QString | backend () const |
void | connectToEndpoint (const QOpcUaEndpointDescription & endpoint ) |
bool | deleteNode (const QString & nodeId , bool deleteTargetReferences = true) |
bool | deleteReference (const QOpcUaDeleteReferenceItem & referenceToDelete ) |
void | disconnectFromEndpoint () |
QOpcUaEndpointDescription | endpoint () const |
QOpcUaClient::ClientError | error () const |
bool | findServers (const QUrl & url , const QStringList & localeIds = QStringList(), const QStringList & serverUris = QStringList()) |
bool | isNamespaceAutoupdateEnabled () const |
QStringList | namespaceArray () const |
int | namespaceAutoupdateInterval () const |
QOpcUaNode * | node (const QString & nodeId ) |
QOpcUaNode * | node (const QOpcUaExpandedNodeId & expandedNodeId ) |
QOpcUaPkiConfiguration | pkiConfiguration () const |
QOpcUaQualifiedName | qualifiedNameFromNamespaceUri (const QString & namespaceUri , const QString & name , bool * ok = nullptr) const |
bool | readNodeAttributes (const QVector<QOpcUaReadItem> & nodesToRead ) |
bool | requestEndpoints (const QUrl & url ) |
QString | resolveExpandedNodeId (const QOpcUaExpandedNodeId & expandedNodeId , bool * ok = nullptr) const |
void | setApplicationIdentity (const QOpcUaApplicationIdentity & identity ) |
void | setAuthenticationInformation (const QOpcUaAuthenticationInformation & authenticationInformation ) |
void | setNamespaceAutoupdate (bool isEnabled ) |
void | setNamespaceAutoupdateInterval (int interval ) |
void | setPkiConfiguration (const QOpcUaPkiConfiguration & config ) |
QOpcUaClient::ClientState | state () const |
QStringList | supportedSecurityPolicies () const |
QVector<QOpcUaUserTokenPolicy::TokenType> | supportedUserTokenTypes () const |
bool | updateNamespaceArray () |
bool | writeNodeAttributes (const QVector<QOpcUaWriteItem> & nodesToWrite ) |
void | addNodeFinished (QOpcUaExpandedNodeId requestedNodeId , QString assignedNodeId , QOpcUa::UaStatusCode statusCode ) |
void | addReferenceFinished (QString sourceNodeId , QString referenceTypeId , QOpcUaExpandedNodeId targetNodeId , bool isForwardReference , QOpcUa::UaStatusCode statusCode ) |
void | connectError (QOpcUaErrorState * errorState ) |
void | connected () |
void | deleteNodeFinished (QString nodeId , QOpcUa::UaStatusCode statusCode ) |
void | deleteReferenceFinished (QString sourceNodeId , QString referenceTypeId , QOpcUaExpandedNodeId targetNodeId , bool isForwardReference , QOpcUa::UaStatusCode statusCode ) |
void | disconnected () |
void | endpointsRequestFinished (QVector<QOpcUaEndpointDescription> endpoints , QOpcUa::UaStatusCode statusCode , QUrl requestUrl ) |
void | errorChanged (QOpcUaClient::ClientError error ) |
void | findServersFinished (QVector<QOpcUaApplicationDescription> servers , QOpcUa::UaStatusCode statusCode , QUrl requestUrl ) |
void | namespaceArrayChanged (QStringList namespaces ) |
void | namespaceArrayUpdated (QStringList namespaces ) |
void | passwordForPrivateKeyRequired (QString keyFilePath , QString * password , bool previousTryWasInvalid ) |
void | readNodeAttributesFinished (QVector<QOpcUaReadResult> 结果 , QOpcUa::UaStatusCode serviceResult ) |
void | stateChanged (QOpcUaClient::ClientState state ) |
void | writeNodeAttributesFinished (QVector<QOpcUaWriteResult> 结果 , QOpcUa::UaStatusCode serviceResult ) |
QOpcUaClient implements basic client capabilities to communicate with OPC UA enabled devices and applications. This includes querying a discovery server for known servers, requesting a list of endpoints from a server, connecting and disconnecting.
After successfully connecting to a server, QOpcUaClient allows getting QOpcUaNode objects which enable further interaction with nodes on the OPC UA server. For operations that concern multiple nodes, QOpcUaClient offers an API which supports reading multiple attributes of multiple nodes in a single request to the server.
QOpcUaClient also keeps a local copy of the server's namespace array which is created after a successful connect. This information can be queried or updated while the connection lasts. The copy of the namespace array is also used for the resolution of expanded node ids and the creation of qualified names from a namespace URI.
For an introduction to nodes and node ids, see QOpcUaNode .
创建 QOpcUaClient 使用 QOpcUaProvider , request a list of endpoints from the server using requestEndpoints 和调用 connectToEndpoint () to connect to one of the available endpoints. After the connection is established, a QOpcUaNode object for the root node is requested.
QOpcUaProvider provider; if (provider.availableBackends().isEmpty()) return; QOpcUaClient *client = provider.createClient(provider.availableBackends()[0]); if (!client) return; // Connect to the stateChanged signal. Compatible slots of QObjects can be used instead of a lambda. QObject::connect(client, &QOpcUaClient::stateChanged, [client](QOpcUaClient::ClientState state) { qDebug() << "Client state changed:" << state; if (state == QOpcUaClient::ClientState::Connected) { QOpcUaNode *node = client->node("ns=0;i=84"); if (node) qDebug() << "A node object has been created"; } }); QObject::connect(client, &QOpcUaClient::endpointsRequestFinished, [client](QVector<QOpcUaEndpointDescription> endpoints) { qDebug() << "Endpoints returned:" << endpoints.count(); if (endpoints.size()) client->connectToEndpoint(endpoints.first()); // Connect to the first endpoint in the list }); client->requestEndpoints(QUrl("opc.tcp://127.0.0.1:4840")); // Request a list of endpoints from the server
This enum type specifies the current error state of the client.
常量 | 值 | 描述 |
---|---|---|
QOpcUaClient::NoError
|
0
|
没有出现错误。 |
QOpcUaClient::InvalidUrl
|
1
|
The url to connect to has been wrongly specified or a connection to this url failed. |
QOpcUaClient::AccessDenied
|
2
|
An attempt to connect to a server using username/password failed due to wrong credentials. |
QOpcUaClient::ConnectionError
|
3
|
连接发生错误。 |
QOpcUaClient::UnknownError
|
4
|
出现未知错误。 |
QOpcUaClient::UnsupportedAuthenticationInformation
|
5
|
The given type or data of authentication information is not supported. |
This enum type specifies the connection state of the client.
常量 | 值 | 描述 |
---|---|---|
QOpcUaClient::Disconnected
|
0
|
The client is not connected to a server. |
QOpcUaClient::Connecting
|
1
|
The client is currently connecting to a server. |
QOpcUaClient::Connected
|
2
|
The client is connected to a server. |
QOpcUaClient::Closing
|
3
|
The client has been connected and requests a disconnect from the server. |
Specifies the current error state of the client.
访问函数:
QOpcUaClient::ClientError | error () const |
通知程序信号:
void | errorChanged (QOpcUaClient::ClientError error ) |
Specifies the current connection state of the client.
访问函数:
QOpcUaClient::ClientState | state () const |
通知程序信号:
void | stateChanged (QOpcUaClient::ClientState state ) |
[signal]
void
QOpcUaClient::
addNodeFinished
(
QOpcUaExpandedNodeId
requestedNodeId
,
QString
assignedNodeId
,
QOpcUa::UaStatusCode
statusCode
)
This signal is emitted after an addNode () operation has finished. requestedNodeId is the requested node id from the addNode () call, assignedNodeId is the node id the server has assigned to the new node. statusCode contains the result of the operation. If the result is Bad , assignedNodeId is empty and no node has been added to the server's address space.
[signal]
void
QOpcUaClient::
addReferenceFinished
(
QString
sourceNodeId
,
QString
referenceTypeId
,
QOpcUaExpandedNodeId
targetNodeId
,
bool
isForwardReference
,
QOpcUa::UaStatusCode
statusCode
)
This signal is emitted after an addReference () operation has finished. sourceNodeId , referenceTypeId , targetNodeId and isForwardReference are the values from the addReference () 调用。 statusCode contains the result of the operation.
[signal]
void
QOpcUaClient::
connectError
(
QOpcUaErrorState
*
errorState
)
This signal is emitted when an error happended during connection establishment. The parameter errorState contains information about the error.
In case of client side errors, these can be ignored by calling QOpcUaErrorState::setIgnoreError on the object.
During execution of a slot connected to this signal the backend is stopped and waits for all slots to return. This allows to pop up a user dialog to ask the enduser for example if to trust an unknown certificate before the backend continues.
This function was introduced in QtOpcUa 5.13.
[signal]
void
QOpcUaClient::
connected
()
This signal is emitted when a connection has been established.
[signal]
void
QOpcUaClient::
deleteNodeFinished
(
QString
nodeId
,
QOpcUa::UaStatusCode
statusCode
)
This signal is emitted after a deleteNode () operation has finished. nodeId is the node id from the deleteNode () 调用。 statusCode contains the result of the operation.
[signal]
void
QOpcUaClient::
deleteReferenceFinished
(
QString
sourceNodeId
,
QString
referenceTypeId
,
QOpcUaExpandedNodeId
targetNodeId
,
bool
isForwardReference
,
QOpcUa::UaStatusCode
statusCode
)
This signal is emitted after a deleteReference () operation has finished. sourceNodeId , referenceTypeId , targetNodeId and isForwardReference are the values from the deleteReference () 调用。 statusCode contains the result of the operation.
[signal]
void
QOpcUaClient::
disconnected
()
This signal is emitted when a connection has been closed following to a close request.
[signal]
void
QOpcUaClient::
endpointsRequestFinished
(
QVector
<
QOpcUaEndpointDescription
>
endpoints
,
QOpcUa::UaStatusCode
statusCode
,
QUrl
requestUrl
)
This signal is emitted after a requestEndpoints () operation has finished. statusCode contains the result of the operation. If the result is Good , endpoints contains the descriptions of all endpoints that are available on the server. requestUrl contains the URL that was used in the requestEndpoints () 调用。
[signal]
void
QOpcUaClient::
findServersFinished
(
QVector
<
QOpcUaApplicationDescription
>
servers
,
QOpcUa::UaStatusCode
statusCode
,
QUrl
requestUrl
)
This signal is emitted after a findServers () operation has finished. statusCode contains the result of the operation. If the result is Good , servers contains the application descriptions of all servers known to the queried server that matched the filter criteria. requestUrl contains the URL that was used in the findServers () 调用。
[signal]
void
QOpcUaClient::
namespaceArrayChanged
(
QStringList
namespaces
)
This signal is emitted after the namespace array has changed. namespaces contains the content of the server's namespace table. The index of an entry in namespaces corresponds to the namespace index used in the node id.
另请参阅 namespaceArrayUpdated () 和 updateNamespaceArray ().
[signal]
void
QOpcUaClient::
namespaceArrayUpdated
(
QStringList
namespaces
)
This signal is emitted after an updateNamespaceArray operation has finished. namespaces contains the content of the server's namespace table. The index of an entry in namespaces corresponds to the namespace index used in the node id.
If the namespace array content stays the same after the update this signal is emitted nevertheless.
另请参阅 namespaceArrayChanged () 和 updateNamespaceArray ().
[signal]
void
QOpcUaClient::
passwordForPrivateKeyRequired
(
QString
keyFilePath
,
QString
*
password
,
bool
previousTryWasInvalid
)
This signal is emitted when a password for an encrypted private key is required. The parameter keyFilePath contains the file path to key which is used. The parameter previousTryWasInvalid is true if a previous try to decrypt the key failed (aka invalid pasword). The parameter password points to a QString that has to be filled with the actual password for the key. In case the previous try failed it contains the previously used password.
During execution of a slot connected to this signal the backend is stopped and waits for all slots to return. This allows to pop up a user dialog to ask the enduser for the password.
This function was introduced in QtOpcUa 5.13.
[signal]
void
QOpcUaClient::
readNodeAttributesFinished
(
QVector
<
QOpcUaReadResult
>
结果
,
QOpcUa::UaStatusCode
serviceResult
)
This signal is emitted after a readNodeAttributes () operation has finished.
The elements in 结果 have the same order as the elements in the request. For each requested element, there is a value together with timestamps and the status code in 结果 . serviceResult contains the status code from the OPC UA Read service.
另请参阅 readNodeAttributes (), QOpcUaReadResult ,和 QOpcUaReadItem .
[signal]
void
QOpcUaClient::
writeNodeAttributesFinished
(
QVector
<
QOpcUaWriteResult
>
结果
,
QOpcUa::UaStatusCode
serviceResult
)
This signal is emitted after a writeNodeAttributes () operation has finished.
The elements in 结果 have the same order as the elements in the write request. They contain the value, timestamps and status code received from the server as well as the node id, attribute and index range from the write item. This facilitates matching the result with the request.
serviceResult is the status code from the the OPC UA Write service. If serviceResult 不是 Good , the entries in 结果 also have an invalid status code and must not be used.
另请参阅 writeNodeAttributes () 和 QOpcUaWriteResult .
[虚拟]
QOpcUaClient::
~QOpcUaClient
()
销毁 QOpcUaClient 实例。
Adds the node described by nodeToAdd on the server.
返回
true
if the asynchronous call has been successfully dispatched.
The success of the operation is returned in the addNodeFinished () 信号。
The following example code adds new a Variable node on the server:
QOpcUaNodeCreationAttributes attributes; attributes.setDisplayName(QOpcUaLocalizedText("en", "My new Variable node")); attributes.setDescription(QOpcUaLocalizedText("en", "A node which has been added at runtime")); attributes.setValue(23.0, QOpcUa::Types::Double); attributes.setDataTypeId(QOpcUa::ns0ID(QOpcUa::NodeIds::Namespace0::Double)); attributes.setValueRank(-2); // Scalar or array attributes.setAccessLevel(QOpcUa::AccessLevelBit::CurrentRead); attributes.setUserAccessLevel(QOpcUa::AccessLevelBit::CurrentRead); QOpcUaAddNodeItem item; item.setParentNodeId(QOpcUaExpandedNodeId("ns=3;s=TestFolder")); item.setReferenceTypeId(QOpcUa::nodeIdFromReferenceType(QOpcUa::ReferenceTypeId::Organizes)); item.setRequestedNewNodeId(QOpcUaExpandedNodeId("ns=3;s=MyNewVariableNode")); item.setBrowseName(QOpcUaQualifiedName(3, "MyNewVariableNode")); item.setNodeClass(QOpcUa::NodeClass::Variable); item.setNodeAttributes(attributes); m_client->addNode(item);
另请参阅 deleteNode (), addNodeFinished (),和 QOpcUaAddNodeItem .
Adds the reference described by referenceToAdd to the server.
返回
true
if the asynchronous call has been successfully dispatched.
The success of the operation is returned in the addReferenceFinished () 信号。
The following example code adds a reference to a node to the "Objects" folder:
QOpcUaAddReferenceItem item; item.setSourceNodeId(QOpcUa::namespace0Id(QOpcUa::NodeIds::Namespace0::ObjectsFolder)); item.setReferenceTypeId(QOpcUa::nodeIdFromInteger(0, static_cast<quint32>(QOpcUa::ReferenceTypeId::Organizes))); item.setIsForwardReference(true); item.setTargetNodeId(QOpcUaExpandedNodeId("ns=3;s=MyNewVariableNode")); item.setTargetNodeClass(QOpcUa::NodeClass::Variable); m_client->addReference(item);
另请参阅 deleteReference (), addReferenceFinished (),和 QOpcUaAddReferenceItem .
Returns the application identity of this QOpcUaClient 实例。
This function was introduced in QtOpcUa 5.13.
另请参阅 setApplicationIdentity ().
Returns the current authentication information.
另请参阅 setAuthenticationInformation ().
Returns the name of the backend used by this instance of QOpcUaClient , e.g. "open62541".
Connects to the OPC UA endpoint given in endpoint .
QEndpointDescription endpointDescription; ... client->connectToEndpoint(endpointDescription);
A list of available endpoints is usually obtained by calling QOpcUaClient::requestEndpoints ().
If the endpoint requires username authentication, at least a user name must be set in QOpcUaAuthenticationInformation . Calling this function before setting an authentication information will use the anonymous authentication.
QOpcUaAuthenticationInformation authInfo; authInfo.setUsernameAuthentication("user", "password"); client->setAuthenticationInformation(authInfo);
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
This function was introduced in QtOpcUa 5.13.
另请参阅 setAuthenticationInformation () 和 QOpcUaEndpointDescription .
Deletes the node with node id
nodeId
from the server. If
deleteTargetReferences
is
false
, only the references with source node
nodeId
are deleted. If
deleteTargetReferences
is
true
, references with
nodeId
as target are deleted too.
返回
true
if the asynchronous call has been successfully dispatched.
The success of the operation is returned in the deleteNodeFinished () 信号。
The following example code deletes a node and all references to it from the server:
m_client->deleteNode(QOpcUaExpandedNodeId("ns=3;s=MyNewVariableNode"), true);
另请参阅 addNode () 和 deleteNodeFinished ().
Deletes the reference described by referenceToDelete from the server.
返回
true
if the asynchronous call has been successfully dispatched.
The success of the operation is returned in the deleteReferenceFinished () 信号。
The following example code deletes a reference to a node from the "Objects" folder:
QOpcUaDeleteReferenceItem item; item.setSourceNodeId(QOpcUa::namespace0Id(QOpcUa::NodeIds::Namespace0::ObjectsFolder)); item.setReferenceTypeId(QOpcUa::nodeIdFromInteger(0, static_cast<quint32>(QOpcUa::ReferenceTypeId::Organizes))); item.setIsForwardReference(true); item.setTargetNodeId(QOpcUaExpandedNodeId("ns=3;s=MyNewVariableNode")); item.setDeleteBidirectional(true); m_client->deleteReference(item);
另请参阅 addReference (), deleteReferenceFinished (),和 QOpcUaDeleteReferenceItem .
Disconnects from the server.
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
另请参阅 connectToEndpoint ().
Returns the description of the endpoint the client is currently connected to or was last connected to.
Returns the current error state of the client.
注意: getter 函数对于特性 error。
Starts an asynchronous FindServers request to read a list of known servers from a server or discovery server at
url
。返回
true
if the asynchronous call has been successfully dispatched.
localeIds can be used to select the language of the application names returned by the request. The format is specified in OPC-UA part 3, 8.4, for example "en" for English, or "de-DE" for German (Germany). If more than one locale ID is specified, the server uses the first match. If there is no match or localeIds is empty, a default locale is chosen by the server.
serverUris may be used to restrict the results to servers with a matching applicationUri in their application description. For example, finding the current URL of the server with the applicationUri "MyPLC", the following call can be used:
client->findServers(discoveryServerUrl, QStringList(), QStringList({"MyPLC"}));
The results are returned in the findServersFinished () 信号。
Returns whether autoupdate of the namespace array is enabled.
Returns the cached value of the namespace array.
The value is only valid after the namespaceArrayUpdated () 信号已发射。
另请参阅 updateNamespaceArray () 和 namespaceArrayUpdated ().
Returns the current revised update inverval of the namespace array.
另请参阅 setNamespaceAutoupdateInterval (int interval).
返回 QOpcUaNode object associated with the OPC UA node identified by nodeId . The caller becomes owner of the node object.
If the client is not connected,
nullptr
is returned. The backends may also return
nullptr
for other error cases (for example for a malformed node id).
返回 QOpcUaNode object associated with the OPC UA node identified by expandedNodeId . The caller becomes owner of the node object.
If the node is not on the currently connected server, the namespace can't be resolved, the node id is malformed or the client is not connected,
nullptr
被返回。
另请参阅 updateNamespaceArray ().
Returns the application's PKI configuration of this QOpcUaClient 实例。
This function was introduced in QtOpcUa 5.13.
另请参阅 setPkiConfiguration ().
Attempts to create a qualified name from namespaceUri and the name string name . Returns the resulting qualified name. An empty qualified name is returned if namespaceUri can't be resolved.
ok
will be set to
true
if the namespace URI resolution has been successful. If the namespace URI could not be resolved,
ok
will be set to
false
.
Starts a read of multiple attributes on different nodes. The node id, the attribute and an index range can be specified for every entry in nodesToRead .
Returns true if the asynchronous request has been successfully dispatched. The results are returned in the readNodeAttributesFinished () 信号。
This read function offers an alternative way to read attributes of nodes which can be used for scenarios where the values of a large number of node attributes on different nodes must be read without requiring the other features of the QOpcUaNode based API like monitoring for value changes. All read items in the request are sent to the server in a single request and are answered in a single response which generates a single readNodeAttributesFinished () signal. This reduces the network overhead and the number of signal slot connections if many different nodes are involved.
In the following example, the display name attribute and the two index ranges "0:2" and "5:7" of the value attribute of the same node and the entire value attribute of a second node are read using a single service call:
QVector<QOpcUaReadItem> request; request.push_back(QOpcUaReadItem("ns=1;s=MyArrayNode", QOpcUa::NodeAttribute::DisplayName)); request.push_back(QOpcUaReadItem("ns=1;s=MyArrayNode", QOpcUa::NodeAttribute::Value, "0:2")); request.push_back(QOpcUaReadItem("ns=1;s=MyArrayNode", QOpcUa::NodeAttribute::Value, "5:7")); request.push_back(QOpcUaReadItem("ns=1;s=MyScalarNode)); m_client->readNodeAttributes(request);
另请参阅 QOpcUaReadItem and readNodeAttributesFinished ().
Starts an asynchronous
GetEndpoints
request to read a list of available endpoints from the server at
url
。返回
true
if the asynchronous call has been successfully dispatched.
The endpoint information is returned in the endpointsRequestFinished () 信号。
Attempts to resolve expandedNodeId to a node id string with numeric namespace index. Returns the node id string if the conversion was successful.
An empty string is returned if the namespace index can't be resolved or if the identifier part of the expanded node id is malformed.
ok
will be set to
true
if the conversion has been successful. If the expanded node id could not be resolved,
ok
will be set to
false
.
Sets the application identity for this QOpcUaClient instance to identity .
This function was introduced in QtOpcUa 5.13.
另请参阅 applicationIdentity ().
Sets the authentication information of this client to authenticationInformation .
另请参阅 authenticationInformation () 和 connectToEndpoint ().
Enables automatic update of the namespace table.
Enabling this will keep the local copy of the namespace table updated automatically. namespaceArrayUpdated will be emitted when the array changed. isEnabled determines if autoupdate is being enabled or disabled.
A subscription will be made on the node on the server to keep track of changes. In case a server does not support subscriptions this will not work and
isNamespaceAutoupdateEnabled
返回
false
.
另请参阅 namespaceArray () 和 namespaceArrayUpdated ().
Sets the interval for the namespace table subscription.
The subscription may be revised by the server.
interval determines the interval to check for changes in milliseconds. The default is once per second.
另请参阅 namespaceAutoupdateInterval () 和 QOpcUaClient::setNamespaceAutoupdate (bool isEnabled).
Sets the application PKI configuration for this QOpcUaClient instance to config .
This function was introduced in QtOpcUa 5.13.
另请参阅 pkiConfiguration ().
Returns the security policies supported by the used backend.
This function is currently available as a Technology Preview, and therefore the API and functionality provided by the function may be subject to change at any time without prior notice.
This function was introduced in QtOpcUa 5.14.
Returns the user token types supported by the used backend.
This function is currently available as a Technology Preview, and therefore the API and functionality provided by the function may be subject to change at any time without prior notice.
This function was introduced in QtOpcUa 5.14.
另请参阅 QOpcUaUserTokenPolicy::TokenType .
Requests an update of the namespace array from the server. Returns
true
if the operation has been successfully dispatched.
The namespaceArrayUpdated () signal is emitted after the operation is finished.
另请参阅 namespaceArray () 和 namespaceArrayUpdated ().
Starts a write for multiple attributes on different nodes. The node id, the attribute, the value, the value type and an index range can be specified for every entry in nodesToWrite .
返回
true
if the asynchronous request has been successfully dispatched. The results are returned in the
writeNodeAttributesFinished
() 信号。
This write function offers an alternative way to write attributes of nodes which can be used for scenarios where the values of a large number of node attributes on different nodes must be written without requiring the other features of the QOpcUaNode based API like monitoring for value changes. All write items in the request are sent to the server in a single request and are answered in a single response which generates a single writeNodeAttributesFinished () signal. This reduces the network overhead and the number of signal slot connections if many different nodes are involved.
In the following example, the Values attributes of two different nodes are written in one call. The second node has an array value of which only the first two elements are overwritten:
QVector<QOpcUaWriteItem> request; request.append(QOpcUaWriteItem("ns=2;s=Demo.Static.Scalar.Double", QOpcUa::NodeAttribute::Value, 23.0, QOpcUa::Types::Double)); request.append(QOpcUaWriteItem("ns=2;s=Demo.Static.Arrays.UInt32", QOpcUa::NodeAttribute::Value, QVariantList({0, 1, 2}), QOpcUa::Types::UInt32, "0:2")); m_client->writeNodeAttributes(request);
另请参阅 QOpcUaWriteItem and writeNodeAttributesFinished ().