Search in sources :

Example 1 with Variant

use of org.eclipse.milo.opcua.stack.core.types.builtin.Variant in project plc4x by apache.

the class Plc4xNamespace method addConfiguredNodes.

private void addConfiguredNodes(UaFolderNode rootNode, DeviceConfiguration c) {
    final List<Tag> tags = c.getTags();
    final String connectionString = c.getConnectionString();
    for (int i = 0; i < tags.size(); i++) {
        logger.info("Adding Tag " + tags.get(i).getAlias() + " - " + tags.get(i).getAddress());
        String name = tags.get(i).getAlias();
        final String tag = tags.get(i).getAddress();
        Class datatype = null;
        NodeId typeId = Identifiers.String;
        UaVariableNode node = null;
        Variant variant = null;
        try {
            datatype = plc4xServer.getField(tag, connectionString).getDefaultJavaType();
            final int length = plc4xServer.getField(tag, connectionString).getNumberOfElements();
            typeId = Plc4xCommunication.getNodeId(plc4xServer.getField(tag, connectionString).getPlcDataType());
            if (length > 1) {
                node = new UaVariableNode.UaVariableNodeBuilder(getNodeContext()).setNodeId(newNodeId(name)).setAccessLevel(AccessLevel.READ_WRITE).setUserAccessLevel(AccessLevel.READ_WRITE).setBrowseName(newQualifiedName(name)).setDisplayName(LocalizedText.english(name)).setDataType(typeId).setTypeDefinition(Identifiers.BaseDataVariableType).setValueRank(ValueRank.OneDimension.getValue()).setArrayDimensions(new UInteger[] { uint(length) }).build();
                Object array = Array.newInstance(datatype, length);
                for (int j = 0; j < length; j++) {
                    Array.set(array, j, false);
                }
                variant = new Variant(array);
            } else {
                node = new UaVariableNode.UaVariableNodeBuilder(getNodeContext()).setNodeId(newNodeId(name)).setAccessLevel(AccessLevel.READ_WRITE).setUserAccessLevel(AccessLevel.READ_WRITE).setBrowseName(newQualifiedName(name)).setDisplayName(LocalizedText.english(name)).setDataType(typeId).setTypeDefinition(Identifiers.BaseDataVariableType).build();
                variant = new Variant(0);
            }
            node.setValue(new DataValue(variant));
            node.getFilterChain().addLast(AttributeFilters.getValue(ctx -> plc4xServer.getValue(ctx, tag, connectionString)));
            node.getFilterChain().addLast(AttributeFilters.setValue((ctx, value) -> {
                if (length > 1) {
                    plc4xServer.setValue(tag, Arrays.toString((Object[]) value.getValue().getValue()), connectionString);
                } else {
                    plc4xServer.setValue(tag, value.getValue().getValue().toString(), connectionString);
                }
            }));
        } catch (PlcConnectionException e) {
            logger.info("Couldn't find data type");
            System.exit(1);
        }
        getNodeManager().addNode(node);
        rootNode.addOrganizes(node);
    }
}
Also used : Arrays(java.util.Arrays) Array(java.lang.reflect.Array) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) DataItem(org.eclipse.milo.opcua.sdk.server.api.DataItem) LoggerFactory(org.slf4j.LoggerFactory) ManagedNamespaceWithLifecycle(org.eclipse.milo.opcua.sdk.server.api.ManagedNamespaceWithLifecycle) UaFolderNode(org.eclipse.milo.opcua.sdk.server.nodes.UaFolderNode) ValueRank(org.eclipse.milo.opcua.sdk.core.ValueRank) AccessLevel(org.eclipse.milo.opcua.sdk.core.AccessLevel) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) Tag(org.apache.plc4x.java.opcuaserver.configuration.Tag) PlcConnectionException(org.apache.plc4x.java.api.exceptions.PlcConnectionException) AttributeFilters(org.eclipse.milo.opcua.sdk.server.nodes.filters.AttributeFilters) PooledPlcDriverManager(org.apache.plc4x.java.utils.connectionpool.PooledPlcDriverManager) Reference(org.eclipse.milo.opcua.sdk.core.Reference) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) Logger(org.slf4j.Logger) UaVariableNode(org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) LocalizedText(org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText) SubscriptionModel(org.eclipse.milo.opcua.sdk.server.util.SubscriptionModel) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) MonitoredItem(org.eclipse.milo.opcua.sdk.server.api.MonitoredItem) List(java.util.List) Configuration(org.apache.plc4x.java.opcuaserver.configuration.Configuration) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) DeviceConfiguration(org.apache.plc4x.java.opcuaserver.configuration.DeviceConfiguration) DataTypeDictionaryManager(org.eclipse.milo.opcua.sdk.server.dtd.DataTypeDictionaryManager) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) UaVariableNode(org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) Tag(org.apache.plc4x.java.opcuaserver.configuration.Tag) PlcConnectionException(org.apache.plc4x.java.api.exceptions.PlcConnectionException)

