CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2010
    Posts
    1

    Console application question, controlling a stepper motor

    I have a console application that controls a stepper motor. Currently, the motor is controlled by issuing a series of signals through the parallel port to move the stepper motor through its steps. Each of these steps requires a 15ms delay between each call, therefore i am utilizing Thread.Sleep to pause the main thread while i issue the commands.

    I would like to give the script an abort feature. Example: "Press any key to abort this action". once the key is pressed, i need to execute a few lines of code to turn off all ports used in the parallel port so i don't burn up the motor.

    Can anyone offer direction on how to implement this type of behavior? can you offer a simple "hello world" example of how to implement this thread? would it require the use of threads?

    I have attempted to place the business logic used in powering the motor in its own thread, but since i have to call Thread.Sleep during it's execution, the thread quits on its own.

    Thanks for any advice.

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Console application question, controlling a stepper motor

    You will need to do the moving in a loop in another thread so that the UI stays 'alive'. Just set a boolean value "_continue" in the button click handler and check it at the top of your motor command loop.

    Code:
    void ContinuousMove
    {    
        while( true )
        {
            if( _continue )
            {
                // run motor
            }
            else
            {
                //disable motor, whatever you need to do
            }
        }
    }
    Last edited by BigEd781; May 11th, 2010 at 01:00 PM.
    If you liked my post go ahead and give me an upvote so that my epee.... ahem, reputation will grow.

    Yes; I have a blog too - http://the-angry-gorilla.com/

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured