Example Code

Communicating Events Between a Sub VI and Main VI

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

Overview

This example uses Dynamic Event Registration to facilitate communication between a top-level VI and its subVIs.

 

Description

This example shows how to not only pass UI messages down to a subVI, but also pass them back to the main application. By using the Event Dynamic Registration terminal I can register user events.  Inside the subVI, I have another event structure that generates another user event that is processed by the main application.

 

Requirements

  • LabVIEW 2012 (or compatible)

 

Steps to Implement or Execute Code

The subVI is set to open when called, and set to close after 20 iterations.  Any button pressed while the subVI is running will be captured and be processed once the current action is complete.  For instance, run the main application and press the Queue Event switch, this will launch the subVI.  Now pull the Queue Event Switch while the subVI is running.  Once the first 20 iterations are complete, then the subVI will launch again and run for another 20 iterations.

 

Additional Information or References

 

Block Diagram of Main.vi

 

1.PNG 

Block Diagram of Sub.vi

 

2.PNG

 

Note by contributor: This is a useful example, but the supplied code is poorly documented.  Attached is my shot at a well-documented (LabVIEW 2009) version of the same example.

 

 

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

A_Ryan
AES
National Instruments

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

Comments
Todd S.
NI Employee (retired)
on

Great code, very usful tutorial!

Todd S.
LabVIEW Community Manager
National Instruments
yulin0629
Member
Member
on

Good, It's easy to understand.