LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Events inside Events... how to clear the buffer?

I am using an event structure inside an event structure in an MMI application, and I am having a problem with front panel events being buffered when an embedded loop with event case (which is handling other events) is executing.   If an operator accidentally pushes a button, that event is buffered and is acted upon when the inside loop exits.  Is it possible to clear the events buffer as the embedded event case exits, or should appropriate buttons be disabled/enabled?  The latter is not preferred as there are many cases and many buttons.  This description may not be very clear, so I’ve attached a simple example of the problem.  Thanks for any help.


Brad
0 Kudos
Message 1 of 3
(3,556 Views)

You can't clear the buffer of the event structure. Locking the UI (an option which you have with each event) would not be helpful either, because your entire UI (including the parts you want) will be locked and because the events will still be buffered. Locking the UI as you suggested would work, but as you mentioned, is inconvenient.

There are ways around this.

The basic solution to this is to move your code out of the event structure. Basically, you can use the event to send a message to a message handler which will then decide which action needs to be taken.  If you will select File>>New, you should have some templates for message handlers which will show you a basic approach for this.

Another option is to structure your UI in such a way that only the relevant section is visible each time. This can be done, for instance, by using a tab control or subpanels.

Yet another would be to leave your code inside the event structure loop, but to place all the events in the same structure and to decide what to do in each case by using case structures. You can use a shift register to carry the information through the iterations of the loop.

Eventually, the point is simple - don't put code which takes a long time to execute inside an event structure, especially not an event structure inside another one, because it's a potential for trouble.


___________________
Try to take over the world!
Message 2 of 3
(3,550 Views)
I addition to the tips by tst, you should really study the online help for the event structure, specifically the section labeled:
 
Caveats and Recommendations when Using Events in LabVIEW
 
One of the points explained in detail is: Avoid Placing Two Event Structures in One Loop
 
(Your situation is even more congested, because you have an event structure within  a loop within an event structure within a loop. Seems rather silly ;))
 
The event structure is mainly used to handle events that occur on the user interface by the operator. Since there is only one user interface and operator, one event structure typically ought to be enough. Just add more event cases if more things need to be handled and don't tie it up with events that take forever.
Message 3 of 3
(3,546 Views)