Example Code

Sharing a Queue between Two VIs in the Same LabVIEW Project

Code and Documents

Attachment

Download All

Overview

This example demonstrates how a queue can be shared by multiple VIs in the same LabVIEW Project. 

Description

The first VI, Enqueue.vi, obtains a queue called myQueue and enqueues integers 0 to 1 in a for loop. The second VI, Dequeue.vi, dequeues each element from myQueue and displays the result in an Array. The purpose of this is to demonstrate how, in a LabVIEW project, you can share a queue across VIs by writing the same queue name in the Obtain Queue function.

Steps to Implement or Execute Code

  1. In order to run this example, save the Zip File attached
  2. Open the project Queue.lvproj
  3. Open both the Enqueue and Dequeue VIs
  4. Run Dequeue.vi and Enqueue.vi
  5. Notice how the Array Indicator in Dequeue.vi is populated with the values which were enqueued in Enqueue.vi

Requirements

Software

LabVIEW 2011 or later

Block Diagram

EnqueueSnippet.png

Dequeue Snippet.png

Julia P.

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

Comments
Larry.C
Active Participant
Active Participant
on

Hi,

It is generally good practise to release the queue reference in both VIs. The reason you have a "force destroy" terminal is that releasing the queue does not destroy it if another queue reference is still live.

By doing this you avoid memory leaks if this method is used in your application in various places being ran sporadically.

Another nice way of doing this is sharing a queue reference wire using an FGV. This allows you to make descrete wrappers for your messagin system (much less spaghetti).


Larry Colvin
Associate Principal Engineer
Dyson Technology Ltd.

crossrulz
Knight of NI Knight of NI
Knight of NI
on

Here's a link to an example of using the Action Engine to hold the queue reference and then you just have to call the Action Engine to send your information.  I do this for almost every system I make.

https://decibel.ni.com/content/docs/DOC-37042


GCentral
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
Contributors