In Beckhoff TwinCAT, there is no single pre-defined global "First Scan" variable like the
END_IF
Task-Specific: Because it is part of the task info structure, it correctly identifies the first scan for the specific task it is called within.
TwinCAT provides internal system information via the Tc2_System library. You can check if the current cycle is the very first one by looking at the system task info.
Without a proper first scan routine, your machine might start with actuators in unpredictable positions or unfinished states from a previous run.
Part 2: The Classic Approach – Standard PLC Libraries
Method 1: Tc2_Standard (TwinCAT 2 Legacy)
In legacy TwinCAT 2 and early TwinCAT 3 projects using the Tc2_Standard library, the standard way to get a first scan bit is:
Edge-detected approach
Step 2: At the very end of your MAIN routine, add: bFirstScan := FALSE;.
