use of org.eclipse.milo.examples.server.types.CustomStructType in project milo by eclipse.
the class ExampleNamespace method addCustomStructTypeVariable.
private void addCustomStructTypeVariable(UaFolderNode rootFolder) throws Exception {
NodeId dataTypeId = CustomStructType.TYPE_ID.toNodeIdOrThrow(getServer().getNamespaceTable());
NodeId binaryEncodingId = CustomStructType.BINARY_ENCODING_ID.toNodeIdOrThrow(getServer().getNamespaceTable());
UaVariableNode customStructTypeVariable = UaVariableNode.builder(getNodeContext()).setNodeId(newNodeId("HelloWorld/CustomStructTypeVariable")).setAccessLevel(AccessLevel.READ_WRITE).setUserAccessLevel(AccessLevel.READ_WRITE).setBrowseName(newQualifiedName("CustomStructTypeVariable")).setDisplayName(LocalizedText.english("CustomStructTypeVariable")).setDataType(dataTypeId).setTypeDefinition(Identifiers.BaseDataVariableType).build();
CustomStructType value = new CustomStructType("foo", uint(42), true);
ExtensionObject xo = ExtensionObject.encodeDefaultBinary(getServer().getSerializationContext(), value, binaryEncodingId);
customStructTypeVariable.setValue(new DataValue(new Variant(xo)));
getNodeManager().addNode(customStructTypeVariable);
customStructTypeVariable.addReference(new Reference(customStructTypeVariable.getNodeId(), Identifiers.Organizes, rootFolder.getNodeId().expanded(), false));
}
use of org.eclipse.milo.examples.server.types.CustomStructType in project milo by eclipse.
the class ReadWriteCustomDataTypeNodeExample method run.
@Override
public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throws Exception {
// synchronous connect
client.connect().get();
registerCustomCodec(client);
// synchronous read request via VariableNode
UaVariableNode node = client.getAddressSpace().getVariableNode(new NodeId(2, "HelloWorld/CustomStructTypeVariable"));
logger.info("DataType={}", node.getDataType());
// Read the current value
DataValue value = node.readValue();
logger.info("Value={}", value);
Variant variant = value.getValue();
ExtensionObject xo = (ExtensionObject) variant.getValue();
CustomStructType decoded = (CustomStructType) xo.decode(client.getStaticSerializationContext());
logger.info("Decoded={}", decoded);
// Write a modified value
CustomStructType modified = new CustomStructType(decoded.getFoo() + "bar", uint(decoded.getBar().intValue() + 1), !decoded.isBaz());
ExtensionObject modifiedXo = ExtensionObject.encode(client.getStaticSerializationContext(), modified, xo.getEncodingId(), OpcUaDefaultBinaryEncoding.getInstance());
node.writeValue(new DataValue(new Variant(modifiedXo)));
// Read the modified value back
value = node.readValue();
logger.info("Value={}", value);
variant = value.getValue();
xo = (ExtensionObject) variant.getValue();
decoded = (CustomStructType) xo.decode(client.getStaticSerializationContext());
logger.info("Decoded={}", decoded);
future.complete(client);
}
Aggregations