Structured Text

See also: IEC 61131 Language Editor Programming

See also: Project Toolbox for IEC

 

Topic Menu

Getting Started with IEC 6-1131 Ladder Logic in Cscape

 

Common Elements to IEC Textual Languages (IL and ST)

See also: Instruction List

See also: IEC Editors and Basic Operations

 

 

The ST editor is a powerful language sensitive text editor dedicated to IEC 61131-3 languages. The editor supports advanced graphic features such as drag and drop, syntax coloring and active tooltips for efficient input and test of programs in ST. ST is a structured literal programming language. A ST program is a list of statements. Each statement describes an action and must end with a semi-colon (" ; "). The presentation of the text has no meaning for a ST program. The user can insert blank characters and line breaks where the user want in the program text.

 

Drag and Drop Features in ST/IL - The ST / IL editor supports powerful drag and drop features that helps the users to develop and test programs.

The User can:

  • drag text (words or lines) from the ST / IL editor to another application (such as a text editor)

  • do the opposite

  • drag a variable symbol from the Program Variables Window to the ST / IL editor

  • drag a variable symbol from the ST / IL editor to the watch list (*)

(*) When dragging the symbol of an array to the watch list, all items of the array are added to the watch list.

 

Comments in ST/IL - Comment texts can be entered anywhere in a ST program. Comment texts have no meaning for the execution of the program. A comment text must begin with "(*" and end with "*)". Comments can be entered on several lines (i.e. a comment text may include line breaks). Comment texts cannot be nested.

 

Expressions in ST/IL

Each statement describes an action and may include evaluation of complex expressions. An expression is evaluated:

  • from the left to the right

  • according to the default priority order of operators<</li>>

  • the default priority can be changed using

 

Arguments of an expression can be:

 

Auto Completion of Words in ST/IL - The ST / IL editor includes powerful commands for automatic completion of typed words, according to declared variables and data types.

 

Auto completion of a variable name - If the user enter the first letters of a variable name, the user can hit the CTRL+SPACE keys for automatically completing the name. A pop-up list is displayed with possible choices if several declared variable names match the type characters.

 

Selection of Function Block in ST - When the user types the name of a function block instance (use either as an instance or a data structure), pressing the point "." after the name of the instance opens a pop-up list with the names of possible members.

 

Other syntax related commands - When lines are selected, the user can automatically indent them. Press TAB or Shift+TAB keys to shift the lines to the left or to the right, by adding or removing blank characters on the left.

 

Return to the Top: Structured Text

 

Statements in ST

Below are available basic statements that can be entered in a ST program:

 

Conditional Statements in ST

Below are the available conditional statements in ST language:

 

Statements for describing Loops in ST

Below are the available statements for describing loops in ST language:

 

Return to the Top: Structured Text

 

IF in ST

IF / THEN / ELSE

ELSIF END_IF

 

Syntax

IF <BOOL expression> THEN

....<statements>

ELSIF <BOOL expression> THEN

....<statements>

ELSE

....<statements>

END_IF;

 

Remarks

The IF statement is available in ST only. The execution of the statements is conditioned by a BooleanClosed Boolean- [Data Type BOOL] - A single bit, binary value, or register/variable. Boolean points have only two possible values, 'TRUE' or 'FALSE'. expression. ELSIF and ELSE statements are optional. There can be several ELSIF statements.

 

ST Language

(*simple condition *)

IF bCond THEN

...Q1 := IN1;

...Q2 := TRUE;

END_If;

 

(* binary selection *)

IF bCond THEN

...Q1 := IN1;

...Q2 := TRUE;

ELSE

IF bCond THEN

...Q1 := IN2;

...Q2 := FALSE;

END_If;

 

(* enumerated conditions)

IF bCond THEN

...Q1 := IN1;

ELSEIF bCond2 THEN

...Q1 := IN2;

ELSEIF bCond3 THEN

...Q1 := IN3;

ELSE

...Q1 := IN4;

END_IF:

 

Return to the Top: Structured Text

 

CASE in ST

CASE / OF / ELSE

END_CASE

 

Statement - switch between enumerated statements.

 

Syntax

CASE <DINT expression> OF

<value>:

..<statements>

<value> , <value>:

..<statements>;

<value> ... <value>:

..<statements>;

ELSE

..<statements>

END_CASE;

 

Remarks

