TwinCAT Notes
Insights, tutorials, and deep dives into industrial automation.
-
Working with Variable-Length Collections in Structured Text Using IEnumerator
How to bypass the limitations of fixed-size arrays in TwinCAT and CoDeSys. Implementing the IEnumerator interface for flexible dynamic sequence iteration.
-
Nuances of Working with Function Block Instances by Value in TwinCAT 3 / CoDeSys
A detailed analysis of memory copying (MEMCPY) and object lifecycle (FB_Init/FB_Exit) when working with function block instances by value in IEC 61131-3.
-
Extending FB_Init Parameters in TwinCAT: Constructors for Derived Classes
How to extend the parameter list of the FB_Init method in derived classes for Predictable Initialization in TwinCAT and CoDeSys. Benefits and compiler limitations.
-
Exception Handling in TwinCAT: __TRY, __CATCH, __FINALLY
An analysis of the exception handling mechanism using TRY-CATCH-FINALLY constructs in TwinCAT 3.1.4026. Usage nuances, runtime limitations, and implementation in TwinCAT.OpenFramework.
-
Type Checking at Runtime in TwinCAT: __QUERYINTERFACE and __QUERYPOINTER
An exploration of runtime type safety in Structured Text, detailing how to check type compatibility using interfaces and compiler casting operators.
-
Abstract Class vs Interface in Structured Text
A comparison of abstract classes and interfaces in CoDeSys/TwinCAT, detailing inheritance, runtime type checking, and polymorphism safety.
-
VAR_GENERIC CONSTANT in TwinCAT: The Nuances Nobody Writes About
A summary of experiments with generic arrays in TwinCAT/CoDeSys, clarifying compiler support for various use cases.
-
Quirks of VAR_IN_OUT CONSTANT in TwinCAT
An exploration of how the TwinCAT compiler handles VAR_IN_OUT CONSTANT parameters, specifically with string literals and temporary variables.
-
A Non-Obvious Pitfall with Resource Cleanup in TwinCAT Programs
Why FB_init and FB_exit inside TwinCAT programs (static classes) are not called automatically, and how to bypass this limitation.
-
Specifics of FB_exit Behavior in TwinCAT
Understanding when and how FB_exit is called automatically in TwinCAT, including key compiler limitations and behaviors.
-
StructuredText Cheat Sheet: Types, FB, Classes, and Objects
An explanation of core object-oriented concepts in the TwinCAT/CoDeSys implementation of Structured Text.
-
Dynamic Object Creation in TwinCAT using FB_Init Parameters
How to dynamically create a class instance in TwinCAT when the class has additional parameters in FB_Init.