ST
Language Reference

Structured Text (ST) Language Reference

How to read this guide

This page is the reference companion to our Ladder Logic editor. Every section follows the same shape: a plain-English summary of what the feature is for, the IEC 61131-3 syntax, a parameters table, behaviour notes that call out the edge cases that bite beginners, one realistic worked example, vendor-specific divergences, and the top one or two beginner mistakes.

If you have never written PLC code before, read sections 1 (Program Structure), 2 (Data Types), 3 (Control Flow) and 5 (Function Blocks) top-to-bottom — they cover enough ground for you to build your first real program. The other sections work as standalone references; jump in when you need them.

Code blocks use the same syntax highlighting as the Ladder editor's Generated ST panel — keywords blue, types teal, addresses orange, literals green, comments green-italic, instance names gold. Click COPY on any block to paste it into the editor and run it.

Where a feature has a graphical counterpart in the editor (timers, counters, latches, contacts, coils), you'll see a "↔ View in Symbol Reference" link in the card — one click takes you to the equivalent diagram. The reverse link in the Ladder page brings you back here.

Program Structure & Basics

A Program Organisation Unit (POU) is one of three kinds. Pick the right one based on whether you need to keep state, return a value, or just react every scan.

POU TypeKeeps State?ReturnsUse For
PROGRAMYesNothingTop-level entry point — the scheduler calls it every scan.
FUNCTIONNoA single valuePure math / helpers — same inputs always give the same output.
FUNCTION_BLOCKYesMultiple outputsReusable components with memory — TON, CTU, your own controllers.
💡 Pro Tip
Use PROGRAM for the top entry, FUNCTION_BLOCK for anything that needs internal memory across scans (timers, edge detectors, state machines), and FUNCTION only for stateless pure transforms (clamp, scale, conversions).

Sources

Operator precedence, pin sets, data-type ranges and behaviour on this page were verified against the references below. The IEC 61131-3 standard text is treated as authoritative; vendor docs are cited for dialect-specific behaviour (e.g. Siemens SCL short-circuit semantics, Rockwell MOV statement form).