LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I handle two UI generated events?

Hello:

I'm working with LabWindows-CVI 5.0 and 5.5 on Windows 2000. I want to do something "simple".

I want to create a panel with two controls.
The first is a pushbutton that will call a function to indefinitely increment an integer variable. And the second is a toggle switch that will immediately reset the value of this same integer variable to zero each time the toggle switch is made to change state by the operator.

In other words, I want the panel to be capable of initiating the execution of a time-consuming routine (incrementing the integer variable) while at the same time remaining responsive to operator input from a 2nd panel control (the toggle switch).

Is it possible to do this? If so, what is the simplest sol
ution? What is the most elegant solution?

Thank you for your time and attention.
Frank Kohtz
0 Kudos
Message 1 of 2
(3,170 Views)
The simplest way is to update the variable in a loop inside the push button callback and put inside the loop a ProcessSystemEvents () function to let the program execute toggle button callback.
A second, more elegant way in my opinion, is to use a timer set to the desired rate and put the algorithm to increment the variable inside the timer callback: the push button callback sets the ATTR_ENABLED attribute of the timer to 1, thus starting the 'ramp'; while the timer is not executing there is time for the program to proceed other tasks such as toggle button callback to stop the ramp or other control's callback.
A problem common to both the solutions is that if other tasks are time consuming, you cannot guarantee the regular rate of increment of the variable
; if this is a seriuos problem for you, you must go to other scenarios such as multithreading or multimedia timers.
Roberto


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?
0 Kudos
Message 2 of 2
(3,170 Views)