LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need to stop a Wait(mS) instruction in the middle of execution

I have an application that needs to be able to stop a process in case of emergency. Currently, this is implemented with a Wait(ms) instruction, with a front panel variable wired to it, to give it the number of milliseconds to wait. This time can be up to 600 seconds (60000 milliseconds). I need to be able to stop the Wait(ms) instruction in the middle of execution, then execute a bit of code to shut down the process safely.
0 Kudos
Message 1 of 11
(5,314 Views)
What you should do for this is make your own Wait(ms) timer. Wire the Tick Count (ms) output to a do loop. Inside the do loop, place another instance of the Tick Count (ms) and subtract the value outside the loop from the value inside the loop on each iteration. Compare this to your desired time delay and stop the loop/exit if the delay is reached. You would also place a 1ms delay inside the loop so it only checks once each millisecond. To abort properly, you would need to OR the comparison function for the time passed with the variable telling the loop to stop if you needed to abort early. If you wanted to place this code inside a subvi you would need to pass a reference to the front panel control (and use a property node to read the control's value) or use
a global variable to abort execution of the loop.
Message 2 of 11
(5,314 Views)
Thanks, I have a similar problem, and it seems that this is the way to solve it. (I have a camera taking pictures in an interval varying from 10s to 24h, and the user needs to be able to stop the application at any time to assign the camera to another task)

I am however completly novice in LabView, and don't understand how I can make that do loop. I can make a do loop in a formula node, but then how do I make that Tick Count inside the loop?

Regards, Kristin
0 Kudos
Message 3 of 11
(5,314 Views)
Take a look at the "Wait (ms).vi" in the Time library of the OpenG Toolkit. It has an input called "Abort wait on occurence". By setting the occurence that is wired to this input, you can prematurely abort the wait timer.

Good luck,

-Jim
0 Kudos
Message 4 of 11
(5,314 Views)
Sorry, but I can't work out how to do this. I've tried to put the stop-button in an event-structure with a "generate occurence" wired to the wait(ms).vi, to be executed when the stop-button changes value, but the program still waits until wait(ms) is done.

What is the rigth way to do this?

-Kristin
0 Kudos
Message 5 of 11
(5,314 Views)
You can't use the built in function at all. Download the example that Jim mentions or write your own as described. The one correction I would make to m3nth's posting is that what he calls a do loop is the while loop structure on the Structures palette. I've attached a picture of a VI that you could pass a Boolean value to. Jims's with an occurence or passing a reference is similar.
0 Kudos
Message 6 of 11
(5,314 Views)
> Sorry, but I can't work out how to do this. I've tried to put the
> stop-button in an event-structure with a "generate occurence" wired to
> the wait(ms).vi, to be executed when the stop-button changes value,
> but the program still waits until wait(ms) is done.
>
> What is the rigth way to do this?
>

You cannot abort a waitMS call. You can replace it with something that
is abortable. For instance, the occurrence and notifiers have timeouts
on them. Wire the same delay value to the timeout of one of these and
it acts the same as wait. If you set the notifier or occurrence that
the node is waiting on, it wakes up immediately rather than timing out.

Greg McKaskle
0 Kudos
Message 7 of 11
(5,314 Views)
Use an event structure with the code you want to time in the timeout case. Wire your variable time to the timeout in the top right corner. Add a stop button and an event using that button. The timeout case will execute at the time you specify and the stop button can react immediately.
Message 8 of 11
(5,052 Views)
Kristin, attached is an example that shows how to abort the the OpenG Toolkit "Wait (ms).vi" by setting an abort occurence.

Cheers,

-Jim
0 Kudos
Message 9 of 11
(5,314 Views)
Thanks! I did use the file from sourceforge, I just did not understand how to pass an occurence when the stop button is pressed.

This soulution seems to work well, but I need to correct my error handling before I can tell for certain. (I have some problem with my camera, but it is beeing fixed)
0 Kudos
Message 10 of 11
(5,314 Views)