Skip to content

Array of Struct / Multidimensional Array C#

Hello,

Can you declare an Array of Structs and a multidimensional array in the C# code and connect that as Input to the PLCnext Engineer?

Can you provide any sample files/definitions on how to do that if it is actually possible?

Thank you in advance.

Comments

  • There is an example in Github that shows how to connect an array of structs to a function block input:

    I think multi-dimensional arrays should also be possible, as an extension of the single-dimension array example. If you can't get that working, please let us know.

    EDIT:

    Actually I'm not sure that multi-dimensional arrays will work. It is possible to declare multi-dimensional arrays in PLCnext Engineer, but I suspect that the type definitions for multi-dimensional arrays generated by the C# project are not recognised by PLCnext Engineer. I will check this.

  • OK, I was wrong about multi-dimensional arrays. They are not supported (yet) as parameters on C# functions or function blocks.



  • edited June 2023

    Hello again,

    I'm having some problems getting my structures and arrays to work.

    What I need to do is have an array of 10 structures which contain 2 arrays of 6 INTs each (since I cannot have a multidimensional array) and a string.

    10* [Struct]

    {

    IntArrayOfSix LB;

    IntArrayOfSix UB;

    String name;

    }

    Could you provide a sample for that?

  • Have you been able to get an array of simple structures working, i.e. using structs that have only simple types (not arrays) as fields?

  • Something like this should work.

    It's a function block with an Input parameter of type "Array of Struct", where the struct contains two DINT arrays and a STRING field.

  • edited June 2023

    Thank you so much! This worked like a charm.

    However I still have a problem after this.

    Using the method you mentioned I declared the following in the PLCnext Engineer:

    Struct_HmiProgram userProgram

    myArrayOf_HmiPrograms[10] programsArray

    The problem is this:

    When the user presses a button I want userProgram to be copied to programsArray[0] from the Hmi, but when I do this:

    I get the error:

    Any ideas on this?

  • Here is also a screenshot of my Struct:


  • This latest question is not related to the C# variable definitions - it also happens in pure IEC code. You can show this by defining a simple STRUCT type in PLCnext Engineer, declaring two variables of that type, and trying to use the "Write value" action to copy the value of one variable to another. This also doesn't work, so this is a missing feature of the HMI, not a problem with the C# code.

    A work-around for this missing feature is for the button on the HMI to set a flag in the PLC which triggers an assignment operation in an IEC program instance.

    (hint: please start a new conversation for each new issue, that way users who have a similar issue in the future will hopefully be able to find this answer more easily :)

Sign In or Register to comment.