Advanced
CODESYS vs TIA Portal: Structured Text Differences Every Engineer Should Know
Moving between CODESYS and TIA Portal? Learn the key Structured Text syntax differences to avoid common pitfalls.
Two platforms you will meet
Work in industrial automation long enough and you will program both CODESYS (used by Beckhoff, Wago, ABB and many others) and Siemens TIA Portal (S7-1200/1500). Both follow IEC 61131-3 for Structured Text, but the syntax and the behaviour differ in places, and those are the places to check when you move code from one to the other.
Where the two differ
1. Program structure
CODESYS uses standard IEC 61131-3 POUs:
PROGRAM Main
VAR
myVar : INT := 0;
END_VAR
// Logic here
END_PROGRAM
TIA Portal wraps code in Organization Blocks (OBs):
2. Timer syntax
CODESYS follows the IEC standard:
myTimer(IN := startCondition, PT := T#5s);
timerDone := myTimer.Q;
elapsed := myTimer.ET;
TIA Portal is similar, but the timer is called through its instance DB:
// Timer called as instance in TIA Portal
"IEC_Timer_DB".TON(
IN := startCondition,
PT := T#5s
);
timerDone := "IEC_Timer_DB".Q;
3. String handling
In CODESYS:
myString : STRING(80) := 'Hello';
length := LEN(myString);
sub := MID(myString, 3, 1); // MID(string, length, position)
In TIA Portal:
// TIA uses slightly different function signatures
length := LEN("myString");
// String indexing starts from 1 in both platforms
4. Data types
| Feature | CODESYS | TIA Portal |
|---|---|---|
| Strings | STRING(length) | String[length] |
| Enums | Standard IEC | Limited before V16 |
| Pointers | POINTER TO | Not available in ST |
| References | REFERENCE TO | InOut parameters |
| Arrays | ARRAY[1..10] OF | Array[1..10] of |
5. Comment styles
Both support:
// Single-line comment
(* Multi-line
comment *)
TIA Portal also accepts:
/* C-style comments */
What carries over unchanged
The core logic transfers well. These constructs are identical on both platforms:
How to write code that ports
Before you move code across
Most of the differences are syntax. The logic, the control structures and the programming patterns are the same, so Structured Text learned on a standard IEC 61131-3 platform carries over to both CODESYS and TIA Portal. What you relearn is the block structure, the timer calls, the string functions and the data types covered above.
You can practise writing portable ST in the free online editor.