LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

event triggeed front panel controls best practices

Highlighted

I have a general question about best practices in regards to front panel controls and event structures.... I've read that it's not good to poll your controls on your front panel, and that it's better to have them as events and just let them trigger an event whenever they have a change in value... is this true?  I'm pretty new to labview and I'm just trying to not fall into any bad habits.... I've never done it this way, does this mean that if I have say ten different controls on my front panel that I will go and make an event case for each one?  Does it matter how many event cases I make? cause I could see this growing into a bunch of cases real quick if I make one for every control on my front panel....

 

Thank you

0 Kudos
Message 1 of 3
(746 Views)

There is nothing wrong with polling if it is done at reasonable intervals and not millions of times per second. Long ago, we did not even have the event structure. 😄

Still events are better. 😉


Fibo wrote:

 I've never done it this way, does this mean that if I have say ten different controls on my front panel that I will go and make an event case for each one?  Does it matter how many event cases I make? cause I could see this growing into a bunch of cases real quick if I make one for every control on my front panel....


You can assign the same event case to multiple events. For example if you have controls A and B and output C (e.g. for A+B=C), you would create a single event case for A(value changed), B(Value changed) and inside the event case you would place the A and B terminal, the math, and the C terminal. It will recalculate if A or A changes.

Message Edited by altenbach on 03-30-2009 07:41 AM

LabVIEW Champion. It all comes together in GCentral GCentral
0 Kudos
Message 2 of 3
(738 Views)

In general you have the right idea.  The event structure does not use any CPU resources until one of the events for which it has a case occurs.

 

You may not need a case for every control.  For example suppose you want to display a line calculated from a slope and intercept.  You could use a Value Changed event for each the slope and intercept controls.  Or you could put both of them in the same case, since the result (calculate and display a line) is the same in both cases.  Or you could add a button, Calculate Now, and have an event for that button and not for the slope and intercept controls at all.  This latter case would keep the line from being recalculated every time the user pushed the increment or decrement buttons on the slope or intercept controls.

 

I like to make a list of all the controls and in a second column put the action required when the control changes.  This documents the event cases needed.

 

Also note that you do not want to put any code inside an event structure which might take a significant amount of time to execute because that would keep the structure from responding to another event.  Read the advice in the detailed help for the event structure before you write much code.

 

Lynn 

0 Kudos
Message 3 of 3
(735 Views)