From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, 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: 

Data Logging using Write to TDMS

Solved!
Go to solution

Hi

I'm trying to write a program where I log values that I measure and send to a host VI as network published shared variables

I'm looking for the following end result
- First column displays time
- Second column displays measurement signal nr 1
- Third column displays measurement signal nr 2
- Fourth column displays measurement signal nr 3
- Etc

I'm a bit confused as to how to work with the the TDMS write function, and I'm currently just getting all measurements and the time stamp in one single column

Also, I'm trying to figure out how to automatically name each log file according to the date; for example: 01/14-Data, 01/15-Data, etc and have a functionality that auomtiatcally creates a new file each time the program is run, for example:

01/14-Data1

01/14-Data2

01/14-Data3, etc

 

Any advice?

Screenshot of code and the VI are attached

Thanks

Download All
0 Kudos
Message 1 of 18
(10,861 Views)

I haven't used TDMS files, but I found an example that came with LabVIEW. I wanted to learn a little myself, so I edited your VI. You can see if it's useful 🙂

 

TDMS Write.png

Message 2 of 18
(10,837 Views)

To make a file name, just use the Build Path VI

 

File Name.png

Message 3 of 18
(10,829 Views)

Wow, thanks! This is perfect

 

Also, is it possible to add data to an existing file, without loosing the old recordings?

 

Thanks

0 Kudos
Message 4 of 18
(10,823 Views)
Solution
Accepted by topic author ghp_1

Yes, open it using "Open or Create"

Message 5 of 18
(10,816 Views)

Thanks!

0 Kudos
Message 6 of 18
(10,808 Views)

What is the name of the symbol between the build path and date/filename string?

0 Kudos
Message 7 of 18
(10,798 Views)

It's Format Date/Time String. If you have LV 2014 or higher you can drag that picture right onto the block diagram and it will make code for you. Unless you're using firefox like me, then you have to drag it to the desktop, and then from the desktop into your block diagram 🙂

Message 8 of 18
(10,788 Views)
Solution
Accepted by topic author ghp_1

@Gregory wrote:

I haven't used TDMS files, but I found an example that came with LabVIEW. I wanted to learn a little myself, so I edited your VI. You can see if it's useful 🙂


There isn't anything inherently wrong with how you're doing it.  But TDMS can become quite fragmented if you are writing one sample at a time the way you are.  Here's an article on file fragmentation:

 

https://decibel.ni.com/content/docs/DOC-20522

 

Basically a TDMS file has the binary data stored in it, and some XML like data that keeps track of where the data is (the index).  This is sorta like a database, and then come cached information about where offsets are, so that reading and writing can happen faster.  If we change how we write the data so we are writing more data, and use less Write functions, the file will be less fragmented, and the index data will be smaller, making reading the data faster too.  That means writing N channels in one write function, or writing N samples, or a combination with multiple channels and samples at once.  Attached is two improved versions which either write all channels at once, or all channels and 50 samples at a time.

 

Example_VI_BD.png

 

Keep in mind to use a single write for N channels, those channels all need to be of the same data type.  Luckily the order of the channels is based on the first time the channels are written to.  So in the past I had a column of a numeric, then a column of a string repeated 10 times.  I could write all the doubles with one write, then all the strings and the order in the file was based on the first write (or setting of properties).

 

There's a ton of other great information on TDMS and why it is amazing for fast writes, but to keep read times down, and file size down, you need to consider how the data is being written.  Oh and then knowing what types of properties to set, so that looking up the data later can be done faster.  Using DataFinder or Diadem you can setup a query like: Find all Files created after this date, where the serial number of the part is 123 and the test failed, while on nest location 2.

 

Many of these types of TDMS tips, or features are not inline with how most programmers think of making text or CSV files, which might be why adopting TDMS can be difficult.  If you treat a TDMS file like a text file, you're gonna have a bad time, and...

 

Message 9 of 18
(10,766 Views)

Edit: got it working!

 

Thanks for the details and alternative solution!

 

0 Kudos
Message 10 of 18
(10,757 Views)