Example 2 with Variant

use of org.eclipse.milo.opcua.stack.core.types.builtin.Variant in project FAAAST-Service by FraunhoferIOSB.

the class OpcUaAssetConnection method registerOperationProvider.

/**
 * {@inheritdoc}
 *
 * @throws AssetConnectionException if nodeId could not be parsed
 * @throws AssetConnectionException if nodeId does not refer to a method
 *             node
 * @throws AssetConnectionException if parent node of nodeId could not be
 *             resolved
 * @throws AssetConnectionException if output variables are null or do
 *             contain any other type than
 *             {@link de.fraunhofer.iosb.ilt.faaast.service.model.value.PropertyValue}
 */
@Override
public void registerOperationProvider(Reference reference, OpcUaOperationProviderConfig operationProvider) throws AssetConnectionException {
    String baseErrorMessage = "error registering operation provider";
    final NodeId nodeId = parseNodeId(operationProvider.getNodeId());
    final UaNode node;
    try {
        node = client.getAddressSpace().getNode(nodeId);
    } catch (UaException ex) {
        throw new AssetConnectionException(String.format("%s - could not resolve nodeId (nodeId: %s)", baseErrorMessage, operationProvider.getNodeId()), ex);
    }
    if (!UaMethodNode.class.isAssignableFrom(node.getClass())) {
        throw new AssetConnectionException(String.format("%s - provided node must be a method (nodeId: %s", baseErrorMessage, operationProvider.getNodeId()));
    }
    final UaMethodNode methodNode = (UaMethodNode) node;
    final NodeId parentNodeId;
    try {
        parentNodeId = client.getAddressSpace().getNode(nodeId).browseNodes(AddressSpace.BrowseOptions.builder().setBrowseDirection(BrowseDirection.Inverse).build()).get(0).getNodeId();
    } catch (UaException ex) {
        throw new AssetConnectionException(String.format("%s - could not resolve parent node (nodeId: %s)", baseErrorMessage, operationProvider.getNodeId()), ex);
    }
    final Argument[] methodArguments;
    try {
        methodArguments = methodNode.readInputArgumentsAsync().get() != null ? methodNode.readInputArgumentsAsync().get() : new Argument[0];
    } catch (InterruptedException | ExecutionException ex) {
        throw new AssetConnectionException(String.format("%s - could not read input arguments (nodeId: %s)", baseErrorMessage, operationProvider.getNodeId()), ex);
    }
    final Argument[] methodOutputArguments;
    try {
        methodOutputArguments = methodNode.readOutputArgumentsAsync().get() != null ? methodNode.readOutputArgumentsAsync().get() : new Argument[0];
    } catch (InterruptedException | ExecutionException ex) {
        throw new AssetConnectionException(String.format("%s - could not read ouput arguments (nodeId: %s)", baseErrorMessage, operationProvider.getNodeId()), ex);
    }
    final OperationVariable[] outputVariables = serviceContext.getOperationOutputVariables(reference) != null ? serviceContext.getOperationOutputVariables(reference) : new OperationVariable[0];
    for (var outputVariable : outputVariables) {
        if (outputVariable == null) {
            throw new AssetConnectionException(String.format("%s - output variable must be non-null (nodeId: %s)", baseErrorMessage, operationProvider.getNodeId()));
        }
        SubmodelElement submodelElement = outputVariable.getValue();
        if (submodelElement == null) {
            throw new AssetConnectionException(String.format("%s - output variable must contain non-null submodel element (nodeId: %s)", baseErrorMessage, operationProvider.getNodeId()));
        }
        if (!Property.class.isAssignableFrom(submodelElement.getClass())) {
            throw new AssetConnectionException(String.format("%s - unsupported element type (nodeId: %s, element type: %s)", baseErrorMessage, submodelElement.getClass(), operationProvider.getNodeId()));
        }
    }
    this.operationProviders.put(reference, new AssetOperationProvider() {

        @Override
        public OperationVariable[] invoke(OperationVariable[] input, OperationVariable[] inoutput) throws AssetConnectionException {
            String baseErrorMessage = "error invoking operation on asset connection";
            Map<String, ElementValue> inputParameter = input == null ? new HashMap<>() : Stream.of(input).collect(Collectors.toMap(x -> x.getValue().getIdShort(), x -> ElementValueMapper.toValue(x.getValue())));
            Map<String, ElementValue> inoutputParameter = inoutput == null ? new HashMap<>() : Stream.of(inoutput).collect(Collectors.toMap(x -> x.getValue().getIdShort(), x -> ElementValueMapper.toValue(x.getValue())));
            if (methodArguments.length != (inputParameter.size() + inoutputParameter.size())) {
                throw new AssetConnectionException(String.format("%s - argument count mismatch (expected: %d, provided input arguments: %d, provided inoutput arguments: %d)", baseErrorMessage, methodArguments.length, inputParameter.size(), inoutputParameter.size()));
            }
            Variant[] actualParameters = new Variant[methodArguments.length];
            for (int i = 0; i < methodArguments.length; i++) {
                String argumentName = methodArguments[i].getName();
                ElementValue parameterValue;
                if (inputParameter.containsKey(argumentName)) {
                    parameterValue = inputParameter.get(argumentName);
                } else if (inoutputParameter.containsKey(argumentName)) {
                    parameterValue = inoutputParameter.get(argumentName);
                } else {
                    throw new AssetConnectionException(String.format("%s - missing argument (argument name: %s)", baseErrorMessage, argumentName));
                }
                if (parameterValue == null) {
                    throw new AssetConnectionException(String.format("%s - parameter value must be non-null (argument name: %s)", baseErrorMessage, argumentName));
                }
                if (!PropertyValue.class.isAssignableFrom(parameterValue.getClass())) {
                    throw new AssetConnectionException(String.format("%s - currently only parameters of the Property are supported (argument name: %s, provided type: %s)", baseErrorMessage, argumentName, parameterValue.getClass()));
                }
                actualParameters[i] = valueConverter.convert(((PropertyValue) parameterValue).getValue(), methodArguments[i].getDataType());
            }
            CallMethodResult methodResult;
            try {
                methodResult = client.call(new CallMethodRequest(parentNodeId, nodeId, actualParameters)).get();
            } catch (InterruptedException | ExecutionException ex) {
                throw new AssetConnectionException(String.format("%s - executing OPC UA method failed (nodeId: %s)", baseErrorMessage, operationProvider.getNodeId()));
            }
            OperationVariable[] result = new OperationVariable[outputVariables.length];
            for (int i = 0; i < methodOutputArguments.length; i++) {
                String argumentName = methodArguments[i].getName();
                for (int j = 0; j < outputVariables.length; j++) {
                    if (Objects.equals(argumentName, outputVariables[j].getValue().getIdShort())) {
                        SubmodelElement element = outputVariables[j].getValue();
                        Datatype targetType = ((PropertyValue) ElementValueMapper.toValue(element)).getValue().getDataType();
                        TypedValue<?> newValue = valueConverter.convert(methodResult.getOutputArguments()[i], targetType);
                        // TODO better use deep copy?
                        DefaultProperty newProperty = new DefaultProperty.Builder().idShort(element.getIdShort()).build();
                        ElementValueMapper.setValue(newProperty, PropertyValue.builder().value(newValue).build());
                        result[j] = new DefaultOperationVariable.Builder().value(newProperty).build();
                    }
                }
                // update inoutput variable values
                if (inoutputParameter.containsKey(argumentName)) {
                    // find in original array and set there
                    for (int j = 0; j < inoutput.length; j++) {
                        if (Objects.equals(argumentName, inoutput[j].getValue().getIdShort())) {
                            ElementValueMapper.setValue(inoutput[j].getValue(), new PropertyValue(valueConverter.convert(methodResult.getOutputArguments()[i], ((PropertyValue) inoutputParameter.get(argumentName)).getValue().getDataType())));
                        }
                    }
                }
            }
            return result;
        }
    });
}
Also used : SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) ValueConversionException(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.opcua.conversion.ValueConversionException) DataElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.DataElementValue) VariableNode(org.eclipse.milo.opcua.sdk.core.nodes.VariableNode) LoggerFactory(org.slf4j.LoggerFactory) CallMethodResult(org.eclipse.milo.opcua.stack.core.types.structured.CallMethodResult) AddressSpace(org.eclipse.milo.opcua.sdk.client.AddressSpace) DefaultProperty(io.adminshell.aas.v3.model.impl.DefaultProperty) NewDataListener(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.NewDataListener) Argument(org.eclipse.milo.opcua.stack.core.types.structured.Argument) ManagedDataItem(org.eclipse.milo.opcua.sdk.client.subscriptions.ManagedDataItem) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) Property(io.adminshell.aas.v3.model.Property) Map(java.util.Map) AssetConnection(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnection) UaMethodNode(org.eclipse.milo.opcua.sdk.client.nodes.UaMethodNode) ManagedSubscription(org.eclipse.milo.opcua.sdk.client.subscriptions.ManagedSubscription) AnonymousProvider(org.eclipse.milo.opcua.sdk.client.api.identity.AnonymousProvider) TimestampsToReturn(org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) BrowseDirection(org.eclipse.milo.opcua.stack.core.types.enumerated.BrowseDirection) Reference(io.adminshell.aas.v3.model.Reference) Collectors(java.util.stream.Collectors) AssetConnectionException(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionException) AasUtils(io.adminshell.aas.v3.dataformat.core.util.AasUtils) TypedValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.TypedValue) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) CoreConfig(de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig) ElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue) UaNode(org.eclipse.milo.opcua.sdk.client.nodes.UaNode) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) TypeInfo(de.fraunhofer.iosb.ilt.faaast.service.typing.TypeInfo) Optional(java.util.Optional) ElementValueTypeInfo(de.fraunhofer.iosb.ilt.faaast.service.typing.ElementValueTypeInfo) CallMethodRequest(org.eclipse.milo.opcua.stack.core.types.structured.CallMethodRequest) DefaultOperationVariable(io.adminshell.aas.v3.model.impl.DefaultOperationVariable) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) OpcUaClient(org.eclipse.milo.opcua.sdk.client.OpcUaClient) OperationVariable(io.adminshell.aas.v3.model.OperationVariable) ServiceContext(de.fraunhofer.iosb.ilt.faaast.service.ServiceContext) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UShort(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UShort) SecurityPolicy(org.eclipse.milo.opcua.stack.core.security.SecurityPolicy) AssetOperationProvider(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetOperationProvider) StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) Logger(org.slf4j.Logger) ElementValueMapper(de.fraunhofer.iosb.ilt.faaast.service.model.value.mapper.ElementValueMapper) Datatype(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.Datatype) LocalizedText(org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText) ValueConverter(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.opcua.conversion.ValueConverter) AssetSubscriptionProvider(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetSubscriptionProvider) ExecutionException(java.util.concurrent.ExecutionException) UaException(org.eclipse.milo.opcua.stack.core.UaException) LambdaExceptionHelper(de.fraunhofer.iosb.ilt.faaast.service.util.LambdaExceptionHelper) AssetValueProvider(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetValueProvider) PropertyValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.PropertyValue) DefaultOperationVariable(io.adminshell.aas.v3.model.impl.DefaultOperationVariable) OperationVariable(io.adminshell.aas.v3.model.OperationVariable) Argument(org.eclipse.milo.opcua.stack.core.types.structured.Argument) HashMap(java.util.HashMap) UaException(org.eclipse.milo.opcua.stack.core.UaException) UaNode(org.eclipse.milo.opcua.sdk.client.nodes.UaNode) Datatype(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.Datatype) UaMethodNode(org.eclipse.milo.opcua.sdk.client.nodes.UaMethodNode) CallMethodResult(org.eclipse.milo.opcua.stack.core.types.structured.CallMethodResult) AssetConnectionException(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionException) ExecutionException(java.util.concurrent.ExecutionException) DefaultProperty(io.adminshell.aas.v3.model.impl.DefaultProperty) Property(io.adminshell.aas.v3.model.Property) TypedValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.TypedValue) PropertyValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.PropertyValue) CallMethodRequest(org.eclipse.milo.opcua.stack.core.types.structured.CallMethodRequest) DataElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.DataElementValue) ElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue) DefaultProperty(io.adminshell.aas.v3.model.impl.DefaultProperty) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) AssetOperationProvider(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetOperationProvider) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with Variant

