The is a simple but powerful tool for safe PLC initialization. Always use the system library version ( FB_FirstScan ), and remember: first scan ≠ warm start. Use it to enforce a clean startup state, especially after program downloads or power cycles.
VAR fbGetCurTaskIdx : GETCURTASKINDEX; // Function block to find the current task ID bFirstScan : BOOL; END_VAR fbGetCurTaskIdx(); // Call the FB // Access the system's internal task info array bFirstScan := _TaskInfo[fbGetCurTaskIdx.index].FirstCycle; IF bFirstScan THEN // Insert initialization logic here END_IF Use code with caution. Copied to clipboard
Do not put long, blocking loops (like heavy WHILE loops) inside your first scan logic. If the first cycle takes too long, it will exceed the configured Task Cycle Time, throwing a and stopping the PLC immediately. 3. Execution Order Matters
IF _TaskInfo[GETCURTASKINDEXEX()].firstCycle THEN // Your initialization code here (e.g., setting default parameters) END_IF Use code with caution. Copied to clipboard
The cleanest and most modern way to retrieve the first scan status in is by utilizing the function block GETCURTASKINDEX paired with the global variable array _TaskInfo . This dynamically captures the cycle state of whichever task is currently calling the code. Structured Text (ST) Implementation
It’s a system flag that is after:
The is a simple but powerful tool for safe PLC initialization. Always use the system library version ( FB_FirstScan ), and remember: first scan ≠ warm start. Use it to enforce a clean startup state, especially after program downloads or power cycles.
VAR fbGetCurTaskIdx : GETCURTASKINDEX; // Function block to find the current task ID bFirstScan : BOOL; END_VAR fbGetCurTaskIdx(); // Call the FB // Access the system's internal task info array bFirstScan := _TaskInfo[fbGetCurTaskIdx.index].FirstCycle; IF bFirstScan THEN // Insert initialization logic here END_IF Use code with caution. Copied to clipboard beckhoff first scan bit
Do not put long, blocking loops (like heavy WHILE loops) inside your first scan logic. If the first cycle takes too long, it will exceed the configured Task Cycle Time, throwing a and stopping the PLC immediately. 3. Execution Order Matters The is a simple but powerful tool for
IF _TaskInfo[GETCURTASKINDEXEX()].firstCycle THEN // Your initialization code here (e.g., setting default parameters) END_IF Use code with caution. Copied to clipboard VAR fbGetCurTaskIdx : GETCURTASKINDEX; // Function block to
The cleanest and most modern way to retrieve the first scan status in is by utilizing the function block GETCURTASKINDEX paired with the global variable array _TaskInfo . This dynamically captures the cycle state of whichever task is currently calling the code. Structured Text (ST) Implementation
It’s a system flag that is after: