Page 1 of 1

UaClient ModelManager Read/Write Array of Structure

Posted: 31 Mar 2021, 14:06
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 ?

Re: UaClient ModelManager Read/Write Array of Structure

Posted: 14 Apr 2021, 19:01
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[]?