Author Topic: Arrays Inside Arrays  (Read 3700 times)

Offline LBee11

  • PLUS+1 Developer
  • ***
  • Posts: 26
  • Karma: +0/-0
Arrays Inside Arrays
« on: February 21, 2017, 08:19:34 AM »
I've been trying to convert some of my CoDeSys Structured Text functions in to Danfoss Plus+1 Structured Text files and ran into an issue.

CoDeSys allows the following Declaration:
Quote
  Errors : ARRAY[0..7] OF ARRAY[0..7] OF BOOL;

But Plus+1 does not. Is there a way of achieving the same result?

Thanks

Offline LBee11

  • PLUS+1 Developer
  • ***
  • Posts: 26
  • Karma: +0/-0
Re: Arrays Inside Arrays
« Reply #1 on: February 22, 2017, 10:26:00 AM »
I found a method to achieve a similar result by using the Data Type feature.


I created a structure of 8 Arrays of 8 Booleans, and then created a function block to turn each Array inside the structure into a Byte value and put that byte value into a new Array of 8 Bytes. After doing this to all Boolean Arrays, I end up with an "Array [0..7] of Array [0..7] Of Boolean". Using another function block to Unpack the bytes back into the new structure I can use the "Array inside the Array" as intended.


Got there in the end!

Offline Nilla

  • PLUS+1 Guru
  • *****
  • Posts: 253
  • Karma: +13/-0
Re: Arrays Inside Arrays
« Reply #2 on: February 22, 2017, 11:34:32 AM »
Hi LBee11!

The syntax ”Errors : ARRAY[0..7] OF ARRAY[0..7] OF BOOL;” is currently not supported in GUIDE.

There are 2 main possibilities to achieve similar results:

1)      Multi-dimensional array:
“Errors1 : ARRAY[0..7,0..7] OF BOOL;”

See picture example1.

2)      Type alias:
 First define: “TBoolArray7 : ARRAY[0..7] OF BOOL;”
Then use it like: “Errors2 : ARRAY[0..7] OF TBoolArray7;”

See picture example2.

I hope this helps!

Best regards
Nilla
PLUS+1 Helpdesk

Offline LBee11

  • PLUS+1 Developer
  • ***
  • Posts: 26
  • Karma: +0/-0
Re: Arrays Inside Arrays
« Reply #3 on: February 22, 2017, 11:54:46 AM »
Thanks for that,


I've done something very similar to your second example using Type Struct, but ultimately I want to be able to use "Errors1[0][0]" format, which your example does nicely.


Thanks!