LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Event structure or case structure

I have some case structures wired to buttons.  When each button is true, code inside the corresponding case structure executes.  `What are the advantages/disadvantages of using an event structure instead of a case structure?
Ron Deavers, CLD
0 Kudos
Message 1 of 6
(3,526 Views)
Well it is all up to how the code is intended to run. If it is to run all of the time while the button is true then use the case structure if is to run once and stop then use an event structure. I will probably be criticised for saying this but this is how I think of it. You also could use a combination of both with the producer/consumer aspect style of programming.
 
 



Joe.
"NOTHING IS EVER EASY"
0 Kudos
Message 2 of 6
(3,520 Views)
Place an indicator for the iteration terminal of the main loop to see an obvious difference 😉
 
Your case structures must be in a loop that constanty runs. If you don't put a delay in the loop, it consumes all CPU, but if your delay is too long, it takes a moment to react to the button changes. The loop spins all the time, no matter if you press buttons or not.
 
Your event structure also sits in a loop, but nothing happens until you press a button. Now the event structure triggers IMMEDIATELY, executes the event case, and then waits for the next event. The loop does not spin unless needed.
You can even mix the functions by using a timeout event. Code in the timeout event occurs at regular intervals, but at any time, any of the other events can take over.
 
Message 3 of 6
(3,518 Views)
I understand that a case structure has to be in a loop to keep running.  Are you saying that an event structure does not have to be in a loop? 
Ron Deavers, CLD
0 Kudos
Message 4 of 6
(3,505 Views)
0 Kudos
Message 5 of 6
(3,497 Views)

 


@altenbach wrote:
... Your event structure also sits in a loop, but nothing happens until you press a button.

@programmindragon wrote:
I understand that a case structure has to be in a loop to keep running.  Are you saying that an event structure does not have to be in a loop? 


Hhhmmmmm! 😮


 

0 Kudos
Message 6 of 6
(3,485 Views)