Skip to content

30From the lab to the plant

The same ST on every platform: SCL, Studio 5000, CODESYS, TwinCAT

What changes and what stays the same when you move a Structured Text program between Siemens, Rockwell, CODESYS, Beckhoff, Schneider, Omron and Mitsubishi.

Lesson 30 of 3414 minIEC 61131-3

One standard, many implementations

IEC 61131-3 describes the language, but every vendor builds its own compiler, library and editor. The result: the idea travels about 90%, the details need review. This line runs unchanged everywhere:

Pump := (Start OR Pump) AND NOT Stop AND Level < 95.0;

The line that calls a timer is the one that changes.

Siemens SCL in TIA Portal

Siemens calls the language SCL (Structured Control Language). Three things matter:

  • A # in front of local variables: #Pump, #T1. Global tags go in quotes: "MotorDB".Running.
  • The IEC timer is TON_TIME, and it needs an instance in the block's data.
  • Optimized block access: memory has no fixed address, so you reach a variable by name and not by %MD20. Faster and safer, but absolute access is gone.
// Siemens SCL
#T1(IN := #Level >= 60.0, PT := T#3s);
#Soaked := #T1.Q;
IF #Soaked THEN
    #Valve := TRUE;
END_IF;

Note the semicolon after END_IF: Siemens wants it.

Rockwell Studio 5000 ST

Closest to standard ST in shape, furthest in timers:

  • No #. Tag names are used directly, and . reaches a member of a UDT.
  • A timer is not a standard function block but an instruction acting on a TIMER structure with PRE, ACC, DN, EN and TT. The preset is an integer in milliseconds, not a TIME.
  • Reusable logic is wrapped in an AOI (Add-On Instruction), Rockwell's equivalent of FUNCTION_BLOCK.
(* Rockwell Studio 5000 *)
T1.PRE := 3000;
TONR(T1);
Soaked := T1.DN;
IF Soaked THEN
    Valve := 1;
END_IF;

Here T1.ACC is T1.ET and T1.DN is T1.Q. TONR does reset its accumulator when the enable drops, which is standard TON behaviour, but the member names differ, so code does not copy across literally.

CODESYS

The practical reference implementation. The Standard library gives you TON, TOF, TP and CTU with the member names from the standard, and TIME written as T#500ms. If your code runs in CODESYS without vendor tricks, it is about as portable as PLC code gets.

Beckhoff TwinCAT 3

Built on CODESYS, so everything above applies, plus two things:

  • A Visual Studio environment, with a build process that feels like software engineering.
  • Full OOP support: METHOD, PROPERTY, INTERFACE, EXTENDS. Advanced TwinCAT code therefore does not move to a controller that does not implement the third edition.

Schneider EcoStruxure / Machine Expert

Machine Expert is also CODESYS-based, so it behaves in the standard way. Older Control Expert (Unity Pro) has its own library and the %M / %MW direct addressing style, and needs more care.

Omron Sysmac Studio

Follows the standard unusually closely and uses names like TON. The practical difference is the variable table: everything is declared as Internal, Input, Output or External in one place, direct addresses carry a % prefix, and Retain is a checkbox per variable.

Mitsubishi GX Works3

ST is supported, but the platform culture is ladder and FBD. Native device names (D100, M0, T5) show up constantly in older code, and the traditional timer is a T device with a 100 ms time base. Standard TON is available but is not the convention in legacy projects.

What changes

Item

Siemens SCL

Rockwell ST

CODESYS / TwinCAT

Omron Sysmac

Local variable prefix

#Name

none

none

none

Timer

TON_TIME

TONR on a TIMER

TON

TON

Preset

PT : TIME

PRE : DINT in ms

PT : TIME

PT : TIME

Elapsed

.ET

.ACC

.ET

.ET

Timer output

.Q

.DN

.Q

.Q

Retain

block Retain, or a non-optimized DB

non-volatile tag area

VAR RETAIN

per-variable Retain

Reusable logic

FUNCTION_BLOCK

AOI

FUNCTION_BLOCK

FUNCTION_BLOCK

Semicolon after END_IF

required

required

optional

optional

What stays the same

  • := for assignment and = for comparison.
  • IF / ELSIF / ELSE / END_IF, CASE OF, FOR, WHILE.
  • AND OR XOR NOT MOD, the arithmetic and the comparisons.
  • The scan cycle, the last assignment winning, and a timer needing a call every scan.
  • State machines, filters, scaling and alarm logic: they move with a rename.

A practical porting rule

Write the logic in your own names and push everything that touches a vendor library into small blocks. Porting then means rewriting the small blocks while 90% of the program stays put. That is also why the lab on this site is useful: you learn the core here and export to SCL when you need to.

Try it in the lab

The lab runs in your browser: an ST editor, a virtual process that suits the lesson, the same program as a live ladder diagram, a watch table, and export to Siemens SCL.

What to try

  1. Run the program and press START: the belt runs and the tall boxes are rejected.
  2. Look at the export panel: the same program as Siemens SCL, with # on the variables and TON_TIME for the timer.
  3. Change T#600ms to T#100ms: the pulse is too short to push the box, so ERR goes up. That tuning depends on the machine, not on the vendor.

People find this lesson by searching

SCL vs structured textsiemens SCL tutorialstructured text studio 5000twincat structured textcodesys structured textrockwell ST timer DN ACCplc code portability

Course outline

  1. 01What is Structured Text, and when to use it instead of ladder
  2. 02How a PLC runs your code: the scan cycle and the process image
  3. 03Program structure: POUs, PROGRAM, FUNCTION and FUNCTION_BLOCK
  4. 04Your first program: starting a pump with seal-in logic
  5. 05Data types: BOOL, INT, REAL, TIME and the rest
  6. 06Declaring variables: VAR, VAR_INPUT and RETAIN
  7. 07Literals and constants: 16#FF, 2#1010 and T#5s
  8. 08Type conversion and scaling a 4-20 mA signal
  9. 09Assignment and arithmetic in ST: := and operator precedence
  10. 10Boolean logic, comparisons and bit operations
  11. 11Standard functions: ABS, SQRT, MIN, MAX, LIMIT, SEL, MUX
  12. 12IF, ELSIF and ELSE: the rules and when to avoid them
  13. 13The CASE statement and your first state machine
  14. 14The FOR loop and the watchdog
  15. 15WHILE, REPEAT, EXIT, CONTINUE and RETURN
  16. 16Edge detection: R_TRIG, F_TRIG and the "it fired every scan" bug
  17. 17Timers: TON, TOF and TP
  18. 18Counters: CTU, CTD and CTUD
  19. 19SR and RS flip-flops: which one wins
  20. 20Writing your own function
  21. 21Writing a function block
  22. 22Arrays in Structured Text
  23. 23Structs and enumerations
  24. 24References and pointers
  25. 25The state machine pattern: a batch sequence that cannot get stuck
  26. 26Alarm management to ISA-18.2: delay, deadband, latch, acknowledge, first-out
  27. 27Analogue signal processing: counts to engineering units, NE43 and filtering
  28. 28Closed-loop control in ST: hysteresis first, then a practical PID
  29. 29Motors and valves in practice: permissives, feedback and travel time
  30. 30The same ST on every platform: SCL, Studio 5000, CODESYS, TwinCAT
  31. 31Testing and debugging ST: the watch table, forcing and simulation
  32. 32An ST style guide: naming, comments, constants and version control
  33. 33Final project: a complete tank station with a state machine and alarms
  34. 3420 interview questions on ST and PLC programming, with answers