LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to avoid opening file for writing each time?

Hi!

 

I have real time data acquisition from a digitizer (NI PXI 5124, but it is not important for my question). Using several NI SCOPE examples I wrote a simple labview program that does the following things in a while loop: configures the digitizer, fetches data and display it in a waveform graph, calculates FFT and display it in a waveform graph, and while the “Save To TDMS File” button is pressed it writes data to a TDMS file. And it works almost fine and “almost” is because from time to time some data are not written to the file. I suppose that the reason is that I open and close the file each time. How can I open the file only once when the button “Save To TDMS File” becomes active and close it at the end, when the button “Save To TDMS File” becomes inactive? I had some ideas using local or global variables but I didn't’t manage to make them work.

 

Additionally, how can I make “File Path” control inactive while the “Save To TDMS File” is active?

 

Thanks!

0 Kudos
Message 1 of 9
(3,550 Views)

You could save the button's value in a shift register.  Then you can see if the value changed.  If the value changed to TRUE, open the file and use a property node (Enabled) for the path control to disable it.  If the value changed to FALSE, close the file and re-enable the path control.  You will need to save the file reference in a shift register as well.


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 2 of 9
(3,527 Views)

Hi salomiva,

why don't you open the file once, before the loop, and then just append the data using "TDMS Write"?

 

 

BR,

0 Kudos
Message 3 of 9
(3,478 Views)

I wish to point out that leaving files open for long periods of time while testing can cause catastrophic problems should power glitch during test. It will hit the hardrive and ruin the data file and possibly the hardrive. This is a very poor data management strategy. You should be minimizing the time any files are left open. Just saying. This has hit me enough to learn my lesson. I NEVER leave files open, just for the sake of leaving them open for convenience.

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

Well, everything depends on the application.

Anyway, opening the file every time anything is written to it is also not an optimal solution.

 

BR,

0 Kudos
Message 5 of 9
(3,472 Views)

Then the better solution for that case would be to save the data until done and then write to minimize write access time and the risk. 

Mateusz your advice is wrong, it is not dependant on the application. It is more dependant on how valuable your data is and how much you choose to risk it with poor programming practices that risk that data. This is a well known risk for data that beginner programmer usually learn a lesson on. You can ignore the advice and risk loosing data at some time, or use good programming practices that protect your data. This is an issue that will hit you eventually, in other words not an "if", but a "when" it will occur. Take it from 30 years test programming experience.

0 Kudos
Message 6 of 9
(3,459 Views)

Hmm.  Smiley Indifferent  I've streamed huge amounts of data to TDMS over the years without ever once considering closing the references until I was done and I've never lost a "BIT" of data, much less a hard drive.  TDMS is a Streaming format that allows multiple references to be open to a particular file all at once.  You can even write to the same file you are reading concurrently if you need to.  Everything is handled under the hood for you.  I'm all for keeping a watch on open references (of all types) and closing them when appropriate but the OP is better off just taking the advice of Mateusz in his first post.  Dump the open/close (Express VI?) stuff and let TDMS do what it's designed to do. 

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019
Message 7 of 9
(3,445 Views)

Can't agree more.

0 Kudos
Message 8 of 9
(3,423 Views)

Dear all,

 

I would like to thank you a lot for your valuable answers. I was away for a while, but finally I made a vi that I am posting. Namely, using a very simple algorithm I made 4 combinations of the Save the button's current and previous values, depending on which I open, close or write to file or do nothing.

 

Any comments?

0 Kudos
Message 9 of 9
(3,374 Views)