Don't cram too much heavy processing into the first scan. If you have massive data to load, consider a dedicated "Initialization" state that spans multiple cycles.
// Startup timer after first scan IF NOT fbFirstScan.bFirstScan AND NOT bStartupComplete THEN tStartupTimer(IN:=TRUE, PT:=T#2S); IF tStartupTimer.Q THEN bStartupComplete := TRUE; // Enable normal operation END_IF END_IF
It is important to distinguish the First Scan bit from the "Cold Start" or "Warm Start" methods. While the First Scan bit fires in both scenarios, the logic attached to it can be bifurcated. A skilled programmer may use additional system flags to determine if the startup is a warm restart (retaining memory) or a cold restart (memory cleared), allowing the First Scan logic to behave differently depending on the severity of the reset. This granularity offers a level of control that separates robust industrial code from hobbyist experimentation.
(* Clear alarms *) bAlarmReset := TRUE;
// -- Reset the first scan trigger for next init -- bInit := FALSE;
When you instantiate a function block, TwinCAT automatically calls its FB_Init method once.
