Search in sources :

Example 1 with UaVariableNode

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());
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) UaVariableNode(org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) Test(org.junit.jupiter.api.Test) AbstractClientServerTest(org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest)

Example 2 with UaVariableNode

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);
}
Also used : UaVariableNode(org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) Test(org.junit.jupiter.api.Test) AbstractClientServerTest(org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest)

Example 3 with UaVariableNode

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());
}
Also used : UaVariableNode(org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode) UaVariableTypeNode(org.eclipse.milo.opcua.sdk.client.nodes.UaVariableTypeNode) Test(org.junit.jupiter.api.Test) AbstractClientServerTest(org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest)

Example 4 with UaVariableNode

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);
    });
}
Also used : UaVariableNode(org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue)

Example 5 with UaVariableNode

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);
            }
        });
    }
}
Also used : UaVariableNode(org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode) ReadResponse(org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) UaException(org.eclipse.milo.opcua.stack.core.UaException) UaNode(org.eclipse.milo.opcua.sdk.client.nodes.UaNode)

Aggregations

UaVariableNode (org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode)15 DataValue (org.eclipse.milo.opcua.stack.core.types.builtin.DataValue)9 AbstractClientServerTest (org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest)7 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)7 Test (org.junit.jupiter.api.Test)7 Variant (org.eclipse.milo.opcua.stack.core.types.builtin.Variant)5 UaException (org.eclipse.milo.opcua.stack.core.UaException)3 ExpandedNodeId (org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId)3 QualifiedName (org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName)3 StatusCode (org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)3 UaNode (org.eclipse.milo.opcua.sdk.client.nodes.UaNode)2 AttributeId (org.eclipse.milo.opcua.stack.core.AttributeId)2 ExtensionObject (org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject)2 ReadResponse (org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse)2 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CustomStructType (org.eclipse.milo.examples.server.types.CustomStructType)1 GenericBsdParser (org.eclipse.milo.opcua.binaryschema.GenericBsdParser)1 OpcUaClient (org.eclipse.milo.opcua.sdk.client.OpcUaClient)1