Skip to content

Language Reference

Commercial

Included in the public demo Compare editions

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.

AreaWhat you can useExample
ProgramOne PROGRAM … END_PROGRAM per PLC Program component, with VAR, VAR CONSTANT and VAR_EXTERNAL blocksPROGRAM Main … END_PROGRAM
Your own functions and function blocksFUNCTION 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 & LibrariesFUNCTION_BLOCK Gate … END_FUNCTION_BLOCK
VariablesOne 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 rejecteda, b : INT := 3;
Temporary variablesVAR_TEMP elementary variables start fresh on every scan or function/block callVAR_TEMP scratch : INT := 1; END_VAR
Retention qualifiersVAR RETAIN and VAR PERSISTENT are accepted with an information message. They behave like ordinary VAR; remanence is not simulatedVAR RETAIN count : INT; END_VAR
PragmasEnum 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'}
EnumerationsTYPE … END_TYPE before PROGRAM or in a PLC Library; named integer states with an optional base type and defaultTYPE E_State : (Idle := 0, Run, Fault := 10) UINT; END_TYPE
Global variable listsVAR_GLOBAL in a PLC Library or before PROGRAM; shared values are internal signals. CONSTANT creates no signal; RETAIN/PERSISTENT are accepted with infoGVL_Cell.count := 7;
AT declarations%I read-only input, %Q output, %M internal; addresses give syntax and direction, binding uses the name or signal pragmasensor AT %IX0.0 : BOOL;
Start valuesA fixed value after :=: literals, constants, arithmetic including **, or pure built-in functionscount : INT := TO_INT(5.0); wait : TIME := T#2s;
ConstantsVAR CONSTANT with a value. Constants cannot be changed. Use them in calculations, as CASE labels and as FOR limitsMAXP : INT := 10;
Function block start inputsStart values for the inputs of a timer or countertDelay : TON := (PT := T#2s);
Numbers and timesDecimal, binary 2#, octal 8#, hex 16# with _ separators; typed literals for all elementary types; TRUE, FALSE, T#2s, TIME#2s2#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 assignabled := i;
DecisionsIF / ELSIF / ELSE; CASE on integer/bit-string types with single values, lists, constants, inclusive ranges and ELSE. Overlapping or reversed ranges are errorsCASE s OF 1..5, 10: x := 1; ELSE x := 0; END_CASE
LoopsFOR … BY, WHILE, REPEAT … UNTILFOR i := 1 TO 10 DO … END_FOR
Leaving earlyEXIT leaves the innermost loop; CONTINUE skips to its next iteration (FOR, WHILE or REPEAT). RETURN ends the scan; outputs are still writtenIF skip THEN CONTINUE; END_IF;
Function block callsInputs with :=, outputs with =>, all by nametDelay(IN := a, PT := T#1s, Q => ready);
FunctionsBuilt-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 Functionsy := TO_INT(MOVE(x));
Reading blocksInputs and outputs of a block instancetDelay.Q, cnt.CV
Setting block inputsAssign an input without running the block; the next call uses its retained inputs. Outputs cannot be assigned directlytDelay.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 millisecondsr := 2.0 ** 3; wait := T#1s / 4;
Comparison= <> < <= > >=IF level >= 80 THEN
Order of operationsStrongest first: brackets, function call, NOT and minus sign, **, * / MOD, + -, < > <= >=, = <>, AND, XOR, OR. Powers group from the right2.0 ** 3 ** 2 means 2.0 ** (3 ** 2)
Logic and bitsAND OR XOR NOT: logical on BOOL, bitwise on integer/bit-string typesmask := flags AND 16#00FF;
Bit accessRead BOOL or set one bit of an integer/bit-string variable; index is a literal or constant, zero-based and within the type widthready := w.3; w.0 := TRUE;
ShiftingSHL, SHR, ROL, ROR with value and number of bitsx := SHL(1, 3);
System variablesRV_SimulationMode and RV_FirstScan, read-onlyIF RV_FirstScan THEN … END_IF;

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 supportedInstead
Arrays (ARRAY[0..3] OF INT)One variable per element, or a CASE
Structures and other TYPE definitions besides enumsSeparate variables
ACTION, METHOD, classes, interfaces, POINTER/REFFUNCTION / 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 dataSeparate variables
Recursion (a function or block that calls itself, directly or through others)Use a loop
MC_ blocks inside your own FUNCTION_BLOCKDeclare them in the PROGRAM
VAR_INPUT, VAR_OUTPUT, VAR_IN_OUT in a PROGRAMInputs 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 positiont(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_EXTERNALSet the value under IF RV_FirstScan THEN
MOD on REAL / LREAL, TIME / TIME, GOTO / JMPRewrite with arithmetic and structured control flow
Mixing BOOL and INT in AND, OR, XOR, NOTCompare 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
BlockInputs → outputsWhat it does
TONIN, PT → Q, ETOn-delay: Q turns on after IN has been on for PT
TOFIN, PT → Q, ETOff-delay: Q turns off PT after IN turns off
TPIN, PT → Q, ETPulse of length PT on a rising edge of IN
CTUCU, R, PV → Q, CVCounts up on each rising edge of CU; Q when CV ≥ PV
CTDCD, LD, PV → Q, CVCounts down from PV; Q when CV ≤ 0
CTUDCU, CD, R, LD, PV → QU, QD, CVUp/down counter
R_TRIG / F_TRIGCLK → QQ for one scan on a rising / falling edge
RS / SRS, R1 → Q1 / S1, R → Q1Reset-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.