Multidimensional Any Arrays in DFBs

Schnider

Member
Join Date
Aug 2016
Location
Perth
Posts
15
Hi,

Does anybody know how to pass a multi-dimensional ANY array into a DFB?

I have some 2D arrays of REALs (e.g. Array[0..99,1..299] of REAL) that I need to pass into a DFB. Both array ranges need to be able to change based on the instance.

I know you can pass an ANY_ARRAY_REAL into a DFB, but is there a way to pass in a 2D array?

Cheers
 
If this is Schneider Control expert, then I think that it could be possible if you locate array to %MW area.


multiarrays like Array_test, Array[0..9,1..2] of REAL located to %MW200 have addresses.



Array_test[0][1] = %MW200
Array_test[0][2] = %MW202



Array_test[1][1] = %MW204
Array_test[1][2] = %MW206


..


Array_test[9][1] = %MW236
Array_test[9][2] = %MW238




and lenght of array is 10*2*reals which could checked with lenght-block. (lenght 80, which you can save to variable)



If you now know beforehand dimensions of both arrays or at least dimension1 lenght, you can locate your %MW_start-address:total_lenght to input pin of DFB with ANY_ARRAY_OF_REAL.


Inside DFB you need to tell also dimensions and copy any_array to one dimension array (long enought)





So DFB would have at least 3 pins.


1st pin = ANY_ARRAY_OF_REAL
2nd pin = dimension1_lenght
3nd = dimension2_lenght


Inside DFB you can then do it like for normal array.


If both dimensions isn't knowed, then it would go difficult as lenght-block only tells total lenght of multi array.
 
Doh - the platform! šŸ™ƒ

Its Schneider Unity v14.1.

Thanks Lare -
I thought of that solution, but I do not want to have to address the arrays. Also, you only need to pass in one of the dimensions, the second dimension can be calculated with:
SIZEOF(Array)/([first Dimension] * 4)
Note: there are 4 bytes per REAL
 
Try extract block and with real PLC.



example at attachment.


PLC simulator gives false lenght if input array is started with location 1..?
With array 0..10 it at least looked that this could move different array dimemsions without %MW-areas.




p.s Byte lenght on extract copy_5 should have multiple 4 instead of 2, so that byte lenght is calculated right.
 
Last edited:
Thinked more.


One method to check array dimensions is that you look %S20 error bit (array oveflow).
Maybe not best way to program as on diagnostic viewer have much index overflow errors.


But here is 2dimesions array copy and checking D1 and D2 start offsets and lenghts.


After that you only need locate these five variables to DFB inputs. (ANY_Array, D1_start, D1_end, D2_start, D2_end.
 
Last edited:
Thanks for the effort Lare

This is what I have to get the dimension of a 2D array:
XLength := SIZEOF(2DArray[1]) / SIZEOF(2DArray[1][1]);
YLength := LENGTH_ARREAL(2DArray[1]);

I have not tested it yet, but it should work.

I am more worried how to pass a 2D array into a DFB. DFBs do not take type ANY_ARRAY. Type ANY_ARRAY_REAL is restricted to a 1D array.
I suspect it is a limitation of the compiler as When passing in these arrays as In/Outs (pointers), I am not sure if the compiler is able to compute the larger dimension inside the DFB.

I have decided to just pass in a 1D array and a 2D divider value and reference it like so:
1DArray[X + Y*2DDiv]
 
XLength := SIZEOF(2DArray[1]) / SIZEOF(2DArray[1][1])
Should work, but for some reason it gives overall lenght of multiarray. (div part isn't working with size of operator on same operate)


But if extra variables are used and divided afterwards, then you get right lenght for X.


Can't you simple use fixed lenght for FDB?
Input can be multiarray if lenghts are constants on variable.


Do you try code common FBD, so that you don't need different multiarray inputs / several FBD blocks if different variables are used?


You can copy multi array to one array, but it have to located on normal section before FBD.
 
It is for a ore stockpile model. As the stockpiles are all different sizes, I'd like the model size to change.

I think I have got a working solution now. Thanks for the help.
 

Similar Topics

Can Ignition Edge handle working with multidimensional structs/UDTs on the PLC? Say I have an array of UDTs each element represent an identical...
Replies
8
Views
2,954
Hi. This is pretty basic but I'm struggling to find an efficient solution. I have a float value of let say 666.555 that I want to move / split...
Replies
3
Views
146
Hello. I've been using the answers in this forum for a while now, so thank you. Usually I can find the answer I'm looking for with a basic...
Replies
8
Views
733
Hello, first time poster here! A belated "thank you" for the direction I've already received from this forum! So, can I do this? Move value 1...
Replies
6
Views
676
My first real attempt at utilising the AOI function in Compactlogix. The issue I'm having is, I have an array of INT[400], but in my AOI I'm only...
Replies
1
Views
439
Back
Top Bottom