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.

Why This Matters

If you work in industrial automation, you'll eventually encounter both CODESYS (used by Beckhoff, Wago, ABB, and many others) and Siemens TIA Portal (S7-1200/1500). While both follow IEC 61131-3 for Structured Text, there are important syntax and behavioral differences.

Key Differences

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), FC/FB blocks
  • Variables declared in the block's interface, not inline VAR blocks
  • Uses Data Blocks (DBs) for persistent storage
  • 2. Timer Syntax

    CODESYS (IEC standard):

    myTimer(IN := startCondition, PT := T#5s);
    timerDone := myTimer.Q;
    elapsed := myTimer.ET;
    

    TIA Portal (similar but with 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

    CODESYS:

    myString : STRING(80) := 'Hello';
    length := LEN(myString);
    sub := MID(myString, 3, 1);  // MID(string, length, position)
    

    TIA Portal:

    // TIA uses slightly different function signatures
    length := LEN("myString");
    // String indexing starts from 1 in both platforms
    

    4. Data Type Differences

    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. Commenting Styles

    Both support:

    // Single-line comment
    (* Multi-line
       comment *)
    

    TIA Portal also accepts:

    / C-style comments /
    

    What Transfers Between Platforms

    The good news: core logic transfers well. These 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)
  • Best Practice: Write Portable Code

  • Stick to IEC 61131-3 standard syntax where possible
  • Avoid platform-specific pointer/reference types
  • Use standard timer and counter function blocks
  • Document platform-specific code with comments
  • Practice in a standard IEC simulator like CodeSchool ST to build transferable skills
  • Conclusion

    Learning Structured Text on a standard IEC 61131-3 platform gives you skills that transfer to both CODESYS and TIA Portal. The differences are mostly syntactic — the logic, control structures, and programming patterns are the same.

    Practice writing portable ST code in our free online editor to build skills that work everywhere.