Search in sources :

Example 1 with QualifiedName

use of org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName 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 2 with QualifiedName

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

the class ExampleNamespace method startBogusEventNotifier.

private void startBogusEventNotifier() {
    // Set the EventNotifier bit on Server Node for Events.
    UaNode serverNode = getServer().getAddressSpaceManager().getManagedNode(Identifiers.Server).orElse(null);
    if (serverNode instanceof ServerTypeNode) {
        ((ServerTypeNode) serverNode).setEventNotifier(ubyte(1));
        // Post a bogus Event every couple seconds
        eventThread = new Thread(() -> {
            while (keepPostingEvents) {
                try {
                    BaseEventTypeNode eventNode = getServer().getEventFactory().createEvent(newNodeId(UUID.randomUUID()), Identifiers.BaseEventType);
                    eventNode.setBrowseName(new QualifiedName(1, "foo"));
                    eventNode.setDisplayName(LocalizedText.english("foo"));
                    eventNode.setEventId(ByteString.of(new byte[] { 0, 1, 2, 3 }));
                    eventNode.setEventType(Identifiers.BaseEventType);
                    eventNode.setSourceNode(serverNode.getNodeId());
                    eventNode.setSourceName(serverNode.getDisplayName().getText());
                    eventNode.setTime(DateTime.now());
                    eventNode.setReceiveTime(DateTime.NULL_VALUE);
                    eventNode.setMessage(LocalizedText.english("event message!"));
                    eventNode.setSeverity(ushort(2));
                    // noinspection UnstableApiUsage
                    getServer().getEventBus().post(eventNode);
                    eventNode.delete();
                } catch (Throwable e) {
                    logger.error("Error creating EventNode: {}", e.getMessage(), e);
                }
                try {
                    // noinspection BusyWait
                    Thread.sleep(2_000);
                } catch (InterruptedException ignored) {
                // ignored
                }
            }
        }, "bogus-event-poster");
        eventThread.start();
    }
}
Also used : BaseEventTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.BaseEventTypeNode) ServerTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerTypeNode) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode)

Example 3 with QualifiedName

use of org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName in project milo by eclipse.

the class DataTypeDictionaryManager method registerStructureDescription.

public void registerStructureDescription(StructureDescription description, NodeId binaryEncodingId) {
    structureDescriptions.put(description.getDataTypeId(), description);
    // Add a DataTypeDescriptionTypeNode with a ComponentOf reference to
    // dictionaryNode.
    DataTypeDescriptionTypeNode descriptionNode = new DataTypeDescriptionTypeNode(getNodeContext(), newNodeId(String.format("%s.Description", description.getName())), newQualifiedName(description.getName().getName()), LocalizedText.english(description.getName().getName()), LocalizedText.NULL_VALUE, uint(0), uint(0));
    descriptionNode.setValue(new DataValue(new Variant(description.getName().getName())));
    descriptionNode.setDataType(Identifiers.String);
    descriptionNode.addReference(new Reference(descriptionNode.getNodeId(), Identifiers.HasTypeDefinition, Identifiers.DataTypeDescriptionType.expanded(), Direction.FORWARD));
    descriptionNode.addReference(new Reference(descriptionNode.getNodeId(), Identifiers.HasComponent, dictionaryNode.getNodeId().expanded(), Direction.INVERSE));
    addNode(descriptionNode);
    // Add a DataTypeEncodingTypeNode with a HasDescription reference to
    // descriptionNode and an EncodingOf reference to the DataTypeNode.
    DataTypeEncodingTypeNode dataTypeEncodingNode = new DataTypeEncodingTypeNode(getNodeContext(), binaryEncodingId, new QualifiedName(0, "Default Binary"), LocalizedText.english("Default Binary"), LocalizedText.NULL_VALUE, uint(0), uint(0));
    dataTypeEncodingNode.addReference(new Reference(dataTypeEncodingNode.getNodeId(), Identifiers.HasTypeDefinition, Identifiers.DataTypeEncodingType.expanded(), Direction.FORWARD));
    dataTypeEncodingNode.addReference(new Reference(dataTypeEncodingNode.getNodeId(), Identifiers.HasDescription, descriptionNode.getNodeId().expanded(), Direction.FORWARD));
    dataTypeEncodingNode.addReference(new Reference(dataTypeEncodingNode.getNodeId(), Identifiers.HasEncoding, description.getDataTypeId().expanded(), Direction.INVERSE));
    addNode(dataTypeEncodingNode);
    dictionaryFile.reset();
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) DataTypeDescriptionTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.variables.DataTypeDescriptionTypeNode) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) Reference(org.eclipse.milo.opcua.sdk.core.Reference) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) DataTypeEncodingTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.DataTypeEncodingTypeNode)

