Example Code

Generating Varying Behavior from the Same Event in an Event Structure

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

Using a blended application architecture, this VI exhibits different behaviors from the same event in an event structure.

 

Description

Real estate on the front panel is a valuable resource.  In many applications, it is not necessary to provide the user separate controls for "initialization" and "process-start", or "open file" and "modify file".  Typical use of event structures would require a separate control for each, even though from the user's standpoint, the operations are synonymous.  From a programming point of view, the operations are certainly different and demand significantly different code.

To maintain the rigors required of well-designed code and maintain an intuitive UI, it is possible to have the code conditionally execute different behaviors from the same Event Case.  The attached example is very simple, but the method demonstrated scales reasonably well to larger tasks and programs.  What is built in this example, is an event structure with a state machine inside one of the event cases.

 

Steps to Implement or Execute Code

  1. Open LabVIEW
  2. Run multipleActions_oneButton_EventStructure.vi

 

Requirements

Software

LabVIEW 2010 or later

 

Additional Images

 

FrontPanel.png

   Front Panel of the VI

 

actionFirst.png

   Behavior elicited on first click of the Go button.

 

actionOther.png

    Behavior elicited on subsequent clicks of the Go button.

 

VI Snippet

blockDiagramSnippet.png

   Block diagram code snippet.

 

An alternate method not demonstrated here registers multiple dynamic events with the Event structure, and then conditionally fires them from elsewhere in the code using the Generate User Event.vi.

 

Note:  The attached code is designed to work in LabVIEW 2010 or later.

Matthew H.
Applications Engineer
National Instruments

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