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: 

Booleans in TDMS files

LV 2013, DIADEM 2012,2014, Win7

 

Not sure if this is a LabVIEW problem or not, but I'd like to find a LV workaround.

 

My app saves properties in the root level of TDMS files, for compatibility with data files, also TDMS.

 

I have a VI which will take a reference to any control (any that we use anyway), and store its value into TDMS properties. 

 

For most types, the code to WRITE it is very simple:

TDMS 1.PNG

 

For other types, it's a tad more complicated, but not much.

 

When reading, it's equally simple for most types:

TDMS 2.PNG

 

the properties are all VARIANTS - I simply feed the variant to the VALUE property of the generic control, and it's all good.  Again, some other types (clusters, arrays) are a tad more complicated, but that's not relevant here.

 

This all works perfectly - I can pass in a reference to a cluster of arbitrary complexity, and it gets written to the file just fine, and it will read back just fine.  The file is readable by DIAdem, which is a requirement. My code even handles arrays and generates names for each item in the control

 

EXCEPT

 

My problem comes with a BOOLEAN value. A simple, binary, Boolean control.

Could be a switch or slideswitch or rocker, or LED - doesn't matter. Just like the stinkin' "C" language, nobody agrees on how to handle it.

 

When I write the file from my LabVIEW app, here is what the property looks like:

Boolean 4.PNG

 

It shows up as a BOOLEAN. That's right, with a TRUE or FALSE value.

Great.

 

Again, if I read this file right now with my LabVIEW tools, it's all good.

 

But DIAdem insists on showing it as a 1 or 0, not TRUE or FALSE:

DIAdem.PNG

 

That's STILL OK, because the users can understand it.

 

The problem is if they EDIT the file, in ANY way, then look what happens to the Boolean when LabVIEW reads it back:

Boolean 5.PNG

 

Yes, the edit added some new properties, that's OK.

 

But it changed the boolean into a U8 !

 

And, of course, feeding a U8 variant into a Boolean control results in a false always (and an error, I suppose, but I'm not checking.

 

It's a freakin' BOOLEAN value - it's not that complicated !

 

So, what do I need to do?

 

I can have a special case for boolean, I guess I have to coerce the variant into an integer and then check for 0 or not? 

 

Any better ideas?

 

 

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

Message 1 of 5
(3,479 Views)

So I don't know if this is related or not, but you know that a boolean is stored as a U8 in both the file, and in memory in LabVIEW.  Something about not being able to allocate a bit of memory from the OS.  So when you log to a binary file, or TDMS and you log a single boolean it will take up 8 bits of storage, not 1.

0 Kudos
Message 2 of 5
(3,438 Views)

@Hooovahh wrote:

So I don't know if this is related or not, but you know that a boolean is stored as a U8 in both the file, and in memory in LabVIEW.  Something about not being able to allocate a bit of memory from the OS.  So when you log to a binary file, or TDMS and you log a single boolean it will take up 8 bits of storage, not 1.


My complaint is NOT that it takes up 8 bits.

My complaint is that it changes the DATA TYPE of the variant stored in the file.

 

If I read it BEFORE editing, the variant's data type is boolean,

If I read it AFTER editing, the variant's data type is U8.

 

And you don't have to edit the boolean itself, you don't have to actually change anything - just SAVing from DIAdem will change the data type.

 

I suspect that DIAdem is reading it wrong, since it displays as 1/0 in DIAdem, instead of T/F or True/False or something sensible.

 

But in any case, it saves it out again as U8.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 3 of 5
(3,430 Views)

Hey there,

 

Apparently this is the expected behavior of DIAdem. As it does not accept boolean types, it coerces them to integers. Then when it saves, it saves them back as integers since it doesn't have a boolean type. 

 

Eden K
Applications Engineer
0 Kudos
Message 4 of 5
(3,390 Views)

If you call DIAdem garbling my Boolean attributes "expected behavior", then I guess, let's keep it that way... Cat Wink

0 Kudos
Message 5 of 5
(2,370 Views)