Write to Binary File Function

LabVIEW 2018 Help

Edition Date: March 2018
Part Number: 371361R-01
View Product Info

DOWNLOAD (Windows Only)

LabVIEW 2016 Help
LabVIEW 2017 Help
LabVIEW 2018 Help
LabVIEW 2019 Help
LabVIEW 2020 Help

Owning Palette: File I/O VIs and Functions

Requires: Base Development System

Writes binary data to a new file, appends data to an existing file, or replaces the contents of a file. This function does not work for files inside an LLB.

If you want to use the Read from Binary File function to read the array or string data you write to file, the prepend array or string size? parameter must indicate TRUE. Otherwise, LabVIEW generates an error.

This VI truncates arrays if the total array size is over 4 GB.

Details  Examples

prepend array or string size? indicates whether LabVIEW includes data size information at the beginning of the file when data is an array or string. If prepend array or string size? is FALSE, LabVIEW does not include the size information. The default is TRUE. prepend array or string size? controls only the top-level data size information. Arrays and strings in hierarchical data types such as clusters always include size information.
prompt is the message that appears above the list of files and directories, or folder, in the file dialog box.
file can be a refnum or absolute file path. If you wire a path to the file input, the function opens or creates the file before writing to it and replaces any previous file contents. If you wire a file refnum to the file input, writing begins at the current file position. To append to an existing file, set the file position to the end of the file by using the Set File Position function. The default is to display a file dialog box and prompt you to select a file.

If you specify an empty or relative path, this function returns an error.
data contains the data to write to the file and can be any data type.
byte order sets the endian form of the resulting data. Byte order, or endian form, indicates whether integers are represented in memory from most-significant byte to least-significant byte or vice versa. The function must read the data in the same byte order that the data was written.

0big-endian, network order (default)—The most-significant byte occupies the lowest memory address. This endian form is used on PowerPC platforms such as VxWorks. This endian-form also is used when reading data written on a different platform.
1native, host order—Uses the byte-ordering format of the host computer. This endian form increases read and write speed.
2little-endian—The least-significant byte occupies the lowest memory address. This endian form is used on Windows, macOS, and Linux.
error in describes error conditions that occur before this node runs. This input provides standard error in functionality.
refnum out is the refnum of the file that the function read. You can wire this output to another file function, depending on what you want to do with the file. The default is to close the file if it is referenced by a file path or selected from the file dialog box. If file is a refnum or if you wire refnum out to another function, LabVIEW assumes that the file is still in use until you close it.
cancelled is TRUE if you cancel the file dialog box. Otherwise, cancelled is FALSE, even if this function returns an error.
error out contains error information. This output provides standard error out functionality.

Write to Binary File Details

Use the Deny Access function to make sure no other users change the file while you write to it. Use the Set File Position function if you need to perform random access.


Refer to the following VIs for examples of using the Write to Binary File function:

  • labview\examples\File IO\Binary\Simple Binary\Simple Binary File.lvproj
  • Buffered Stream to Tab-Delimited Text File VI: labview\examples\File IO\Spreadsheet\Tab-Delimited Data


Not Helpful