Issue
Use eclipse milo to connect a OPCUA server, can use browse to get the method nodes, and then how to get the DataType of method arguments?
Just like: final BrowseDescription browseDesc = new BrowseDescription(nodeIdRoot, BrowseDirection.Forward, Identifiers.References, true, uint(NodeClass.Method.getValue()), uint(BrowseResultMask.All.getValue()));
BrowseResult browseResult = client.browse(browseDesc).get();
for (final ReferenceDescription rf : browseResult.getReferences()) {
final NodeId childId = rf.getNodeId().local().orElse(null);
List<Node> nodes = client.getAddressSpace().browse(childId).get();
for (Node node : nodes) {
// Now, I get the Node of method.
// How to get the method arguments data types?
system.out.println("need Input types {}" /*, InputArgument */);
system.out.println("will get Output types {}" /*, OutputArgument */);
}
}
Solution
Method Nodes have HasProperty References to Property Nodes named InputArguments and/or OutputArguments, as long as that method receives input or output arguments.
If you read the Value Attribute if these Nodes you'll get an Argument[]
describing the arguments (Name, DataType, ValueRank, ArrayDimensions, Description).
UaMethodNode has getInputArguments
and getOutputArguments
calls on it that can help as well:
UaMethodNode methodNode = (UaMethodNode) client.getAddressSpace().getNodeInstance(methodId).get();
CompletableFuture<Argument[]> iaf = methodNode
.getInputArguments()
.exceptionally(ex -> new Argument[0]);
CompletableFuture<Argument[]> oaf = methodNode
.getOutputArguments()
.exceptionally(ex -> new Argument[0]);
iaf.thenAcceptBoth(oaf, (ia, oa) -> {
System.out.println("inputArgs: " + Arrays.toString(ia));
System.out.println("outputArgs: " + Arrays.toString(oa));
});
Answered By - Kevin Herron