QOpcUaNode#
QOpcUaNode
allows interaction with an OPC UA node. More…
Synopsis#
Functions#
def
attribute
(attribute)def
attributeError
(attribute)def
browse
(request)def
browseChildren
([referenceType=QOpcUa.ReferenceTypeId.HierarchicalReferences[, nodeClassMask=QOpcUa.NodeClass.Undefined]])def
callMethod
(methodNodeId[, args=list()])def
client
()def
disableMonitoring
(attr)def
enableMonitoring
(attr, settings)def
modifyDataChangeFilter
(attr, filter)def
modifyEventFilter
(eventFilter)def
modifyMonitoring
(attr, item, value)def
monitoringStatus
(attr)def
nodeId
()def
readAttributeRange
(attribute, indexRange)def
readAttributes
([attributes=QOpcUaNode.mandatoryBaseAttributes()])def
readHistoryRaw
(startTime, endTime, numValues, returnBounds)def
readValueAttribute
()def
resolveBrowsePath
(path)def
serverTimestamp
(attribute)def
sourceTimestamp
(attribute)def
valueAttribute
()def
valueAttributeError
()def
writeAttribute
(attribute, value[, type=QOpcUa.Types.Undefined])def
writeAttributeRange
(attribute, value, indexRange[, type=QOpcUa.Types.Undefined])def
writeAttributes
(toWrite[, valueAttributeType=QOpcUa.Types.Undefined])def
writeValueAttribute
(value[, type=QOpcUa.Types.Undefined])
Signals#
def
attributeRead
(attributes)def
attributeUpdated
(attr, value)def
attributeWritten
(attribute, statusCode)def
browseFinished
(children, statusCode)def
dataChangeOccurred
(attr, value)def
disableMonitoringFinished
(attr, statusCode)def
enableMonitoringFinished
(attr, statusCode)def
eventOccurred
(eventFields)def
methodCallFinished
(methodNodeId, result, statusCode)def
monitoringStatusChanged
(attr, items, statusCode)def
resolveBrowsePathFinished
(targets, path, statusCode)
Static functions#
def
allBaseAttributes
()def
mandatoryBaseAttributes
()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description#
The node is the basic building block of the OPC UA address space. It has attributes like browse name, value, associated properties and can have references to other nodes in the address space. Nodes are organized in namespaces and have IDs which can e.g. be numeric, a string, a namespace-specific format (opaque) or a globally unique identifier. A node is identified by the namespace ID and the node ID. This identifier is usually given as a string: The identifier of a node residing in namespace 0 and having the numeric identifier 42 results in the string ns=0;i=42
. A node with a string identifier can be addressed via ns=0;s=myStringIdentifier
.
Objects of this type are owned by the user and must be deleted when they are no longer needed. They are valid as long as the QOpcUaClient
which created them exists.
Reading and writing of attributes#
The node attributes are read from the server when readAttributes()
or readAttributeRange()
is called. The results are cached locally and can be retrieved using attribute()
after the attributeRead
signal has been received.
Attributes can be written using writeAttribute()
, writeAttributes()
and writeAttributeRange()
if the user has the necessary rights. Success of the write operation is reported using the attributeWritten
signal.
attributeError()
contains a status code associated with the last read or write operation on the attribute. This is the low level status code returned by the OPC UA service. This status code can be simplified by converting it to a ErrorCategory
using errorCategory()
.
Subscriptions and monitored items#
Subscriptions are a concept in OPC UA which allows receiving of notifications for changes in data or in case of events instead of continuously polling a node for changes. Monitored items define how attributes of a node are watched for changes. They are added to a subscription and any notifications they generate are forwarded to the user via the subscription. The interval of the updates as well as many other options of the monitored items and subscriptions can be configured by the user.
QOpcUaNode
offers an abstraction to interact with subscriptions and monitored items. enableMonitoring()
enables data change notifications for one or more attributes. The dataChangeOccurred
signal contains new values and the local cache is updated. disableMonitoring()
disables the data change notifications. The monitoringStatusChanged
signal notifies about changes of the monitoring status, e. g. after manual enable and disable or a status change on the server.
Event monitoring uses the same API for setup and life cycle management. The EventNotifier
attribute must be monitored using an EventFilter
which selects the required event fields and filters the reported events by user defined criteria. The events are reported in the eventOccurred()
signal as a QVariantList which contains the values of the selected event fields.
Settings of the subscription and monitored item can be modified at runtime using modifyMonitoring()
.
Browsing the address space#
The OPC UA address space consists of nodes connected by references. browseChildren
follows these references in forward direction and returns attributes from all nodes connected to the node behind an instance of QOpcUaNode
in the browseFinished
signal. browse()
is similar to browseChildren()
but offers more options to configure the browse call.
Method calls#
OPC UA specifies methods on the server which can be called by the user. QOpcUaNode
supports this via callMethod
which takes parameters and returns the results of the call in the methodCallFinished
signal.
Resolving browse paths#
To support programming against a type description, OPC UA supports the resolution of a path of browse names starting from a certain node to obtain the node id of the target node. The resolveBrowsePath()
method follows a path starting from the node it was called on and returns the result in the resolveBrowsePathFinished()
signal.
Example#
For connecting the client to a server and getting a QOpcUaNode
object, see QOpcUaClient
.
After the node has been successfully created, the BrowseName of the root node is read from the server:
QOpcUaNode *rootNode; // Created before, see QOpcUaClient documentation. // Connect to the attributeRead signal. Compatible slots of QObjects can be used instead of a lambda. QObject::connect(rootNode, &QOpcUaNode::attributeRead, [rootNode, client](QOpcUa::NodeAttributes attr) { qDebug() << "Signal for attributes:" << attr; if (rootNode->attributeError(QOpcUa::NodeAttribute::BrowseName) != QOpcUa::UaStatusCode::Good) { qDebug() << "Failed to read attribute:" << rootNode->attributeError(QOpcUa::NodeAttribute::BrowseName); client->disconnectFromEndpoint(); } qDebug() << "Browse name:" << rootNode->attribute(QOpcUa::NodeAttribute::BrowseName).value<QOpcUaQualifiedName>().name(); }); rootNode->readAttributes(QOpcUa::NodeAttribute::BrowseName); // Start a read operation for the node's BrowseName attribute.
- class PySide6.QtOpcUa.QOpcUaNode#
- static PySide6.QtOpcUa.QOpcUaNode.allBaseAttributes()#
- Return type:
NodeAttributes
Contains all attributes of the OPC UA base node class.
- PySide6.QtOpcUa.QOpcUaNode.attribute(attribute)#
- Parameters:
attribute –
NodeAttribute
- Return type:
object
Returns the value of the attribute given in attribute
.
The value is only valid after the attributeRead
signal has been emitted. An empty QVariant
is returned if there is no cached value for the attribute.
- PySide6.QtOpcUa.QOpcUaNode.attributeError(attribute)#
- Parameters:
attribute –
NodeAttribute
- Return type:
Returns the error code for the attribute given in attribute
.
The error code is only valid after the attributeRead
or attributeWritten
signal has been emitted.
If there is no entry in the attribute cache, BadNoEntryExists
is returned.
See also
- PySide6.QtOpcUa.QOpcUaNode.attributeRead(attributes)#
- Parameters:
attributes –
NodeAttributes
This signal is emitted after a readAttributes()
or readAttributeRange()
operation has finished. The receiver has to check the status code for the attributes contained in attributes
.
- PySide6.QtOpcUa.QOpcUaNode.attributeUpdated(attr, value)#
- Parameters:
attr –
NodeAttribute
value – object
This signal is emitted after the value in the attribute cache has been updated by a data change notification from the server, a read or a write operation. value
contains the new value for the node attribute attr
.
- PySide6.QtOpcUa.QOpcUaNode.attributeWritten(attribute, statusCode)#
- Parameters:
attribute –
NodeAttribute
statusCode –
UaStatusCode
This signal is emitted after a writeAttribute()
, writeAttributes()
or writeAttributeRange()
operation has finished.
Before this signal is emitted, the attribute cache is updated in case of a successful write. For writeAttributes()
a signal is emitted for each attribute in the write call. statusCode
contains the success information for the write operation on attribute
.
- PySide6.QtOpcUa.QOpcUaNode.browse(request)#
- Parameters:
request –
PySide6.QtOpcUa.QOpcUaBrowseRequest
- Return type:
bool
Starts a browse call from this node.
Returns true
if the asynchronous call has been successfully dispatched.
All references matching the criteria specified in request
are returned in the browseFinished()
signal.
For example, an inverse browse call can be used to find the parent node of a property node:
QOpcUaBrowseRequest request; request.setBrowseDirection(QOpcUaBrowseRequest::BrowseDirection::Inverse); request.setReferenceTypeId(QOpcUa::ReferenceTypeId::HasProperty); propertyNode->browse(request);
- PySide6.QtOpcUa.QOpcUaNode.browseChildren([referenceType=QOpcUa.ReferenceTypeId.HierarchicalReferences[, nodeClassMask=QOpcUa.NodeClass.Undefined]])#
- Parameters:
referenceType –
ReferenceTypeId
nodeClassMask –
NodeClasses
- Return type:
bool
Executes a forward browse call starting from the node this method is called on. The browse operation collects information about child nodes connected to the node and delivers the results in the browseFinished()
signal.
Returns true
if the asynchronous call has been successfully dispatched.
To request only children connected to the node by a certain type of reference, referenceType
must be set to that reference type. For example, this can be used to get all properties of a node by passing HasProperty
in referenceType
. The results can be filtered to contain only nodes with certain node classes by setting them in nodeClassMask
.
- PySide6.QtOpcUa.QOpcUaNode.browseFinished(children, statusCode)#
- Parameters:
children –
statusCode –
UaStatusCode
This signal is emitted after a browseChildren()
or browse()
operation has finished.
children
contains information about all nodes which matched the criteria in browseChildren()
. statusCode
contains the service result of the browse operation. If statusCode
is not Good
, the passed children
vector is empty.
See also
- PySide6.QtOpcUa.QOpcUaNode.callMethod(methodNodeId[, args=list()])#
- Parameters:
methodNodeId – str
args –
- Return type:
bool
Calls the OPC UA method methodNodeId
with the parameters given via args
. The result is returned in the methodCallFinished
signal.
Returns true
if the asynchronous call has been successfully dispatched.
- PySide6.QtOpcUa.QOpcUaNode.client()#
- Return type:
Returns a pointer to the client that has created this node.
- PySide6.QtOpcUa.QOpcUaNode.dataChangeOccurred(attr, value)#
- Parameters:
attr –
NodeAttribute
value – object
This signal is emitted after a data change notification has been received. value
contains the new value for the node attribute attr
.
- PySide6.QtOpcUa.QOpcUaNode.disableMonitoring(attr)#
- Parameters:
attr –
NodeAttributes
- Return type:
bool
This method disables monitoring for the attributes given in attr
.
Returns true
if the asynchronous call has been successfully dispatched.
After the call is finished, the disableMonitoringFinished
signal is emitted and monitoringStatus
returns a default constructed value with status code BadMonitoredItemIdIinvalid for attr
.
- PySide6.QtOpcUa.QOpcUaNode.disableMonitoringFinished(attr, statusCode)#
- Parameters:
attr –
NodeAttribute
statusCode –
UaStatusCode
This signal is emitted after an asynchronous call to disableMonitoring()
has finished. statusCode
contains the status code generated by the operation. After this signal has been emitted, monitoringStatus
returns a default constructed value with status code BadMonitoredItemIdIinvalid for attr
.
- PySide6.QtOpcUa.QOpcUaNode.enableMonitoring(attr, settings)#
- Parameters:
attr –
NodeAttributes
settings –
PySide6.QtOpcUa.QOpcUaMonitoringParameters
- Return type:
bool
This method creates a monitored item for each of the attributes given in attr
. The settings from settings
are used in the creation of the monitored items and the subscription.
Returns true
if the asynchronous call has been successfully dispatched.
On completion of the call, the enableMonitoringFinished
signal is emitted. There are multiple error cases in which a bad status code is generated: A subscription with the subscription id specified in settings
does not exist, the node does not exist on the server, the node does not have the requested attribute or the maximum number of monitored items for the server is reached.
The same method is used to enable event monitoring. Events are special objects in the OPC UA address space which contain information about an event that has occurred. If an event is triggered on the server, an event monitored item collects selected values of node attributes of the event object and its child nodes. Every node that has an event source can be monitored for events. To monitor a node for events, the attribute EventNotifier
must be monitored using an EventFilter which contains the event fields the user needs and optionally a where clause which is used to filter events by criteria (for more details, see EventFilter
).
- PySide6.QtOpcUa.QOpcUaNode.enableMonitoringFinished(attr, statusCode)#
- Parameters:
attr –
NodeAttribute
statusCode –
UaStatusCode
This signal is emitted after an asynchronous call to enableMonitoring()
has finished. After this signal has been emitted, monitoringStatus()
returns valid information for attr
. statusCode
contains the status code for the operation.
- PySide6.QtOpcUa.QOpcUaNode.eventOccurred(eventFields)#
- Parameters:
eventFields –
This signal is emitted after a new event has been received.
eventFields
contains the values of the event fields in the order specified in the select
clause of the event filter.
- static PySide6.QtOpcUa.QOpcUaNode.mandatoryBaseAttributes()#
- Return type:
NodeAttributes
Contains all mandatory attributes of the OPC UA base node class.
- PySide6.QtOpcUa.QOpcUaNode.methodCallFinished(methodNodeId, result, statusCode)#
- Parameters:
methodNodeId – str
result – object
statusCode –
UaStatusCode
This signal is emitted after a method call for methodNodeId
has finished on the server. statusCode
contains the status code from the method call, result
contains the output arguments of the method. result
is empty if the method has no output arguments or statusCode
is not Good
. The result
variant is either a single value if there is only one output argument or it contains a list of variants in case the called function returned multiple output arguments.
if (result.canConvert<QVariantList>()) { // handle list type } else { // handle value type }
- PySide6.QtOpcUa.QOpcUaNode.modifyDataChangeFilter(attr, filter)#
- Parameters:
- Return type:
bool
Modifies an existing data change monitoring to use filter
as data change filter.
Returns true
if the filter modification request has been successfully dispatched to the backend.
monitoringStatusChanged
for attr
is emitted after the operation has finished.
- PySide6.QtOpcUa.QOpcUaNode.modifyEventFilter(eventFilter)#
- Parameters:
eventFilter –
PySide6.QtOpcUa.QOpcUaMonitoringParameters.EventFilter
- Return type:
bool
Modifies an existing event monitoring to use eventFilter
as event filter.
Returns true
if the filter modification request has been successfully dispatched to the backend.
monitoringStatusChanged
for EventNotifier
is emitted after the operation has finished.
- PySide6.QtOpcUa.QOpcUaNode.modifyMonitoring(attr, item, value)#
- Parameters:
attr –
NodeAttribute
item –
Parameter
value – object
- Return type:
bool
This method modifies settings of the monitored item or the subscription. The parameter item
of the monitored item or subscription associated with attr
is attempted to set to value
.
Returns true
if the asynchronous call has been successfully dispatched.
After the call has finished, the monitoringStatusChanged
signal is emitted. This signal contains the modified parameters and the status code. A bad status code is generated if there is no monitored item associated with the requested attribute, modifying the requested parameter is not implemented or if the server has rejected the requested value.
- PySide6.QtOpcUa.QOpcUaNode.monitoringStatus(attr)#
- Parameters:
attr –
NodeAttribute
- Return type:
Returns the monitoring parameters associated with the attribute attr
. This can be used to check the success of enableMonitoring()
or if parameters have been revised. The returned values are only valid after enableMonitoringFinished
or monitoringStatusChanged
have been emitted for attr
. If the status is queried before a signal has been emitted, statusCode()
returns BadNoEntryExists
.
- PySide6.QtOpcUa.QOpcUaNode.monitoringStatusChanged(attr, items, statusCode)#
- Parameters:
attr –
NodeAttribute
items –
Parameters
statusCode –
UaStatusCode
This signal is emitted after an asynchronous call to modifyMonitoring()
has finished. The node attribute for which the operation was requested is returned in attr
. items
contains the parameters that have been modified. statusCode
contains the result of the modify operation on the server.
- PySide6.QtOpcUa.QOpcUaNode.nodeId()#
- Return type:
str
Returns the ID of the OPC UA node.
- PySide6.QtOpcUa.QOpcUaNode.readAttributeRange(attribute, indexRange)#
- Parameters:
attribute –
NodeAttribute
indexRange – str
- Return type:
bool
Starts an asynchronous read operation for the node attribute attribute
. indexRange
is a string which can be used to select a part of an array. It is defined in OPC-UA part 4, 7.22. The first element in an array is 0, “1” returns the second element, “0:9” returns the first 10 elements, “0,1” returns the second element of the first row in a two-dimensional array.
Returns true
if the asynchronous call has been successfully dispatched.
Attribute values only contain valid information after the attributeRead
signal has been emitted.
- PySide6.QtOpcUa.QOpcUaNode.readAttributes([attributes=QOpcUaNode.mandatoryBaseAttributes()])#
- Parameters:
attributes –
NodeAttributes
- Return type:
bool
Starts an asynchronous read operation for the node attributes in attributes
.
Returns true
if the asynchronous call has been successfully dispatched.
Attribute values only contain valid information after the attributeRead
signal has been emitted.
- PySide6.QtOpcUa.QOpcUaNode.readHistoryRaw(startTime, endTime, numValues, returnBounds)#
- Parameters:
startTime –
PySide6.QtCore.QDateTime
endTime –
PySide6.QtCore.QDateTime
numValues – int
returnBounds – bool
- Return type:
Starts a read history request for this node. This is the Qt OPC UA representation for the OPC UA ReadHistory service for reading raw historical data defined in OPC-UA part 4, 5.10.3 . It reads the history based on the parementers, startTime
, endTime
, numValues
, and returnBounds
.
Returns a QOpcUaHistoryReadResponse
which contains the state of the request if the asynchronous request has been successfully dispatched. The results are returned in the UaStatusCode serviceResult)
signal.
In the following example, the historic data from the last two days of a node are requested and printed. The result is limited to ten values per node.
QOpcUaHistoryReadResponse *response = node->readHistoryRaw(QDateTime::currentDateTime(), QDateTime::currentDateTime().addDays(-2), 10, true); if (response) { QObject::connect(response123, &QOpcUaHistoryReadResponse::readHistoryDataFinished, [] (QList<QOpcUaHistoryData> results, QOpcUa::UaStatusCode serviceResult) { if (serviceResult != QOpcUa::UaStatusCode::Good) { qWarning() << "Fetching historical data failed with:" << serviceResult; } else { for (const auto& result : results) { qInfo() << "NodeId:" << result.nodeId(); for (const auto &dataValue : result.result()) qInfo() << "Value:" << dataValue.value(); } } }); }
- PySide6.QtOpcUa.QOpcUaNode.readValueAttribute()#
- Return type:
bool
Starts an asynchronous read operation for the node’s Value attribute.
Returns true
if the asynchronous call has been successfully dispatched.
See also
- PySide6.QtOpcUa.QOpcUaNode.resolveBrowsePath(path)#
- Parameters:
path –
- Return type:
bool
Resolves the browse path path
to one or more node ids starting from this node using the TranslateBrowsePathsToNodeIds service specified in OPC-UA part 4, 5.8.4.
Returns true
if the asynchronous call has been successfully dispatched.
TranslateBrowsePathsToNodeIds is mainly used to program against type definitions instead of a concrete set of nodes in the OPC UA address space. For example, a type definition for a machine model could consist of a starting node with browse name “Machine” which has a component with browse name “Fan”. Fan has a component with browse name “RPM” which is a Variable node holding the current RPM value of the fan. There are multiple machines of that type and each of these machines is mapped into the OPC UA address space as an object of the machine type. For each of these machine objects, the path from the machine node to the “RPM” node is the same. If a client wants to read the current RPM value, it needs to call resolveBrowsePath() with the machine node as starting node and the browse path from the machine to the “RPM” node:
QScopedPointer<QOpcUaNode> node(opcuaClient->node("ns=1;s=machine1")); QList<QOpcUaRelativePathElement> path; path.append(QOpcUaRelativePathElement(QOpcUaQualifiedName(1, "Fan"), QOpcUa::ReferenceTypeId::HasComponent)); path.append(QOpcUaRelativePathElement(QOpcUaQualifiedName(1, "RPM"), QOpcUa::ReferenceTypeId::HasComponent)); node->resolveBrowsePath(path);
The result returned in resolveBrowsePathFinished()
contains the node id of the “RPM” node which can be used to access the node’s attributes:
if (!results.size()) { qWarning() << "Browse path resolution failed"; return; } if (results.at(0).isFullyResolved()) { QOpcUaNode *rpmNode = client->node(results.at(0).targetId()); if (!rpmNode) { qWarning() << "Failed to create node"; return; } // Connect slots, call methods } else { qWarning() << "Browse path could not be fully resolved, the target node is on another server"; return; }
- PySide6.QtOpcUa.QOpcUaNode.resolveBrowsePathFinished(targets, path, statusCode)#
- Parameters:
targets –
path –
statusCode –
UaStatusCode
This signal is emitted after a resolveBrowsePath()
call has finished.
QOpcUaBrowsePathTarget
targets
contains the matches, statusCode
is the status code of the operation. If statusCode
is not Good
, targets
is empty. The browse path path
is the browse path from the request. It can be used to associate results with requests.
- PySide6.QtOpcUa.QOpcUaNode.serverTimestamp(attribute)#
- Parameters:
attribute –
NodeAttribute
- Return type:
Returns the server timestamp from the last read or data change of attribute
. Before at least one attributeRead
or dataChangeOccurred
signal has been emitted, a null datetime is returned.
- PySide6.QtOpcUa.QOpcUaNode.sourceTimestamp(attribute)#
- Parameters:
attribute –
NodeAttribute
- Return type:
Returns the source timestamp from the last read or data change of attribute
. Before at least one attributeRead
or dataChangeOccurred
signal has been emitted, a null datetime is returned.
- PySide6.QtOpcUa.QOpcUaNode.valueAttribute()#
- Return type:
object
Returns the value of the node’s Value attribute.
The returned value is only valid after the Value attribute has been successfully read or written or after a data change from a monitoring has updated the attribute cache. This is indicated by a attributeRead()
or attributeWritten()
signal with status code Good
or a dataChangeOccurred()
signal for the Value attribute.
If there is no value in the attribute cache, an invalid QVariant
is returned.
- PySide6.QtOpcUa.QOpcUaNode.valueAttributeError()#
- Return type:
Returns the error code for the node’s Value attribute. The status code Good
indicates a valid return value for valueAttribute()
. If there is no entry in the attribute cache, BadNoEntryExists
is returned.
- PySide6.QtOpcUa.QOpcUaNode.writeAttribute(attribute, value[, type=QOpcUa.Types.Undefined])#
- Parameters:
attribute –
NodeAttribute
value – object
type –
Types
- Return type:
bool
Writes value
to the attribute given in attribute
using the type information from type
. Returns true
if the asynchronous call has been successfully dispatched.
If the type
parameter is omitted, the backend tries to find the correct type. The following default types are assumed:
Qt MetaType
OPC UA type
Bool
Boolean
UChar
Byte
Char
SByte
UShort
UInt16
Short
Int16
Int
Int32
UInt
UInt32
ULongLong
UInt64
LongLong
Int64
Double
Double
Float
Float
QString
String
QDateTime
DateTime
QByteArray
ByteString
QUuid
Guid
- PySide6.QtOpcUa.QOpcUaNode.writeAttributeRange(attribute, value, indexRange[, type=QOpcUa.Types.Undefined])#
- Parameters:
attribute –
NodeAttribute
value – object
indexRange – str
type –
Types
- Return type:
bool
Writes value
to the attribute given in attribute
using the type information from type
. For indexRange
, see readAttributeRange()
.
Returns true
if the asynchronous call has been successfully dispatched.
- PySide6.QtOpcUa.QOpcUaNode.writeAttributes(toWrite[, valueAttributeType=QOpcUa.Types.Undefined])#
- Parameters:
toWrite –
valueAttributeType –
Types
- Return type:
bool
Executes a write operation for the attributes and values specified in toWrite
.
Returns true
if the asynchronous call has been successfully dispatched.
The valueAttributeType
parameter can be used to supply type information for the value attribute. All other attributes have known types.
See also
- PySide6.QtOpcUa.QOpcUaNode.writeValueAttribute(value[, type=QOpcUa.Types.Undefined])#
- Parameters:
value – object
type –
Types
- Return type:
bool
Writes value
to the node’s Value attribute using the type information from type
.
Returns true
if the asynchronous call has been successfully dispatched.
See also