// Normal cyclic logic here IF initDone AND NOT bSystemReady THEN // Perform post-init checks END_IF The Beckhoff first scan bit ( _FIRSTSCAN ) is a reliable, simple mechanism for one-time PLC initialization in TwinCAT. When combined with careful handling of retentive data and task scheduling, it ensures deterministic startup behavior. Programmers should prefer the built-in system variable over manual constructs for clarity and correctness. Report prepared for: Beckhoff TwinCAT developers Last reviewed: April 2026 Version: 1.0
VAR bFirstScan : BOOL; END_VAR bFirstScan := TwinCAT_SystemInfoVarList._FirstScan; beckhoff first scan bit
VAR firstScan : BOOL := TRUE; (* initial value = TRUE *) END_VAR // In main cyclic logic: IF firstScan THEN // Initialization code here firstScan := FALSE; END_IF ⚠️ : This manual method works only if firstScan is declared with RETAIN or PERSISTENT (to survive warm restart), otherwise a cold restart will re-trigger it, which might be intended or not. 4. Comparison with Other PLC Platforms | Platform | First Scan Flag | |------------------|---------------------------------| | Beckhoff TwinCAT | _FIRSTSCAN (system global) | | Siemens S7 | FirstScan in OB100 | | Rockwell ControlLogix | S:FS (First Scan) | | CODESYS | _FirstScan (implicit) | // Normal cyclic logic here IF initDone AND