The Beckhoff First Scan Bit, also known as the "FirstScan" bit, is a special bit in the TwinCAT 3 system that indicates when the PLC (Programmable Logic Controller) is executing its first scan cycle. In other words, it is a flag that is set during the initial scan of the PLC program. This bit is typically used to execute specific code or actions only once, during the first scan of the PLC.
In legacy TwinCAT 2 and early TwinCAT 3 projects using the Tc2_Standard library, the standard way to get a first scan bit is:
In Beckhoff TwinCAT, the "first scan bit" is a fundamental tool used to execute initialization code only once when the PLC starts or transitions into Run mode. Unlike some other platforms that use a fixed system bit (like Siemens' S:FS ), TwinCAT provides a more flexible approach using built-in system structures or manual variable initialization. Direct Solution for First Scan Bit beckhoff first scan bit
If you are working on older legacy controllers (such as the Beckhoff CX1010 or CX1020 series) or maintaining an legacy system, you may find the global system array variable explicit:
By leveraging the robust and standardized method involving the GETCURTASKINDEX function block and the _TaskInfo system array, developers can create highly maintainable and transparent initialization logic. Whether you are using Structured Text, Ladder Diagram, or any other IEC 61131-3 language, the ability to trap the very first scan cycle is universally available. The Beckhoff First Scan Bit, also known as
Beckhoff's TwinCAT 3 environment does not have a dedicated pre-defined "first scan" system bit like Allen-Bradley's S:FS . Instead, developers typically implement this functionality manually using an initial value or by referencing specific PLC task variables.
It is cleaner to have one IF bFirstScan block at the beginning of your code rather than scattering multiple IF bFirstScan blocks throughout your program, which can make debugging difficult. 4. First Scan Bit vs. PLC_PRG_Init In legacy TwinCAT 2 and early TwinCAT 3
| Variable Type | Behavior on Power Cycle | Behavior on Program Download | Interaction with First Scan | |---|---|---|---| | | Re-initializes to declared start value | Re-initializes | First scan can set custom initial values | | RETAIN | Retains last value from before power loss | Retains last value (by default) | Useful for detecting first scan without losing value | | PERSISTENT | Retains value across program changes | Retains value across program downloads | Often used with first scan to determine if first run after major update |