![Avatar](https://opcfoundation.org/wp-content/uploads/sp-resources/forum-avatars/defaults/userdefault.png)
07/05/2021
![sp_UserOfflineSmall](https://opcfoundation.org/wp-content/sp-resources/forum-themes/reboot/images/darkpack/sp_UserOfflineSmall.png)
Hi, I am new to OPC ua and I am having problems reading structure data in a server from an opc ua client.
My code is very simple:
ComplexTypeSystem complexTypeSystem = new ComplexTypeSystem(uaClient.Session); await complexTypeSystem.Load().ConfigureAwait(false); EncodeableFactory.GlobalFactory.AddEncodeableType(typeof(ConfigType)); var conf = uaClient.Session.Call("ns=6;s=::Program", "ns=6;s=::Program:TestGetConfig"); IEncodeable confEncod = ExtensionObject.ToEncodeable((ExtensionObject)conf[0]); ConfigType configuration = confEncod as ConfigType; ConfigType casted = (ConfigType)confEncod ;
Where ConfigType is a C# class with properties equal to PLC server structure i want read :
public class ConfigType: EncodeableObject
{
public override ExpandedNodeId TypeId => ExpandedNodeId.Parse("nsu=http://br-automation.com/OpcUa/PLC/PV/;i=100020");
public override ExpandedNodeId BinaryEncodingId => ExpandedNodeId.Parse("nsu=http://br-automation.com/OpcUa/PLC/PV/;i=100021");
public override ExpandedNodeId XmlEncodingId => NodeId.Null;
public override void Decode(IDecoder decoder)
{
}
public override void Encode(IEncoder encoder)
{
}
public ushort param1
{
get;
set;
}
public ushort param2
{
get;
set;
}
}
The properties value of Conf variable after call method are good but the type of Conf[0].body variable is "Opc.Ua.ComplexTyper.ne=6.i=99999.6.ConfigType" so confEncod is of the same type and configuration is null.
If i try a direct cast the error is
'Unable to cast object of type 'Opc.Ua.ComplexTypes.ns=6;i=99999.6.ConfigType' to type 'Quickstarts.ConsoleReferenceClient.ConfigType'
Anyone can help me?
Thanks a lot
![Avatar](https://opcfoundation.org/wp-content/uploads/sp-resources/forum-avatars/defaults/admindefault.png)
05/30/2017
![sp_UserOfflineSmall](https://opcfoundation.org/wp-content/sp-resources/forum-themes/reboot/images/darkpack/sp_UserOfflineSmall.png)
You may want to try asking here:
https://github.com/OPCFoundati.....iscussions
It looks like the SDK is converting the type to the generic structure class instead of your specific class.
You need to ask how to tell the SDK to use your class.
That said, you can access you data using the Opc.Ua.ComplexType class.
Take a look at the class definition.
1 Guest(s)