Example Code

Using Events In LabVIEW To Handle Run-Time Menu Selections

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 piece of example code shows you how to combine the Producer/Consumer (events) design pattern with menu handling so we can keep a responsive user interface while queuing up potentially CPU intensive operations that can be run from the menu bar.

 

 

Description

This VI uses the Menu Selection (User) event exposed by LabVIEW to respond to menu bar selections.

In this VI the Menu Reference is being used to get the selected menu name from the tag on the menu bar. At the same time the VI compares the menu name to the value "Exit". If the user has selected File >> Exit the VI will stop executing.

 

Once the VI has queued up the menu selection in the producer loop the data will be passed to the the consumer loop for processing.

You can use a case structure to determine which menu button was pressed and then run the corresponding code or analysis.

As an example you can refer to the "About" state which is handled in this VI.

 

 

Requirements

LabVIEW 2012 (or compatible)

 

 

Steps to Implement or Execute Code

1. Unzip the attached example and run the Producer Consumer Events Custom Menu.vi

2. Run the VI

3. Click on any item in the Menu bar and notice how it is displayed in the string

4. Stop Execution

 

 

Additional Information or References

For more information on how to create a menu reference you can refer to this link

How Do I Create Custom Run-Time Menus in LabVIEW?

 

Block Diagram

 

BD.PNG

 

Front Panel

 

FP.PNG

 

 

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

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

Comments
WangHao_ChinaCD
Member
Member
on

Thanks!This is very usefull for my project!