This VI shows the different behavior of using local variables and queues in a producer/consumer design pattern with different loop rates
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.
LabVIEW 2012 (or compatible)
4. Steps to Implement or Execute Code
Extract the files from "Queues vs Local Variables LabVIEW 2012 NI Verified.zip"
Run "Queues vs Local Variables LabVIEW 2012 NI Verified.vi"
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
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
**This document has been updated to meet the current required format for the NI Code Exchange.**
Justin Parker National Instruments Product Support Engineer