LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I stop an opperation?

Hi.

If I start my program it enters into a big loop.
Now I need to implement a mettod to stop the program at one time. I have a button "Cancel" but I can't push it until the program ends.

Thanks.
0 Kudos
Message 1 of 3
(3,121 Views)
To execute some operation in the user interface during a loop you must call ProcessSystemEvents () at regular intervals.

In a case like yours, I would change the button with a toggle button (without callback) and read back its value regularly in the loop: if "1", execute the stopping routine if needed and exit the loop.

In pseudo code:

do {
// Your code
// ...

ProcessSystemEvents ();
GetCtrlVal (yourpanel, yourbutton, &sts);
if (sts) {
// Stopping operations
// ...
break; // Exit from the loop
}
}


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 3
(3,119 Views)
Roberto's suggestion is a good one if your program isn't too complicated.

I find that using multiple threads works better for me because I have a lot going on in my programs. Generally, I run my user interface in the main thread (the one created automatically when CVI starts a program). I then create other threads to handle things like instrument control, data acquisition, computation and data logging.

Is one approach better than the other? Not really, it all depends on how your program is structured and how data is acquired and manipulated. I choose to use the multithreading because I have a need to log large chunks of data while making a lot of measurements. It all comes down to what makes sense for what you are doing.
Martin Fredrickson
Test Engineer

Northrop Grumman
Advanced Systems and Products
San Diego, CA 92128
Message 3 of 3
(3,108 Views)