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));
}
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);
}
}
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);
}
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);
}
}
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);
}
}
Aggregations