use of org.eclipse.milo.opcua.stack.core.types.builtin.Variant in project FAAAST-Service by FraunhoferIOSB.

the class ExampleNamespace method addDataAccessNodes.

private void addDataAccessNodes(UaFolderNode rootNode) {
    // DataAccess folder
    UaFolderNode dataAccessFolder = new UaFolderNode(getNodeContext(), newNodeId("HelloWorld/DataAccess"), newQualifiedName("DataAccess"), LocalizedText.english("DataAccess"));
    getNodeManager().addNode(dataAccessFolder);
    rootNode.addOrganizes(dataAccessFolder);
    try {
        AnalogItemTypeNode node = (AnalogItemTypeNode) getNodeFactory().createNode(newNodeId("HelloWorld/DataAccess/AnalogValue"), Identifiers.AnalogItemType, new NodeFactory.InstantiationCallback() {

            @Override
            public boolean includeOptionalNode(NodeId typeDefinitionId, QualifiedName browseName) {
                return true;
            }
        });
        node.setBrowseName(newQualifiedName("AnalogValue"));
        node.setDisplayName(LocalizedText.english("AnalogValue"));
        node.setDataType(Identifiers.Double);
        node.setValue(new DataValue(new Variant(3.14d)));
        node.setEURange(new Range(0.0, 100.0));
        getNodeManager().addNode(node);
        dataAccessFolder.addOrganizes(node);
    } catch (UaException e) {
        logger.error("Error creating AnalogItemType instance: {}", e.getMessage(), e);
    }
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) AnalogItemTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.variables.AnalogItemTypeNode) 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) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) UaFolderNode(org.eclipse.milo.opcua.sdk.server.nodes.UaFolderNode) Range(org.eclipse.milo.opcua.stack.core.types.structured.Range)

