Writing Binary Files with LabVIEW That Can Be Read by Other ApplicationsPrimary Software: LabVIEW Development Systems>>Full Development System
Primary Software Version: 7.1
Primary Software Fixed Version: N/A
Secondary Software: LabVIEW Development Systems>>Base Package, LabVIEW Development Systems>>Professional Development System
I am using LabVIEW for Windows. When I write binary data to a file from LabVIEW and then try to read it back with a program written in another language, my data does not appear to be correct. I have already checked, and the program reading the data is reading the correct bytes for each field. How do I get LabVIEW to write a binary file that can be read in a C (or another language) program on Windows platforms?
The problem is that LabVIEW uses Big Endian format for its binary numbers, while most Windows programs use Little Endian format. LabVIEW uses Big Endian, because that is what the MacOS uses, and LabVIEW was created first for the Macintosh.
In Big Endian format, the most significant byte (MSB) of a multi-byte number is written first, then the second MSB, and so on down to the least significant byte (LSB). However in Little Endian, it is reversed such that the LSB is written first, then the second LSB on up to the MSB.
In LabVIEW 8.0 and later, the Write Binary File VI and Read from Binary File VI have an input to specify the byte order. The byte order can also be specified when using Flatten to String VI and Unflatten from String VI.
Byte order input values of these VIs, indicating the endian format of the data:
For an example on how to write a file using proper "Endian" representation, check out Write Binary File.vi in the Example Finder. Select Help»Find Examples. Then navigate to Fundamentals»File Input and Output»Write Binary File.vi.
To read a little endian binary file in LabVIEW 7.1, check out the Developer Zone Example Program: Reading Little Endian Binary Files with LabVIEW 7.1.
LabWindows/CVI has formatting and scanning functions that can specify byte order. The format modifier is [o0123], [o01] for 32 and 16 bit Intel, and [o3210] and [o10] for Motorola byte order. This is another way to interpret them.
KnowledgeBase 1XU8RQPH: What Does the Term "Endian" Mean?
Developer Zone Example Program: Reading Little Endian Binary Files with LabVIEW 7.1
Report Date: 08/31/1997
Last Updated: 09/05/2008
Document ID: 10U39NAQ