Structured text

from Wikipedia, the free encyclopedia

The structured text (English Structured Text , abbreviation: ST ; in Siemens S7 also English Structured Control Language , abbreviation SCL ) is a programming language for programmable logic controllers (PLC). The EN 61131-3 standard also defines the language scope of ST, among others. The syntax of the language elements is similar to that of the high-level language Pascal and, as with all languages ​​of EN 61131-3, no distinction is made between upper and lower case for keywords (case insensitive).

ST offers more structuring options than STL and is therefore increasingly replacing them. Complex algorithms and mathematical functions can be programmed more clearly and quickly in ST.

Structured text language elements

allocation

": =" Is used as the assignment operator in the structured text.

 Wert := Wert1 + Wert2;

The operand on the left is assigned the value of the expression on the right. The assignment operator is not to be confused with the comparison operator "=". Each statement ends with a semicolon.

IF statement

IF statements can be used to program statements that are dependent on conditions. The conditions are checked in turn. If condition 1 of the IF statement is true, the condition of the ELSIF branch is no longer checked.

IF Bedingung1 THEN
  Anweisung1;
ELSIF Bedingung2 THEN
  Anweisung2;
ELSE
  Anweisung3;
END_IF;

CASE statement

Several conditional statements can be programmed with a CASE statement, all of which are dependent on the same conditional variable. If the condition variable does not take on any of the specified values, the ELSE branch is executed.

  CASE Bedingungsvariable OF
    1 : Anweisung1;
    2 : Anweisung2;
    3 : Anweisung3;
    ELSE Anweisung4;
  END_CASE;

FOR statement

Repetitive processes can be programmed with the aid of for loops. The statement is repeated in the loop until the variable i exceeds the end value. The variable is increased by one step with each loop pass.

FOR i := 0 TO 499 BY 1 DO
  Zahl := Zahl +1;
  D[i] := Zahl;
END_FOR;

The code example describes an array with 500 locations.

WHILE statement

With WHILE loops, processes can be programmed that have to be repeated often. The statement in the loop is repeated as long as the condition is met. If the number of loop runs is known, a FOR loop is usually used. With a WHILE loop, you should note that the condition is not permanently fulfilled. Otherwise, endless loops are created.

  WHILE Bedingung DO
    Anweisung;
  END_WHILE;

REPEAT statement

The REPEAT statement is very similar to a WHILE statement. The difference to a WHILE loop is that the termination condition is only checked after the loop has been executed (C ++: do {} / while ()).

  REPEAT
    Anweisung;
  UNTIL Bedingung
  END_REPEAT;

In this example, the statement is executed until the condition is met. The statement is executed at least once because the termination condition is only queried after the statement has been executed.

EXIT statement

A FOR, WHILE, or REPEAT loop can be left prematurely with an EXIT statement.

pointer

Pointers contain the addresses of the memory location of variables. The address of a variable is determined by the address operator ADR. A pointer is dereferenced with the help of the content operator "^".

  pAdresse  := ADR(Wert1);
  Wert2     := pAdresse^;

In this example the content of the variable Value1 is assigned to the variable Value2 with the help of a pointer. The assignment takes place via the dereferencing of the pointer pAdresse.

literature

Individual evidence

  1. a b c Dr. Ulrich Becker: Introduction to the Structured Text (ST) programming language. (PDF) Retrieved August 9, 2018 .
  2. a b Manual for PLC programming with CoDeSys 2.3. (PDF) Retrieved June 21, 2017 .
  3. Beckhoff Information System - German. Retrieved May 22, 2017 .