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
- Single node API Please see OpcUaNode.
- For standard node constants, see WellKnownNodes.
Indexer
| Index | Return | Note |
|---|---|---|
| nodes[node_id_str] | OpcUaNode | String NodeId Access |
Predefined Entry Properties
For your convenience, here are some commonly used shortcuts:
| Category | Property | Type | Access | Description |
|---|---|---|---|---|
| Standard Entry | root | OpcUaNode | R | Address Space Root (i=84) |
objects | OpcUaNode | R | Business Data Root (i=85) | |
types | OpcUaNode | R | Root of type definitions (i=86) | |
views | OpcUaNode | R | View root (i=87) | |
server | OpcUaNode | R | Server 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:
- Use
browse(current_node_id)to get the list of child nodes immediately - Find the child of (
browse_name == "ChildName"ordisplay_name == "ChildName"), and return the wrapperOpcUaNode - 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
| Scenario | Recommendations |
|---|---|
| Known with precision NodeId | String (ua.read("ns=2;s=...")) |
| Standard Nodes (Server Status, etc.) | ua.nodes.server[...] |
| Browse Tree / Write a One-Time Script | Indexer (ua.nodes["..."]["..."]) |
| Batch (100+ nodes) | read_many / browse_many, Do not loop |