Search in sources :

Example 21 with UaVariableNode

use of org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode in project tech-pdai-spring-demos by realpdai.

the class ExampleNamespace method addCustomUnionTypeVariable.

private void addCustomUnionTypeVariable(UaFolderNode rootFolder) throws Exception {
    NodeId dataTypeId = CustomUnionType.TYPE_ID.toNodeIdOrThrow(getServer().getNamespaceTable());
    NodeId binaryEncodingId = CustomUnionType.BINARY_ENCODING_ID.toNodeIdOrThrow(getServer().getNamespaceTable());
    UaVariableNode customUnionTypeVariable = UaVariableNode.builder(getNodeContext()).setNodeId(newNodeId("HelloWorld/CustomUnionTypeVariable")).setAccessLevel(AccessLevel.READ_WRITE).setUserAccessLevel(AccessLevel.READ_WRITE).setBrowseName(newQualifiedName("CustomUnionTypeVariable")).setDisplayName(LocalizedText.english("CustomUnionTypeVariable")).setDataType(dataTypeId).setTypeDefinition(Identifiers.BaseDataVariableType).build();
    CustomUnionType value = CustomUnionType.ofBar("hello");
    ExtensionObject xo = ExtensionObject.encodeDefaultBinary(getServer().getSerializationContext(), value, binaryEncodingId);
    customUnionTypeVariable.setValue(new DataValue(new Variant(xo)));
    getNodeManager().addNode(customUnionTypeVariable);
    customUnionTypeVariable.addReference(new Reference(customUnionTypeVariable.getNodeId(), Identifiers.Organizes, rootFolder.getNodeId().expanded(), false));
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) UaVariableNode(org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode) CustomUnionType(tech.pdai.opcua.milo.server.types.CustomUnionType) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) Reference(org.eclipse.milo.opcua.sdk.core.Reference) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)

Example 22 with UaVariableNode

use of org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode in project tech-pdai-spring-demos by realpdai.

the class ExampleNamespace method addCustomObjectTypeAndInstance.

private void addCustomObjectTypeAndInstance(UaFolderNode rootFolder) {
    // Define a new ObjectType called "MyObjectType".
    UaObjectTypeNode objectTypeNode = UaObjectTypeNode.builder(getNodeContext()).setNodeId(newNodeId("ObjectTypes/MyObjectType")).setBrowseName(newQualifiedName("MyObjectType")).setDisplayName(LocalizedText.english("MyObjectType")).setIsAbstract(false).build();
    // "Foo" and "Bar" are members. These nodes are what are called "instance declarations" by the spec.
    UaVariableNode foo = UaVariableNode.builder(getNodeContext()).setNodeId(newNodeId("ObjectTypes/MyObjectType.Foo")).setAccessLevel(AccessLevel.READ_WRITE).setBrowseName(newQualifiedName("Foo")).setDisplayName(LocalizedText.english("Foo")).setDataType(Identifiers.Int16).setTypeDefinition(Identifiers.BaseDataVariableType).build();
    foo.addReference(new Reference(foo.getNodeId(), Identifiers.HasModellingRule, Identifiers.ModellingRule_Mandatory.expanded(), true));
    foo.setValue(new DataValue(new Variant(0)));
    objectTypeNode.addComponent(foo);
    UaVariableNode bar = UaVariableNode.builder(getNodeContext()).setNodeId(newNodeId("ObjectTypes/MyObjectType.Bar")).setAccessLevel(AccessLevel.READ_WRITE).setBrowseName(newQualifiedName("Bar")).setDisplayName(LocalizedText.english("Bar")).setDataType(Identifiers.String).setTypeDefinition(Identifiers.BaseDataVariableType).build();
    bar.addReference(new Reference(bar.getNodeId(), Identifiers.HasModellingRule, Identifiers.ModellingRule_Mandatory.expanded(), true));
    bar.setValue(new DataValue(new Variant("bar")));
    objectTypeNode.addComponent(bar);
    // Tell the ObjectTypeManager about our new type.
    // This let's us use NodeFactory to instantiate instances of the type.
    getServer().getObjectTypeManager().registerObjectType(objectTypeNode.getNodeId(), UaObjectNode.class, UaObjectNode::new);
    // Add the inverse SubtypeOf relationship.
    objectTypeNode.addReference(new Reference(objectTypeNode.getNodeId(), Identifiers.HasSubtype, Identifiers.BaseObjectType.expanded(), false));
    // Add type definition and declarations to address space.
    getNodeManager().addNode(objectTypeNode);
    getNodeManager().addNode(foo);
    getNodeManager().addNode(bar);
    // as well as adding all nodes to the address space.
    try {
        UaObjectNode myObject = (UaObjectNode) getNodeFactory().createNode(newNodeId("HelloWorld/MyObject"), objectTypeNode.getNodeId());
        myObject.setBrowseName(newQualifiedName("MyObject"));
        myObject.setDisplayName(LocalizedText.english("MyObject"));
        // Add forward and inverse references from the root folder.
        rootFolder.addOrganizes(myObject);
        myObject.addReference(new Reference(myObject.getNodeId(), Identifiers.Organizes, rootFolder.getNodeId().expanded(), false));
    } catch (UaException e) {
        logger.error("Error creating MyObjectType instance: {}", e.getMessage(), e);
    }
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) UaObjectTypeNode(org.eclipse.milo.opcua.sdk.server.nodes.UaObjectTypeNode) UaVariableNode(org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode) UaObjectNode(org.eclipse.milo.opcua.sdk.server.nodes.UaObjectNode) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) Reference(org.eclipse.milo.opcua.sdk.core.Reference) UaException(org.eclipse.milo.opcua.stack.core.UaException)

