LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

While loop with stop button within event structure locks up front panel.

I am not sure if this is a bug with my program or a bug within LabVIEW.  If you believe that this is a bug with my program then I will post my program to be looked at.

The problem I am having is there is a while loop within an event structure that fires when a particular value changes.  Once the "Activate" button is pressed the while loop within the event structure starts going with a polling frequency of 1hz (1000ms wired to the "wait till next ms multiple" vi).  There is a "Deactivate" button that is wired to the stop control of the while loop and an outter while loop that resets the event structure so that the activate button is being listened to again.

Once inside the while loop, however, none of the button are responsive within the front panel.  The VI continues to run, and only 60% of my CPU is being consumed, but none of the button or scroll bars work.  The only way for me to terminate the program is with the "Abort" button next to the "Run" button.  If I remove the event structure so that the while loop in question runs as soon as the program starts, the front panel remains responsive.  I've inserted probes within the while loop and verified that it is not running prior to the "Activate" button being asserted, and it is running after the assertion of the "Activate" button with the expected polling frequency set by the "wait till next ms multiple" vi.

Can anyone help?  Do I need to post my code?

-Nic
0 Kudos
Message 1 of 5
(4,503 Views)
Nic,

It sounds like you have normal LabVIEW dataflow. The event case does not end until the code inside the case completes. It cannot complete because the default setting for an event case is to "Lock front panel until the case for this event completes." With the panel locked the porgram does not respond to your "Deactivate" button.

Any code which requires more than 10s of milliseconds probably should not be inside the event structure. Put it outside in a parallel loop and send a command to it via a notifier or queue from the event case. The Activate case and the Deactivate case would each send the appropriate command to the other loop.

That loop should also have a slight delay to allow CPU sharing bewteen loops.

Lynn
0 Kudos
Message 2 of 5
(4,496 Views)
It would help if you can post your code or a screenshot, but I suspect the problem is that you when you set up the event structure you did not uncheck the box that says "Lock front panel until the event case for this event completes."  You can find this at the bottom of the window that appears when you choose "Edit Events Handled by This Case...".  Since the front panel is locked waiting for your while loop to stop, you're unable to stop the while loop by clicking on the button.

In general it's a bad idea to put logic that will take a long time to complete inside of an event structure, because you cannot respond to other events at the same time.  Consider moving your while loop outside your event structure, and use a notifier to start and stop the while loop when the activate and deactivate buttons are pressed.
Message 3 of 5
(4,495 Views)
It is typically not a good idea to stall an event structure by placing loops inside event cases. What good is an event structure if it is not free to repond to events? 😉
 
Have a look at some alternative solutions, such as in the following link:
 
0 Kudos
Message 4 of 5
(4,488 Views)
I am not sure what is meant by a notifier...

My thought is to have the event structure before the loop I want to start and then have data that is wired from my event structure to the loop so that the event has to happen before the loop structure begins execution.  Then, when the loop is stopped via the "Deactivate" button the outter loop will reset the event structure.

The event structure only has 2 events within it: "Activate value change" and "Stop value change."  The "Stop" is the global stop for the program.
0 Kudos
Message 5 of 5
(4,476 Views)