OpcUaNode
OpcUaNode Yes NodeCollection The wrapper object returned by the indexer represents a remote node. Lazy Load — Only access properties trigger RPC.
Prerequisite Reading
- For the entry point, see NodeCollection.
- To avoid multiple lookups in a chained index, use RPC translate_browse_paths Parse the path once.
Public Attributes
| Category | Property | Type | Access | Description |
|---|---|---|---|---|
| Tags (None RPC) | node_id | str | R | Node ID string |
| Data (Trigger RPC) | value | OpcUaDataValue | R | Current value — triggers a read(Value) |
display_name | Optional[str] | R | Display name — triggers read(DisplayName) | |
browse_name | Optional[str] | R | Browse name — triggers read(BrowseName) | |
description | Optional[str] | R | Description — Triggers a read (Description) | |
node_class | NodeClass | R | Node class — triggers read(NodeClass) | |
data_type_node_id | Optional[str] | R | Data type NodeId — triggers read(DataType) | |
is_readable | bool | R | AccessLevel bit0 | |
is_writable | bool | R | AccessLevel bit1 | |
| Child Nodes (Triggered RPC) | children | List[Reference] | R | List of child nodes — triggers browse |
Indexer
| Index | Return | Note |
|---|---|---|
| node[browse_name] | Optional[OpcUaNode] | Press to retrieve BrowseName a direct child node; if none is found, return None. |
Public Methods
| Methods | Note |
|---|---|
| read_attribute(attr) | Reads the specified attribute and returns OpcUaDataValue |
| write(value) | Write the Value property, return StatusCode |
| write_attribute(attr, value) | Write any property |
| resolve(path) | In-Depth BrowsePath Analysis (Relative to the Current Node) |
| call(parent_object_node_id, *inputs) | Call this node as a method |
Examples
from darra_opcua import OpcUaVariant, AttributeId
# 1. Get Node (None RPC)
temp = ua.nodes["ns=2;s=Temperature"]
# 2. Read the basic information (1 RPC each)
print(f"NodeId = {temp.node_id}")
print(f"display_name = {temp.display_name}")
print(f"node_class = {temp.node_class.name}")
print(f"data_type = {temp.data_type_node_id}")
# 3. Read Values (with automatic disposal)
with temp.value as dv:
print(f"Value = {dv.value} °C @ {dv.source_timestamp}")
# 4. Write
temp.write(OpcUaVariant().set_double(25.5))
# 5. Browse Subnodes
for child in temp.children:
print(f" {child.browse_name} -> {child.node_id}")
# 6. Chained Access (Server.ServerStatus.CurrentTime)
with ua.nodes.server["ServerStatus"]["CurrentTime"].value as dv:
print(f"Server time = {dv.value}")
Important Notes
- All properties RPC that are triggered are "read-once, return-once," Do not cache. I want to cache a variable I've stored myself
- Chain-based access: One access
a["b"]["c"]per segment browse RPC, for a total of N accesses OpcUaDataValue/OpcUaVariantMust be disposed of; otherwise, native memory will be leaked. Usewith.OpcUaNodeIt only stores a session handle and a string NodeId (initialized to zero when created RPC); itNo Guarantee of Thread Safety — The concurrency capabilities of the underlying session are determined SDK by; do not allow multiple threads to read from or write to the same simultaneouslyOpcUaDataValue/OpcUaVariant
Comparison with "resolve"
# Method A: Chain Indexer — 3 times RPC
# ["ServerStatus"] once browse, ["CurrentTime"] once browse, .value once read
with ua.nodes.server["ServerStatus"]["CurrentTime"].value as dv:
print(dv.value)
# Method B: Path Resolution — 4 times browse + 1 read = 5 times RPC
# "resolve" is performed segment by browse segment; it sends as many messages as there are segments in the path. browse
node = ua.resolve("/Objects/Server/ServerStatus/CurrentTime")
with node.value as dv:
print(dv.value)
# Method C: Directly NodeId — 1 time RPC
with ua.read("i=2258") as dv:
print(dv.value)
resolve It is no more efficient than the chained indexer ( RPC which loops browse through each segment on the client side; see translate_browse-paths). To retrieve a batch of paths at once, use translate_browse_paths.
If the path is known → Approach C; exploratory development → Approach A; use Approach B if it results in more readable code.