Variable-length ARRAY variables
Hi,
according to IEC 61131-3 section 6.5.3, it should be possible to declare a variable-length ARRAY variable using VAR_IN_OUT statement :
But in PLCnext Eng, we cannot declare variables using the VAR construct, all variables must be declared in the variable table.
So how can I use this IEC 61131-3 feature ?
Best regards
Comments
You define arrays in the data type worksheet but I couldn't find a syntax that works for variable-length arrays.
I get compile errors like LEX0003: Invalid identifier '*,'. or DTP0013: Range expected. It looks like this part of the IEC is not supported (yet?).
Cheers
DivisionByZero
It looks like this part of the IEC specification allows variable-length arrays as parameters on function blocks (and maybe functions?), but not as actual variables themselves. This makes sense, because it means that all array variables will still be fixed length, so memory does not need to be allocated during run-time (which is not good for real-time performance). But this feature would allow an array variable of the correct type, but of any length, to be passed as an IN-OUT parameter to a function block. This is effectively the same thing as passing a pointer, but with additional type-checking.
I am fairly sure that this is not currently possible in PLCnext Engineer, at least not for function blocks developed in IEC 61131 languages. As DivisionByZero describes, it would require a new type definition in a Data Type sheet, something like:
... and while that would allow FB parameters of that type to be defined, this would also allow new variables of that type to be declared - which is not a good idea for real-time performance, and which is not part of the IEC specification (if I'm reading it correctly).
I will ask someone from the PLCnext Engineer support team to check this and give feedback here.
The closest equivalent that I can think of, that is useable in PLCnext Engineer, is the
ANY
type that can be used for parameters on function blocks written in C#. But (as the name implies) that will accept any type, not only an array of a certain type. It's also possible to pass an array to a C# function block by reference, which effectively passes a pointer to the array. But I'm pretty sure the parameter in that case still needs to be an array type with a fixed length.