I've written a script using Zaber Console to control a Zaber device that executes several steps in a loop. How can I pause it in the middle of the loop and resume it without having to go back to the start?
I've written a script using Zaber Console to control a Zaber device that executes several steps in a loop. How can I pause it in the middle of the loop and resume it without having to go back to the start?
I can think of four options to support this.
Here's an example of using separate scripts to pause and resume your routine. It also describes how to use Joystick buttons.
The Original Routine
To start with, I created this simple routine.
The Pause
Here's the script to pause the routine.
The stop command will cause an error in the main script, but we'll change the main script to catch that error and add the pause/resume logic.
The Resume
Here's the script to resume the routine.
The Routine Plus Pause Logic
The pause and resume scripts are pretty trivial; the real work is in making the main script listen for the error from the stop command and the magic number to resume. Here's the new version of the routine with all that added. Run this script in the main Script Editor window and run the other two from the grid in the Scripts tab of the main window.
The Joystick
If you have a Zaber joystick, it can be more convenient to tap a couple of joystick buttons than it is to run the pause and resume scripts in Zaber Console. The default command for button 1 on a joystick is Stop, so you've already got the pause taken care of. If you program one of the other buttons to send Echo Data 42, that can resume your script. The final script above will run the routine with pause and resume logic whether you use separate scripts to send the pause and resume commands or use joystick buttons to send them.