May 11th, 2010, 12:06 AM
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.
May 11th, 2010, 01:58 PM
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.
while( true )
if( _continue )
// run motor
//disable motor, whatever you need to do
Last edited by BigEd781; May 11th, 2010 at 02: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
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.