Example 23 with UaVariableNode

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

use of org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode in project FAAAST-Service by FraunhoferIOSB.

the class ExampleNamespace method addCustomObjectTypeAndInstance.

private void addCustomObjectTypeAndInstance(UaFolderNode rootFolder) {
    // Define a new ObjectType called "MyObjectType".
    UaObjectTypeNode objectTypeNode = UaObjectTypeNode.builder(getNodeContext()).setNodeId(newNodeId("ObjectTypes/MyObjectType")).setBrowseName(newQualifiedName("MyObjectType")).setDisplayName(LocalizedText.english("MyObjectType")).setIsAbstract(false).build();
    // "Foo" and "Bar" are members. These nodes are what are called "instance declarations" by the spec.
    UaVariableNode foo = UaVariableNode.builder(getNodeContext()).setNodeId(newNodeId("ObjectTypes/MyObjectType.Foo")).setAccessLevel(AccessLevel.READ_WRITE).setBrowseName(newQualifiedName("Foo")).setDisplayName(LocalizedText.english("Foo")).setDataType(Identifiers.Int16).setTypeDefinition(Identifiers.BaseDataVariableType).build();
    foo.addReference(new Reference(foo.getNodeId(), Identifiers.HasModellingRule, Identifiers.ModellingRule_Mandatory.expanded(), true));
    foo.setValue(new DataValue(new Variant(0)));
    objectTypeNode.addComponent(foo);
    UaVariableNode bar = UaVariableNode.builder(getNodeContext()).setNodeId(newNodeId("ObjectTypes/MyObjectType.Bar")).setAccessLevel(AccessLevel.READ_WRITE).setBrowseName(newQualifiedName("Bar")).setDisplayName(LocalizedText.english("Bar")).setDataType(Identifiers.String).setTypeDefinition(Identifiers.BaseDataVariableType).build();
    bar.addReference(new Reference(bar.getNodeId(), Identifiers.HasModellingRule, Identifiers.ModellingRule_Mandatory.expanded(), true));
    bar.setValue(new DataValue(new Variant("bar")));
    objectTypeNode.addComponent(bar);
    // Tell the ObjectTypeManager about our new type.
    // This let's us use NodeFactory to instantiate instances of the type.
    getServer().getObjectTypeManager().registerObjectType(objectTypeNode.getNodeId(), UaObjectNode.class, UaObjectNode::new);
    // Add the inverse SubtypeOf relationship.
    objectTypeNode.addReference(new Reference(objectTypeNode.getNodeId(), Identifiers.HasSubtype, Identifiers.BaseObjectType.expanded(), false));
    // Add type definition and declarations to address space.
    getNodeManager().addNode(objectTypeNode);
    getNodeManager().addNode(foo);
    getNodeManager().addNode(bar);
    // as well as adding all nodes to the address space.
    try {
        UaObjectNode myObject = (UaObjectNode) getNodeFactory().createNode(newNodeId("HelloWorld/MyObject"), objectTypeNode.getNodeId());
        myObject.setBrowseName(newQualifiedName("MyObject"));
        myObject.setDisplayName(LocalizedText.english("MyObject"));
        // Add forward and inverse references from the root folder.
        rootFolder.addOrganizes(myObject);
        myObject.addReference(new Reference(myObject.getNodeId(), Identifiers.Organizes, rootFolder.getNodeId().expanded(), false));
    } catch (UaException e) {
        logger.error("Error creating MyObjectType instance: {}", e.getMessage(), e);
    }
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) UaObjectTypeNode(org.eclipse.milo.opcua.sdk.server.nodes.UaObjectTypeNode) UaVariableNode(org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode) UaObjectNode(org.eclipse.milo.opcua.sdk.server.nodes.UaObjectNode) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) Reference(org.eclipse.milo.opcua.sdk.core.Reference) UaException(org.eclipse.milo.opcua.stack.core.UaException)

