Search in sources :

Example 6 with UaFolderNode

use of org.eclipse.milo.opcua.sdk.server.nodes.UaFolderNode in project OpenMUC by isc-konstanz.

the class ChannelNamespace method addChannelNode.

public void addChannelNode(OpcChannel channel) throws UaException {
    String folderName = channel.getFolder();
    UaFolderNode folderNode;
    if (folderName != null) {
        folderNode = new UaFolderNode(getNodeContext(), newNodeId(folderName), newQualifiedName(folderName), LocalizedText.english(folderName));
        folderNode.addReference(new Reference(folderNode.getNodeId(), Identifiers.Organizes, Identifiers.ObjectsFolder.expanded(), false));
    } else {
        folderNode = new UaFolderNode(getNodeContext(), Identifiers.ObjectsFolder, newQualifiedName("ObjectsFolder"), LocalizedText.english("ObjectsFolder"));
        folderNode.addReference(new Reference(folderNode.getNodeId(), Identifiers.Organizes, Identifiers.RootFolder.expanded(), false));
    }
    getNodeManager().addNode(folderNode);
    // Adding variable to address space
    AttributeContext context = new AttributeContext(getServer());
    String name = channel.getDescription();
    if (name.isEmpty()) {
        name = channel.getId();
    }
    UaVariableNode node = new UaVariableNode.UaVariableNodeBuilder(getNodeContext()).setNodeId(newNodeId(channel.getId())).setAccessLevel(AccessLevel.toValue(AccessLevel.READ_WRITE)).setBrowseName(newQualifiedName(channel.getId())).setDisplayName(LocalizedText.english(name)).setDataType(channel.getNodeType()).setTypeDefinition(Identifiers.BaseDataVariableType).build();
    node.setValue(channel.getValue(context, node));
    node.setAttributeDelegate(channel);
    getNodeManager().addNode(node);
    folderNode.addOrganizes(node);
}
Also used : AttributeContext(org.eclipse.milo.opcua.sdk.server.nodes.AttributeContext) UaVariableNode(org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode) Reference(org.eclipse.milo.opcua.sdk.core.Reference) UaFolderNode(org.eclipse.milo.opcua.sdk.server.nodes.UaFolderNode)

Example 7 with UaFolderNode

use of org.eclipse.milo.opcua.sdk.server.nodes.UaFolderNode 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 8 with UaFolderNode

use of org.eclipse.milo.opcua.sdk.server.nodes.UaFolderNode 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 9 with UaFolderNode

use of org.eclipse.milo.opcua.sdk.server.nodes.UaFolderNode 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)

Example 10 with UaFolderNode

use of org.eclipse.milo.opcua.sdk.server.nodes.UaFolderNode in project milo by eclipse.

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));
        node.getFilterChain().addLast(new AttributeLoggingFilter(), AttributeFilters.getValue(ctx -> new DataValue(new Variant(random.nextBoolean()))));
        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));
        node.getFilterChain().addLast(new AttributeLoggingFilter(), AttributeFilters.getValue(ctx -> new DataValue(new Variant(random.nextInt()))));
        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));
        node.getFilterChain().addLast(new AttributeLoggingFilter(), AttributeFilters.getValue(ctx -> new DataValue(new Variant(random.nextDouble()))));
        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)

Aggregations

UaFolderNode (org.eclipse.milo.opcua.sdk.server.nodes.UaFolderNode)27 DataValue (org.eclipse.milo.opcua.stack.core.types.builtin.DataValue)22 Variant (org.eclipse.milo.opcua.stack.core.types.builtin.Variant)22 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)21 ByteString (org.eclipse.milo.opcua.stack.core.types.builtin.ByteString)18 UaVariableNode (org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode)17 Reference (org.eclipse.milo.opcua.sdk.core.Reference)13 UaException (org.eclipse.milo.opcua.stack.core.UaException)9 AttributeId (org.eclipse.milo.opcua.stack.core.AttributeId)8 ExtensionObject (org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject)8 Unsigned.uint (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint)8 AnalogItemTypeNode (org.eclipse.milo.opcua.sdk.server.model.nodes.variables.AnalogItemTypeNode)7 QualifiedName (org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName)7 Range (org.eclipse.milo.opcua.stack.core.types.structured.Range)7 Array (java.lang.reflect.Array)5 List (java.util.List)5 AccessLevel (org.eclipse.milo.opcua.sdk.core.AccessLevel)5 ValueRank (org.eclipse.milo.opcua.sdk.core.ValueRank)5 OpcUaServer (org.eclipse.milo.opcua.sdk.server.OpcUaServer)5 DataItem (org.eclipse.milo.opcua.sdk.server.api.DataItem)5