Structured text

From XennisWiki
Jump to: navigation, search

Structured text is one of the five languages supported by the IEC 61131-3 standard, designed for programmable logic controllers (PLCs). It is a high level language that is block structured and syntactically resembles Pascal, on which it is based. All of the languages share IEC61131 Common Elements. (Wikipedia)

Basics

Variables

motor := TRUE;
pos := pos + 1;
motor := (pos = 10 AND pos_y = 10);

Condition

IF (pos > 10) THEN
    // ...
ELSEIF (pos < 10) THEN
    // ...
ELSE
    // ...
END_IF

Also possible IF (NOT motor) THEN or IF (motor AND pos > 10) THEN

Loop

While loop
WHILE counter < 100 DO
   counter := counter - 1;
   // ...
END_WHILE

Function

Call a function block (here named Control)

Control();
slider(start_position := 40, motor := M1);
XY := slider.position;