OpcUaNode
OpcUaNode Yes NodeCollection.get The returned wrapper object 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 TranslateBrowsePaths Parse the path once.
Public Methods
| Category | Property | Type | Access | Description |
|---|---|---|---|---|
| Tags (None RPC) | getNodeId() | String | R | Node ID string |
| Data (Trigger RPC) | getValue() | OpcUaDataValue | R | Current value — triggers a read(Value) operation; must be closed |
getDisplayName() | String | R | Display name — triggers read(DisplayName) | |
getBrowseName() | String | R | Browse name — triggers read(BrowseName) | |
getDescription() | String | R | Description — Triggers read(Description) | |
getNodeClass() | Enums.NodeClass | R | Node class — triggers read(NodeClass) | |
getDataTypeNodeId() | String | R | Data type NodeId — triggers read(DataType) | |
isReadable() | boolean | R | AccessLevel bit0 — triggers read(AccessLevel) | |
isWritable() | boolean | R | AccessLevel bit1 — same as above | |
| Child Nodes (Triggered RPC) | getChildren() | List<Reference> | R | List of child nodes — Trigger browse |
Child Node Access
| Methods | Return | Note |
|---|---|---|
| node.get(String browseName) | OpcUaNode (Cannot find; returns null) | Press BrowseName / DisplayName to select a direct child node |
| node.resolve(String path) | OpcUaNode | By BrowsePath Multi-layer Analysis |
Instructions
| Methods | Note |
|---|---|
| readAttribute(Enums.AttributeId attr) | Reads the specified attribute and returns a value ( OpcUaDataValue must be closed) |
| write(OpcUaVariant v) | Write "Value," then return Enums.StatusCode |
| writeAttribute(Enums.AttributeId attr, OpcUaVariant v) | Write a specified attribute; return Enums.StatusCode |
| call(String parentObjectNodeId, OpcUaVariant... inputs) | Call this node as a method; return List<OpcUaVariant> |
Examples
// 1. Get node (None RPC)
OpcUaNode temp = ua.nodes.get("ns=2;s=Temperature");
// 2. Read the basic information (1 RPC each)
System.out.println("NodeId = " + temp.getNodeId());
System.out.println("DisplayName = " + temp.getDisplayName());
System.out.println("DataType = " + temp.getDataTypeNodeId());
System.out.println("NodeClass = " + temp.getNodeClass());
// 3. Read the value
try (OpcUaDataValue dv = temp.getValue()) {
System.out.println("Value = " + dv.variant().asDouble() + " °C");
}
// 4. Write
try (OpcUaVariant v = new OpcUaVariant().setDouble(25.5)) {
temp.write(v);
}
// 5. Browse Subnodes
for (Reference child : temp.getChildren()) {
System.out.println(" " + child.getBrowseName() + " -> " + child.getNodeId());
}
// 6. Chained Access (Server.ServerStatus.CurrentTime)
try (OpcUaDataValue time = ua.nodes.server().get("ServerStatus").get("CurrentTime").getValue()) {
long ft = time.variant().asFileTime();
System.out.println("Server time FileTime = " + ft);
}
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-based access: One access
a.get("b").get("c")per segment Browse RPC, for a total of N accesses OpcUaDataValueMust be closed; otherwise, native memory will be leaked.- Cross-thread usage is safe
OpcUaNode(stateless), but do notOpcUaDataValueuse it across threads. node.get(browseName)Cannot find the return null (Java style), do not throw exceptions — explicit null checks in the outer layer
Comparison with "resolve"
// Method A: Linked Index - 4 times RPC
try (OpcUaDataValue time = ua.nodes.server().get("ServerStatus").get("CurrentTime").getValue()) {
// 4 times Read: server() (none RPC) + get("ServerStatus") + get("CurrentTime") + getValue()
// Actually 3 times Browse + 1 time Read
}
// Method B: Path Resolution—2 times RPC
OpcUaNode node = ua.resolve("/Objects/Server/ServerStatus/CurrentTime"); // 1 time
try (OpcUaDataValue time = node.getValue()) { /* 1 time */ }
// Method C: Directly NodeId - 1 time RPC
try (OpcUaDataValue time = ua.read("i=2258")) { /* ... */ }
If the path is known → Approach C; exploratory development → Approach A.