All enumerated values correspond to the evaluation of the DINTClosed Double Integer - [Data Type DINT] - A 32-bit signed value. Double Integers are used where the value of the data is expected to be in the range of -2,147,483,648 to +2,147,483,647. expression and are possible cases in the execution of the statements. The statements specified after the ELSE keyword are executed if the expression takes a value that is not enumerated in the switch. For each case, the user must specify either a value, or a list of possible values separated by commas (",") or a range of values specified by a " min .. max" interval. The user must enter space characters before and after the ".." separator.

 

ST Language

(* this example check first prime numbers *)

CASE iNumber OF

0 :

....Alarm := TRUE;

......AlarmText := '0 gives no result';

1 . . 3, 5, :

......bPrime :=TRUE;

4, 6, :

......bPrime := FALSE;

ELSE

....Alarm := TRUE;

......AlarmText := 'I don't know after 6 ! ';

END_CASE;

 

Return to the Top: Structured Text

 

WHILE in ST

WHILE / DO

END / WHILE

 

Statement - Repeat a list of statements.

 

Syntax

WHILE <BOOL expression> DO

....<statements>

END_WHILE;

 

Remarks

The statements between "DO" and "END_WHILE" are executed while the BooleanClosed Boolean- [Data Type BOOL] - A single bit, binary value, or register/variable. Boolean points have only two possible values, 'TRUE' or 'FALSE'. expression is TRUE. The condition is evaluated before the statements are executed. If the condition is FALSE when WHILE is first reached, statements are never executed. WARNING: Loop instructions may lead to infinite loops that block the target cycle. Never test the state of an input in the condition as the input will not be refreshed before the next cycle.

 

ST Language

iPos := 0;

WHILE iPos < iMax DO

....MyArray [iPos] := 0;

....iNbCleared := iNbCleared + 1;

END_WHILE;

 

Return to the Top: Structured Text

 

REPEAT in ST

REPEAT / UNTIL

END_REPEAT

 

Statement - Repeat a list of statements.

 

Syntax

REPEAT

....<statements>

UNTIL <BOOL expression> END_REPEAT;

 

Remarks

The statements between "REPEAT" and "UNTIL" are executed until the BooleanClosed Boolean- [Data Type BOOL] - A single bit, binary value, or register/variable. Boolean points have only two possible values, 'TRUE' or 'FALSE'. expression is TRUE. The condition is evaluated after the statements are executed. Statements are executed at least once. WARNING: Loop instructions may lead to infinite loops that block the target cycle. Never test the state of an input in the condition as the input will not be refreshed before the next cycle.

 

ST Language

iPos := 0;

REPEAT

....MyArray[iPos] := 0;

....iNbCleared := iNbCleared + 1;

....iPos := iPos + 1;

UNTIL iPos = iMax END_REPEAT;

 

Return to the Top: Structured Text

 

FOR in ST

FOR / TO / BY

END_FOR

 

Statement - Iteration of statement execution.

 

Syntax

FOR <index> := <minimum> TO <maximum> BY <step> DO

....<statements>

END_FOR;

 

index = DINTClosed Double Integer - [Data Type DINT] - A 32-bit signed value. Double Integers are used where the value of the data is expected to be in the range of -2,147,483,648 to +2,147,483,647. internal variable used as index

minimum = DINT expression: initial value for index

maximum = DINT expression: maximum allowed value for index

step = DINT expression: increasing step of index after each iteration (default is 1)

 

Remarks

The "BY <step>" statement can be omitted. The default value for the step is 1.

 

ST Language

iArrayDim := 10;

 

(* resets all items of the array to 0 *)

FOR iPos := 0 TO (iArrayDim - 1) DO

....MyArray[iPos] := 0;

END_ FOR;

 

(* resets all items of the array to 1 *)

FOR iPos := 1 TO 9 BY 2 DO

....MyArray[iPos] := 1;

END_ FOR;

 

Return to the Top: Structured Text

 

EXIT in ST

Statement - Exit from a loop statement

 

Remarks

The EXIT statement indicates that the current loop (WHILE, REPEAT or FOR) must be finished. The execution continues after the END_WHILE, END_REPEAT or END_FOR keyword or the loop where the EXIT is. EXIT quits only one loop and cannot be used to exit at the same time several levels of nested loops. WARNING: Loop instructions may lead to infinite loops that block the target cycle.

 

ST Language

(* this program searches for the first non null item of an array *)

iFound = -1; (* means: not found *)

FOR iPos := 0 TO (iArrayDim - 1) DO

...IF iPos <> 0 THEN

.......iFound := iPos;

.......EXIT;

...END_IF;

END_FOR;

 

Return to the Top: Structured Text