LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

multithread

I'm writing a test program. The test program executes an algorithm.
The first function in the program is an event driven from the front panel. I want to have a button in the front panel to enable the user interrupts the algorithm and execute something else,  then the program returns back to finish the algorithm. How can I do that?

Thanks
0 Kudos
Message 1 of 5
(3,750 Views)

You could place your algorithm in a function that you run as a thread. You can suspend and resume threads at any time.

You also work with different thread priorities to have the operating system decide when scheduling CPU time to a thread. I would prefer this way as this approach could finish earlier on computers with multiple CPUs.

Do you have a special scenario in mind that you want your algorithm to suspend (= not continue execution if CPU resources are available) ?

Regards, Guenter

0 Kudos
Message 2 of 5
(3,745 Views)

Hi Mr. Guenter,

my program is reading the position of a positioner over GPIB bus. If the user sees the
positioner in abnormal condition, he suppose to press button to send command to
stop it. The program is first commands the positioner to move in one direction and while
the positioner is moving the data is gathered and when the positioner reaches it target,
the program commands it again to move in the opposite direction. While the program
is running, I want the user to be able to press a button to send command to stop it.
Currently, when the program runs I can't press any button unless the program finishes execution.

0 Kudos
Message 3 of 5
(3,733 Views)

I am assuming you would like to avoid using threads if possible.  I am also assuming that the positioner code is running in some form of loop.  Add ProcessSystemEvents() to the loop and use a flag set by the button callback to enable or disable the positioner.  This is a crude way to handle your problem but in general you do not want a CVI program to spend a long period of time in a callback or function without returning control back to the main program. 

It would probably be better in the long run to redesign your code to run off an event such as a timer control event to handle the positioner movement or to move positioner control into a separate thread.  It will be very easy to use a timer if all you are doing is reading the positioner.  There are some example programs in CVI on how to set up multithreaded programs or on how to update periodically using a timer.  Look for "Find Examples" under the help menu.

Message Edited by mvr on 09-11-2007 03:46 PM

0 Kudos
Message 4 of 5
(3,736 Views)
Thanks, it works for the current active Popup panel.
0 Kudos
Message 5 of 5
(3,684 Views)