I'm accessing structs defined in the PLC of a controller. I've created clones of that structs in my C# project. This was done by creating classes with the same member types as the structs on the server side. The classes and members have been annotated with the UaTypeDefinition resp. the UaInstanceDeclaration attributes.
Reading and writing of these structs work fine with
Code: Select all
var modelHandle = session.Model.Read(nodeId, obj); // where obj is an instance of my C# class
Code: Select all
var modelHandle = session.Model.Write(nodeId, obj);
In the subscription.DataChanged eventhandler I can get the DataChange values and thus the DataValue of each DataChange.
But: All I can see in my DataValue is a body of type byte[].
I retrieve this like
Code: Select all
byte[] GetBuffer(DataValue dataValue)
{
var wrappedValue = dataValue.WrappedValue;
ExtensionObject extensionObject = wrappedValue.GetValue<ExtensionObject>(null);
return (byte[])extensionObject.Body;
}
Is there an elegant way to deserialize structs to local C# instances in DataChanged events of the subscription?
Any tip is appreciated.
Thanks,
Bruno