LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

FYI TDMS open and read on empty file gives no error's out

I found that if you 'open' an empty (0 byte) file using TDMS open, you will not get any error messages when you open it, nor when you call functions such as "Get properties" or "List content", also no error when you close the TDMS file.

 

If the file is non-empty, but not a valid TDMS file, TDMS open returns an error.

 

I would have expected that I would get an error or a warning at least when trying to read a non-existant property or group, if not by the open function itself?!

 

The 2013 snippet below creates a 1-byte or empty file in the local user temporary folder, closes the file, then attempts to open and read it as a TDMS file.  The temporary file is deleted afterwards.

If the file is empty, NO errors or warnings occur at any point.  If the file is not empty, it fails on the TDMS open. (Note the sequence structure is because the path out of the tdms close is invalid if the tdms open failed.

 

This could conceivably cause an issue if your program does not do additional fault checking to catch existing but empty files.  (Which of course shouldn't ever happen, but in some situations it could happen.)

open empty TDMS file.png

QFang
-------------
CLD LabVIEW 7.1 to 2016
0 Kudos
Message 1 of 12
(4,964 Views)

Hi QFang,

Actually, TDMS Open allows an empty .tdms file of 0 byte if your open option is one of the following four options: "open", "open or create", "create or replace", "create", because TDMS recognize the 0 byte file as a valid .tdms file format and it will write some TDMS header information into the empty file to make it a real TDMS file. (You may notice that file size isn't zero byte after running your VI)

I would recommend a quick way to detect 0 byte file, you can use just the "TDMS Open" function followed by "TDMS Close" immediately, with the "open (read-only)" option wired to the open function, then the open function will return error as you expected, because the open(read-only) mode doesn't allow empty .tdms file.

 

 

Message 2 of 12
(4,935 Views)
Surely the quickest way of detecting a 0 byte file is by wiring its path to the Get File Size primitive on the File IO palette? 😉
---
CLA
0 Kudos
Message 3 of 12
(4,922 Views)

Hi Tianbin_Xu,

 

Okay, I'll accept that for the "open tdms" function, that opening a 0 byte file is (in some cases) 'valid'.  Could you comment on why there are no errors or warnings when attempting to list a group that does not exist?

 

Hi thoult, 

Yes there are plenty of ways to check for a 0 byte file before or after, I'm more questioning why this is not apparant from e.g. reading from an empty file?  It seems like one of those things that you wouldn't think that you needed to test for 0 byte files, if the file 'opens' you should be able to expect it is valid (thanks to Tianbin_Xu it seems it is in this case), and furthermore, if I try to list a group (e.g. Spectrum) and I get '0' I feel that implies the group exist, but there are 0 channels in it, without ambiguity of if the group even exist.   (Did you know that getting the file-properties, such as size, on a cRIO can take 10's to 100's of ms to complete if the file you inspect is particularily large and/or it is in an 'overpopulated folder'?)

 

 

All that said, this behavior was unexpected to me, but I've coded around it, the issue wasn't necessarily 'hard to deal with' once you know about it, it was just rather unexpected meaning I am now doing non-obvious extra steps that only makes sense once you know about this 'feature'.

QFang
-------------
CLD LabVIEW 7.1 to 2016
0 Kudos
Message 4 of 12
(4,912 Views)

QFang - the response was merely to Tianbin_Xu's method for opening and closing the TDMS to find out if it's zero size.

 

Didn't know that about the cRIO, nor the behaviour you see, so thank you.

---
CLA
0 Kudos
Message 5 of 12
(4,905 Views)

@QFang wrote:

Could you comment on why there are no errors or warnings when attempting to list a group that does not exist? 


You asked the find the groups in the file, and it returned you the groups in that file.  Why would an error be generated?  The fact that there were no groups again to me doesn't mean an error.  Having no groups is a valid state of a file.

0 Kudos
Message 6 of 12
(4,904 Views)

Hooovahh

I asked to list the channels in a named group.  If that named group did not exist, I would think that should at least be a warning,  but I could see how it should not be an error, it was just unexpected to me that reading a non existant group (in an empty file) did not indicate any issues at all.   To me, 'error out' should give a warning or an error if something unexpected happened, but I may just have stricter opinion on something that by nature is very philosophical and open for debate. (And there are always tradeoffs, overt checks and bounds in a function obviously leads to overhead, and TDMS is optimized for performance, so that may be one reason it is the way it is.)

 

(This situation came up for me because when a file is first created, we datetime tag it and write a bunch of other meta-data to the file, then later (and over time) we add the spectrum goup + data.  [Edit] actually, in the old code, if the file existed, it was assumed to have been setup correctly. so if the group exists, the old code assumed all the meta data has already been written [end edit].. One of the many fixes possible, I'll rely on the 'found' boolean output of the parameter read instead of relying on the error/warning. If the datetime tag is found, the code will asume the file exists and has been filled with the meta data I expect.)

 

Thoult ::  I wasn't sure, but in either case, my intent was to provide extra information, not 'knock you' for participating in the discussion, I hope thats not how I came accross.  English is a second language to me, so I sometimes come across 'wrong' from what I mean.

QFang
-------------
CLD LabVIEW 7.1 to 2016
0 Kudos
Message 7 of 12
(4,897 Views)

@QFang wrote:

Hooovahh

I asked to list the channels in a named group.  If that named group did not exist,


Sorry for the misunderstanding.  I thought you were using the List function with no group specified.  This would then list the groups in the file.  I would agree then this should return an error saying the group doesn't exist.

0 Kudos
Message 8 of 12
(4,886 Views)

The List Contents function seems to have a bug in your case, and this issue has been reported. Thanks!

Message 9 of 12
(4,859 Views)

Hi Tianbin_Xu,  

 

Thanks for reporting the issue.  Could you post the CAR# when it has been assigned please?

 

Thanks!

-QFang

QFang
-------------
CLD LabVIEW 7.1 to 2016
0 Kudos
Message 10 of 12
(4,841 Views)