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):

  • OB1 (main scan), OB100 (startup), and FC/FB blocks
  • Variables are declared in the block's interface, not in inline VAR blocks
  • Data Blocks (DBs) hold persistent storage
  • 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

    FeatureCODESYSTIA Portal
    StringsSTRING(length)String[length]
    EnumsStandard IECLimited before V16
    PointersPOINTER TONot available in ST
    ReferencesREFERENCE TOInOut parameters
    ArraysARRAY[1..10] OFArray[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:

  • IF/ELSIF/ELSE/END_IF
  • FOR/WHILE/REPEAT loops
  • CASE statements
  • Boolean operators (AND, OR, NOT, XOR)
  • Arithmetic operators (+, -, *, /, MOD)
  • Comparison operators (=, <>, <, >, <=, >=)
  • Most IEC function blocks (TON, TOF, TP, CTU, CTD)
  • How to write code that ports

  • Stick to IEC 61131-3 standard syntax where possible.
  • Avoid the platform-specific pointer and reference types.
  • Use the standard timer and counter function blocks.
  • Mark platform-specific code with comments.
  • Practise in a standard IEC simulator such as CodeSchool ST, so the skills you build are not tied to one vendor.
  • 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.