Example 25 with UaVariableNode

use of org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode in project FAAAST-Service by FraunhoferIOSB.

the class ExampleNamespace method addScalarNodes.

private void addScalarNodes(UaFolderNode rootNode) {
    UaFolderNode scalarTypesFolder = new UaFolderNode(getNodeContext(), newNodeId("HelloWorld/ScalarTypes"), newQualifiedName("ScalarTypes"), LocalizedText.english("ScalarTypes"));
    getNodeManager().addNode(scalarTypesFolder);
    rootNode.addOrganizes(scalarTypesFolder);
    for (Object[] os : STATIC_SCALAR_NODES) {
        String name = (String) os[0];
        NodeId typeId = (NodeId) os[1];
        Variant variant = (Variant) os[2];
        UaVariableNode node = new UaVariableNode.UaVariableNodeBuilder(getNodeContext()).setNodeId(newNodeId("HelloWorld/ScalarTypes/" + name)).setAccessLevel(AccessLevel.READ_WRITE).setUserAccessLevel(AccessLevel.READ_WRITE).setBrowseName(newQualifiedName(name)).setDisplayName(LocalizedText.english(name)).setDataType(typeId).setTypeDefinition(Identifiers.BaseDataVariableType).build();
        node.setValue(new DataValue(variant));
        getNodeManager().addNode(node);
        scalarTypesFolder.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

UaVariableNode (org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode)38 DataValue (org.eclipse.milo.opcua.stack.core.types.builtin.DataValue)31 Variant (org.eclipse.milo.opcua.stack.core.types.builtin.Variant)31 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)25 UaFolderNode (org.eclipse.milo.opcua.sdk.server.nodes.UaFolderNode)17 Reference (org.eclipse.milo.opcua.sdk.core.Reference)16 ByteString (org.eclipse.milo.opcua.stack.core.types.builtin.ByteString)15 UaObjectNode (org.eclipse.milo.opcua.sdk.server.nodes.UaObjectNode)13 UaNode (org.eclipse.milo.opcua.sdk.server.nodes.UaNode)11 ExtensionObject (org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject)10 LocalizedText (org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText)10 QualifiedName (org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName)10 UaObjectTypeNode (org.eclipse.milo.opcua.sdk.server.nodes.UaObjectTypeNode)9 UaException (org.eclipse.milo.opcua.stack.core.UaException)9 AttributeFilters (org.eclipse.milo.opcua.sdk.server.nodes.filters.AttributeFilters)8 Identifiers (org.eclipse.milo.opcua.stack.core.Identifiers)8 OpcUaServer (org.eclipse.milo.opcua.sdk.server.OpcUaServer)7 UaMethodNode (org.eclipse.milo.opcua.sdk.server.nodes.UaMethodNode)7 AccessLevel (org.eclipse.milo.opcua.sdk.core.AccessLevel)6 AttributeId (org.eclipse.milo.opcua.stack.core.AttributeId)6