Example Programs

cancel
Showing results for 
Search instead for 
Did you mean: 

Queues vs Local Variables in LabVIEW

1. Overview:

This VI shows the different behavior of using local variables and queues in a producer/consumer design pattern with different loop rates


2. Description: 

This vi is based on the producer consumer design pattern where the producer loop generates one point of a sine signal every 50ms. This data is stored in a local variable and in a queue that are read from different loops which rate is configurable. With this architecture it can be easily seen which is the effect of reading data from a variable and from a queue at rates that differ from the rates of the producer loop.

In the local variable consumer loop, the number of samples that are duplicated (in case the loop rate is faster than the producer loop rate) and the number of samples that are missed (in case the loop rate is slower than the producer loop rate) are calculated.

In the queue consumer loop, the number of samples in the queue when the loop rate is slower than the producer loop rate are calculated.

When the applications stops, all the data in the queue is retrieved.

   

3. Requirements

  • LabVIEW 2012 (or compatible)

4. Steps to Implement or Execute Code

  1. Extract the files from "Queues vs Local Variables LabVIEW 2012 NI Verified.zip"
  2. Run "Queues vs Local Variables LabVIEW 2012 NI Verified.vi"
  3.  Change the value of Local Variable Loop Speed. If the speed is higher than producer loop, missing samples increment. If the speed is lower, duplicated samples will increase
  4.  Change the value of Queue Loop Speed. If the speed is higher, there won't be samples in the queue. If the speed is lower, samples in the queue will increase.

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.**

Justin Parker
National Instruments
Product Support Engineer