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
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
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
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 :-)
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 code:
VAR
a_referenz_array : ARRAY[0..2] OF BOOL := TRUE, FALSE ;
END_VAR