Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8421997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:18:39+00:00 2026-06-10T03:18:39+00:00

I’ve written a script using Zaber Console to control a Zaber device that executes

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T03:18:41+00:00Added an answer on June 10, 2026 at 3:18 am

    I can think of four options to support this.

    1. Make your script somehow detect the current state when it starts and figure out what part of the routine it should start with. Depending on your routine, you might be able to read the current position to tell what step you are at. If not, you could also use user memory or write the current state to a text file. One of the example scripts shows how to write to a text file.
    2. In addition to your main script, write a pause script and a resume script. The main script notices the responses from the other two scripts. I’ll include an example below.
    3. Instead of separate scripts to pause and resume, use a Zaber Joystick and program the buttons to send the pause and resume commands. The example below will cover that as well.
    4. Convert your script to a plug in that runs the main routine in a BackgroundWorker. Then you can hold the state in the control class, and add a Pause/Resume button.

    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.

    /* C# example of how to pause and resume a Zaber Console script.
     * This script is the original routine without the pause and resume logic.
     * It moves to position zero, then makes four moves of 10000 microsteps each 
     * and goes back to zero. This loops forever.
     */
    #template(simple)
    
    while (true)
    {
        for (var i = 0; i < 5; i++)
        {
            var position = i*10000;
            Output.WriteLine("moving to {0}", position);
            Conversation.Request(Command.MoveAbsolute, position);
        }
    }
    

    The Pause

    Here’s the script to pause the routine.

    /* C# example of how to pause and resume a Zaber Console script.
     * This script pauses the main routine by sending a Stop command. Running this 
     * script twice will stop the routine.
     */
    #template(simple)
    
    Conversation.Request(Command.Stop);
    

    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.

    /* C# example of how to pause and resume a Zaber Console script.
     * This script resumes the main routine by sending an EchoData command with a
     * magic number.
     */
    #template(simple)
    
    const int RESUME_NUMBER = 42;// Matches the main routine.
    Conversation.Request(Command.EchoData, RESUME_NUMBER);
    

    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.

    /* C# example of how to pause and resume a Zaber Console script.
     * This script is the main routine that moves to position zero, then makes four
     * moves of 10000 microsteps each and goes back to zero. This loops forever.
     * To pause the routine, run the Pause.cs script. To resume the routine, run
     * the Resume.cs script. Running the pause script twice will stop the routine.
     */
    #template(methods)
    
    /* We switched to the methods template so we can put the move with pause and
     * resume into a helper method.
     */
    public override void Run()
    {
        while ( ! IsCanceled)
        {
            for (var i = 0; i < 5 && ! IsCanceled; i++)
            {
                var position = i*10000;
                MoveTo(position);
            }
        }
    }
    
    /* This wraps the pause and resume logic around a simple MoveAbsolute command.
     * If your resume logic is more complicated, you can put more commands inside 
     * the try/catch block, or use the return value of this function to tell the
     * main routine what to do next.
     * When this method returns, either the move has successfully completed, or
     * IsCanceled is true.
     */
    private void MoveTo(int position)
    {
        bool isComplete = false;
        while ( ! isComplete && ! IsCanceled)
        {
            try
            {
                Output.WriteLine("moving to {0}", position);
                Conversation.Request(Command.MoveAbsolute, position);
                isComplete = true;
            }
            catch (RequestReplacedException ex)
            {
                Pause();
            }
            catch (RequestCollectionException ex)
            {
                /* If you are running against device number zero
                 * or some other alias, you get a slightly
                 * different exception.
                 */
                Pause();
            }
        }
    }
    
    /* Just wait for responses from your device. If a response is an EchoData 
     * command with the magic number, then this method will return. If the response
     * is a Stop command, then IsCanceled is set to true and this method will 
     * return. All other responses are ignored.
     */
    private void Pause()
    {
        Output.WriteLine("paused");
    
        /* Let the device finish processing the current stop command before
         * you start listening, otherwise you sometimes see the stop command
             * again.
             */
        Sleep(100); 
    
        const int RESUME_NUMBER = 42;// Matches the resume script.
        var listener = new DeviceListener(Conversation.Device);
        bool isPaused = ! IsCanceled;// Don't pause if already canceled.
        while (isPaused)
        {
            var response = listener.NextResponse();// wait
            if (response.Command == Command.EchoData && 
                response.Data == RESUME_NUMBER)
            {
                isPaused = false;
                Output.WriteLine("resumed");
            }
            else if (response.Command == Command.Stop)
            {
                isPaused = false;
                IsCanceled = true;
                Output.WriteLine("stopped");
            }
        }
    }
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.