Example Program Drafts

Showing results for 
Search instead for 
Did you mean: 

Generate Dynamic User Event from another VI

by Active Participant gt3000 ‎02-24-2012 06:51 AM - edited ‎01-30-2017 10:21 AM

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, we can see 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:

Register Event.png

Fire Event.png

Attached is a ZIP file which contains the FGV as a Sub VI, as well as a complete Example Project with two VIs.  To operate the example:

  1. Unzip the files to a preferred location.
  2. Open the LabVIEW project file.
  3. Open and run the 'Main VI' first.
  4. Then open and run the 'Other 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.
Member Philibuster

Please convert your project to LV 8.6 or LV 2009.

Active Participant gt3000
Active Participant

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?

Member Philibuster

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:

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.

Member ymadhuri@rediffmail.com

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?

Active Participant gt3000
Active Participant

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.