Example 4 with QualifiedName

use of org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName in project milo by eclipse.

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 5 with QualifiedName

use of org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName in project milo by eclipse.

the class ExampleNamespace method registerCustomEnumType.

private void registerCustomEnumType() throws Exception {
    NodeId dataTypeId = CustomEnumType.TYPE_ID.toNodeIdOrThrow(getServer().getNamespaceTable());
    dictionaryManager.registerEnumCodec(new CustomEnumType.Codec().asBinaryCodec(), "CustomEnumType", dataTypeId);
    UaNode node = getNodeManager().get(dataTypeId);
    if (node instanceof UaDataTypeNode) {
        UaDataTypeNode dataTypeNode = (UaDataTypeNode) node;
        dataTypeNode.setEnumStrings(new LocalizedText[] { LocalizedText.english("Field0"), LocalizedText.english("Field1"), LocalizedText.english("Field2") });
    }
    EnumField[] fields = new EnumField[] { new EnumField(0L, LocalizedText.english("Field0"), LocalizedText.NULL_VALUE, "Field0"), new EnumField(1L, LocalizedText.english("Field1"), LocalizedText.NULL_VALUE, "Field1"), new EnumField(2L, LocalizedText.english("Field2"), LocalizedText.NULL_VALUE, "Field2") };
    EnumDefinition definition = new EnumDefinition(fields);
    EnumDescription description = new EnumDescription(dataTypeId, new QualifiedName(getNamespaceIndex(), "CustomEnumType"), definition, ubyte(BuiltinDataType.Int32.getTypeId()));
    dictionaryManager.registerEnumDescription(description);
}
Also used : EnumField(org.eclipse.milo.opcua.stack.core.types.structured.EnumField) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) EnumDefinition(org.eclipse.milo.opcua.stack.core.types.structured.EnumDefinition) UaDataTypeNode(org.eclipse.milo.opcua.sdk.server.nodes.UaDataTypeNode) EnumDescription(org.eclipse.milo.opcua.stack.core.types.structured.EnumDescription)

Aggregations

QualifiedName (org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName)1615 LocalizedText (org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText)1562 Reference (org.eclipse.milo.opcua.sdk.core.Reference)1551 DataValue (org.eclipse.milo.opcua.stack.core.types.builtin.DataValue)881 PropertyTypeNode (org.eclipse.milo.opcua.sdk.server.model.nodes.variables.PropertyTypeNode)477 Variant (org.eclipse.milo.opcua.stack.core.types.builtin.Variant)265 StringReader (java.io.StringReader)243 OpcUaXmlStreamDecoder (org.eclipse.milo.opcua.stack.core.serialization.OpcUaXmlStreamDecoder)243 BaseDataVariableTypeNode (org.eclipse.milo.opcua.sdk.server.model.nodes.variables.BaseDataVariableTypeNode)227 UaMethodNode (org.eclipse.milo.opcua.sdk.server.nodes.UaMethodNode)145 UaDataTypeNode (org.eclipse.milo.opcua.sdk.server.nodes.UaDataTypeNode)131 DataTypeEncodingTypeNode (org.eclipse.milo.opcua.sdk.server.model.nodes.objects.DataTypeEncodingTypeNode)121 UaObjectTypeNode (org.eclipse.milo.opcua.sdk.server.nodes.UaObjectTypeNode)121 DataTypeDescriptionTypeNode (org.eclipse.milo.opcua.sdk.server.model.nodes.variables.DataTypeDescriptionTypeNode)74 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)45 AggregateFunctionTypeNode (org.eclipse.milo.opcua.sdk.server.model.nodes.objects.AggregateFunctionTypeNode)37 UaVariableTypeNode (org.eclipse.milo.opcua.sdk.server.nodes.UaVariableTypeNode)37 UaReferenceTypeNode (org.eclipse.milo.opcua.sdk.server.nodes.UaReferenceTypeNode)27 UaException (org.eclipse.milo.opcua.stack.core.UaException)27 UInteger (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger)21