18

Labview File Io

Embed Size (px)

Citation preview

Page 1: Labview File Io
Page 2: Labview File Io

LabVIEW File I/O• File I/O operations pass data to and

from files.

Page 3: Labview File Io

File I/O Functions

Page 4: Labview File Io

Write to spreadsheet

Block Diagram

Page 5: Labview File Io

Write to spreadsheet

Front Panel

Page 6: Labview File Io

Read from spreadsheet txt

Block Diagram

Page 7: Labview File Io

Read from spreadsheet

Front Panel

Page 8: Labview File Io

Typical file I/O operation

A typical file I/O operation involves three steps.1- Create or open a file.2- Read from or write to3- Close the file

Page 9: Labview File Io

Opens an existing file, creates a new file, or replaces an existing file

function is the operation to perform.

0 Opens an existing file (default). Error 7 occurs if the file cannot be found.

1 Opens an existing file or creates a new file if one does not exist.

2Creates a new file or replaces a file if it exists and you give permission. This VI replaces a file by opening the file and setting its end of file to 0. Error 43 occurs if you do not select the replacement in an advisory dialog box.

3 Creates a new file. Error 8 occurs if the file already exists.

4 Opens an existing file for read only. Error 7 occurs if the file cannot be found.

Other File I/O Functions

Page 10: Labview File Io

pos mode, together with pos offset, specifies where the read or write operation begins. If you wire pos offset, pos mode defaults to 0, and the offset is relative to the beginning of the file. If you do not wire pos offset, it defaults to 0, pos mode defaults to 2, and the operation starts at the current file mark.

0 Start—The operation begins at the beginning of the file plus pos offset. If pos mode is 0, pos offset should be positive.

1 End—The operation begins at the end of the file plus pos offset. If pos mode is 1, pos offset should be negative.

2 Current—The operation begins at the current location of the file mark plus pos offset.

pos offset specifies how far from the location specified by pos mode to start reading or writing. You express pos offset in units of bytes. The default is 0. If you do not wire pos modeor pos offset, the functions reads or writes the data following the most recently read or written data.

Page 11: Labview File Io

pos mode, together with pos offset, specifies where the read or write operationbegins. If you wire pos offset, pos mode defaults to 0, and the offset is relative to the beginning of the file. If you do not wire pos offset, it defaults to 0, pos mode defaults to 2, and the operation starts atthe current file mark.

0 Start—The operation begins at the beginning of the file plus pos offset. If pos mode is 0, pos offset should be positive.

1 End—The operation begins at the end of the file plus pos offset. If pos mode is 1, pos offset should be negative.

2 Current—The operation begins at the current location of the file mark plus pos offset.

refnum is the file refnum associated with the file you want to read. If you want to read more than one element at a time,wire the count parameter and use pos mode, pos offset,and offset to track the location of the file mark.

pos offset specifies how far from the location specified by pos mode to start reading or writing. You express pos offset in units of bytes. The default is 0. If you do not wire pos mode or pos offset, the functions reads or writes the data following the most recently read or written data.

Reads data from an open file specified by refnum and returns it in data. Reading begins at the current file mark or a location in the file specified by pos mode and pos offset. How the data is read depends on the format of the specified file.

Page 12: Labview File Io

Writes data to an open file specified by refnum. Writing begins at a location specified by pos modeand pos offset for byte stream files and at the end of the file for datalog files. data, header, and the format of the specified file determine the amount of data written.

pos mode, together with pos offset, specifies where the read or write operationbegins. If you wire pos offset, pos mode defaults to 0, and the offset is relative to the beginning of the file. If you do not wire pos offset, it defaults to 0, pos mode defaults to 2, and the operation starts atthe current file mark.

0 Start—The operation begins at the beginning of the file plus pos offset. If pos mode is 0, pos offset should be positive.

1 End—The operation begins at the end of the file plus pos offset. If pos mode is 1, pos offset should be negative.

2 Current—The operation begins at the current location of the file mark plus pos offset.

pos offset specifies how far from the location specified by pos mode to start reading or writing. You express pos offset in units of bytes. The default is 0.

Page 13: Labview File Io

Closes an open file specified by refnum and returns the path to the file associated with the refnum. Error I/O operates uniquely in this function, which closes regardless of whether an error occurred in a preceding operation. This ensures that files are closed correctly.

Page 14: Labview File Io

Write to File Example

Page 15: Labview File Io

Reading Data From File

Page 16: Labview File Io

Other File I/O Functions

Page 17: Labview File Io

Other File I/O Functions

Page 18: Labview File Io

Waveform Data Type• The waveform data type carries the data, start time, and ∆t of a

waveform.

• You can create waveforms using the Build Waveform function.

• Many of the VIs and functions you use to acquire or analyze waveforms accept and return the waveform data type by default.

• When you wire a waveform data type to a waveform graph or chart,the graph or chart automatically plots a waveform based on the data, start time, and ∆x of the waveform.