LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Run Event Structure Only When Button Is Pressed, NOT Released

Hello,

 

I am developing a simple state machine. I have a 'wait for event' state, where it waits until I press a boolean button before it goes to the next state. The button is "switch when pressed." When it is pressed, it remains pressed down until it is released. While it is down, the state machine does to the 'reading' state and collects two arrays of data. Once the button is released, the state machine goes to the 'calculation' state, and arrays of data are displayed on two graphs and calculations are made. Immediately after, the state machine goes back to 'wait for event.' The problem is that since the event structure executes based on the button's 'value change,' when I release the button the event structure executes again, and all my data indicators and graphs are reset to default. I need them to all reset, but only when the button is pressed down, not when it is released. Does anyone know how to fix this?

 

Thanks, Kadin

0 Kudos
Message 1 of 2
(472 Views)

You have several serious architectural problems. First of all, the event locks the panel until the event completes, but since the code is in the inner while loop elsewhere at that time, it cannot react to the user and the loop can never complete. Catch 22!

 

You need to rearchitect in a more reasonable way. Think State Machine!

 

Maybe get rid of the inner loop and use the outer while loop (and timeout event to do the looping). Maybe place the event structure in a parallel loop to do the UI.

 

Maybe all you need is get rid of the useless event structure and use a case structure and a reasonable polling wait. (The FALSE case has the inputs wired through)

 

altenbach_0-1680297173310.png

 

Note that is is typically a bad idea to autoindex on a while loop output tunnels, because if it runs forever, you'll eventually run out of memory. Not bulletproof!

 

 

0 Kudos
Message 2 of 2
(460 Views)