Read Complex structure |OPC UA Implementation: Stacks, Tools, and Samples|Forum|OPC Foundation

Avatar
Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
Lost password?
sp_Feed sp_PrintTopic sp_TopicIcon
Read Complex structure
Avatar
Yuri Medici
New Member
Members
Forum Posts: 2
Member Since:
07/05/2021
sp_UserOfflineSmall Offline
1
10/04/2023 - 02:44
sp_Permalink sp_Print sp_EditHistory

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
Randy Armstrong
Admin
Forum Posts: 1457
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
2
10/04/2023 - 20:22
sp_Permalink sp_Print

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.

Avatar
Yuri Medici
New Member
Members
Forum Posts: 2
Member Since:
07/05/2021
sp_UserOfflineSmall Offline
3
10/05/2023 - 01:26
sp_Permalink sp_Print

Tanks Randy for your fast reply. 

If it's possible i would like to use the features of the library for convert automatically the type.

For the moment i can work with reflection on ComplexType variable?

Thanks

Forum Timezone: America/Phoenix
Most Users Ever Online: 510
Currently Online:
Guest(s) 17
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Forum Stats:
Groups: 2
Forums: 10
Topics: 1353
Posts: 4589