LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Producer/Consumer loop data display problem

Solved!
Go to solution

I am having trouble with displaying data from my consumer loop. I am using a producer loop to acquire and save data. The consumer loop is only to display data for the user with indicators and graphs. The indicators appear to flash as the data is displayed too quickly. I have tried slowing the loop, switching to notifications instead of queues and other tips from the forums and examples but nothing seems to work. Does anyone have a suggestion?

 

My vi is attached. I am using labview 2015 sp1.

 

Thank you,

 

Chris

0 Kudos
Message 1 of 9
(3,353 Views)

Remove all timers (including, and especially, the Elapsed Time Express VI) from the Consumer Loop.  The "clock" for the Consumer Loop is the Queue -- the Consumer Loop will run at the same speed (or slower) than the speed at which the Producer puts elements on the Queue.  Suppose an element goes on once a second -- the Consumer will take off an Element, "do its thing" with the data (for LabVIEW's sake, get rid of that Sequence Frame -- Data Flow handles all the sequencing you need), and will loop, "stalling" (and thus not updating any of the displays) until the next data point comes in a second later.  If the Producer is faster, the Consumer will "try to keep up" and become faster.

 

Bob Schor

0 Kudos
Message 2 of 9
(3,338 Views)
Solution
Accepted by topic author ChrisH76

1. Your DAQmx tasks should be combined into 1 task.  This will make things a lot simpler for you.

EDIT: I just noticed I missed the task wire from the second Create Virtual Channel and the DAQmx Timing.  Too lazy to fix it right now.

2. Tell the DAQmx Read how many samples to read.  Since your sample rate is 100Hz I would just use 10, giving your producer a loop rate of 100ms.

3. You really should move your logging to the consumer loop.  Alternatively, just use the DAQmx Configure Logging and then DAQmx will handle all of the logging for you.  This would be a lot more efficient than even a Producer/Consumer for logging.

4. You do not want a wait in your consumer loop.  If we slow down the producer loop like I told you in 2, then your consumer loop will not be able to go faster (unless it get really slow for a few seconds, but that would be a different issue).

5. You can expand the Index Array to get all of your elements without even using an index constant (first defaults to index 0 and increments from there).


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
Message 3 of 9
(3,333 Views)

@Bob_Schor wrote:

Remove all timers (including, and especially, the Elapsed Time Express VI) from the Consumer Loop.  The "clock" for the Consumer Loop is the Queue -- the Consumer Loop will run at the same speed (or slower) than the speed at which the Producer puts elements on the Queue.  Suppose an element goes on once a second -- the Consumer will take off an Element, "do its thing" with the data (for LabVIEW's sake, get rid of that Sequence Frame -- Data Flow handles all the sequencing you need), and will loop, "stalling" (and thus not updating any of the displays) until the next data point comes in a second later.  If the Producer is faster, the Consumer will "try to keep up" and become faster.

 

Bob Schor


I read the requirement a bit differently.  I read it as "take a snapshot every x seconds and display it to the user".  In this case, I feel an Elapsed Time Express VI is still appropriate, but used in a different way.  Let the consumer do its thing the way you described above, but only display what's in the queue if the elapsed time has expired.  So if the Elapsed Time Express VI is set to 5 seconds, the consumer keeps dequeueing as fast as the data is coming in, but only when the elapsed time has expired do you actually display it.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 9
(3,331 Views)

Croosrulz,

 

Thank you for the suggestions. I did what you suggested and the vi works much better. I didn't know the index array could be expanded. It is much easier and neater to work with it like that. Combining the DAQmx tasks into one task made the vi work much faster.  I will move the data write to the consumer loop. I have seen this approach in other examples. I left it in the producer loop only because the code was working.

 

Thank you,

 

Chris

 

0 Kudos
Message 5 of 9
(3,303 Views)

Bob,

 

Thank you for the explanation on timing between the loops. I figured since they were different loops one can be run slower than the other. I understand it is better to let the producer control the speed and have the consumer loop follow.

 

I would like a timer on the front panel for the user to see how long the process is running. I can put this in a separate loop.

 

Thank you,

 

Chris

0 Kudos
Message 6 of 9
(3,301 Views)

Bill,

 

I like this concept and was tried this approach earlier with no luck. If I add a timer with a case or event structure in the consumer loop to only display the data every x seconds would it also impact the dequeuer?

 

Thank you,

 

Chris

0 Kudos
Message 7 of 9
(3,299 Views)

ChrisH76 wrote:

If I add a timer with a case or event structure in the consumer loop to only display the data every x seconds would it also impact the dequeuer?


Not with the Elapsed Time.  It has no waits in it: just checks the time and sets a Boolean output if X seconds have passed.  Just wire this output to the case structure.


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
0 Kudos
Message 8 of 9
(3,295 Views)

You can absolutely put an Elapsed Timer in a separate loop (be sure to build in a mechanism to stop the loop when the program ends).  The simplest Elapsed Time loop is a While Loop surrounding a Delay (ms) with 1000 wired to the input (a 1 second counter).  Take the Loop Index, run it through an Integer Divide by 60, call the Quotient "Minutes", the Remainder "Seconds".  Note that you can do another "Divide by 60" on the previous Quotient to get Hours and Minutes (or Days, Hours, Minutes, Seconds as needed).

 

Bob Schor

0 Kudos
Message 9 of 9
(3,266 Views)