09-11-2008 12:08 PM
Hi, I have been trying to teach myself LabVIEW for a few months now.
I have learned a lot, most of which I learn as I need it.
I have seen a lot of people mention "events", so I have been trying to learn about those.
It appears to me that events are chunks of code that run when a user does something (ie clicks a mouse or presses the keyboard).
What I don't understand is, why is this different than wiring a button on the front panel to control some loop (while loop, for loop, etc)?
When would you use one instead of the other?
09-11-2008 12:40 PM
When you use a while loop and read the status of a front panel Boolean, you are using what is called polling. So, depending on what kind of wait you have in the loop, the loop is spinning constantly. When you use the event structure, the loop does not spin. It just waits for an event to fire. It's much more efficient in terms of cpu usage. It makes for a 'neater' diagram since you don't have to create separate case statements for each Boolean. If you wanted to monitor a numeric control for a change, without the event structure you would need a shift register to keep the old value and then do a comparison to the current value - more polling and additional wiring.
There are other reasons. I think the event structure is one of the greatest additions to LabVIEW. It made the creation of user interfaces so much simpler.
09-11-2008 12:42 PM
In this nugget I describe the differences between the two modes
09-11-2008 12:46 PM
Ahhhh, that makes a lot of sense.
OK, well then I have another question
It is easier if I give you an example:
Say I have an event that runs some code when i press "k".
Will the code only run the first time i press "k"? or will it run everytime I press "k"?
Also, when you were talking about "polling" does a case structure do that too? or just a while loop?
09-11-2008 12:48 PM
In general a loop (while or for) without an event structure are polling loops, they are controlled by timing or CPU power. (for every rule there are exceptions but we ignore them).
In your case you will need an event structure inside a while loop. This way the while loop only spins if the event is triggered.
Ton