LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Binary File format

Hi, 

      I have a binary file written in LabVIEW 2021. The data format is as in figure below. 

      I would like to read the data in Matlab 2017. I am reading data as below:

 

gain=1st 64 bits

offset= next 64 bits.

sampling Rate 1= next 64 bits

Sampling Rate 2 = next 64 bits. 

 

And so on.. Am I reading the data correctly? Is my assumption correct that data is written sequentially without any embedded information about cluster and other controls etc? 

 

 

 

File format.png

jayant
0 Kudos
Message 1 of 6
(1,933 Views)

Have a look at the flattened data documentation: https://www.ni.com/docs/de-DE/bundle/labview/page/flattened-data.html

I am assuming the data was written using Write to Binary File. What you need to know is that arrays and strings are prepended by an int32 indicating the number of array/string entries. Like you said, there is no type information stored in the flattened data and also no padding (leaving out classes for now).

 

In your example the array length is missing and the data length for Sampling Rate is too big.

 

The flattened layout for your cluster should be:

 

int32 scaling coefficient array length

f64 gain[0]

f64 offset[0]

...

f64 gain[n-1]

f64 offset[n-1]

u16 Sampling Rate 1

....

0 Kudos
Message 2 of 6
(1,920 Views)

Hi, 

   Thank you for prompt response. I am using Write to Binary File. I have follow up questions:

 

1. Does cluster also prepended with int32 indicating number of elements? 

 

 

Thanks

 

 

jayant
0 Kudos
Message 3 of 6
(1,892 Views)

jayantbala@gmail.com wrote:

1. Does cluster also prepended with int32 indicating number of elements? 


No.  But your strings and arrays inside of the cluster will regardless of the "Prepend Array/String Size" setting.

 

Another thing of note is that Matlab defaults to a byte order of Little Endian while LabVIEW defaults to Big Endian.  It is a simple input on the LabVIEW side if you want to make it easier for the Matlab side.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 6
(1,884 Views)

Hi, 

     Can you please elaborate your earlier suggestion " In your example the array length is missing and the data length for Sampling Rate is too big". 

Also, the the suggested link on flattened data seems broken . Is there any alternate link?  

jayant
0 Kudos
Message 5 of 6
(1,796 Views)

jayantbala@gmail.com  ha scritto:

Hi, 

     Can you please elaborate your earlier suggestion " In your example the array length is missing and the data length for Sampling Rate is too big". 

Also, the the suggested link on flattened data seems broken . Is there any alternate link?  


According to your printout, you are writing 4 sampling rates, each long 16 bits.

Thus, if you declare

    sampling Rate 1= next 64 bits

   Sampling Rate 2 = next 64 bits

    ...

you are reading 8 bytes instead of 2 for each sampling rate. Too long.

 

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 6 of 6
(1,785 Views)