PLCnext / CSharpExamples

Collection of various C# sample code for PLCnext Technology controllers.
MIT License
13 stars 11 forks source link

Array Of Struct Example #6

Open OWarneke opened 3 years ago

OWarneke commented 3 years ago

It is possible to declare Arrays of Struct by combining the UserArray and UserStruct example. You have to carefully calculate the length of your struct.

ArrayAttribute = the Dimensions! not the number of elements (at the moment only 1 Dimension allowed) ArrayDimensionAttribute = Sets

  1. Define a Structure "YourStruct" (with structureAttribute)
  2. Create Array after the UserArray Pattern of Type "YourStruct"

Please add an example for this usecase.

martinboers commented 2 years ago

The User Array example now shows how to use an Arrays of Structs as an Input parameter on a function block, however it is not clear how to use an Array of Structs as an Output parameter.

Using the current example, it's not possible to directly write to elements of structs in an array, as is required for Output parameters. Instead, pointers must be used. This example copies each struct element from an input array of structs (arrPara) to an output array of structs (arrOutput):

image

It would be great to include a case like this in the example.