LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Obtain Queue Data Type

Solved!
Go to solution

I am working my way through my first Producer Consumer vi and have two questions. 

 

1. The data I am enqueuing is x,y,z acceleration samples of type Waveform. The snippet shows how I set the data type in Obtain Queue. It's rather ugly and disturbing even though it appears to work.  Is there a more elegant and beautiful way to set the data type?

 

2. The sample rate of the accelerometer is 5120 Hz.  The DAQmx Read buffer is of lenght 1024 samples.  Hence, it takes 200 [ms] to fill the buffer.  I've set the metronome to 100 [ms] to ensure that the Producer doesn't miss any samples.  That means the Producer While Loop will spend a good portion of its time waiting.  Right?  Does having wait cost anything?

 

In LabVIEW's ProducerConsumerExample.vi the sample rate is 10000.  The Read buffer size is 1000.  And the metronome is set to 100 [ms].  The sample rate of the device comes from the hardware device in the cDAQ.  The 100 [ms] interval comes from the PC.  Won't there be a mismatch?  I'd like to understand this before I set my metronome to 200 [ms].

 

ObtainQueueDataType.jpg

0 Kudos
Message 1 of 9
(4,580 Views)

Short answer.

 

You don't need the "metronome".  The DAQmx Read controls the pacing of the loop.

 

(I'm confused as to how your subject line relates to the question.  Your subject is "obtain queue datatype" but the question is about loop timing.)

0 Kudos
Message 2 of 9
(4,578 Views)

2. OK.  Thanks for the answer to the metronome question.  But, if it is unnecessary, why would LabVIEW include one in their example?  Also, what is the While Loop doing while the DAQmx is pacing the loop?  Does it grab one sample and then wait for 1/5120 [sec] for the next?  Wouldn't this keep the While Loop very busy? Or, desirably, does it service the DAQmx Read when DAQmx Read has acquired 1024 samples?  In my first attempt at this I tried to use the N Sample Event to trigger an event when 1024 samples were obtained.  However, I got an error saying that this is not supported on the NI 9234. 

 

1. "The snippet shows how I set the data type in Obtain Queue"  In particular note the Feedback block next to the label AccelFIFO. That's the issue.

0 Kudos
Message 3 of 9
(4,560 Views)

Delete the feedback node. Then right click the wire running between the DAQmx read and the enqueue and select create>>constant. Wire that into the create queue data type.

Now Using LabVIEW 2019SP1 and TestStand 2019
Message 4 of 9
(4,553 Views)

Thank you very much.  That's what I was looking for.  Something I may've seen on YouTube.  I'll do a Kudo++.

 

 

SettingObtainQueueDataType.jpg

0 Kudos
Message 5 of 9
(4,544 Views)

@Arizona_Joe wrote:

2. OK.  Thanks for the answer to the metronome question.  But, if it is unnecessary, why would LabVIEW include one in their example?  Also, what is the While Loop doing while the DAQmx is pacing the loop?  Does it grab one sample and then wait for 1/5120 [sec] for the next?  Wouldn't this keep the While Loop very busy? Or, desirably, does it service the DAQmx Read when DAQmx Read has acquired 1024 samples?  In my first attempt at this I tried to use the N Sample Event to trigger an event when 1024 samples were obtained.  However, I got an error saying that this is not supported on the NI 9234. 

 


You'd have to show me that example.  The one template I see for producer/consumer by way of the New... file menu uses a regular wait (not the wait next ms).  And it doesn't have any DAQmx.  It needed the wait because without it, the producer would run as fast as it could.

 

With DAQmx, the while loop isn't busy.  The loop will wait at the DAQmx read until N samples are available in the buffer.  It will then read them and move on.  (Right now your code doesn't show how many samples are being acquired on each Read.)

 

I don't know why you'd get an error for trying to acquire 1024 samples from an NI-9234.  You'd have to give me more information such as what the error code was.  (Or when you say N sample event, were you trying to set up some sort of special DAQmx event in an event structure?)

0 Kudos
Message 6 of 9
(4,532 Views)

Attached is the example I found.  At this point I don't recall from where it came.

 

So, can you shed some light on the behavior of the While Loop you mentioned that does not have a metronome and is is paced by DAQmx? I would think it would do a lot of spinning. 

0 Kudos
Message 7 of 9
(4,508 Views)
Solution
Accepted by topic author Arizona_Joe

Arizona_Joe wrote:

So, can you shed some light on the behavior of the While Loop you mentioned that does not have a metronome and is is paced by DAQmx? I would think it would do a lot of spinning. 


It isn't spinning because it is waiting inside of the DAQmx Read for N samples to be gathered.  That is not an instant data request.  It takes time to gather those samples.  That length of time is dependant on your sample rate and how many samples you are requesting.  So because it is waiting inside of the DAQmx Read, there is no need to add an additional wait.  Let the DAQmx Read limit the loop rate.

 

It is actually just like the consumer loop for the Producer Consumer.  The reading of the queue will limit the rate at which that loop runs.  Therefore, it needs no wait.


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 8 of 9
(4,499 Views)

OK. Thanks for that explanation.  That is the way I had hoped it works.  My questions were a result of the code I started with written by someone else which, while not a Producer/Consumer pattern, had a wrist watch in the While Loop that was reading from DAQmx Read that was configured to a fixed buffer size.  Since this program will run for hours unattended, I want to make sure it is reliable.  I'll try this tomorrow.  Kudo++.

0 Kudos
Message 9 of 9
(4,485 Views)