Example 4 with Variant

use of org.eclipse.milo.opcua.stack.core.types.builtin.Variant in project FAAAST-Service by FraunhoferIOSB.

the class ExampleNamespace method addDynamicNodes.

private void addDynamicNodes(UaFolderNode rootNode) {
    UaFolderNode dynamicFolder = new UaFolderNode(getNodeContext(), newNodeId("HelloWorld/Dynamic"), newQualifiedName("Dynamic"), LocalizedText.english("Dynamic"));
    getNodeManager().addNode(dynamicFolder);
    rootNode.addOrganizes(dynamicFolder);
    // Dynamic Boolean
    {
        String name = "Boolean";
        NodeId typeId = Identifiers.Boolean;
        Variant variant = new Variant(false);
        UaVariableNode node = new UaVariableNode.UaVariableNodeBuilder(getNodeContext()).setNodeId(newNodeId("HelloWorld/Dynamic/" + name)).setAccessLevel(AccessLevel.READ_WRITE).setBrowseName(newQualifiedName(name)).setDisplayName(LocalizedText.english(name)).setDataType(typeId).setTypeDefinition(Identifiers.BaseDataVariableType).build();
        node.setValue(new DataValue(variant));
        getNodeManager().addNode(node);
        dynamicFolder.addOrganizes(node);
    }
    // Dynamic Int32
    {
        String name = "Int32";
        NodeId typeId = Identifiers.Int32;
        Variant variant = new Variant(0);
        UaVariableNode node = new UaVariableNode.UaVariableNodeBuilder(getNodeContext()).setNodeId(newNodeId("HelloWorld/Dynamic/" + name)).setAccessLevel(AccessLevel.READ_WRITE).setBrowseName(newQualifiedName(name)).setDisplayName(LocalizedText.english(name)).setDataType(typeId).setTypeDefinition(Identifiers.BaseDataVariableType).build();
        node.setValue(new DataValue(variant));
        getNodeManager().addNode(node);
        dynamicFolder.addOrganizes(node);
    }
    // Dynamic Double
    {
        String name = "Double";
        NodeId typeId = Identifiers.Double;
        Variant variant = new Variant(0.0);
        UaVariableNode node = new UaVariableNode.UaVariableNodeBuilder(getNodeContext()).setNodeId(newNodeId("HelloWorld/Dynamic/" + name)).setAccessLevel(AccessLevel.READ_WRITE).setBrowseName(newQualifiedName(name)).setDisplayName(LocalizedText.english(name)).setDataType(typeId).setTypeDefinition(Identifiers.BaseDataVariableType).build();
        node.setValue(new DataValue(variant));
        getNodeManager().addNode(node);
        dynamicFolder.addOrganizes(node);
    }
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) UaVariableNode(org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) UaFolderNode(org.eclipse.milo.opcua.sdk.server.nodes.UaFolderNode) ByteString(org.eclipse.milo.opcua.stack.core.types.builtin.ByteString)

