Structured Text overview
Structured Text (ST) is a way to write PLC logic as statements. Each statement reads tags, calculates a value or chooses what runs next.
When to use it
Choose ST for calculations, several choices or a bounded loop. Ladder makes contacts, coils and interlocks easy to follow as a circuit. Both work on the same project tags and run within the PLC scan.
Create and run a routine
- Stop the simulator. In Project Explorer, right-click the program or its Routines folder and choose New Routine.
- Enter a name, choose Structured Text (ST) under Language, then choose Create routine.
- Create the tags below in the tag table, then type the example. Tags are declared in the project, outside the source text.
- Right-click the routine and choose Set as Main Routine to run it every scan. A different routine runs only when the Main Routine reaches a
CALL_ROUTINEthat calls it, directly or through other routines. Opening a tab does not run it. - Choose Build (Ctrl+Shift+B). Fix any errors, then choose Run. Run also checks a changed project before it starts.
StartPB — BOOL; StopPB — BOOL; MotorRun — BOOL.MotorRun := StartPB AND NOT StopPB;This writes MotorRun on every scan. It follows StartPB while StopPB is false; it does not latch the motor on.
Edit, check and watch
Edit only while stopped. Build and Run check the source. Errors appear beside the affected line, in the ST status bar and in Problems. Select a problem to go to its line. The last check stays visible while you type; build again to check the new text.
While running, live values appear beside executed lines, with branch and loop activity. If the routine was not called, it has no new execution to show. Turn on Toggle Bits to click a live, writable BOOL value; forced or read-only tags cannot be toggled there. Stop before changing the code.
Read next
- Statements
- Values and operators
- Data types and conversions
- Functions and instructions
- Limits and what’s not in ST yet
- Common errors and fixes