use of org.eclipse.milo.opcua.sdk.client.subscriptions.ManagedDataItem in project milo by eclipse.
the class ManagedSubscriptionDataExample method run.
@Override
public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throws Exception {
client.connect().get();
ManagedSubscription subscription = ManagedSubscription.create(client);
subscription.addDataChangeListener((items, values) -> {
for (int i = 0; i < items.size(); i++) {
logger.info("subscription value received: item={}, value={}", items.get(i).getNodeId(), values.get(i).getValue());
}
});
ManagedDataItem dataItem = subscription.createDataItem(Identifiers.Server_ServerStatus_CurrentTime);
if (dataItem.getStatusCode().isGood()) {
logger.info("item created for nodeId={}", dataItem.getNodeId());
// let the example run for 5 seconds before completing
Thread.sleep(5000);
dataItem.delete();
} else {
logger.warn("failed to create item for nodeId={} (status={})", dataItem.getNodeId(), dataItem.getStatusCode());
}
future.complete(client);
}
use of org.eclipse.milo.opcua.sdk.client.subscriptions.ManagedDataItem 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.subscriptions.ManagedDataItem 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());
}
Aggregations