Navigation:  Programming > Structured Text > Concepts >

Introduction

Previous pageReturn to chapter overviewNext page

The Structured Text (ST) programming language is defined at IEC-61131-3. It is a programming language derived from other high-level languages such as C or PASCAL.

With the language it is possible to call function blocks, assignments and conditionally execute repeating instructions and tasks. It provides programmers with greater flexibility when compared to the Ladder and greater ease in mathematical operations.

Elements of Structured Text (ST)

 

Expressions

An expression is a structure that, when evaluated, produces a value corresponding to one of the data types. Expressions are composed of operators and operands.

 

Operands

 

An operand can be a literal, an enumerated value, a variable, a method, function call, function block instance call or another expression.

 

Operators

 

It is a symbol used to represent arithmetic, logical operations or functions. They adapt to data types and are executed according to their respective priorities.

 

Assignment

 

Assignment replaces the current value of a variable (operand) with the result of evaluating an expression. It consisted of a reference variable on the left side, followed by the assignment operator “:=”, followed by the expression to be evaluated and finalized by the ending “;”.

 

     Examples:

 

1)Assigning the value of one variable to another.

 

A := B;

 

2)Assigning the value of a literal to variable.

 

A := 10;

 

3)Assigning the value resulting from an operation to variable.

 

A := (B+5);

 

4)Assigning the result value of a function to a variable.

 

A := FB_ACOS(B);

 

Comparison

 

A comparison returns a boolean value as a result. A comparison must consist of an operand on the left, followed by a comparison operator, followed by a second operator on the right, with its result assigned to a variable.

 

    Examples:

     1) Compares if two operands are equal:

 A := B = C;

     2) Compares whether an operand is greater than or equal to a second operand:

 A := B >= 100 ;

Calls

1)Functions - must be called by a statement consisting of the function name followed by a list of parameters enclosed in parentheses.

A := FB_ACOS(B);

2)Function blocks - must be called by an instruction consisting of the function block instance name followed by a list of parameters in parentheses.

VAR

   A, B : BOOL;

   C : INT;

   COUNTER : FB_CTU;

END_VAR

 

COUNTER(R:=A, PV:= 100);

C := COUNTER.CV;

B := COUNTER.Q;