Search in sources :

Example 1 with UaVariableTypeNode

use of org.eclipse.milo.opcua.sdk.client.nodes.UaVariableTypeNode 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 2 with UaVariableTypeNode

use of org.eclipse.milo.opcua.sdk.client.nodes.UaVariableTypeNode in project milo by eclipse.

the class AddressSpace method createVariableTypeNodeFromBaseAttributes.

private CompletableFuture<UaVariableTypeNode> createVariableTypeNodeFromBaseAttributes(NodeId nodeId, List<DataValue> baseAttributeValues) {
    Set<AttributeId> remainingAttributes = Sets.difference(AttributeId.VARIABLE_TYPE_ATTRIBUTES, AttributeId.BASE_ATTRIBUTES);
    CompletableFuture<ReadResponse> attributesFuture = readAttributes(nodeId, remainingAttributes);
    return attributesFuture.thenCompose(response -> {
        List<DataValue> attributeValues = new ArrayList<>(baseAttributeValues);
        Collections.addAll(attributeValues, response.getResults());
        try {
            UaVariableTypeNode node = newVariableTypeNode(nodeId, attributeValues);
            nodeCache.put(node.getNodeId(), node);
            return completedFuture(node);
        } catch (UaException e) {
            return failedFuture(e);
        }
    });
}
Also used : ReadResponse(org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) UaVariableTypeNode(org.eclipse.milo.opcua.sdk.client.nodes.UaVariableTypeNode) AttributeId(org.eclipse.milo.opcua.stack.core.AttributeId) UaException(org.eclipse.milo.opcua.stack.core.UaException) ArrayList(java.util.ArrayList)

Example 3 with UaVariableTypeNode

use of org.eclipse.milo.opcua.sdk.client.nodes.UaVariableTypeNode in project milo by eclipse.

the class AddressSpace method newVariableTypeNode.

private UaVariableTypeNode newVariableTypeNode(NodeId nodeId, List<DataValue> attributeValues) throws UaException {
    DataValue nodeIdDataValue = attributeValues.get(0);
    StatusCode nodeIdStatusCode = nodeIdDataValue.getStatusCode();
    if (nodeIdStatusCode != null && nodeIdStatusCode.isBad()) {
        throw new UaException(nodeIdStatusCode);
    }
    try {
        NodeClass nodeClass = NodeClass.from((Integer) attributeValues.get(1).getValue().getValue());
        Preconditions.checkArgument(nodeClass == NodeClass.VariableType, "expected NodeClass.VariableType, got NodeClass." + nodeClass);
        QualifiedName browseName = (QualifiedName) attributeValues.get(2).getValue().getValue();
        LocalizedText displayName = (LocalizedText) attributeValues.get(3).getValue().getValue();
        LocalizedText description = getAttributeOrNull(attributeValues.get(4), LocalizedText.class);
        UInteger writeMask = getAttributeOrNull(attributeValues.get(5), UInteger.class);
        UInteger userWriteMask = getAttributeOrNull(attributeValues.get(6), UInteger.class);
        DataValue value = attributeValues.get(7);
        NodeId dataType = (NodeId) attributeValues.get(8).getValue().getValue();
        Integer valueRank = (Integer) attributeValues.get(9).getValue().getValue();
        UInteger[] arrayDimensions = getAttributeOrNull(attributeValues.get(10), UInteger[].class);
        Boolean isAbstract = (Boolean) attributeValues.get(11).getValue().getValue();
        return new UaVariableTypeNode(client, nodeId, nodeClass, browseName, displayName, description, writeMask, userWriteMask, value, dataType, valueRank, arrayDimensions, isAbstract);
    } catch (Throwable t) {
        throw UaException.extract(t).orElse(new UaException(StatusCodes.Bad_UnexpectedError, t));
    }
}
Also used : DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) UaException(org.eclipse.milo.opcua.stack.core.UaException) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) LocalizedText(org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) NodeClass(org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass) UaVariableTypeNode(org.eclipse.milo.opcua.sdk.client.nodes.UaVariableTypeNode) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId)

Aggregations

UaVariableTypeNode (org.eclipse.milo.opcua.sdk.client.nodes.UaVariableTypeNode)3 UaException (org.eclipse.milo.opcua.stack.core.UaException)2 DataValue (org.eclipse.milo.opcua.stack.core.types.builtin.DataValue)2 ArrayList (java.util.ArrayList)1 UaVariableNode (org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode)1 AbstractClientServerTest (org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest)1 AttributeId (org.eclipse.milo.opcua.stack.core.AttributeId)1 ExpandedNodeId (org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId)1 LocalizedText (org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText)1 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)1 QualifiedName (org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName)1 StatusCode (org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)1 UInteger (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger)1 NodeClass (org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass)1 ReadResponse (org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse)1 Test (org.junit.jupiter.api.Test)1