Beckhoff | First Scan Bit |verified|
: Setting initial values for variables that aren't retentive. Communication Setup
In legacy TwinCAT 2 and early TwinCAT 3 projects using the Tc2_Standard library, the standard way to get a first scan bit is: beckhoff first scan bit
⚠️ Note that in TwinCAT 3, _TaskInfo[].FirstCycle behaves strictly as the first cycle after the TwinCAT Runtime starts up (moving to Green mode). Toggling the PLC project between STOP and RUN alone does not always re-trigger it unless the system is restarted. : Setting initial values for variables that aren't retentive
// -- Normal logic after first scan done -- IF NOT bFirstScanDone THEN // Final first-scan tasks that require bus ready fbAxis1.ExecuteHome(); bFirstScanDone := TRUE; END_IF // -- Normal logic after first scan done
VAR fbGetCurTaskIndex : GETCURTASKINDEX; bFirstScan : BOOL; END_VAR fbGetCurTaskIndex(); // Get the index of the current PLC task bFirstScan := _TaskInfo[fbGetCurTaskIndex.index].FirstCycle; // Extract the bit IF bFirstScan THEN // Place initialization logic here (e.g., loading presets or clearing memory) END_IF Use code with caution. Copied to clipboard 1. Understanding System Information Structure
PROGRAM MAIN VAR myOutput : BOOL; END_VAR