02-05-2013 04:27 AM
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!
02-05-2013 07:13 AM
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.
02-06-2013 11:14 AM
Hi salomiva,
why don't you open the file once, before the loop, and then just append the data using "TDMS Write"?
BR,
02-06-2013 11:20 AM
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.
02-06-2013 11:23 AM
Well, everything depends on the application.
Anyway, opening the file every time anything is written to it is also not an optimal solution.
BR,
02-06-2013 11:44 AM
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.
02-06-2013 12:56 PM - edited 02-06-2013 12:58 PM
Hmm. 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.
02-06-2013 07:43 PM
Can't agree more.
02-21-2013 04:34 AM
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?