LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need to read data files originally created in LabVIEW in C++

I have originally created binary files in LabVIEW. These files are made by flattening labview data to a string, then converting the string to a U8 byte array which is then saved to a binary data file. A separate file is used to keep track of the variables written to the data file. (FAT) a 2D-String array (first element = variable name, 2nd element = staring byte location in .dat file, 3rd element = byte length of variable) is flattened to U32 and then written to a binary file.
Opening the files in LabVIEW follows the inverse proceedure. The FAT file is read as a U32 binary data, converted to a byte array, converted to a string, and then unflattened from the string into a LabVIEW 2D-string data type. From this the starting location and length of the variable is extracted. These are used to read the data file, in U8, which is then converted bu a string and then unflattened to LabVIEW data according to the LabVIEW data type.
I now need to now open these files in a Linux environment using C++. I am at a loss at how to emulate all of this data-type conversion, flattening, and unflattening in C++. Does anyone have any ideas?
0 Kudos
Message 1 of 5
(2,575 Views)
I don't think it can be done. My understanding of LabVIEW binary files is that they can only be read by LabVIEW. I could be wrong. My total knowledge of C++ could fit on the head of a pin.

Normally when you want to use data in another environment, you save it as an ASCII file. You might want to look into creating a conversion utility in LabVIEW to save the binary files you need to ASCII.

Ed


Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.
0 Kudos
Message 2 of 5
(2,568 Views)
Faraclas wrote:

> written to a binary file.<br> Opening the files in LabVIEW follows
> the inverse proceedure. The FAT file is read as a U32 binary data,
> converted to a byte array, converted to a string, and then unflattened
> from the string into a LabVIEW 2D-string data type. From this the
> starting location and length of the variable is extracted. These are
> used to read the data file, in U8, which is then converted bu a string
> and then unflattened to LabVIEW data according to the LabVIEW data type.

I didn't try to follow the entire stream of operations but at first
glance a few steps are simply superfluous such as typecasting a string
into an U8 array and others wouldn't be necessary to maintain your data
consistency but removing them would change your file format.

> I now need to now open these files in a Linux environment using C++.
> I am at a loss at how to emulate all of this data-type conversion,
> flattening, and unflattening in C++. Does anyone have any ideas?

This can be done but it won't be trivial. Read the application note
under Help->Search the LabVIEW Bookshelf->Application Notes and White
Papers->(on second page)LabVIEW Data Storage Formats. This isn't easy
text reading but it contains everything to understand how LabVIEW stores
data and what flattened data means.

You can also take a look at the lvdata Toolkit from the OpenG toolkits
which does the entire flattened data parsing in LabVIEW itself.

Rolf Kalbermatter
Rolf Kalbermatter
My Blog
0 Kudos
Message 3 of 5
(2,562 Views)
Thanks rolfk, I will do the reading. But just to make sure you don't misunderstand me, everything works beautifully in LabVIEW. The problem I am having is trying to open up these files in C++. This system has been around for a couple of years now, so I cannot change the data structure in the LabVIEW programs (well I could but I don't want to because it is really a very flexible system that works well). The previous suggestion was to have LabVIEW open the data files and re-write them in ASCII. (Is encryption doable in ASCII the same as binrary? I'm using the 128-bit keyed XOR technique) This is a great suggestion except I am doing this only because I want to extend our software to linux where there is no LabVIEW (because we don't have the LabVIEW for linux and I don't really want to pay for it).

Thanks again for the document tips!
0 Kudos
Message 4 of 5
(2,560 Views)
Faraclas wrote:

> Thanks rolfk, I will do the reading. But just to make sure you don't misunderstand
> me, everything works beautifully in LabVIEW.

I gathered that. But reading through the description gave me the
impression that a few conversions/typecasts may actually be superfluous
without any change to the actual data.

> The problem I am having is trying to open up these files in C++. This system has
> been around for a couple of years now, so I cannot change the data structure in
> the LabVIEW programs (well I could but I don't want to because it is really a very
> flexible system that works well).

Well, it really isn't that difficult, it just won't be a one hour job
for sure. A few guidelines:

1) LabVIEW flattened data contains the actual data as is for all fixed
size elements (scalars and clusters of scalars). Any variable sized data
(strings, arrays) is prepended with an int32 for each dimension
containing the number of elements for that dimension.

2) LabVIEW flattened data is always in Big Endian (Most significant Byte
first) format. This means for normal C(++) programs developed on an x86
system you will have to byteswap every single 16 bit and 32 bit integer.

3) LabVIEW Typecast really is similar to Flattened data but no
prepending of the number of elements is done for variable sized data.
And Typecast can't convert any type containing variable sized data, but
any arbitrary complex datatype only containing fixed size data, or a
simple array or string can be typecasted.

Rolf Kalbermatter
Rolf Kalbermatter
My Blog
Message 5 of 5
(2,555 Views)