LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Fire event from within another event ?

It seems that an event fired from within another event does not
actually execute its code until the firing event completes. The fired
event's Time value in its Event Data Node indicates the time that it
was told to execute, but using GetTickCount calls shows that its code
does not execute until the firing event is finished. This happens
whether Value Signaling is used to generate a Value Change event or if
CreateUserEvent and GenerateUserEvent is used. Is this because events
are placed in a queue ? This behavior is different from Delphi for
example where the fired event executes right away when called from the
firing event (before the firing event completes).

I have an event that executes upon a button value change. I would

like that same event's code to execute when another button is pressed,
but also have other code in the second button's event execute after
that first button's event's code completes. Is there another way to
accomplish this ?

Steve
0 Kudos
Message 1 of 3
(2,825 Views)
Are these events all handled in the same structure? You can't execute something in that node for a second event until it completes the first.
0 Kudos
Message 2 of 3
(2,825 Views)
> It seems that an event fired from within another event does not
> actually execute its code until the firing event completes. The fired
> event's Time value in its Event Data Node indicates the time that it
> was told to execute, but using GetTickCount calls shows that its code
> does not execute until the firing event is finished. This happens
> whether Value Signaling is used to generate a Value Change event or if
> CreateUserEvent and GenerateUserEvent is used. Is this because events
> are placed in a queue ? This behavior is different from Delphi for
> example where the fired event executes right away when called from the
> firing event (before the firing event completes).

I'm not that familiar with Delphi, but LV events are asynchronous.
Window
s OS has two ways of firing events, Send and Post. The LV events
are always posted. The primary reason is that the LV events are handled
by a node, not by a callback. The node you are calling is in the middle
of a diagram, and reentering it not valid.

> I have an event that executes upon a button value change. I would
> like that same event's code to execute when another button is pressed,
> but also have other code in the second button's event execute after
> that first button's event's code completes. Is there another way to
> accomplish this ?

The best way to reuse code is to use subVIs. Firing events, or rather
sending events is pretty close in other events to making a function call
dispatched to anyone interested in the event. The event just hides who
you are calling and makes you put your parameters in a funny format
stuffed inside the event. IMO it also makes the code very hard to read
since you don't know what calls what.

Instead, just put the code into a sub
VI and call it whenever you need
to, from the event structure in one or more locations, and from other
loops and diagrams.

Greg McKaskle
Message 3 of 3
(2,825 Views)