Node
Node Yes NodeCollection A lightweight value object returned, representing a remote node.
Lazy Load — Only access properties trigger RPC.
Prerequisite Reading
- For the entry point, see NodeCollection.
- To avoid multiple chained calls, please use RPC TranslateBrowsePaths Parse the path once.
Public Methods
| Category | Property | Type | Access | Description |
|---|---|---|---|---|
| Tags (None RPC) | node_id() | &str | R | Node ID string |
| Data (Trigger RPC) | value() | Result<DataValue, OpcUaError> | R | Current value — triggers Read(Value) |
display_name() | Option<String> | R | Display name — Triggers Read(DisplayName) | |
browse_name() | Option<String> | R | View Name — Triggers Read(BrowseName) | |
description() | Option<String> | R | Description — Triggers Read(Description) | |
node_class() | NodeClass | R | Node class — Triggers Read(NodeClass) | |
is_readable() | bool | R | AccessLevel bit0 — Triggers Read(AccessLevel) | |
is_writable() | bool | R | AccessLevel bit1 — triggers Read(AccessLevel) | |
| Child Nodes (Triggered RPC) | children() | Result<Vec<Reference>, OpcUaError> | R | List of child nodes — triggered Browse |
child(browse_name) | Option<Node> | R | BrowseName Retrieve child nodes by — trigger Browse |
Public Methods
| Methods | Note |
|---|---|
| read_attribute(attr) | Reads the specified attribute and returns Result<DataValue, OpcUaError> |
| write(&Variant) | Write Value, return Result<StatusCode, OpcUaError> |
| write_attribute(attr, &Variant) | Write a Specified Attribute |
| resolve(path) | Relative to the resolution of this node BrowsePath, returns Option<Node> |
| call(parent_obj_id, &[Variant]) | When this node is a Method, call it |
Examples
use darra_opcua::Variant;
// 1. Get node (None RPC)
let temp = s.nodes().get("ns=2;s=Temperature");
// 2. Read the basic information (1 RPC each)
println!("NodeId = {}", temp.node_id());
println!("DisplayName = {:?}", temp.display_name());
println!("NodeClass = {:?}", temp.node_class());
// 3. Read the value
let dv = temp.value()?;
let val = dv.variant().try_get_f64().unwrap_or(0.0);
println!("Value = {} °C @ {:?}", val, dv.source_timestamp());
// 4. Write
let mut v = Variant::new();
v.set_f64(25.5);
temp.write(&v)?;
// 5. Browse Subnodes
for child in temp.children()? {
println!(" {} -> {}", child.browse_name, child.node_id);
}
// 6. Chained Access (Server.ServerStatus.CurrentTime)
if let Some(status) = s.nodes().server().child("ServerStatus") {
if let Some(time) = status.child("CurrentTime") {
println!("Server time = {:?}", time.value()?.source_timestamp());
}
}
Node Differences from "Reference"
Reference This is a returned Browse field snapshot (BrowseName / DisplayName / NodeId / NodeClass),
which does not hold a session handle. It can be to_node(&session) converted to an actionable object via Node:
use darra_opcua::NodeClass;
for r in s.browse("ns=2;s=Boiler1", NodeClass::Unspecified)? {
let node = r.to_node(&s);
let dv = node.value()?;
println!("{} = {:?}", r.browse_name, dv.variant());
}
Important Notes
- All methods RPC that are triggered follow a "read-once, return-once" pattern, Do not cache. I want to cache a variable I've stored myself
- Chain Access
node.child("a").unwrap().child("b").unwrap()Each segment is a single instance Browse RPC, A total of N times. If the path is known, useSession::resolve()/translate_browse_paths()A single-pass analysis is faster DataValueAutomatically dropped when leaving the scope; no manual release required- Cross-thread usage of safe Node (
Send + Sync)
Comparison with Resolve
// Method A: Chained child - 4 times RPC
let time = s.nodes().server()
.child("ServerStatus").unwrap()
.child("CurrentTime").unwrap()
.value()?;
// 1 time 2 times 3 times 4 times Read
// Method B: Path Resolution—2 times RPC
let node = s.resolve("/Objects/Server/ServerStatus/CurrentTime")?.unwrap(); // 1 time
let time = node.value()?; // 1 time
// Method C: Directly NodeId - 1 time RPC
let time = s.read("i=2258")?;
If the path is known → Approach C; exploratory development → Approach A.