LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Flush data TDMS, programmatically saving data and retrieval

Solved!
Go to solution

Hi all,

 

The purpose of this LabView is to simulate a DAQ&writting-to-file scenario. The first loop creates the data, within this loop, if the user pushed the write to file toggle switch, the data will be queued and then sent to a TDMS file writing loop (second loop). Finally the last loop retrieves the saved data and displays it in the scroll bar Waveform graph.

 

If TDMS-OPEN VI option operation option is "open or create"; at first the program seems to work fine but if I want to run the program again, new values will be appended to the ‘first run’ values. The correct operation would be to rewrite or replace the old file and save it with new values (keep same file name). The most logical thing to do is to change the option of the TDMS OPEN to “create or replace” but this doesn’t work and the data or file is not even created.  I do not understand why this is happening.

 

Thanks in advance for your help

 

호아킨

 

 

Block Diagram snippet.png

 

 

 

 

 

 

0 Kudos
Message 1 of 10
(4,650 Views)
Solution
Accepted by topic author jquinno

Hi,

 

From your problem description, I think if your purpose is to append new values to end of old values in file, then your current VI diagram is fine and the appending work should be done correctly.

 

But if you want to create a brand new file every time you run this VI, then you've changed the open option to "create or replace", I assume you were change this open option for the writing while loop(second loop), that's correct but still not enough, you should branch an error out wire from the "create or replace" Open(second loop) to the error in of "open or create" Open(third loop), this can avoid errors which you haven't noticed and the file/data will be created correctly.

 

Then you can try if the VI works as your expectation.

Message 2 of 10
(4,624 Views)

Worked perfectly. 

 

Thank you!

0 Kudos
Message 3 of 10
(4,619 Views)

I wanto further improve this VI.

 

As you can the the while loop that generates the data contain the Write to File boolean control. Would it be possible create the TDMS file ONLY when the user presses this buttom. 

 

Any suggestions on how to get started?

0 Kudos
Message 4 of 10
(4,576 Views)

The below diagram should work for your needs. Put your second and third loop in the case structure, and use a "local variable" of "Write To File" control for this case structure input in the below while loop. Then the VI can generate the file only when "Write To File" is clicked, not at the beginning time you run this VI.

 

P.S.: To create the local variable, right-click on "Write To File" >> Create >> Local Variable.

 

Waveform with optional file writting.pngcase structure

0 Kudos
Message 5 of 10
(4,567 Views)

Thank you so much!!

 

I did what you told me but I'm having trouble generating the Local variable which you told me to generate by right cliking in the Boolean icon. If I do this I get another kind of variable which does not work with the case structure.

 

 

Local variable.png

0 Kudos
Message 6 of 10
(4,558 Views)

You may try this way: Right click on your generated local variable, and click "Change To Read" menu item. This changes the local variable to output its value, and then you can wire it to the case structure. In the "FALSE" case structure frame, it should give a default false boolean value to "Stop While Loop", otherwise, the below loop will stop when "Write To File" is false, I assume it's not what you expect.

 

By the way, you should be careful with "Create or Replace" input, this can help you create a brand new file(or overwrite old file) each time you run this VI, but you should make sure it will not overwrite your data every time you click the "Write To File".

Message 7 of 10
(4,554 Views)

Worked fine. Thanks for the tip regarding file saving options, thats why I have changed the first 'TDMS Open' to "Open or Create" this way my data wont be rewritten but new samples will be added to the existing file. 

 

So for the "FALSE" case of the Case structure, I should simply wire the Case structure terminal to the while loop condition terminal? 

 

I noticed that once the Stop Writting or the Stop reading Data buttons are pressed, I wont be able to save data any more until I restart the program, even when the Write To File button is pressed. I would like to have a common swtich between the Stop DAQ, Stop Writting and Stop reading and their respective while loops. So when I press it, all the loops finish and the program terminates. Is there any way to do this?

 

Cheers!

0 Kudos
Message 8 of 10
(4,544 Views)

For the "False" case frame, it's fine to wire the case structure terminal to the while loop condition terminal, or just wire a "F" boolean constant to it, both way shuold work.

 

To stop the VI by clicking only one stop button, I think you should use a global STOP button for all the while loops. For example, you can wire this STOP button to the loop condition terminal of your DAQ while loop, and use two local variable copies of this STOP button in the other write and read while loop. Then all the loops are controlled by the common switch, once it is clicked, the VI will stop running.

 

By the way, you should configure this STOP button's properties as below dialog(Right click >> Properties), otherwise the VI might be broken because the local variable copy doesn't work.

 

config stop button.png

Message 9 of 10
(4,526 Views)

Gotta ya!

 

谢谢 🙂

0 Kudos
Message 10 of 10
(4,518 Views)