Structured Text 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.
The following 4 literals are available.
-
0
-
1
-
TRUE
-
FALSE
Format:
-
Decimal: <Literal>
-
Binary: 2#<Literal>
-
Octal: 8#<Literal>
-
Hexadecimal: 16#<Literal>
Examples:
Decimal: 1234
Binary: 2#101010
Octal: 8#12
Hexadecimal: 16#1AF5
Examples:
1.234
1.234E-5
1.233999956e-005
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
Format:
‘<String>’
The XMC supports 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!’
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 XMC modules don’t support ‘us’ and ‘ns’.
Examples:
TIME#1d2h3m4s5ms
T#1d2h3m4s5ms
Format:
-
DATE#<yyyy>-<mm>-<dd>
-
D#<yyyy>-<mm>-<dd>
Examples:
DATE#2023-01-01
D#2023-01-01
Format:
-
TIME_OF_DAY#<hh>:<mm>:<ss>
-
TOD#<hh>:<mm>:<ss>
Examples:
TIME_OF_DAY#12:34:45
TOD#12:34:45
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 following statements are handled as the same.
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 *)
LM113-1