Quickstart Guide
Introduction RIO Academic RIO Application examples Your first RT app Your first FPGA app
Basic procedures System admin File system I/O monitor System controller architecture Timed loops Inter-process communication RT/Host communication RT/FPGA communication FPGA personalities Interrupts Datalogger (file I/O)
Design flow Simulation Inter-process communication RT/host communication Derived clock domain IP blocks FPGA personality
Get connected Email Web services UDP TCP IP addresses
Site Map
Guides Code examples Procedures Tags LabVIEW block diagram elements Targets Communications All pages
Glossary How to use About
RIO Developer Essentials Guide for Academia
PC code example

Event-driven producer-consumer state machine

Create a responsive user interface based on two loops operating in parallel: the "producer" loop event structure responds immediately to user interactions such as button clicks and mouse movements that send commands through a queue to the "consumer" loop which performs the required tasks. Separating the state machine into two loops allows the user interface to remain responsive should a consumer task require an unusual amount of time or must wait for a shared resource to become available.

LabVIEW PC block diagram: producer-loop contains event structure and guard clause; consumer-loop contains guard clause and case structure; both loops share the same queue reference

Use cases


NOTE: This controller has specific behavior for the “Home Security System”, but the overall structure itself is a standard and well-accepted architecture that can be easily modified for your own controllers.

See the complete Home Security System project to get an idea of how this producer-consumer state machine interacts with the RT system.

Keep in mind

LabVIEW block diagram elements

Locate these elements with "Quick Drop" (press Ctrl+Space and start typing the name); click on an icon to see more sample code that uses that element:

Event Structure
Obtain Queue
Release Queue
Enqueue Element
Enqueue Element at Opposite End
Dequeue Element
Invoke Node
Property Node
Format Into String
Create Network Stream Writer Endpoint
Write Single Element to Stream
Flush Stream
Destroy Stream Endpoint
Error Ring

Example code

Expected results

https://youtu.be/i8B3l4Gpo5c (1:41)

Developer walk-through

https://youtu.be/B-EmDOQCcIc (11:03)


For more information

  1. Effective LabVIEW Programming (http://www.ntspress.com/publications/effective-labview-programming/)
    An excellent textbook by Dr. Thomas J. Bress covering all aspects of system design; Chapter 27 describes the "Event-driven Producer-Consumer State Machine" in detail. Download all of the code examples from this textbook: follow the link above, select "User Resources", and then "All VIs".
  2. The LabVIEW Style Book (https://www.pearson.com/us/higher-education/program/Blume-Lab-VIEW-Style-Book-The/PGM219404.html)
    This comprehensive textbook by Peter A. Blume lays out everything you need to know about best practices for LabVIEW system design.