Company Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Read from Binary File

LabVIEW 8.2 Help
August 2006

NI Part Number:
371361B-01

»View Product Info

Reads binary data from a file and returns it in data. How the data is read depends on the format of the specified file. Use the Deny Access function to make sure no other users change the file while you read from it. Use the Set File Position function if you need to perform random access. Examples

data type sets the type of data the function uses to read from the binary file. The function interprets the data starting at the current file position to be count instances of data type. If the type is an array, string, or cluster containing an array or string, the function assumes that each instance of that data type contains size information. If an instance does not include size information, the function misinterprets the data. If LabVIEW determines that the data does not match the type, it sets data to the default for the specified type and returns an error.
prompt (Open existing file) is the message that appears above the list of files and directories, or folder, in the file dialog box.
file (use dialog) can be a refnum or absolute file path. If it is a path, this function opens the file specified by the path. The default is to display a file dialog box and prompt you to select a file. This function creates the specified file if it does not already exist.

If you specify an empty or relative path or if the file does not exist, this function returns an error.

count is the number of data elements to read. Data elements can be bytes or instances of data type. The function returns count data elements in data, or if it reaches the end of the file, it returns all the complete data elements read thus far and an end-of-file error. By default, the function returns a single data element. If count is –1, the function reads the entire file. If count is less than –1, the function returns an error.

If count calls for an array of elements and the specified data type is an array, the function automatically returns a cluster of arrays or cluster array because LabVIEW does not allow arrays of arrays.

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. Used on Mac OS and when reading data written on a different platform.
1native, host order—Uses the byte-ordering format of the host computer. Increases read and write speed.
2little-endian—The least-significant byte occupies the lowest memory address. Used on Windows and Linux.
error in describes error conditions that occur before this VI or function runs. The default is no error. If an error occurred before this VI or function runs, the VI or function passes the error in value to error out. This VI or function runs normally only if no error occurred before this VI or function runs. If an error occurs while this VI or function runs, it runs normally and sets its own error status in error out. Use the Simple Error Handler or General Error Handler VIs to display the description of the error code. Use error in and error out to check errors and to specify execution order by wiring error out from one node to error in of the next node.
status is TRUE (X) if an error occurred before this VI or function ran or FALSE (checkmark) to indicate a warning or that no error occurred before this VI or function ran. The default is FALSE.
code is the error or warning code. The default is 0. If status is TRUE, code is a nonzero error code. If status is FALSE, code is 0 or a warning code.
source specifies the origin of the error or warning and is, in most cases, the name of the VI or function that produced the error or warning. The default is an empty string.
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.
data contains the data read from the file in the specified data type. It can consist of a string, an array, a cluster of arrays, or a cluster array, depending on which data type you are reading and how count is set.
Is TRUE if you cancel the dialog box or if an error occurs during the execution of the dialog box.
error out contains error information. If error in indicates that an error occurred before this VI or function ran, error out contains the same error information. Otherwise, it describes the error status that this VI or function produces. Right-click the error out front panel indicator and select Explain Error from the shortcut menu for more information about the error.
status is TRUE (X) if an error occurred or FALSE (checkmark) to indicate a warning or that no error occurred.
code is the error or warning code. If status is TRUE, code is a nonzero error code. If status is FALSE, code is 0 or a warning code.
source describes the origin of the error or warning and is, in most cases, the name of the VI or function that produced the error or warning.

Examples

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

  • labview\examples\file\datalog.llb\Read Datalog File Example.vi

     

  • labview\examples\file\smplfile.llb\Read from Text File.vi

     

  • labview\examples\file\smplfile.llb\Read Binary File.vi

     

  • labview\examples\file\endian\endian.llb\Endian Data.vi

     


Resources


 

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
Add Comments 1 2 3 4 5 submit