LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

A Question About an Event Handler & Events Prior to its Execution

Solved!
Go to solution

This problem came up while maintaining an existing VI. If I was starting from scratch I'd approach the problem diffently. (Something I'll probably end up doing anyway.)

 

I have a "Next"  and a "Cancel" button and I have an event loop with event cases for their value change which terminate the first loop. If the Next button was True, flow proceeds to another, similar event loop with cases for the value change events for those same buttons.

 

So my question is when I hit the Next button while the first event loop was executing and the second one was not, does the second event loop receive the event even though it was not exectuting at the time of that event? When it does start executing does it immediately act on that event that occured before it started executing?

 

While I'm at it, is there some way to "flush" a UI object's event queue prior to an event loop executing? (I don't need detailed instructions, just point me to what I need to look it up.)

 

Thanx and Peace

 

Roger

0 Kudos
Message 1 of 6
(3,300 Views)
Solution
Accepted by topic author phrog

All events queue up events even if dataflow prevents them from reacting to them at the current moment.

 

Never place event structures in code areas where they cannot be reached in a reasonable time. All you probably need is a single loop and a single event structure. Use a state machine to distiguish what current code to run. You should rearchitect your code.

0 Kudos
Message 2 of 6
(3,295 Views)

Thanks for the quick answer. It confirmed what I was observing.

 

Likewise, I assume that if I want to implement a state machine I can't have a case structure for the states and in each state-case I have an event structure. Instead, I must do one event structure and for each event-case I need to place a case structure that defines what action the event executes for each state. Correct? (I'd prefer the former since, IMHO it resembles a state diagram but I'll go with the latter since I hate banging my head into a wall.)

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

Just to be interesting I have found that ( in LV2010 at least)

IF I use an event structure inside a VI and an event fires in that event structure then if the VI closes the event queue does not dispose.

 

WHen reloading the VI for another round  I have observed events firing from the last time the VI was called.

This made some dialogs I developed for myself to act very strangely and I was very confused.

 

 

Thus if your VI is being held in memory but reserved the event queue might not dispose from one call to the next.

(I don't think you can count on it in LV2010)

My only work around was to load the VI dynamically using Call setup : reload for each call.

 

My code must be very badly formed.

I am using one notifier along with the event structure. This to allow an external VI to shut down the dialog VI.

 

I would have assumed the event queue would reset once the VI finished execution but this is not what I observed.

 

0 Kudos
Message 4 of 6
(3,260 Views)

Thanks! I'll be on the look-out for that one.

0 Kudos
Message 5 of 6
(3,257 Views)

@phrog wrote:

Thanks for the quick answer. It confirmed what I was observing.

 

Likewise, I assume that if I want to implement a state machine I can't have a case structure for the states and in each state-case I have an event structure. Instead, I must do one event structure and for each event-case I need to place a case structure that defines what action the event executes for each state. Correct? (I'd prefer the former since, IMHO it resembles a state diagram but I'll go with the latter since I hate banging my head into a wall.)


Yes. Typically you have two parallel loops, one containing an event structure and handling the UI. It can communicate with the code running in other loops e.g. via queues or similar. Look at the design templates that ship with LabVIEW.

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