06-27-2016 08:27 PM - edited 06-27-2016 08:29 PM
I am trying to acquire resistance data on a DAQmx channel. The data is being acquired in a while loop.
I need the program to keep storing the data into an array that expands according to the incoming data and then writes all the data to a file when the program is terminated.
I currently have an index array with the iteration counter of the while loop wired to its index terminal and a 'write to measurement file' vi placed outside the while loop. However, when I terminate the program, there is no output file.
What's the best way to do this in Labview 2011? If auto-expansion of the array is not possible, I can pre-allocate a large size and then have it store the data but I will still need it to output all the data only once at the end of the program.
Solved! Go to Solution.
06-27-2016 08:45 PM
Instead of building up a huge array, use a Producer/Consumer setup. The idea is to use a second loop that logs your data as you acquire it. This way, you can open the file before the loop, format and write the data to the file inside of the loop, and then close the file at the end. To send the data to the logging loop, use a Queue.
Alternatively, you could use the DAQmx Configure Streaming VI to tell DAQmx to log your data as it is read straight to a TDMS file. Much more efficient than anything you will come up with.
06-27-2016 08:59 PM
Thanks.
I just built the producer/consumer loop by looking at the link you provided.
When I wired the 'element' terminal from the 'Dequeue Element' block to the 'Write to measurement file' vi, I got an error that said 'type of source is variant, type of sink is dynamic data'. All the other terminals look fine.
06-27-2016 09:05 PM
Sounds like you did not supply the type at the Obtain Queue. And I would recommend using the waveform (or array of waveforms) instead of the Dynamic Data Type.
06-27-2016 09:29 PM
When I right-click on the element data type terminal and pick 'control', it gives me a window the front panel where I cannot enter anything. Alternatively, if I pick 'constant' , I get a blank box and I cannot type into that either. How do you set element type for 'obtain queue'.
06-27-2016 09:34 PM
Never mind, I figured it out.
I also tried the TDMS approach and I got a blank file with no data.
06-27-2016 10:00 PM
The producer/consumer loop writes at a good rate but it starts to log as soon as the VI is started and ignores the 'Enable' control that I have on the 'write to measurement' VI. Is this supposed to happen?
06-28-2016 01:40 AM
Hi kumv,
usually a program does exactly what the programmer told it to do!
So when your program starts to log right from the start you surely have it programmed this way!
Let's try some pseudocode:
IF enable THEN Write data to log ENDIF
Doesn't look that complicated. In LabVIEW I would use a case structure…
Don't you think it would be a good idea to attach your VI when you want us to help on specific problems WITHIN your VI?
06-28-2016 03:24 AM
06-28-2016 03:44 AM - edited 06-28-2016 03:46 AM
Hi kumv,
Crossrulz seemed to be following the discussion and my comment was directed to him since he was replying within a few mintues of my posts.
This is a public forum and anybody can answer here!
If you don't like this you should use PNs instead - but I guess Crossrulz wouldn't like to communicate using PNs…
Most of us here are volunteers. We have a live of our own, we have to work for our money, we cannot always answer questions.
But as we are living all over the world there will almost always someone available to continue the discussion…
A daqmx vi acquiring data in the producer loop and writing in the consumer loop is ignoring the enable control that I have on the file and starts writing as soon as I run the vi. Seems straight forward.
Yes, sure.
It's a producer-consumer-scheme…
What's your problem to read the data in the consumer loop and to decide in the consumer loop about saving to file or to discard the data?
What's the problem to embed the pseudocode I wrote above?
Not sure why an image is required.
Because LabVIEW beginners tend to do funny things in their VIs.
It is built exactly as in the producer/consumer link provided above but with the daqmx in the producer loop and write express vi in the consumer loop.
How can we know without a VI?