LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Event handler in later sequence frame is handling my event

Consider a case where you have a sequence with two frames.  Each frame has an event handler.  If you are in frame 0 processing events, do you think that the event handler in frame 1 should have any relevance?  The attached vi demonstrates that it does.  This seems like a bug to me or at least something to watch out for.  I spent a half-day trying to figure this one out.
0 Kudos
Message 1 of 21
(3,232 Views)
Using two different event structures in separate frames is bad design. Each event handler is always capturing events. This is described in the on-line help for event structures. Open the help and click the 'caveats and recomendations' link.
 
p.s. Using a sequence structure in itself is often a sign of bad design. Better to use a state machine or use dataflow with error in/out clusters.
Message 2 of 21
(3,231 Views)
Dennis--



@Dennis wrote:
Using two different event structures in separate frames is bad design. Each event handler is always capturing events. This is described in the on-line help for event structures. Open the help and click the 'caveats and recomendations' link.



I read the caveats and recommendations several times.  I recognize that my example vi shows two event structures in one loop but, in my application , this is not the case.  I don't see any clear instruction on that help page that would indicate that I have broken some rule of event structure use.



@Dennis wrote:
Using a sequence structure in itself is often a sign of bad design. Better to use a state machine or use dataflow with error in/out clusters.


That's bothersome.  I use sequences all the time and nobody has ever commented that my code is badly designed.  I wonder why NI provides that function if it promotes poor code design.  You did say "often" and not "always" so I have an out. :^)
 



0 Kudos
Message 3 of 21
(3,201 Views)
People recommend against sequence structures for reasons like this.  Your assumption that an event structure won't handle events until its sequence is reached would be valid for many other items, but an event structure will queue up the events it is assigned to handle, and then handle them in order when its frame is reached.
 
Also, when you use a sequence frame, you are seriously hamstringing the compiler's parallelism.  Things that could be performed in parallel are now forced to execute serially, which can increase your execution time by orders of magnitude.
Message 4 of 21
(3,193 Views)


kc64 wrote:
 
I read the caveats and recommendations several times.  I recognize that my example vi shows two event structures in one loop but, in my application , this is not the case.  I don't see any clear instruction on that help page that would indicate that I have broken some rule of event structure use.
That's bothersome.  I use sequences all the time and nobody has ever commented that my code is badly designed.  I wonder why NI provides that function if it promotes poor code design.  You did say "often" and not "always" so I have an out. :^)
 

Well, maybe they missed something in the caveats 😉  But using more than one Event Structure is not a good idea.
I just posted something to that effect this morning: http://forums.ni.com/ni/board/message?board.id=170&thread.id=337440
 
As for using a sequence structure (especially Stacked Sequences), I totally agree with Denis that it is poor design.  Unfortunatley, NI cannot remove them from the palette due to compatibility with older versions.  I would vote that they be removed ASAP.
 
However, it is your choice to follow other people's advice or not to follow it.   
 

Message 5 of 21
(3,191 Views)
I understand that sequences prevent parallel execution but that is often required.  Of course, using a sequence on code that could be parallel would be undesirable.

Can any of you guys help me understand with an example that shows how to execute three steps in order using the without-sequence method (and I don't mean showing dataflow on error clusters).
0 Kudos
Message 6 of 21
(3,184 Views)


I read the caveats and recommendations several times.  I recognize that my example vi shows two event structures in one loop but, in my application , this is not the case.  I don't see any clear instruction on that help page that would indicate that I have broken some rule of event structure use.

I don't understand. You first say that your example does have two event structures in a single loop and the then you say it's not the case. If you have two events structures in a sequence structure, they are in the same while loop.
 
There is a discussion of the sequence structure in the style guide. This is in the help file. There are some cases when you can't avoid using one but in many cases, it's just a text based programmer trying to apply those rules to LabVIEW. LabVIEW is a DATAFLOW programming language. Data determines the order of execution. The flat sequence structure is better than the stacked sequence structure but as I said, something like a state machine works better. A state machine can be easily modified to change the order of things to be done, including stopping at any point. A sequence structure always runs every frame and that is something that you might not want to do.
Message 7 of 21
(3,182 Views)
Dennis--

Sorry for the confusion.  This example vi is not my application.  I simply made a vi to demonstrate my point of concern.  In my real application, the event structures are not in the same loop but are in the same sequence (different frames).

kc64
0 Kudos
Message 8 of 21
(3,176 Views)

You can't have separate frames of the same sequence structure in different loops. It's impossible.



Message Edited by Dennis Knutson on 07-03-2008 07:59 AM
Message 9 of 21
(3,171 Views)

Denis, you physically can, but the program won't work 😉

R

Message 10 of 21
(3,156 Views)