Beckhoff First Scan - Bit [best]
PROGRAM MAIN VAR initDone : BOOL := FALSE; startupTime : TIME; END_VAR
Unlike some other PLC platforms that have a dedicated system bit (like Siemens' or Allen-Bradley's
VAR bFirstScan : BOOL; END_VAR
In Beckhoff TwinCAT systems, a "First Scan Bit" is a boolean flag that is
METHOD FB_init : BOOL VAR_INPUT bInitRetains : BOOL; // TRUE if instance is initialized bInCopyCode : BOOL; // TRUE if instance is copied END_VAR beckhoff first scan bit
If you are using Beckhoff’s object-oriented extensions (Classes/Function Blocks), the FB_init method is the most elegant first scan mechanism. It runs the first cycle of the PLC.
In online mode, the first scan runs immediately after login. To debug, insert a JMP or use breakpoints carefully, or simulate the condition by forcing _FIRSTSCAN via a watch window (possible only if variable is writable — usually not). PROGRAM MAIN VAR initDone : BOOL := FALSE;
. This is a special method that runs automatically when a Function Block instance is initialized, effectively acting as a "constructor" and removing the need for a manual first scan check inside that block. AI responses may include mistakes. Learn more