Skip to main content

OpcUaNode

OpcUaNode Yes NodeCollection The wrapper object returned by the indexer represents a remote node. Lazy Load — Only access properties trigger RPC.

Prerequisite Reading

Public Attributes​

CategoryPropertyTypeAccessDescription
Tags (None RPC)node_idstrRNode ID string
Data (Trigger RPC)valueOpcUaDataValueRCurrent value — triggers a read(Value)
display_nameOptional[str]RDisplay name — triggers read(DisplayName)
browse_nameOptional[str]RBrowse name — triggers read(BrowseName)
descriptionOptional[str]RDescription — Triggers a read (Description)
node_classNodeClassRNode class — triggers read(NodeClass)
data_type_node_idOptional[str]RData type NodeId — triggers read(DataType)
is_readableboolRAccessLevel bit0
is_writableboolRAccessLevel bit1
Child Nodes (Triggered RPC)childrenList[Reference]RList of child nodes — triggers browse

Indexer​

IndexReturnNote
node[browse_name]Optional[OpcUaNode]Press to retrieve BrowseName a direct child node; if none is found, return None.

Public Methods​

MethodsNote
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 / OpcUaVariant Must be disposed of; otherwise, native memory will be leaked. Use with.
  • OpcUaNode It 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 simultaneously OpcUaDataValue / 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.

Next Step​