Skip to main content

NodeCollection — ua.nodes

NodeCollection This is the entry point for accessing Session nodes; it is returned via the indexer []. OpcUaNode Items to be packaged, Not triggered immediately RPC (Lazy Load).

Prerequisite Reading

Indexer​

IndexReturnNote
nodes[node_id_str]OpcUaNodeString NodeId Access

Predefined Entry Properties​

For your convenience, here are some commonly used shortcuts:

CategoryPropertyTypeAccessDescription
Standard EntryrootOpcUaNodeRAddress Space Root (i=84)
objectsOpcUaNodeRBusiness Data Root (i=85)
typesOpcUaNodeRRoot of type definitions (i=86)
viewsOpcUaNodeRView root (i=87)
serverOpcUaNodeRServer object (i=2253)
# These two lines are equivalent (where "server" corresponds to i=2253).
with ua.nodes.server["ServerStatus"]["CurrentTime"].value as dv:
t1 = dv.value
with ua.nodes["i=2253"]["ServerStatus"]["CurrentTime"].value as dv:
t2 = dv.value

Lazy Load Mechanism​

node = ua.nodes["ns=2;s=Temperature"]   # ← Do not trigger RPC
with node.value as dv: # ← The first time .value is called, a read is triggered
print(dv.value)

On the second access, it will still .value be read from scratch (no caching), because the variable values can change at any time. I want to cache the values I store myself.

Child Node BrowseName Index​

sub = node["ChildName"]   # Browse BrowseName child nodes

Underlying Logic:

  1. Use browse(current_node_id) to get the list of child nodes immediately
  2. Find the child of ( browse_name == "ChildName" or display_name == "ChildName"), and return the wrapper OpcUaNode
  3. Cannot find the return path None

A result is returned once on the first access browse RPC; subsequent accesses to the same path all return the result browse from that single access.

NodeId Assembly Aid​

# Press NamespaceUri + number ID to create (Dynamic ns Recommendations)
n = ua.nodes.make_numeric("urn:my-company:plc1", 1234)

# Construct NamespaceUri a string using the " ID +" operator
n = ua.nodes.make_string("urn:my-company:plc1", "Counter")

URI Throw an exception if it cannot be found OpcUaException(DarraInvalidArgument).

When to Use an Indexer, When to Use a String​

ScenarioRecommendations
Known with precision NodeIdString (ua.read("ns=2;s=..."))
Standard Nodes (Server Status, etc.)ua.nodes.server[...]
Browse Tree / Write a One-Time ScriptIndexer (ua.nodes["..."]["..."])
Batch (100+ nodes)read_many / browse_many, Do not loop

Next Step​