Example Code

Referencing Queues by Their Unique Names in Multiple VIs

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

Overview

Using queues in a single producer/consumer architecture is easy to implement with lots of example code available off the community. What we will look at here is another way of dequeuing data out of a queue

 

Description

Geneally the queue functions can be referenced to each other by simply connecting the "Queue in" and "Queue out" terminals of the function. This is very straight forward and the fastest way to do it if queues are to be enqueued and dequeued in the same VI. But how do you connect these terminals if you are to dequeue elements from a queue in another VI? Or in multiple VIs?

An amazing feature about queues is that they can be given unique names which can be used as references when obtaining the queue. The following example produces random data in two seperate VIs (Producer1 VI & Producer2 VI), each getting stored in separate queues. These queues have associated names to them and are then called in a third VI to dequeue each of the respective queues.

It is important to note that no Ref Nums have been used to locate the queues. This approach can be used in SubVIs or even different VIs altogether. It does not neccesarily need to be a subVI

 

Requirement

  1. LabVIEW 2014 (or compatible)

 

Steps to Implement or Execute Code

  1. Open & Run Producer VI.vi
  2. Open & Run Producer2 VI.vi
  3. Open & Run Consumer VI.vi
  4. Click on the respective "Get Data" buttons to retreive data from the respective queues.

 

Additional Information or References

Block Diagram

 

consumer.JPG

 

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

Shazil M.
CLAD
Applications Engineer
National Instruments UK & Ireland

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

Comments
crossrulz
Knight of NI Knight of NI
Knight of NI
on

Make sure you are closing those references, otherwise this could turn into a very interesting memory leak.

Personally, I find it best to use an Action Engine to hold your queue references.  The consumer should create the queue and be the only place that dequeues.  Other VIs can just use the Action Engine to enqueue data.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5