Skip to main content

Call

Preliminary / Supporting
  • Data Types OpcUaVariant It is a container for input and output parameters.
  • Find a way to use NodeId Browse Pair with filter=Enums.NodeClass.Method.

Signature​

public List<OpcUaVariant> call(
String objectNodeId,
String methodNodeId,
OpcUaVariant... inputs);
ParametersNote
objectNodeIdThe method is located in the Object node
methodNodeIdThe Method Itself NodeId
inputsInput: OpcUaVariant Array (optional)

Returns List of output List<OpcUaVariant> parameters.

Memory Ownership (Important)​

In the returned list, Each OpcUaVariant one holds a native handle, Must be closed; otherwise, native memory Variant will be leaked.

Input parameters are also OpcUaVariant user-defined and must be closed. We recommend try-with-resources grouping the input parameters with the close block:

try (OpcUaVariant a = new OpcUaVariant().setInt32(3);
OpcUaVariant b = new OpcUaVariant().setInt32(4)) {
List<OpcUaVariant> outputs = ua.call(objId, mtdId, a, b);
try {
for (OpcUaVariant v : outputs) {
// Use v.asXxx() ...
}
} finally {
for (OpcUaVariant v : outputs) v.close();
}
}

Examples​

// Adjust Calculator.Add(3, 4)
try (OpcUaVariant a = new OpcUaVariant().setInt32(3);
OpcUaVariant b = new OpcUaVariant().setInt32(4)) {
List<OpcUaVariant> outputs = ua.call(
"ns=2;s=Calculator",
"ns=2;s=Calculator.Add",
a, b);
try {
for (OpcUaVariant v : outputs) {
System.out.println("sum = " + v.asInt32());
}
} finally {
for (OpcUaVariant v : outputs) v.close();
}
}

Exception​

ExceptionMeaning
OpcUaException(BadNodeIdInvalid)NodeId Parsing Failed
OpcUaException(BadCommunicationError)Transport Error
OpcUaException Business CodeThe status returned by the server (statusCode the field is the business code)

Business-level failures (when a method returns a value other than "Good") also throw exceptions OpcUaException— ex.statusCode specifically, business codes.

Looking for a way to... NodeId​

// 1. Browse Object Child Node Filtering Method
List<Reference> methods = ua.browse("ns=2;s=Calculator", Enums.NodeClass.Method);
for (Reference m : methods) {
System.out.println(" " + m.getBrowseName() + " -> " + m.getNodeId());
}

// 2. Check the input/output parameter signatures (Browse the Property of the method node)
List<Reference> props = ua.browse(methods.get(0).getNodeId());
// Find the Property for == BrowseName "InputArguments" / "OutputArguments", then read it to see the description of Argument[]

Input Parameter Construction​

Constructing method signatures OpcUaVariant:

// Add(Int32, Int32) -> Int32
new OpcUaVariant().setInt32(3), new OpcUaVariant().setInt32(4)

// SetTemperature(string deviceId, double value)
new OpcUaVariant().setString("Boiler1"), new OpcUaVariant().setDouble(85.5)

// Complex Structures (ExtensionObject) — Advanced Usage; to be refined in future versions

Asynchronous (Future Versions)​

Currently, this is call a synchronous, blocking operation (internally, it performs RPC + waits for a response). An asynchronous version (callAsync) will be available in a future release.

If you want to do this asynchronously, use CompletableFuture.supplyAsync:

import java.util.concurrent.CompletableFuture;

CompletableFuture<List<OpcUaVariant>> f = CompletableFuture.supplyAsync(() -> {
try (OpcUaVariant a = new OpcUaVariant().setInt32(3);
OpcUaVariant b = new OpcUaVariant().setInt32(4)) {
return ua.call(objId, mtdId, a, b);
}
});

List<OpcUaVariant> outputs = f.join();
try { /* Use outputs */ }
finally { for (OpcUaVariant v : outputs) v.close(); }

Next Step​