LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

for loop data acq

Are there any issues of using a for loop instead of a while loop for data acquistion? All the examples and discussions I've seen use a while loop. I'm collecting a finite number of samples inputed by the user. For example 1 sample per second for 10 hours. With the while loop I need to include a wait ms which I don't need in the for loop. Any performance issues I'm missing? Sample program included.
 
Thanks
0 Kudos
Message 1 of 13
(3,542 Views)
Hi Knoebel. It seems to me that you don't understand the concept of the data acquisition. You define the rate of the acquisition and you define the number of samples. Once you start the data acquisition the card starts to acquire the samples into it's buffer. The card uses it's internal accurate clock to obtain the samples with precise timing. In the While/For loop you only read the data from the card buffer - YOU DON'T ACQUIRE THEM AT THAT MOMENT. So it's better to use the While loop, check the amount of available samples and if it reaches some expected amount to read it from the buffer. To use For loop doesn't provide any improvement and it could bring you into some unexpected problems(timeouts, not reading all available samples...). Hope it helped!

Message Edited by ceties on 07-18-2008 03:51 PM
LV 2011, Win7
0 Kudos
Message 2 of 13
(3,527 Views)
I think my problem is that I don't understand how to determine when all the data is collected and the program can move on. Using the for loop I could instruct the program that all the data was read and continue to the next task. I didn't include the next task for simplicity. With the while loop I only know how to include a stop button as you did. This acquisition can run for a few hours or a few days and I don't want it to wait for a user input to tell it when a finite number of samples have been collected (if the user is even aware that all the samples have been collected and read). I just started using property nodes and don't know if there is one to say all samples have been collected and read or does that need to be done by programming as I was trying to do with the foor loop. BTW I didn't know there was a property node to check for a given amount of samples in the buffer, thats pretty cool. ,
0 Kudos
Message 3 of 13
(3,487 Views)

I edited the vi by Ceties to stop the while loop when the task done is true. The problem is I only collect 24 samples instead of 30. There is a property node that keeps track of the number of samples read. I will attempt to use that to determine when the program should continue to the next task. I guess I will be using a state machine, but my original question still seams relevant. I can use a simple for loop or a more complex piece of code. I know Ceties addressed this but the answer didn't seem definitive. Any help or answers would be appreciated.

Eric

0 Kudos
Message 4 of 13
(3,470 Views)
Hi! There are couple ways how to accomplish this since you know the number of samples in advance. The most elegant is outlined in attached VI. The DAQmx Is Task done.vi tells you whether the acquisition task was already completed. See modified example. Cheers
LV 2011, Win7
0 Kudos
Message 5 of 13
(3,468 Views)
Here is vi altered to acquire 24samples. I tried to explain you that using For Loop for acquisition may put you into possible troubles. One example may be if you want to stop the acquisition. If using For Loop you have no way to stop it untill all the iterations are finished (unless you use conditional terminal available for For Loops since LV 8.5). In addition you mentioned that you want to use state machine later. For such an approach it's not wise to put For Loop into one of the states and thus stop the application to run until the state is finished.

Message Edited by ceties on 07-21-2008 12:06 PM
LV 2011, Win7
0 Kudos
Message 6 of 13
(3,461 Views)

Ceties were starting to type faster than the responses.

When I run your vi, sometimes I only get 25 (not 24 my mistake) samples and other times I get 30. I wrote a post a comple months ago about unwanted data rows in my data file and was told it was a timing issue with the wait ms. I've been trying to avoid this. It seems when I use the while loop with finite samples and don't use a stop bottom I'm not sure if I get all the samples as in this case. If I run the vi several times, I will either read or write 25 sample to my data file and other times 30. Hope that clears up what I'm trying to say.

0 Kudos
Message 7 of 13
(3,455 Views)
You are right. I think I understood it. Attached VI solves your issue. You just count the number of samples you acquired so far and you compare it to the expected amount.
LV 2011, Win7
0 Kudos
Message 8 of 13
(3,449 Views)

Ceties,

It seems like quite a lot of work for something that is so basic. "Collect a finite number of samples and move on." Maybe NI should look into making this more streamlined. If we need to double check to see if the proper number of samples were acquired why even create the finite sample vi?

Thanks for all your help.

Eric

0 Kudos
Message 9 of 13
(3,440 Views)
The expected amount is ALWAYS reached! We just didn't read the last sample(s) from the card buffer. The task is done when all samples are in the buffer not when they are read from it - I never used this vi before so I didn't know it. So the last sample(s) was not read because when it step into case where it checks if the task is done(when the buffer is empty) meanwhile the last sample(s) was acquired and thus it announced that the task was done before reading the last sample(s). The attached example may explain it to you. After announcing that all samples were read you will see that there is still one sample in the buffer (AvailSampPerChan). Hope it helped
LV 2011, Win7
0 Kudos
Message 10 of 13
(3,424 Views)