Dynamic Arrays

Engrlife

Member
Join Date
Aug 2017
Location
British Columbia
Posts
41
Is it possible to create a dynamic array with a length that is set by variables in Schneider Unity Pro? I am using an M580.

For example in a normal array the type would be "array[n..m] of int" I would like n and m to be set on my HMI. I am having trouble finding anything useful regarding dynamic arrays. I have found the data type anyarray_of_xxx but not really sure how it works.
 
you can make own DFB block with input of any array of int, bool etc.
You also need start row and how many variables to copy variable inputs to DFB.

inside block use extract block. (with extract you can tell to from which array row you start copy and how many variables you want copy) extract copies on byte level, I think.


So basically array to DFB block is allways constant lenght, but you can extract dynamically from this array to another.

Also output needs to be constant leght, but you can locate to certain parts of array.

DFB isn't must, but makes cleaner look.
 
Last edited:
I don't have any experience with unity pro, but every PLC I've ever heard of (except some PC based systems that allow C code) requires statically assigned memory. I've seen systems that allow pointers to an array of variable size, but wherever the array sits it is fixed.

To me, this is one of the things that separates a PLC from typical PC based code: memory leaks are basically impossible in the user code of a PLC, but they are half of the performance problems you see on your laptop.
 
That has been my experience also, and I think Peter is right in his assessment on memory management aspects and the CPU time involved. Pointers can be a very powerful feature on PLC's, but good awareness of the how and why is required. One can run into crazy problems and inexplicable behavior whenever pointers are used improperly.

Use of pointers in production code typically demands more than basic programming experience. Rigorous testing required. Here be dragons.
 
Yes you can have dynamically sized arrays as inputs to DFBs, then that DFB input will accept any sized array. The definition in the DFB is type ANY_ARRAY_xxxx where xxxx is a elementary data type (eg WORD).In the project settings go to General Configuration Then tick the box 'Allow dynamic Arrays'.
 

Similar Topics

I saw that you can set an input/output type on a DFB to "ANY_ARRAY_XXX" where x is the data type. So I'm assuming that lets you pass an array of...
Replies
4
Views
3,543
Hello Is there any way to manipulate the length / number of members of an array in a program in runtime? I store time-stamped events in a buffer...
Replies
16
Views
14,616
Hello, I have a requirement to manage the text alignment dynamically. So, for example: 1. English Texts should be displayed from Left in...
Replies
0
Views
108
Rockwell Tech Support seemed to have hit a wall with this question. Already updated the version to 5.00.13 per their suggestio but am still...
Replies
2
Views
271
Maybe this is just not possible, or maybe I am doing something wrong. Background; I have a data array of over 1500 products. For sorting I...
Replies
6
Views
778
Back
Top Bottom