use of org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode in project milo by eclipse.
the class UaNodeTest method write.
@Test
public void write() throws UaException {
AddressSpace addressSpace = client.getAddressSpace();
UaVariableNode testNode = (UaVariableNode) addressSpace.getNode(new NodeId(2, "TestInt32"));
Integer i1 = (Integer) testNode.readValue().getValue().getValue();
testNode.writeValue(new Variant(i1 + 1));
Integer i2 = (Integer) testNode.readValue().getValue().getValue();
assertEquals(i1 + 1, i2);
StatusCode statusCode = testNode.writeAttribute(AttributeId.Value, DataValue.valueOnly(new Variant(42)));
assertTrue(statusCode.isGood());
}
use of org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode in project milo by eclipse.
the class UaNodeTest method read.
@Test
public void read() throws UaException {
AddressSpace addressSpace = client.getAddressSpace();
UaVariableNode testNode = (UaVariableNode) addressSpace.getNode(new NodeId(2, "TestInt32"));
DataValue value = testNode.readValue();
assertNotNull(value);
QualifiedName browseName = testNode.readBrowseName();
assertNotNull(browseName);
DataValue descriptionValue = testNode.readAttribute(AttributeId.Description);
assertNotNull(descriptionValue);
}
use of org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode in project milo by eclipse.
the class UaVariableNodeTest method getTypeDefinition.
@Test
public void getTypeDefinition() throws UaException {
UaVariableNode variableNode = client.getAddressSpace().getVariableNode(Identifiers.Server_ServerStatus);
UaVariableTypeNode variableTypeNode = variableNode.getTypeDefinition();
assertEquals(Identifiers.ServerStatusType, variableTypeNode.getNodeId());
}
use of org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode in project milo by eclipse.
the class ReadExample method run.
@Override
public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throws Exception {
// synchronous connect
client.connect().get();
// synchronous read request via VariableNode
UaVariableNode node = client.getAddressSpace().getVariableNode(Identifiers.Server_ServerStatus_StartTime);
DataValue value = node.readValue();
logger.info("StartTime={}", value.getValue().getValue());
// asynchronous read request
readServerStateAndTime(client).thenAccept(values -> {
DataValue v0 = values.get(0);
DataValue v1 = values.get(1);
logger.info("State={}", ServerState.from((Integer) v0.getValue().getValue()));
logger.info("CurrentTime={}", v1.getValue().getValue());
future.complete(client);
});
}
use of org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode in project milo by eclipse.
the class AddressSpace method getVariableNodeAsync.
/**
* Get a {@link UaVariableNode} instance for the VariableNode identified by {@code nodeId},
* assuming the type definition identified by {@code typeDefinitionId}.
* <p>
* If this type definition is registered with the {@link VariableTypeManager} a
* {@link UaVariableNode} of the appropriate subclass will be returned.
* <p>
* This call completes asynchronously.
*
* @param nodeId the {@link NodeId} identifying the VariableNode to get.
* @param typeDefinitionId the {@link NodeId} identifying the type definition.
* @return a CompletableFuture that completes successfully with a {@link UaVariableNode}
* instance for the VariableNode identified by {@code nodeId} or completes exceptionally if an
* error occurs while creating the VariableNode.
*/
public CompletableFuture<UaVariableNode> getVariableNodeAsync(NodeId nodeId, NodeId typeDefinitionId) {
UaNode cachedNode = nodeCache.getIfPresent(nodeId);
if (cachedNode instanceof UaVariableNode) {
return completedFuture((UaVariableNode) cachedNode);
} else {
CompletableFuture<ReadResponse> future = readAttributes(nodeId, AttributeId.VARIABLE_ATTRIBUTES);
return future.thenCompose(response -> {
List<DataValue> attributeValues = l(response.getResults());
try {
UaVariableNode node = newVariableNode(nodeId, typeDefinitionId, attributeValues);
nodeCache.put(node.getNodeId(), node);
return completedFuture(node);
} catch (UaException e) {
return failedFuture(e);
}
});
}
}
Aggregations