I was wondering what the best practice is for halting a script from continuing to execute until a condition is met.
Essentially, I have a timer script that is running and I don’t want the timer script to run another instance of the script until a condition is met. What’s the best way to do this?
My first thought is that the very first thing the script does is to inspect the condition, and if it is not met, then exit from the script. This does mean that the timer event and the script are still consuming resources while the condition is not met.
Hi Peter, I already have that implemented. But if I have a trigger as the condition to execute that script, I want to wait for the trigger to go low before exiting the script.
I’m obviously missing something. Is your script actually doing anything while the trigger is true? Or are simply you wanting to burn resources until the trigger becomes false again?
And why is the script being started by a timer and not the trigger?
Yes I have a block of code that is executing when the trigger is high. After the execution of the script, a handshake is sent to the PLC indicating the completion of this script. However, I don’t want the script to run again until the PLC sees the handshake and drops the trigger low. If not, the script will execute again on the same high trigger… before the PLC can actively put the trigger low. And the script is being started by a timer and not the trigger because the tag change gateway script doesn’t have the functionality to run only off of a rising edge. Therefore, the script will run on the trigger going low, which I don’t want.
Just use the tag change event and check that the new value is true before running your logic. Consider not using boolean handshaking. A small integer that changes to signal an event is far more efficient (and non-racy).