use of org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject 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));
}
use of org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject in project milo by eclipse.
the class UnifiedAutomationReadCustomDataTypeExample method run.
@Override
public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throws Exception {
// Decoding a struct with custom DataType requires a DataTypeManager
// that has the codec registered with it.
// Add a SessionInitializer that will read any DataTypeDictionary
// nodes present in the server every time the session is activated
// and dynamically generate codecs for custom structures.
client.addSessionInitializer(new DataTypeDictionarySessionInitializer(new GenericBsdParser()));
client.connect().get();
DataValue dataValue = client.readValue(0.0, TimestampsToReturn.Neither, NodeId.parse("ns=2;s=Demo.Static.Scalar.WorkOrder")).get();
ExtensionObject xo = (ExtensionObject) dataValue.getValue().getValue();
Object value = xo.decode(client.getDynamicSerializationContext());
logger.info("value: {}", value);
future.complete(client);
}
use of org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject in project milo by eclipse.
the class SessionDiagnosticsObjectTypeNode method setSessionDiagnostics.
@Override
public void setSessionDiagnostics(SessionDiagnosticsDataType sessionDiagnostics) throws UaException {
SessionDiagnosticsVariableTypeNode node = getSessionDiagnosticsNode();
ExtensionObject value = ExtensionObject.encode(client.getStaticSerializationContext(), sessionDiagnostics);
node.setValue(new Variant(value));
}
use of org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject in project milo by eclipse.
the class SessionDiagnosticsObjectTypeNode method setSubscriptionDiagnosticsArray.
@Override
public void setSubscriptionDiagnosticsArray(SubscriptionDiagnosticsDataType[] subscriptionDiagnosticsArray) throws UaException {
SubscriptionDiagnosticsArrayTypeNode node = getSubscriptionDiagnosticsArrayNode();
ExtensionObject[] encoded = ExtensionObject.encodeArray(client.getStaticSerializationContext(), subscriptionDiagnosticsArray);
node.setValue(new Variant(encoded));
}
use of org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject in project milo by eclipse.
the class ServerDiagnosticsTypeNode method setSubscriptionDiagnosticsArray.
@Override
public void setSubscriptionDiagnosticsArray(SubscriptionDiagnosticsDataType[] subscriptionDiagnosticsArray) throws UaException {
SubscriptionDiagnosticsArrayTypeNode node = getSubscriptionDiagnosticsArrayNode();
ExtensionObject[] encoded = ExtensionObject.encodeArray(client.getStaticSerializationContext(), subscriptionDiagnosticsArray);
node.setValue(new Variant(encoded));
}
Aggregations