Example Code

Fire An Event Automatically When Another Event Is Triggered in LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Description

Overview

This VI allows you to trigger an event after another event has finished executing, using dynamic events. Specifically, the VI is designed to trigger 'Event 2' after 'Event 1' is triggered, while it is also possible to trigger 'Event 2' separately.

 

Description

This example utilizes the event structure and its dynamic event registration terminals as well as a user event, to demonstrate a specific situation. Suppose you have a number of events that are handled by an event structure. When you produce a specific event, the appropriate event sub-diagram is run. Suppose that one of your events should always be run after another event. This example gives you a way to automatically fire one event after a different event finishes executing. It also has the advantage of allowing you to still trigger the event by itself as well.

 

First we register for events, which allows us to add the dynamic event registration terminals to the case structure.When the Event 1 button is pressed, this generates a user event with Generate User Event. After this event has finished operation, this new User Event is triggered and is handled in the same way as 'Event 2 value change' in the case structure.

 

A single event case handles both the User Event and Event 2 Value Change. Thus the event sub-diagram can be fired by either a value change on Event 2, or a user event created in Event 1.

You can use the user event to pass specific information between the two events: that feature is not included in this example.

 

Requirements

LabVIEW 2012 (or compatible)

 

Steps to Implement or Execute Code

1. Run this VI.
2. Click the 'Event 1' button and observe that Event 1 and 2 indicators light up.
3. Click the 'Event 2' button and observe that it is still possible to fire Event 2 on its own.
4. Click 'Event 1' followed by 'Event 2' and observe what happens.

 

 

Additional Information or References

 

Front Panel of the VI

Event Fired From Other Event 2012 NIVerified Front Panel.PNG

 

Block Diagram of the VI

Event Fired From Other Event 2012 NIVerified Block Diagram.png

 

The LabVIEW 8.6 version requires the Professional Development System as event structures were not originally included in LabVIEW Base.

 

Dynamically Registering for Events - LabVIEW Help
Event Driven Programming in LabVIEW

 

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

Asa Kirby
CompactRIO Product Marketing Manager
________________
Sail Fast!

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

Comments
randy1815
Member
Member
on

Took a minute to figure out how it works but does exactly what I needed.