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: 

write to file at the end of program

Solved!
Go to solution

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.

 

 

0 Kudos
Message 1 of 11
(3,828 Views)
Solution
Accepted by topic author kumv10

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.


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
0 Kudos
Message 2 of 11
(3,824 Views)

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.

 

 

0 Kudos
Message 3 of 11
(3,821 Views)

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.


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
0 Kudos
Message 4 of 11
(3,815 Views)

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'.

 

 

0 Kudos
Message 5 of 11
(3,809 Views)

Never mind, I figured it out.

 

I also tried the TDMS approach and I got a blank file with no data.

0 Kudos
Message 6 of 11
(3,807 Views)

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?

 

 

0 Kudos
Message 7 of 11
(3,797 Views)

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?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 11
(3,745 Views)
GerdW,

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.

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. Not sure why an image is required. 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.

If the answer was that obvious for a new user, we would all be knights of NI.

Thanks for the input though.
0 Kudos
Message 9 of 11
(3,729 Views)

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?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 11
(3,724 Views)