0

How to init a boolean array in Structured Text (Twincat 2) with TRUE?

For example like this:

VAR

    a_referenz_array : ARRAY[0..2] OF BOOL := TRUE, FALSE ; (* This does not work !! *)

END_VAR
Richard Teubner
  • 303
  • 2
  • 11

3 Answers3

0

You can use FOR loop in your initialisation's section (it implements once on starting PLC):

FOR I:=0 TO 2 DO
   a_referenz_array[I]:=TRUE;
END_FOR
to1234go
  • 1
  • 1
0

Google/Beckhoff infosys is your friend. Google "Arrays TwinCAT": https://infosys.beckhoff.com/english.php?content=../content/1033/tcplccontrol/html/TcPlcCtrl_ARRAY.htm&id=

In TwinCAT2: arr1 : ARRAY [1..2] OF BOOL := TRUE,FALSE;

TwinCAT3: arr1 : ARRAY [1..2] OF BOOL := [TRUE,FALSE];

Edit, should have checked your question more properly. This works in TwinCAT3, obviously not in TwinCAT2 :-)

Jakob
  • 1,288
  • 7
  • 13
0

Your code WILL work as intended, I tested it in TC2. But there are a couple of issues with it that could confuse while testing...

  • Your array has a size of 3 booleans but you only initialize 2. This means that only index 0 and 1 will be initialized and depending on the rest of your code you might discover it or not.
  • The array will only be initialized following a PLC reset, so changing the code, recompiling and monitoring it online might not have any effect at all. You should send a reset command to the PLC and then re-run the program.
  • My TC2 version is 2.11.2301... It's a long shot, but if yours is very much older, that could be the cause too.

Your code:

VAR
    a_referenz_array : ARRAY[0..2] OF BOOL := TRUE, FALSE ;
END_VAR
pboedker
  • 523
  • 1
  • 3
  • 17