Beckhoff First Scan Bit Jun 2026
If you are maintaining legacy TwinCAT 2 systems or want to utilize structural system flags, you can monitor the state of the PLC task control flags. TwinCAT provides standard libraries containing system structures that reflect the state of the execution engine.
PROGRAM MAIN VAR bInitDone : BOOL; myCounter : INT; END_VAR
For advanced applications, TwinCAT provides internal system structures that expose the state of the PLC task execution. You can inspect the task information via the TwinCAT_SystemInfoVarList . Code Implementation
| Variable | Data type | Description | | :--- | :--- | :--- | | active | BOOL | TRUE if the task is active. | | taskName | STRING(16) | The name of the task. | | | BOOL | TRUE only on the first scan cycle after system startup; FALSE thereafter. | | cycleTimeExceeded | BOOL | TRUE if the task's execution time exceeds the configured cycle time. | | cycleTime | UDINT | The configured cycle time of the task (in 100 ns increments). | | lastExecTime | UDINT | The execution time of the task during the previous cycle (in 100 ns increments). | | priority | BYTE | The priority of the task. | | cycleCount | UDINT | The number of completed cycles since the task started. | beckhoff first scan bit
Simple flag:
IF FirstScan THEN // Configure encoder input Encoder_SetMode(ENC_MODE_QUADRATURE); Encoder_SetResolution(4096); END_IF
Purging old data arrays, resetting FIFO (First-In, First-Out) pointers, and sending initial handshakes to Modbus, EtherCAT, or EtherNet/IP slaves. If you are maintaining legacy TwinCAT 2 systems
Next time you write a new PLC program, ask yourself: “If this were a cold start right now, would my system behave safely?” If the answer isn’t an immediate “yes,” you need FirstScan .
fbFirstScan();
A first scan bit is a boolean flag that remains TRUE for exactly one execution cycle of the PLC task. After the first logic solve is complete, the bit drops to FALSE and stays there until the PLC is restarted. You can inspect the task information via the
Here’s a technical feature article exploring the in Beckhoff TwinCAT systems.
The array _TaskInfo is automatically exposed by the TwinCAT runtime engine. Fetching the index programmatically ensures that if you reuse this code across different tasks (e.g., a fast 1 ms motion task vs. a slow 50 ms housekeeping task), it will always monitor the correct execution context.
IF TwinCAT_SystemInfoVarList._TaskInfo[1].CycleCount = 1 THEN // Execute first scan logic END_IF; Use code with caution.