Example Code

UI Producer Loop with State Machine Consumer Loop Using 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.


  • LabVIEW

Code and Documents



A producer/consumer architecture with a UI producer loop and a state machine consumer loop. Allows the user to queue multiple state sequences.



This VI illustrates an architecture that allows the user to queue multiple processes. Each process contains multiple states, or in this case stages.The queueing of events is handled by the producer UI loop while the consumer loop goes through each process' states. The processes can have functionality different from one another or can have the same functionality. This architecture allows for expansion on the number of processes as well as the number of states for each process by augmenting the states enum and inputting state functionality in the state case. I have changed the consumer loop to have a time of 500 ms in order to make it easier for the user to enqueue elements. The slowed down consumer loops allowed queue processes to build due to the slow progression of the queue. To hasten the program, the user can change the time constant.


This type of architecture can apply to an application containing multiple processes, who each have multiple states. This allows the user to easily queue up processes that will proceed in the order that the user selects. There are also two different stop functionalities in order to ensure that a current process is completed or that the current state is completed before stopping the program. This can easily be scaled by editing the type-def enum and adding states to the state machine.



  • LabVIEW 2012 (or compatible)


Steps to Implement or Execute Code

  1. Run VI.
  2. Press various Process buttons to see the Queue build.
  3. See the Process and Stage in the Cluster of Boolean indicators.
  4. Press Stop during Process to see Stop functionality.
  5. Run VI again after the program has stopped.
  6. Repeat step 2.
  7. Press Emergency Stop button to see Emergency Stop functionality.


Additional Information or References VI Block Diagram

VI Snippet



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



Paolo F.
National Instruments
Applications Engineer

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