LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Question on how Queues work

I'm trying to understand how LV queues work. Code I'm writing for data acquisition in our lab for a Force Gage works except for the queue. Can anyone tell me what I'm doing wrong?

 

Thank you.

0 Kudos
Message 1 of 8
(3,290 Views)

You'll have to tell us what it is doing wrong now.

 

When I open your VI, I get a broken run arrow because of several broken wires.  Those wires are broken because you are trying to make a 1-D array out of dynamic data, then feeding it into a function that cannot handle and array of dynamic data.

0 Kudos
Message 2 of 8
(3,270 Views)

I see a few things.

 

Right now your producer loop currently does all the producing and consuming. A queue sends data from the producer loop to the consumer loop. The consumer loop will wait for incoming data and will execute once when some data arrives. The way you have it set up, the raw signal from the DAQ is sent to the consumer, where it does nothing, and then the signal is processed in the consumer loop.

 

 

Are you trying to make it output all the data you have gathered as an array? Having a build array function wired to the wall of a loop will only output the last piece of data as an array when the loop ends. It won't remember the previous data.

20539i73C71725EDA0CF5C

 

Instead, wire the data directly to the edge of the loop and enable indexing. Now when the loop ends, every data set will be in an array.

20543i1592F6C04A03BEEA

 

 

Also, I think you're supposed to use a shift register with a producer/consumer queue. I think if you don't use a shift register and your producer creates data faster than your consumer loop can process it, it will be lost. Use a shift register to allow it to remember the queue. I'm not 100% sure about this one, but the Producer/Consumer template in LabVIEW uses a shift register so I just always do too.

20545i64CBABEB865C7157

 

 

Are you trying to make it write to the excel file every loop? The code to write to the excel file is sitting outside the loop, so it will only execute once. But there's nothing stopping the first few blocks from starting. If you wire the 'error in' terminal of the New Report VI to the output of one of the loops it will prevent it from running until the DAQ has finished. Or you could put it in the consumer loop so it writes the data gathered to the excel file as it runs.

 

Basically, a producer/consumer loop works by separating the data acquisition from the data analysis. The producer loop should pretty much only read some data and load it into the queue, it produces data. The consumer loop is the loop that does all the work. It takes the data from the queue, runs functions on it, graphs it, writes it, etc. It consumes data.

 

You should at least move everything except the DAQ from the producer loop to the consumer loop. You want the producer loop to do as little as possible. You could then make a third loop that writes everything to an excel file once it's been processed, or have the writing occur after the data-acquisition by putting wiring the error input to the New Report VI to one of the loops.

 

Also check out;

http://zone.ni.com/devzone/cda/tut/p/id/3023

http://zone.ni.com/devzone/cda/tut/p/id/7605

http://decibel.ni.com/content/docs/DOC-2431

0 Kudos
Message 3 of 8
(3,262 Views)

This is the same vi as posted here.  The vi name there is "Test after talking to Chuck".  I assume that you are Chuck.  In that thread I said to eliminate the Build Array function on the Dynamic Data wire.  Evidently you haven't done so.  You need to do this or your vi will continue to be broken.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 4 of 8
(3,248 Views)

@NickQ wrote:

 

  

Also, I think you're supposed to use a shift register with a producer/consumer queue. I think if you don't use a shift register and your producer creates data faster than your consumer loop can process it, it will be lost. Use a shift register to allow it to remember the queue. I'm not 100% sure about this one, but the Producer/Consumer template in LabVIEW uses a shift register so I just always do too.

 

 


No, not at all.  The queue won't lose any elements (unless you create a lossy queue) no matter how fast the producer or consumer runs.  It is not necessary to use a shift register in the loop.

0 Kudos
Message 5 of 8
(3,229 Views)

Ooh ok, thanks RavensFan. Learn something new every day 🙂

0 Kudos
Message 6 of 8
(3,198 Views)

@Ravens Fan wrote:

@NickQ wrote:

 

  

Also, I think you're supposed to use a shift register with a producer/consumer queue. I think if you don't use a shift register and your producer creates data faster than your consumer loop can process it, it will be lost. Use a shift register to allow it to remember the queue. I'm not 100% sure about this one, but the Producer/Consumer template in LabVIEW uses a shift register so I just always do too.

 

 


No, not at all.  The queue won't lose any elements (unless you create a lossy queue) no matter how fast the producer or consumer runs.  It is not necessary to use a shift register in the loop.


Where it is important to use those shift registers though, is an auto indexing for loop. Let's say you queue up multiple strings by using an array auto indexed with the enqueue function inside that for loop. Now let's say there is a button click which you want nothing to be added to the queue so you wire up and empty array. Well, because you are using auto indexing, the for loop wont execute and you will lose your reference to the queue. In this situation you need to use shift registers.

 

 

Message 7 of 8
(3,183 Views)


Oh oh, for(imstuck), you forgot to put the shift register on the error wires on the inner For Loop.  You could lose errors. Smiley Wink

 

I put shift registers on error wires and reference wires on For and While Loops always.  Although it isn't necessary on reference wires in While Loops, it helps to form a habit.  A NI instructor told me that once.  I've been doing it ever since.

- tbob

Inventor of the WORM Global
Message 8 of 8
(3,157 Views)