use of org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode 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);
}
}
use of org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode 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);
}
}
use of org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode 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);
}
use of org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode 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);
}
}
use of org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode in project milo by eclipse.
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));
}
Aggregations