Example Code

Variations on the State Machine

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

Download All

Overview
The example VI shows how to add an event structure to the state machine in a way that allows the state machine to do what it needs to do while the user isn't pressing buttons, and handle button presses as they come in.


Description
The attached zip file contains a .lvproj with two 'main' VIs.

Main.vi contains a very basic state machine with an event structure in the same loop as the typical state-machine-case-structure.  This is a fairly common arrangement for a program that contains fairly uncomplicated logic in each state.  If the output of your program will not be damaged by the occasional interruption caused by the 'firing' of an event, this is a sane approach.

Main2.vi contains a very basic state machine with an event structure in a separate while loop.  The instructions from the event structure are transmitted to the state machine by way of a queue.  This setup is often seen where the state machine is in charge of the logic governing the operation of hardware.


Requirements

  1. LabVIEW 2012 (or compatible)


Steps to Implement or Execute Code

  1. Download the zip file and extract its contents.
  2. Run the 'main' VIs. 

 

Additional Information or References
NI Snippet

main.png

 main2.png

 

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

Matthew H.
Applications Engineer
National Instruments

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