Example 5 with Variant

use of org.eclipse.milo.opcua.stack.core.types.builtin.Variant in project FAAAST-Service by FraunhoferIOSB.

the class ExampleNamespace method addAdminWritableNodes.

private void addAdminWritableNodes(UaFolderNode rootNode) {
    UaFolderNode adminFolder = new UaFolderNode(getNodeContext(), newNodeId("HelloWorld/OnlyAdminCanWrite"), newQualifiedName("OnlyAdminCanWrite"), LocalizedText.english("OnlyAdminCanWrite"));
    getNodeManager().addNode(adminFolder);
    rootNode.addOrganizes(adminFolder);
    String name = "String";
    UaVariableNode node = new UaVariableNode.UaVariableNodeBuilder(getNodeContext()).setNodeId(newNodeId("HelloWorld/OnlyAdminCanWrite/" + name)).setAccessLevel(AccessLevel.READ_WRITE).setBrowseName(newQualifiedName(name)).setDisplayName(LocalizedText.english(name)).setDataType(Identifiers.String).setTypeDefinition(Identifiers.BaseDataVariableType).build();
    node.setValue(new DataValue(new Variant("admin was here")));
    getNodeManager().addNode(node);
    adminFolder.addOrganizes(node);
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) UaVariableNode(org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) UaFolderNode(org.eclipse.milo.opcua.sdk.server.nodes.UaFolderNode) ByteString(org.eclipse.milo.opcua.stack.core.types.builtin.ByteString)

