Skip to main content

OpcUaNode

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

Prerequisite Reading

Public Methods​

CategoryPropertyTypeAccessDescription
Tags (None RPC)getNodeId()StringRNode ID string
Data (Trigger RPC)getValue()OpcUaDataValueRCurrent value — triggers a read(Value) operation; must be closed
getDisplayName()StringRDisplay name — triggers read(DisplayName)
getBrowseName()StringRBrowse name — triggers read(BrowseName)
getDescription()StringRDescription — Triggers read(Description)
getNodeClass()Enums.NodeClassRNode class — triggers read(NodeClass)
getDataTypeNodeId()StringRData type NodeId — triggers read(DataType)
isReadable()booleanRAccessLevel bit0 — triggers read(AccessLevel)
isWritable()booleanRAccessLevel bit1 — same as above
Child Nodes (Triggered RPC)getChildren()List<Reference>RList of child nodes — Trigger browse

Child Node Access​

MethodsReturnNote
node.get(String browseName)OpcUaNode (Cannot find; returns null)Press BrowseName / DisplayName to select a direct child node
node.resolve(String path)OpcUaNodeBy BrowsePath Multi-layer Analysis

Instructions​

MethodsNote
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
  • OpcUaDataValue Must be closed; otherwise, native memory will be leaked.
  • Cross-thread usage is safe OpcUaNode (stateless), but do not OpcUaDataValue use 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.

Next Step​