From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx Producer/Consumer help

I have a very simple program to read data from a DAQmx, and put that data in a queue in the producer portion of my program. In the consumer portion, I take that data and write it to a spreadsheet file. It kind of works, but I have a few questions:

  • As it stands right now, the consumer portion just grabs the elements from the queue as soon as it is placed there by the producer portion. How can I make it so the consumer dequeues and writes all of the elements in the queue say every 15 or 30 seconds?
  • I have one stop button wired to both of the stop conditionals on each loop. When pressed, the button does nothing and I am forced to use the abort button on the toolbar. What am I doing wrong here?
  • I need to perform operations on the individual array elements before writing them to the spreadsheet. What is the best way to do this?

Please forgive my newbishness, as I am still very much learning LabVIEW. Thanks in advance for your help. 

 

producer_consumer.PNG

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

1.  Why do you want to do that.  You could put a wait statement in there to make the loop run slower.  But that just makes the individual dequeues that much more infrequent. So what you could do is put the dequeues in a loop, read them and concatenate them together into a larger array.  Then every 15-30 seconds, write out the larger array.

 

2.  Dataflow.  The Stop button is only read one time at the beginning of the program before the loops begin, and is never read again.  Put the stop button in one of the loops.  Put a local variable of it in the other loop.  You will need to change the mechanical action to switch.  Which means you will have to add code at the end of your program to switch it back to false so that it sort of acts like a pop up latch when released mechanical action.

 

3.  Do it in the consumer loop.  Without more detail as to what you want to do, there is no further explanation that I can give.

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

Thanks for your reply!

 

The reason I want to only write every 15-30 seconds is because as it stands now, it opens the file, writes the 8 data points, and closes it every second. It just seemed a little wasteful of system resources to me.

 

I took your advice and put the stop button inside one of the loops and created a local variable for the other loop. It does seem to stop acquiring data and writing it to the file, but it doesn't actually stop the vi. I still have to press the abort button to get the 'grid' back on the front panel. Perhaps because there is still an element in the queue? I don't know. Also, where and how do I add code to make it 'pop' back out when the program ends?

 

As far as the operations on the elements in the array: I am acquiring voltages from the DAQmx, and I need to do operations on the elements to transform the voltages to temperature/pressure/etc. What is the best way to accomplish this?

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

You won't need to worry about opening and closing files every iteration if you just do it once.

The locals are what Raven'sFan was talking about.  You can also monitor the Queue and end while loops by wiring the error to the stop terminal in the other loop.  You won't need to change mechanical action or use locals if you use the Queue method.

untitled.PNG

 

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019 - Unfortunately now moving back to C#, .NET, Python due to forced change to subscription model by NI. 8^{
0 Kudos
Message 4 of 8
(3,222 Views)

Previous post was a bit terse so in case I confused you...

untitled2.PNG

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019 - Unfortunately now moving back to C#, .NET, Python due to forced change to subscription model by NI. 8^{
Message 5 of 8
(3,220 Views)

Thanks, very helpful!

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

hi bgallasp,

simply go to vi from template and select standard producer consumer loop (data) .

Message 7 of 8
(3,197 Views)

Thanks, alok123. That is awesome, I didn't even think about templates!

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