UaClient ModelManager Read/Write Array of Structure

Questions regarding the use of the .NET SDK 2.0 for Server or Client development or integration into customer products ...

Moderator: uasdknet

Post Reply
m.stang
Jr. Member
Jr. Member
Posts: 1
Joined: 09 Dec 2016, 14:15

UaClient ModelManager Read/Write Array of Structure

Post by m.stang »

Hello everyone,

i want to read and write a structure with an array of structures from/to my PLC (Simatic S7-1500).
Reading and writing to complex structures without arrays works fine.

My Structure of the Nodes:
TypeA
- [int] usiNumber
- [TypeB] Zyklus[50]

TypeB
-[int] usiLoops
-[bool] xActive

My Sample Code:

Code: Select all

TypeA data = new TypeA();
UnifiedAutomation.UaBase.NodeId nodeID = new UnifiedAutomation.UaBase.NodeId(nodeName, NamespaceIndexPLC);
UnifiedAutomation.UaBase.ModelHandle modelHandle = OPCUA_Connection.Model.Read(nodeID, data);

Code: Select all

    [UnifiedAutomation.UaBase.UaTypeDefinition(NodeId = "ST05_Farbsystem_Data_V1.0", NamespaceUri = "http://www.siemens.com/simatic-s7-opcua")]
    public class TypeA
    {
        [UnifiedAutomation.UaBase.UaInstanceDeclaration(BrowseName = "usiNumber", NamespaceUri = "http://www.siemens.com/simatic-s7-opcua")]
        public byte usiNumber { get; set; }

        [UnifiedAutomation.UaBase.UaInstanceDeclaration(BrowseName = "Zyklus", NamespaceUri = "http://www.siemens.com/simatic-s7-opcua")]
        public TypeB[] Zyklus { get; set; }
    }

Code: Select all

    [UnifiedAutomation.UaBase.UaTypeDefinition(NodeId = "ST05_Farbsystem_Zyklus_V1.0", NamespaceUri = "http://www.siemens.com/simatic-s7-opcua")]
    public class TypeB
    {
        [UnifiedAutomation.UaBase.UaInstanceDeclaration(BrowseName = "xEndlos", NamespaceUri = "http://www.siemens.com/simatic-s7-opcua")]
        public bool xActive { get; set; }

        [UnifiedAutomation.UaBase.UaInstanceDeclaration(BrowseName = "usiLoops", NamespaceUri = "http://www.siemens.com/simatic-s7-opcua")]
        public byte usiLoops { get; set; }
    }
Diagnostics:
[Bad] Could not convert mapped value for field '{3:TypeB}'.|InvalidCastException|Das Objekt kann nicht in diesem Arraytyp gespeichert werden.

Changing TypeB[] to Object[] works also, but i need to de-/serialize binary data <-> TypeB.

Does anyone have an idea ?

User avatar
Support Team
Hero Member
Hero Member
Posts: 2649
Joined: 18 Mar 2011, 15:09

Re: UaClient ModelManager Read/Write Array of Structure

Post by Support Team »

Hello,

It is possible to specify arrays as instance declaration in model classes. However these arrays must related to variable values.

In your example TypeB is the model class for an ObjectType or a VariableType. The ModelManager is trying to map nodes from the addressspace to the properties of the model class. In TypeA Zyklus is TypeB[] which is a different from TypeB.

What is your use case for setting the type of Zyklus to TypeB[]?
Best regards
Unified Automation Support Team

Post Reply