09-03-2019 12:28 PM
Hi everyone, I'm new to LabVIEW. I'm trying to read data using DAQmx and then calculate the center of gravity of each series of data. I read 20 number each time and then do the calculation work. Now I want to output the result to an array to check the stability, but I get into trouble in how to output the results in the while loop.
Any feedback would be helpful. Thanks.
Solved! Go to Solution.
09-03-2019 01:41 PM
1. No need for a Timed While Loop. Just change it to a regular While loop and the acquisition will set your loop rate.
2. No need to wire up the N terminal on the FOR loop. The Autoindexing tunnel will tell the FOR loop how many times to iterate.
3. Your first value in the read array is multiplied with 0, so it is not actually being counted in your calculation. Is that desired?
4. Since you are using Continuous Sampling, do NOT wire up the Samples Per Channel on the DAQmx Timing VI. You are just limiting your buffer and increasing the chance of getting an overflow error by wiring it up.
5. There are a few options for building up an array. Do you want to compare everything while the acquisition is still happening? Post process? Do you want to compare every loop iteration's data? Or just the last X iterations?
09-03-2019 01:47 PM
Thanks for your advice.
Reply to Q3: Yes it is desired.
Reply to Q5: I want to compare every loop iteration's data. I'm sorry for my poor English. To be specific, I can get 20 numbers of data each time and then calculate the center of gravity. I want to save these results into an array and then output it using the DAQmx write.
09-03-2019 02:28 PM
@chen3477 wrote:To be specific, I can get 20 numbers of data each time and then calculate the center of gravity. I want to save these results into an array and then output it using the DAQmx write.
Why not just write the data as you get it? Then you wouldn't need the array.
09-03-2019 03:13 PM
Thank you! I'll try it!
09-03-2019 03:46 PM
I added the DAQmx write to the loop but it turned out that it could only output the first data. I need to output the data in each iteration.
09-03-2019 03:50 PM
You need to initialize and start the AO before the loop. Be sure to clear it after the loop.
09-03-2019 03:54 PM
I tried to make it correct but I failed...
Attached is my code. Could you help debug it?
Thanks!
09-03-2019 04:03 PM
@chen3477 wrote:
I tried to make it correct but I failed...
Attached is my code. Could you help debug it?
Thanks!
Reread Crossrulz' message:
"You need to initialize and start the AO before the loop. Be sure to clear it after the loop."
09-03-2019 04:06 PM
I did move it out of the while loop but it didn't work...