then better way is to not block at all... let each instruction take the time it needs and look at the program state for verification and sequential activating of the commands.
maybe something like this
Code Display MoreIF ABORT_PROGRAM THEN MODE=#SYNC IF $PRO_ACTIVE THEN CWRITE($CMD, STAT, MODE, "STOP 1") ELSE IF $PRO_STATE1<>#P_FREE THEN CWRITE($CMD, STAT, MODE, "CANCEL 1") ELSE ABORT_PROGRAM = FALSE ENDIF ENDIF
this version not only checks program state but only executes commands that may be needed. if program is not running, there is no need to issue STOP command, if program is already deselected there is no need for CANCEL either.
Would this not call CWRITE continuously until the checked flags are false? I have not looked at the documentation to know enough about whats going on behind the scenes, but have found that in my experience it is always best to ensure that all calls to functions are explicit. Wouldn't it be better to implement falling edge triggers on $PRO_ACTIVE and $PRO_STATE1 or does it not matter in this case?