Example Code

Generate Dynamic User Event from another VI

Code and Documents

Attachment

Overview
 This VI is useful for User Interface focused VIs which expect interaction from the Operator on a Front Panel.

 


Description
An Event Structure is useful for User Interface focused VIs which expect interaction from the Operator on a Front Panel. Dynamic User Events, which are covered in the LabVIEW Core 3 course, are able to generate user events programmatically, and are often a good way to get data back into the Event Structure.With this example, which can seen how to generate a Dynamic User Event from any VI on the same PC as the main VI with the Event Structure. This is achieved by Registering and Generating Events from within a Functional Global Variable (FGV) called in all the relevant VIs. Screenshots of the code within the FGV are below:

 


Requirements

  • LabVIEW 2012 (or compatible)


Steps to Implement or Execute Code

  1. Download the attachment to your computer
  2. Open the LabVIEW project file
  3. Open and run the "Main VI.vi" first
  4. Then open and run the "Other VI with event.vi"
  5. Notice that three methods of causing an event of are possible ( via the Main VI, the Dynamic Event in the consumer loop, and the FGV from the Other VI.)

 

Additional Information or References
VI Block Diagram of "Main VI.vi"

 Block Diagram.png

 

 **This document has been updated to meet the current required format for the NI Code Exchange.**

George T.
Senior Applications Engineer
National Instruments UK and Ireland

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
Philibuster
Member
Member
on

Please convert your project to LV 8.6 or LV 2009.

gt3000
NI Employee (retired)
on

Hello Philibuster,

I have performed a 'Save for previous version' in LabVIEW, and saved the code for LabVIEW 2009.  What application are you creating that uses this example?

George T.
Senior Applications Engineer
National Instruments UK and Ireland
Philibuster
Member
Member
on

Hi gt3000,

I have been trying to wrap .NET user controls within XControls and need to process and propagate .NET events. It appears that a LV dynamic user event is required to make this happen. The .NET event handler fires a user event by invoking a ‘Fire Event’ action in a FGV global VI.  In the XControl the FGV’s event ref is wired into the event structure to provide an event bridge.

An outline of what was planned:

XControl:
1. Init.vi – register the user event via the ‘Register Event’ action which uses ‘Create User Event Function’.
2. When the .NET event fires (on the Façade) it will invoke the FGV ‘Fire Event’ action which generates a user event via the ‘Generate User Event Function’.
3. Uninit.vi – un register the event via the FGV’s ‘Unregister Event’ action which used the  ‘Unregister For Events Function’.

At load time when I register the user event in the XControl’s ‘Init.vi’, I request a ‘Register Event’ action and when the Init finishes this registration a ‘Fire Event’ event is unexpectedly generated without being invoked. This is the current problem I’m investigating. I also noticed that .NET generated user events seem to be queued and not processed. I was hoping to see something in your example that would give me a clue as to why this would happen. I also noticed that LV debug breakpoints don’t seem to work.

Note: I replaced the .NET control on the Façade with a simple LV button to simplify things - but with no change in symptoms.

Thanks for your help.

ymadhuri@rediffmail.com
Member
Member
on

I want to run a vi as a response to occurance of event in the consumer loop.How should I do that?

And what is the disabled block function?

gt3000
NI Employee (retired)
on

Hi ymadhuri,

Generally, the main VI shows that the third loop at the bottom of the block diagram is causing a User Event which is dealt with in the Producer loop.  In your case, you can just use similar code in the Consumer Loop, and then place the VI you would like to execute as a response within the Event Structure that matches as a Sub VI.

As for the Disabled Structure, please ignore it.  I had it when I was debugging and then I think I forgot about it after I resized the window.  It is bad programming practice to leave Disabled Structures in a 'finalized' code, so that is just a mistake on my behalf.

George T.
Senior Applications Engineer
National Instruments UK and Ireland