1

i'm learning structured text, to program with Cx-programmer, an Omron software.

i' ve looked around but i can't find a way to assign multiple element to an array, i've tried this soluion, but it doesn't work,

this is Arrays declaration(internals variables):

Name              Data type   Initial value
SenCheck_Array      BOOL[8]     FALSE       
SEN                 INT[2]       0          

Array of INT:

     SEN[1...2]:=[1,2];

Array of BOOL:

      SenCheck_Array[0...7] := [ S_LF,S_LS,S_LH2O,S_LO,S_Col ,S_BAR,S_TAP,S_ET ] ;

The error is the same:

ERROR:  Missing ]

i succeded in assigning element singularly, but i need to assign them in a single line.

Any help is apreciated:)

P.S: i'm using cx programmer educational edition.

1 Answers1

0

Edit: This example (showing the declaration part of the SCL block code) is only valid for Siemens PLCs.

To initialize an array the values must be separated by a comma without square brackets:

CONST
    // Constants
    S_LF := TRUE;
    S_LS := FALSE;
    S_LH2O := FALSE;
    S_LO := FALSE;
    S_Col := TRUE;
    S_BAR := TRUE;
    S_TAP := TRUE;
    S_ET  := TRUE;
END_CONST

VAR
    // Static Variables
    SEN: ARRAY[1..2] OF INT := 1, 2;
    SenCheck_Array: ARRAY[0..7] OF BOOL := S_LF, S_LS, S_LH2O, S_LO, S_Col , S_BAR, S_TAP, S_ET;
END_VAR
dergroncki
  • 798
  • 1
  • 12
  • 24
  • Hmm, i've tried your solution but it seems to me that cx-programmer structured text is a bit different from your sketch. For instance i cannot assign value to S_LS,S_LF etc, because they are input variables in a function block; and i must declare array and any other variable as tag before the program... – Muccagelato Dec 25 '16 at 16:05
  • VAR and ARRAY are unsupported keywords, so i can't declare any variables in the sketch... – Muccagelato Dec 25 '16 at 16:09
  • You must refer to the specific documentation of Omron because structured text may vary from manufacturer to manufacturer. Basically, how should the compiler use input variables for initializing an array because the content of the input variables is unknown at compile time. – dergroncki Dec 25 '16 at 18:43
  • Variables, and variables' initial values are set before the sketch, so when i try to assign values to the array they have already been initialized and already have a value. My question was if somebody knows why it tells me:"missing [", unfortunatly there is not much documentation of array assignement in cx programmer, i've also asked omron support, and i'm waiting for an answer. – Muccagelato Dec 25 '16 at 19:01
  • I've added a screen shot – Muccagelato Dec 25 '16 at 19:21
  • I refer to your screenshot: Your are using declaration syntax inside the program section. Sensors [0..3] = … is not valid here. You have not declared an array, only 3 bools (Sens1, Sens2 and Sens3). – dergroncki Dec 26 '16 at 08:28
  • See my answer for an example. Here is a link to an Omron artical "Passing An Array Of Data To A Function Block": https://www.myomron.com/index.php?action=kb&article=1258 – dergroncki Dec 26 '16 at 10:35