LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How does Labview stores the binary data - The header, where the actual data starts etc.

I have problem in reading the binary file which is written by labview. I wish to access the data (which is stored in binary format) in Matlab. I am not able to understand - how the data will be streamed in to binary file (the binary file format) when we save the data in to a binary format through Labview program. I am saving my data in binary format and I was not able to access the same data in Matlab.

I found a couple of articles which discusses about converting Labview to Matlab but What I really wanna know is - How can I access the binary file in Matlab which is actually written in Labview?

Once I know the format Labview uses to store its binary files, It may be easy for me to read the file in Matlab. I know that Labview stores the binary files in Big Endian format which is

Base Address+0 Byte3
Base Address+1 Byte2
Base Address+2 Byte1
Base Address+3 Byte0

But I am really confused about the headers, where the actual data start. Hence I request someone to provide me data about - How Labview stores the Binary Data. Where does the original data start. Below attached is the VI that I am using for writing in to a binary file.
0 Kudos
Message 1 of 16
(8,781 Views)
The function in your attachement as it is uses the LVM files to write the data to disk. Those functions should write an ASCII spreadsheet formatted text file and not binary.
The disabled branch uses the "Write To SGL File.vi". This function, while writing binary data to disk, does not write any header at all.

Rolf Kalbermatter
Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 16
(8,742 Views)
Hello,

You are correct that LabVIEW uses Big Endian representation. I see you are using Write SGL File.vi to write a 2D array to a binary file. This VI does not supply a binary file header.

There is a thread here about writing binary files in LabVIEW and reading them in Matlab that might help.

Also, this document describes how to convert binary files from Big Endian to Little Endian and supplies examples:
Writing Binary Files with LabVIEW That Can Be Read by Other Applications

With regards to the Write to LabVIEW Measurement File express VI, it creates a text file (with .lvm extension) and you can open it with any text editor and examine it's header information and format.

Good luck and let me know if you have more questions about this.

Best regards,
Shakhina P.
Applications Engineer
NI
Message 3 of 16
(8,729 Views)
Hello Sir/Mam,
Thanks for your responses. I have followed the two steps in Matlab from the link you have provided

fin=fopen('C:\MATLAB7\work\DAQ\5amp.bin','r','b')
data=fread(fin,[5,2],'single')

I am getting the data as

data =

5.4313 0
0 5.4313
5.4313 0
0 5.4313
5.4313 0

I dont understand the reason why I am getting the zeros. It is because of the PRECISION paramter in fread (or) still am doing a mistake in reading the binary data?
0 Kudos
Message 4 of 16
(8,720 Views)
Hello Mam/Sir,
Actually I tried everything on Matlab. Finally I am getting some values but in the output. I am getting the 1st, 3rd, 5th and so on - correct values and 2nd, 4th, 6th and so on - all zeros. I dunno the reason. When I have edited the same binary file (which is the output of attached VI) in hex editor I able to see some data like

00000000 41 A2 EC 0F 00 00 00 00 41 A2 EC 0F 00 00 00 00
00000010 41 A2 88 1B 00 00 00 00 41 A2 88 1B 00 00 00 00
00000020 41 A2 88 1B 00 00 00 00 41 A2 88 1B 00 00 00 00
00000030 41 A2 88 1B 00 00 00 00 41 A2 88 1B 00 00 00 00

I am not able to understand the data contained in it and the reason why I am getting the zeros in between. When Labview stores the file in binay format without header, does it store the data with some zeros in it? I would be thankful to you if you can help me in resolving the problem.

Have a Good Day

Regards,
Krishna
0 Kudos
Message 5 of 16
(8,696 Views)
Hi Everybody!

I have attached a VI (Write MAT file.vi - written in LabVIEW 7.1) that takes a waveform and directly converts it to a 2D array where the first column is the timestamps and the second column is the data points. You can then pass this 2D array of scalars directly to the Save Mat.vi. You can then read the .MAT file that is created directly from Matlab.

For more information on this, you can reference the following document:
Can I Import Data from MATLAB to LabVIEW or Vice Versa?
http://digital.ni.com/public.nsf/websearch/2F8ED0F588E06BE1862565A90066E9BA?OpenDocument

However, I would definitely recommend using the Matlab Script node (All Functions->Analyze->Mathematics->Formula->Matlab Script). In order to use the Matlab Script node, you must have Matlab installed on the same computer. Using the MatlabScript node, you can take data generated or acquired in LabVIEW and save it directly to a .mat (Matlab binary) file using the 'save' command (just like in Matlab). You can see this in example VI entitled MathScriptNode.vi - written in LabVIEW 7.1.

I hope this helps!
Travis H.
LabVIEW R&D
National Instruments
Message 6 of 16
(8,666 Views)
Hi,

I have some binary files that were created with labview 4. I think the program you attached might work with these files as, I believe, they are in the format date/time stamp then data point - not 100% sure though. Do you have a version that could be run in labview 4, gave an error when I tried to open it with 4?

Thanks.
0 Kudos
Message 7 of 16
(8,614 Views)
Hi Bgenswei,

The KB mentioned above has attached VIs that were written in LabVIEW 4.0. My Write MAT file.zip files were just modifications to those VIs.
Travis H.
LabVIEW R&D
National Instruments
0 Kudos
Message 8 of 16
(8,582 Views)

Is there any way I could get the Write MAT file in 7.0 format?

Thanks,

Brent

0 Kudos
Message 9 of 16
(8,337 Views)
I didnt get you exactly. What do you mean by Mat file in 7.0 format. I never heard of 7.0 format. You can write the files in Mat format which can be read in all versions of Matlab.
 
Krishna
0 Kudos
Message 10 of 16
(8,058 Views)