LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Queues via Multiple VIs

Good day everyone,

Simple Question:
How can I have two different VIs, running concurrently and independently, pass data to each other using a queue?

Situation:
I have an instrument VI acquiring data from a DAQ board which will be inserting elements into a named queue. I have another VI which will remove the elements from the same named queue and write them into a file.

I have encountered problems with this method. If the queue that inserts the elements is not created within the same VI that removes the elements, the queue is empty when I try to read it.

I am already loading the VIs dynamically using the VI reference functions. I could use the Set Control Value method to pass the queue refnums but I'm assuming the queues should be easier to
use than this. There is an input to 'Use Existing' however when I set this input to true, I start receiving errors.

Environment:
LabVIEW 6i (updated to 6.0.2 via the patch)

Any help on this would be greatly appreciated.

Thank you!
Mark Roberto
MD Robotics
0 Kudos
Message 1 of 5
(3,703 Views)
Mark,

The simple answer is to create your own queue. I did this by simply putting an array in a shift register, and when updating or adding to it, I simply build the add to the array. When taking data out, I simply delete from the array. This is very simple for inserting and removing single data points, but becomes only slightly more complex when working with multiple points. Just remember two things: don't initialize the shift register; and make sure that the VI is NOT reentrant.

For the more complicated answer, I am not sure what you are trying to do with queues. I haven't worked with them very much. Looking at them I see that they rely on queues. I have to assume then that using queues is similar to using a mutex in C (not that I even know what that is
.) As far as I can tell, you have to obtain a key to the queue in order to pass the data. They seem to be independent, so I would have to assume that in order to implement them that a VI has to create one, and then other VIs can use that queue, such as VIs called dynamically by the main VI.

Depending on your application, I would avoid using queues. They seem to be more complex than you need. The first thing to remember about programming, and usually the first thing to be forgotten, is the KISS principle: Keep it Simple Stupid.

Give that a shot. Let us know what you come up with.

Good luck
0 Kudos
Message 2 of 5
(3,703 Views)
Hi Mark,

If this is all that you are doing, then is sounds like you are making task
this unnessarily complicated.

I have attached an example that uses a sound card instead of a daq card
but the processes are the same.

It has two process loops.
-The first is a subvi that is opened directly after creating a queue and
starts acquiring data and putting it into the queue.
-The second is a top level while loop that has subvi's that remove data
from the queue which processes the data and outputs results which then are
passed to the top level displays.

This type of system should fulfil your requirements without dynamically
loading vi's etc.

For all of the other readers, this is a simple but accurate stand alone
sound card SINAD meter that was developed
before the SINAD measurement
function was added in LV6. I personally prefer this version because of its
simplicity and speed and accuracy.

Tim

Mark Roberto wrote:

> Good day everyone,
>
> Simple Question:
> How can I have two different VIs, running concurrently and
> independently, pass data to each other using a queue?
>
> Situation:
> I have an instrument VI acquiring data from a DAQ board which will be
> inserting elements into a named queue. I have another VI which will
> remove the elements from the same named queue and write them into a
> file.
>
> I have encountered problems with this method. If the queue that
> inserts the elements is not created within the same VI that removes
> the elements, the queue is empty when I try to read it.
>
> I am already loading the VIs dynamically using the VI reference
> functions. I could use the Set Control Value method to pass the queue
> refnums but I'm assuming the queues should be easier to use than this.
> There is an input to 'Use Exi
sting' however when I set this input to
> true, I start receiving errors.
>
> Environment:
> LabVIEW 6i (updated to 6.0.2 via the patch)
>
> Any help on this would be greatly appreciated.
>
> Thank you!
> Mark Roberto
> MD Robotics
0 Kudos
Message 3 of 5
(3,703 Views)
....
> I am already loading the VIs dynamically using the VI reference
> functions. I could use the Set Control Value method to pass the queue
> refnums but I'm assuming the queues should be easier to use than this.
> There is an input to 'Use Existing' however when I set this input to
> true, I start receiving errors.
>

It is the combination of the queue and the dynamic loading that can
cause problems. When a top-level VI goes idle, it releases its
resources. That means that files that it opened are closed, and
queues that it created are destroyed including any data they
contain.

So, I hope that explains why. The way to fix it using dynamic VIs
is to make sure that the queue is created and kept alive until all
of the users are through with it. Another way of
doing this is to
not use dynamic VIs if they aren't really needed. This will be less
to deal with, and the queues will be very easy to use if the subVIs
are normal subVI calls.

The other suggestion of making your own queue is fine, and not that
difficult either. Make a simple LV2 style global VI that has an
append, a fetch, a clear, and whatever else you decide is needed.
This may in fact work better if you are storing lots of data inside
the queue as the built-in queues only deal with strings.

Greg McKaskle
0 Kudos
Message 4 of 5
(3,703 Views)
Greg McKaskle writes:

> It is the combination of the queue and the dynamic loading that can
> cause problems. When a top-level VI goes idle, it releases its
> resources. That means that files that it opened are closed, and
> queues that it created are destroyed including any data they
> contain.

That's why my dynamically loaded VI's create the queues. As I have a
consistant naming scheme it's easy to use "create queue" to look up
the refnums in another VI. And trying to create the same named queue
twice returns the refnum of the existing queue.

Johannes Niess
0 Kudos
Message 5 of 5
(3,703 Views)