use of org.eclipse.milo.opcua.sdk.client.AddressSpace in project milo by eclipse.
the class UaMethodTest method findMethod.
@Test
public void findMethod() throws UaException {
ManagedSubscription subscription = ManagedSubscription.create(client);
ManagedDataItem dataItem = subscription.createDataItem(Identifiers.Server_ServerStatus_CurrentTime);
AddressSpace addressSpace = client.getAddressSpace();
UaObjectNode serverNode = addressSpace.getObjectNode(Identifiers.Server);
UaMethod getMonitoredItems = serverNode.getMethod("GetMonitoredItems");
assertNotNull(getMonitoredItems);
Argument[] inputArguments = getMonitoredItems.getInputArguments();
Argument[] outputArguments = getMonitoredItems.getOutputArguments();
assertEquals(1, inputArguments.length);
assertEquals("SubscriptionId", inputArguments[0].getName());
assertEquals(2, outputArguments.length);
assertEquals("ServerHandles", outputArguments[0].getName());
assertEquals("ClientHandles", outputArguments[1].getName());
Variant[] outputs = getMonitoredItems.call(new Variant[] { new Variant(subscription.getSubscription().getSubscriptionId()) });
UInteger[] expected0 = { dataItem.getMonitoredItem().getMonitoredItemId() };
UInteger[] expected1 = { dataItem.getMonitoredItem().getClientHandle() };
assertArrayEquals(expected0, (UInteger[]) outputs[0].getValue());
assertArrayEquals(expected1, (UInteger[]) outputs[1].getValue());
}
use of org.eclipse.milo.opcua.sdk.client.AddressSpace in project milo by eclipse.
the class UaMethodTest method callMethodWithHasOrderedComponentReference.
@Test
public void callMethodWithHasOrderedComponentReference() throws UaException {
AddressSpace addressSpace = client.getAddressSpace();
UaObjectNode objectsNode = addressSpace.getObjectNode(Identifiers.ObjectsFolder);
Variant[] outputs = objectsNode.callMethod(new QualifiedName(2, "sqrt2(x)"), new Variant[] { new Variant(16.0) });
assertEquals(4.0, outputs[0].getValue());
}
use of org.eclipse.milo.opcua.sdk.client.AddressSpace in project milo by eclipse.
the class UaMethodTest method callMethodException.
@Test
public void callMethodException() throws UaException {
AddressSpace addressSpace = client.getAddressSpace();
UaObjectNode serverNode = addressSpace.getObjectNode(Identifiers.Server);
assertThrows(UaMethodException.class, () -> serverNode.callMethod("GetMonitoredItems", new Variant[] { new Variant(uint(0)) }));
}
use of org.eclipse.milo.opcua.sdk.client.AddressSpace in project milo by eclipse.
the class UaMethodTest method callMethod.
@Test
public void callMethod() throws UaException {
ManagedSubscription subscription = ManagedSubscription.create(client);
ManagedDataItem dataItem = subscription.createDataItem(Identifiers.Server_ServerStatus_CurrentTime);
AddressSpace addressSpace = client.getAddressSpace();
UaObjectNode serverNode = addressSpace.getObjectNode(Identifiers.Server);
Variant[] outputs = serverNode.callMethod("GetMonitoredItems", new Variant[] { new Variant(subscription.getSubscription().getSubscriptionId()) });
UInteger[] expected0 = { dataItem.getMonitoredItem().getMonitoredItemId() };
UInteger[] expected1 = { dataItem.getMonitoredItem().getClientHandle() };
assertArrayEquals(expected0, (UInteger[]) outputs[0].getValue());
assertArrayEquals(expected1, (UInteger[]) outputs[1].getValue());
}
use of org.eclipse.milo.opcua.sdk.client.AddressSpace in project milo by eclipse.
the class UaObjectNode method getMethodAsync.
/**
* Get the method named {@code methodName} on this Object, if it exists.
* <p>
* This call completes asynchronously.
*
* @param methodName the name of the method.
* @return a {@link CompletableFuture} that completes successfully with a {@link UaMethod} or
* completes exceptionally if an operation- or service-level error occurs or if a method named
* {@code methodName} could not be found.
*/
public CompletableFuture<UaMethod> getMethodAsync(QualifiedName methodName) {
UInteger nodeClassMask = uint(NodeClass.Method.getValue());
UInteger resultMask = uint(BrowseResultMask.All.getValue());
CompletableFuture<BrowseResult> future = client.browse(new BrowseDescription(getNodeId(), BrowseDirection.Forward, Identifiers.HasComponent, true, nodeClassMask, resultMask));
return future.thenCompose(result -> {
StatusCode statusCode = result.getStatusCode();
if (statusCode != null && statusCode.isGood()) {
Optional<ExpandedNodeId> methodNodeId = l(result.getReferences()).stream().filter(rd -> Objects.equals(methodName, rd.getBrowseName())).findFirst().map(ReferenceDescription::getNodeId);
return methodNodeId.map(xni -> {
AddressSpace addressSpace = client.getAddressSpace();
return addressSpace.toNodeIdAsync(xni).thenCompose(nodeId -> addressSpace.getNodeAsync(nodeId).thenCompose(node -> {
UaMethodNode methodNode = (UaMethodNode) node;
CompletableFuture<Argument[]> inputArguments = methodNode.readInputArgumentsAsync().exceptionally(t -> new Argument[0]);
CompletableFuture<Argument[]> outputArguments = methodNode.readOutputArgumentsAsync().exceptionally(t -> new Argument[0]);
return inputArguments.thenCombine(outputArguments, (in, out) -> new UaMethod(client, this, methodNode, in, out));
}));
}).orElse(failedFuture(new UaException(StatusCodes.Bad_NotFound, "method not found: " + methodName)));
} else {
return failedFuture(new UaException(statusCode, "browsing for MethodNodes failed"));
}
});
}
Aggregations