Language
Section titled “Language”The PLC supports a practical subset of IEC 61131-3 Structured Text. Keywords are not case-sensitive; comments are written (* … *) (they cannot be nested) or // …. Unsupported constructs produce diagnostics with line and column when you deploy. A source with several PROGRAM declarations produces a warning and no runnable program. The compiler never runs something other than what you wrote.
Beyond the program itself you can call built-in functions, write your own FUNCTION and FUNCTION_BLOCK in a PLC Library, and command axes with PLCopen motion blocks.
What works
Section titled “What works”| Area | What you can use | Example |
|---|---|---|
| Program | One PROGRAM … END_PROGRAM per PLC Program component, with VAR, VAR CONSTANT and VAR_EXTERNAL blocks | PROGRAM Main … END_PROGRAM |
| Your own functions and function blocks | FUNCTION and FUNCTION_BLOCK with VAR_INPUT, VAR_OUTPUT, VAR_IN_OUT and VAR, kept in a PLC Library and usable in every program of the model. See Function Blocks & Libraries | FUNCTION_BLOCK Gate … END_FUNCTION_BLOCK |
| Variables | One or several names per declaration; types BOOL, SINT, USINT, INT, UINT, DINT, UDINT, LINT, ULINT, BYTE, WORD, DWORD, LWORD, REAL, LREAL, TIME, STRING, STRING(n), WSTRING, WSTRING(n) (see Strings) or a function block (standard, your own, or a PLCopen MC_ block). Names may start with _; __ and names made only of _ are rejected | a, b : INT := 3; |
| Temporary variables | VAR_TEMP elementary variables start fresh on every scan or function/block call | VAR_TEMP scratch : INT := 1; END_VAR |
| Retention qualifiers | VAR RETAIN and VAR PERSISTENT are accepted with an information message. They behave like ordinary VAR; remanence is not simulated | VAR RETAIN count : INT; END_VAR |
| Pragmas | Enum attributes qualified_only and strict, and GVL qualified_only, are evaluated. Other attributes, regions and unknown {…} pragmas are ignored. {error '…'} reports an error; conditional compilation pragmas are rejected | {attribute 'qualified_only'} |
| Enumerations | TYPE … END_TYPE before PROGRAM or in a PLC Library; named integer states with an optional base type and default | TYPE E_State : (Idle := 0, Run, Fault := 10) UINT; END_TYPE |
| Global variable lists | VAR_GLOBAL in a PLC Library or before PROGRAM; shared values are internal signals. CONSTANT creates no signal; RETAIN/PERSISTENT are accepted with info | GVL_Cell.count := 7; |
| AT declarations | %I read-only input, %Q output, %M internal; addresses give syntax and direction, binding uses the name or signal pragma | sensor AT %IX0.0 : BOOL; |
| Start values | A fixed value after :=: literals, constants, arithmetic including **, or pure built-in functions | count : INT := TO_INT(5.0); wait : TIME := T#2s; |
| Constants | VAR CONSTANT with a value. Constants cannot be changed. Use them in calculations, as CASE labels and as FOR limits | MAXP : INT := 10; |
| Function block start inputs | Start values for the inputs of a timer or counter | tDelay : TON := (PT := T#2s); |
| Numbers and times | Decimal, binary 2#, octal 8#, hex 16# with _ separators; typed literals for all elementary types; TRUE, FALSE, T#2s, TIME#2s | 2#1010_0101, 8#17, INT#5, LREAL#1.5, T#1m30s |
| Assignment | :=. Integers widen by width/signedness and can widen to REAL/LREAL; REAL and LREAL are mutually assignable | d := i; |
| Decisions | IF / ELSIF / ELSE; CASE on integer/bit-string types with single values, lists, constants, inclusive ranges and ELSE. Overlapping or reversed ranges are errors | CASE s OF 1..5, 10: x := 1; ELSE x := 0; END_CASE |
| Loops | FOR … BY, WHILE, REPEAT … UNTIL | FOR i := 1 TO 10 DO … END_FOR |
| Leaving early | EXIT leaves the innermost loop; CONTINUE skips to its next iteration (FOR, WHILE or REPEAT). RETURN ends the scan; outputs are still written | IF skip THEN CONTINUE; END_IF; |
| Function block calls | Inputs with :=, outputs with =>, all by name | tDelay(IN := a, PT := T#1s, Q => ready); |
| Functions | Built-ins such as ABS, LIMIT, SEL, SQRT, EXPT, TRUNC, MOVE, MUL_TIME, DIV_TIME and conversions <S>_TO_<T> / TO_<T>, by position or all by name. See ST Functions | y := TO_INT(MOVE(x)); |
| Reading blocks | Inputs and outputs of a block instance | tDelay.Q, cnt.CV |
| Setting block inputs | Assign an input without running the block; the next call uses its retained inputs. Outputs cannot be assigned directly | tDelay.IN := enabled; tDelay.PT := T#1s; tDelay(); |
| Calculation | + - * /, MOD, minus sign, powers with ** (REAL/LREAL result). Integer division cuts off decimals. TIME × number in either order and TIME / number return TIME, truncated to whole milliseconds | r := 2.0 ** 3; wait := T#1s / 4; |
| Comparison | = <> < <= > >= | IF level >= 80 THEN |
| Order of operations | Strongest first: brackets, function call, NOT and minus sign, **, * / MOD, + -, < > <= >=, = <>, AND, XOR, OR. Powers group from the right | 2.0 ** 3 ** 2 means 2.0 ** (3 ** 2) |
| Logic and bits | AND OR XOR NOT: logical on BOOL, bitwise on integer/bit-string types | mask := flags AND 16#00FF; |
| Bit access | Read BOOL or set one bit of an integer/bit-string variable; index is a literal or constant, zero-based and within the type width | ready := w.3; w.0 := TRUE; |
| Shifting | SHL, SHR, ROL, ROR with value and number of bits | x := SHL(1, 3); |
| System variables | RV_SimulationMode and RV_FirstScan, read-only | IF RV_FirstScan THEN … END_IF; |
Not supported
Section titled “Not supported”The compiler reports unsupported constructs instead of running something unexpected. These are errors except for several PROGRAM declarations, which produce a warning and no runnable program.
| Not supported | Instead |
|---|---|
Arrays (ARRAY[0..3] OF INT) | One variable per element, or a CASE |
Structures and other TYPE definitions besides enums | Separate variables |
ACTION, METHOD, classes, interfaces, POINTER/REF | FUNCTION / FUNCTION_BLOCK and scalar parameters |
Other data types such as DATE, TOD, LTIME / LT# | TIME for durations |
More than one PROGRAM in one program text (warning; no runnable program) | One PLC Program component per PROGRAM |
| Standard functions not listed in ST Functions (such as date functions) | Write the calculation with IF and arithmetic |
| Structures and custom data types for text or other data | Separate variables |
| Recursion (a function or block that calls itself, directly or through others) | Use a loop |
MC_ blocks inside your own FUNCTION_BLOCK | Declare them in the PROGRAM |
VAR_INPUT, VAR_OUTPUT, VAR_IN_OUT in a PROGRAM | Inputs and outputs belong in a FUNCTION_BLOCK; use VAR_EXTERNAL or AT for signals |
Conditional compilation pragmas ({IF …}, {define …}) | Select the source before compiling; both branches must not run together |
Function block calls without names (t(TRUE, T#1s)); functions may be called by position | t(IN := TRUE, PT := T#1s) |
Setting a block output directly (t.Q := TRUE;) | Read the output after a call, or copy it with => |
Start values that depend on variables, or on a VAR_EXTERNAL | Set the value under IF RV_FirstScan THEN |
MOD on REAL / LREAL, TIME / TIME, GOTO / JMP | Rewrite with arithmetic and structured control flow |
Mixing BOOL and INT in AND, OR, XOR, NOT | Compare first: (n <> 0) AND b |
Converting a larger type into a smaller one by assignment (DINT to INT, REAL to INT) | Convert explicitly: REAL_TO_INT, DINT_TO_INT or TRUNC |
Nested comments ((* a (* b *) *)) | Close the outer comment first, or use // line comments |
Function blocks
Section titled “Function blocks”| Block | Inputs → outputs | What it does |
|---|---|---|
| TON | IN, PT → Q, ET | On-delay: Q turns on after IN has been on for PT |
| TOF | IN, PT → Q, ET | Off-delay: Q turns off PT after IN turns off |
| TP | IN, PT → Q, ET | Pulse of length PT on a rising edge of IN |
| CTU | CU, R, PV → Q, CV | Counts up on each rising edge of CU; Q when CV ≥ PV |
| CTD | CD, LD, PV → Q, CV | Counts down from PV; Q when CV ≤ 0 |
| CTUD | CU, CD, R, LD, PV → QU, QD, CV | Up/down counter |
| R_TRIG / F_TRIG | CLK → Q | Q for one scan on a rising / falling edge |
| RS / SR | S, R1 → Q1 / S1, R → Q1 | Reset-dominant / set-dominant flip-flop |
Timers run on simulation time: when you pause the simulation, timers pause too.
Besides these standard blocks you can write your own function blocks (Function Blocks & Libraries) and use the PLCopen motion blocks MC_Power, MC_MoveAbsolute, MC_MoveLinearAbsolute and others to move axes and Cartesian groups with jerk-limited profiles (PLCopen Motion). Programs with MC_ blocks need continuous simulation; they are not DES-suitable.