Example Code

Producer/Constumer (Events) With No Data Loss in 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.

    Software

  • LabVIEW

Code and Documents

Attachment

1. Overview:
This VI implements producer/consumer design patter. Instead of destroying the queue as soon as the VI is stopped, this VI retrieves all the data in the queue before exiting.

 
2. Description:

The design template Producer/Consumer (Events) is a great parallel loop architecture for situations where the processing of data can take longer than the time it takes to acquire thedata, and it is necessary to process all data that is acquired by the producer loop.  However, with the default design template the queue is destroyed as soon as the user clicks on the stop button, erasing any elements that remained in the queue to be processed by the consumer loop.

 

The attached VI eliminates this behavior, by utilizing the Get Queue Status.vi function to see if any elements remain in the queue, and does not stop until all elements in the queue have been processed by the consumer loop.

 
3. Requirements

  • LabVIEW 2012 (or compatible)

 

4. Steps to Implement or Execute Code

  1. Set the parameters as described in the Front Panel
  2. Execute the code
  3. Modify the value of Wait and see how the producer loop behaves
  4. Stop the code to see how the remaining data in the queue is dequeued after stopping the VI

 

5. Additional Information or References 

 VI Block Diagram

Block Diagram.JPG


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

Chris_G
Sr Test Engineer
Medtronic, Inc.

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