Example Code

Queue Refnum Functional Global Variable (FGV) 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

Download All

Overview

This example shows how to keep queue references in an FGV, which can then be used in a Producer and Consumer design pattern.

 

Description

FGVs make use of uninitialized shift registers to hold data between each call. The FGV is implemented to receive 3 commands, namely initialize, get and release. "Initialize" is used at the start of the program to obtain the desired queue reference, "get" is used to obtain the queue reference at any part of the code after it has been initialized, and "release" is used at the end of the program to release the queue reference.

 

The FGV is also implemented in a Producer and Consumer design pattern to clearly show how this can be utilized.

 

Requirements

  • LabVIEW 2013 (or compatible).

 

Steps to Implement or Execute Code

  1. Run the main vi, and press the "Do something" button.
  2. Note that the "Do something" message is being handled by the consumer loop.
  3. Press the "Stop button" to exit the program.
  4. Open up the "Queue Access FGV.vi" to study how it is implemented and note that there queue references are initialized and extracted from the same FGV.

Additional Information or References 

Main vi block diagram

Capture.JPG

 

Queue Access FGV block diagram

Capture2.JPG

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

 

Ian K.
Software Developer
Data Ahead AG

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

I would recommend adding a Send Message case.  That way those who are sending the commands done have to get the reference and then enqueue the element.  They just call this VI to send the command.


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
Knoxberry
Member
Member
on

Hey crossrulz,

I left the send message case off the FGV in case of a fixed queue size. Because this VI is non-reentrant, if you attempt to enqueue a message to a full queue, you could run into a deadlock if you have a non-zero timeout. If you abstract the send message case one level higher to individual message APIs, you can avoid this issue.

Ian K.
Software Developer
Data Ahead AG
crossrulz
Knight of NI Knight of NI
Knight of NI
on

If you get deadlock, then you have more issues.  Only one place should be reading from the queue.  so what you do is Create the queue and then pass the reference into your reading loop.  That loop then doesn't care about this VI.  Only those sending will need it.  So you shouldn't have any deadlock.

Call the Close case after the reading loop is complete.


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
caplee
Member
Member
on

hello there

i am a new one. i want to ask that: how to creat the queue model.i try million times already! thank you if you can answer~

caplee
Member
Member
on

i mean the queue out model with green color. by the way, i`d like to know how i can improve my skil in labVIEW.

crossrulz
Knight of NI Knight of NI
Knight of NI
on

What do you mean by "queue model"?


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
caplee
Member
Member
on

the green one indicator. data type

crossrulz
Knight of NI Knight of NI
Knight of NI
on

Right-click on the queue output of the Obtain Queue and create an indicator.

There are tutorials availabe online.  I also highly recommend looking into LabVIEW training courses.


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
caplee
Member
Member
on

with the label"queue out"

caplee
Member
Member
on

thank you very much. and i am a graduate, it is really hard for me to learn labVIEW

caplee
Member
Member
on

it did work. but i have to do so everytime when i need this type of indicator?

crossrulz
Knight of NI Knight of NI
Knight of NI
on

The problem is that the queue reference also has to contain the type of data in the queue.  You can copy the queue reference and paste is where ever you need it.


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