LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

binary file

hi
i write in labview to binary file the data is double i suppose the default mode is without any headers i have succed to read it back in labview
the problem is that i cant read the file from other places
in matlab i recieve garbage
fid = fopen(filename,'bin')
data = fread(fid,....)
fclose(fid)
 
Message 1 of 6
(4,349 Views)
The binary data that LabVIEW writes is going to be readable only by LabVIEW because there is no "standard" binary file format. Each application that can handle binary files has it's own method of creating the file format.

If you want the data to be available to read in other applications, you should save it as an ASCII (text) file. Most applications can read an ASCII file is some standard format like comma separated values or tab delimited files.

If writing speed is an issue, try first writting the files as binary, then convert them to ASCII when needed.

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 6
(4,342 Views)

Many application CAN read plain binary data if you tell them the binary format and data type. One complication under Windows is the fact that LabVIEW writes big-endian binary format, while most other W32 programs are little-endian. You need to reverse the bytes in each DBL.

Unfortunately my matlab knowledge is limited, but you should be able to read it with the right commands. Good luck! 🙂

 
 
0 Kudos
Message 3 of 6
(4,328 Views)

Hello
You should have no problem to read labview binary files in Matlab. Matlab "bin" is little endian , but you can instruct it to read big endian,

Just try the options for fread.

Cheers
Alipio

---------------------------------------------------------
"Qod natura non dat, Salmantica non praestat"
---------------------------------------------------------
0 Kudos
Message 4 of 6
(4,318 Views)

Yes, the problem is most likely with the endian, LabView was developed for the Mac, as such it reads big endian (or little endian, i get them mixed up), and Intel machines are the opposite (or course).  I have had this problem repeatedly.  I have written a small program which will correct the endian, I have attached it.  You will have to put this endian swap program inside a for loop and swap every single word.

You can rewite the program for signed intergers and floats too. 

Please let me know if this works for you.

Chris

Chris Reyerson
Optical Systems Engineer
Arete Associates
Tucson, AZ
0 Kudos
Message 5 of 6
(4,206 Views)

Thanks for this post, I was trying to import data into matlab and was getting garbage, turns out it was the endianness. Here's what I used in matlab to read an array of double that I wrote using the 'write to binary file' VI.

 

example for a 1D array of 5 elements of double type

 

fid = fopen('c:\test.dat','r','b');

f = fread(fid, [5],'double',0,'b')

 

it's the 'b' parameter that specifies to read the file as big endian

 

Thanks!

0 Kudos
Message 6 of 6
(3,244 Views)