Structured Text - Summary and Syntax
This topic covers the summary and syntax of the Structured Text language.
Summary of Structured Text (ST) language
Structured Text (ST) is one of the textual languages defined in the standard IEC61131-3. The Structured Text programs look very similar to the programs written with C, JAVA and Python.
D := B * B - 4 * A * C;
IF D < 0.0 THEN
NROOTS := 0;
ELSIF D = 0.0 THEN
NROOTS := 1;
X1 := - B / (2.0 * A);
ELSE
NROOTS := 2;
X1 := (- B + SQRT(D)) / (2.0 * A);
X2 := (- B - SQRT(D)) / (2.0 * A);
END_IF;
You can use Structured Text to program the followings in the XG5000 software.
-
Scan program
-
Task
-
Within the Sequential Function Chart (SFC) program to describe the Action and Transition programs.
-
User function
-
User function block
Syntax
Examples:
A := B;
You can put more than one statement in a line like this.
A := 100; B := 200; C:= 300;
Note: Statements need a semicolon at the end only.
IF statement
IF iA < 100 THEN (← No semicolon)
iB := 2;
ELSIF iA = 0 THEN (← No semicolon)
iB := 1;
ELSE (← No semicolon)
iB := 0;
END_IF; (← Need a semicolon)
FOR statement
FOR iI := 1 TO 100 BY 1 DO (← No semicolon)
iA[iI] = iI;
END_FOR; (← Need a semicolon)
For example, the variable names ‘ABC’ and ‘abc’ are handled as the same.
(1) Boolean literals
The following 4 literals are available.
-
0
-
1
-
TRUE
-
FALSE
(2) Integer literals
Format:
-
Decimal: <Literal>
-
Binary: 2#<Literal>
-
Octal: 8#<Literal>
-
Hexadecimal: 16#<Literal>
Examples:
-
Decimal: 1234
-
Binary: 2#101010
-
Octal: 8#12
-
Hexadecimal: 16#1AF5
(3) Real literals
Examples:
-
1.234
-
1.234E-5
-
1.233999956e-005
(4) Typed literals
Format:
<Data type>#<Literal>
Examples:
The following 15 data types are available.
-
BOOL#1
-
BYTE#12
-
WORD#123
-
DWORD#123
-
LWORD#123
-
SINT#123
-
INT#123
-
DINT#123
-
LINT#123
-
USINT#123
-
UINT#123
-
UDINT#123
-
ULINT#123
-
REAL#1.23
-
LREAL#1.23
(5) String literals
Format:
‘<String>’
The XEM CPU modules support up to 32 characters in a STRING data.
The following $ codes are available.
-
$N (New line)
-
$R (Carriage return)
-
$T (Tab)
-
$’ (Apostrophe)
-
$$ (Dollar sign)
Examples:
-
‘ABC’
-
‘That$’s it!’
(6) Duration literals
Format:
-
TIME#<d>d<h>h<m>m<s>s<ms>ms
-
T#<d>d<h>h<m>m<s>s<ms>ms
-
d (Day)
-
h (Hour)
-
m (Minute)
-
s (Second)
-
ms (Millisecond)
Note: The XEM CPU modules don’t support ‘us’ and ‘ns’.
Examples:
-
TIME#1d2h3m4s5ms
-
T#1d2h3m4s5ms
(7) Date literals
Format:
-
DATE#<yyyy>-<mm>-<dd>
-
D#<yyyy>-<mm>-<dd>
Examples:
-
DATE#2023-01-01
-
D#2023-01-01
(8) Time-of-Day literals
Format:
-
TIME_OF_DAY#<hh>:<mm>:<ss>
-
TOD#<hh>:<mm>:<ss>
Examples:
-
TIME_OF_DAY#12:34:45
-
TOD#12:34:45
(9) Date-and-Time literals
Format:
-
DATE_AND_TIME#<yyyy>-<mm>-<dd>- <hh>:<mm>:<ss>
-
DT#<yyyy>-<mm>-<dd>- <hh>:<mm>:<ss>
Examples:
-
DATE_AND_TIME#2023-01-01-12:34:45
-
DT#2023-01-01-12:34:45
The XEM CPU modules support up to 3 dimensional array.
Format:
-
<Variable name>[<Index1>]
-
<Variable name>[<Index1>, <Index2>]
-
<Variable name>[<Index1>, <Index2>, <Index3>]
Note: The index of array starts from 0 with the XEM CPU modules.
Examples:
-
iA[2]
-
wB[iD, 4]
-
rC[iE, 6, 7]
The following statements have the same result, the space and return formatting don't change anything.
Two commenting methods are available in the Structured Text program.
-
Line Comment: Use ‘//’ (Two slashes) for a single line comment.
// comment
-
Block Comment: Use ‘(*’ and ‘*)’ for a single line or multiple line comment.
(* comment *)
(* comment
comment
comment *)
LP304A