Aggregations

Variant (org.eclipse.milo.opcua.stack.core.types.builtin.Variant)902 DataValue (org.eclipse.milo.opcua.stack.core.types.builtin.DataValue)419 QualifiedName (org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName)272 Reference (org.eclipse.milo.opcua.sdk.core.Reference)267 LocalizedText (org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText)265 StringReader (java.io.StringReader)243 OpcUaXmlStreamDecoder (org.eclipse.milo.opcua.stack.core.serialization.OpcUaXmlStreamDecoder)243 PropertyTypeNode (org.eclipse.milo.opcua.sdk.client.model.nodes.variables.PropertyTypeNode)196 ExtensionObject (org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject)190 PropertyTypeNode (org.eclipse.milo.opcua.sdk.server.model.nodes.variables.PropertyTypeNode)169 DataTypeDescriptionTypeNode (org.eclipse.milo.opcua.sdk.server.model.nodes.variables.DataTypeDescriptionTypeNode)75 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)58 UaException (org.eclipse.milo.opcua.stack.core.UaException)57 ByteString (org.eclipse.milo.opcua.stack.core.types.builtin.ByteString)42 StatusCode (org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)40 Test (org.testng.annotations.Test)35 UaVariableNode (org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode)34 UInteger (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger)29 UaFolderNode (org.eclipse.milo.opcua.sdk.server.nodes.UaFolderNode)22 Identifiers (org.eclipse.milo.opcua.stack.core.Identifiers)22