In TwinCAT, the PROGRAM or FUNCTION_BLOCK structure has a specific order of execution. The VAR section declares variables, but it doesn't execute logic. To run logic on the first scan, you declare a boolean flag and check its state.
IF _TaskInfo[GETCURTASKINDEX()].FirstCycle THEN // Your initialization logic here END_IF; Use code with caution. Copied to clipboard Custom Variable Method
In TwinCAT, the PROGRAM or FUNCTION_BLOCK structure has a specific order of execution. The VAR section declares variables, but it doesn't execute logic. To run logic on the first scan, you declare a boolean flag and check its state.
IF _TaskInfo[GETCURTASKINDEX()].FirstCycle THEN // Your initialization logic here END_IF; Use code with caution. Copied to clipboard Custom Variable Method beckhoff first scan bit