How Can I Write and Read Binary Files Using LabVIEW?Primary Software:
Primary Software Version: 7.1
Primary Software Fixed Version: N/A
Secondary Software: N/A
I would like to read and write binary files using LabVIEW. I would also like to understand how the procedure works so I can write and read data such as two dimensional arrays.
You can write and read from a binary file using the Write to Binary File and Read from Binary File VIs located in the Programming»File I/O functions palette. The Write to Binary File VI will also create a new binary file if the input file path does not yet exist.
When reading a binary file, you must know the format the data was in when it was written to the file. Take careful notes of the format in which you store the numbers so that you will know how to read them later. Furthermore, there is no universally accepted format for binary files (unlike ASCII) so other applications or operating systems may be unable to read the file.
To read the binary file, you need to wire a dummy data type representing the data in the file into the Data Type input. For example, if we previously wrote a 2D array of double precision numbers to a file, in our read program we would have to wire a double precision number to the Data Type input to match the data type. LabVIEW will then assume that the appropriate header for the dummy data type is stored in the file, and uses it to extract the binary information.
To easily save data to disk in binary format:
LabVIEW versions 7.1 and later ship with examples of both reading and writing binary files, which can be found using Example Finder (Help»Find Examples...). The files are named Read Binary File.vi and Write Binary File.vi and can be found by browsing to Fundamentals»File Input and Output directory in Example Finder, or by doing a search for Binary.
KnowledgeBase 10U39NAQ: Writing Binary Files with LabVIEW That Can Be Read by Other Applications
KnowledgeBase 1XU8RQPH: What Does the Term "Endian" Mean?
KnowledgeBase 2MKB41DV: How Can I Read the Binary Representation of a Floating Point Number in LabVIEW?
Developer Zone Example: Reading Little Endian Binary Files with LabVIEW 7.1
Developer Zone Example: How LabVIEW Stores SGL Floating-Point Numbers in Memory (IEEE 754 Format)
Report Date: 07/02/2002
Last Updated: 10/02/2008
Document ID: 2N1DMKM5