Вы находитесь на странице: 1из 9

Tutorial 3 Writing and Reading Data (JEE344 Applied Control Engineering) Learning Objectives Write data to files Read

ad data from files Writing and Reading Data to/from Files When conducting experiments with equipment it is important to record data for analysis and calibration of instruments. LabVIEW has several functions for writing data to files - both continuous writing (online, while the VI runs) and batch (offline) writing. LabVIEW has also functions for reading data in such log-files. These functions are available on the Programming > File I/O palette [Haugen]. File Formats The file formats that are supported by the File I/O functions are: LVM (LabVIEW Measurement) which are text files that contain data that can be read by a human being because numbers are represented as text. For example, the number 0.231 is stored as the text (or string) "0.231". A large benefit of storing numerical data in the text format is that the file can be opened and displayed in any tool that supports text files, e.g. MS Word, Notepad, Excel, MATLAB, Web browsers. (It may be necessary to change the file name extension from lvm to e.g. txt or dat before opening the file in such tools). Thus, text files provide great portability. However, the text files will be larger than if the data were written in a binary format, and the data are stored with less accuracy, but these issues are not important on ordinary PC's, but may be important on dedicated computers with limited storage [Haugen]. TDMS (Technical Data Management - Streaming) which are binary files in an internal LabVIEW file format. The TDMS format gives more effective and accurate data storage than the LVM format. TDMS files may be opened in LabVIEW, of course, and in NI DIAdem which is a software tool for managing, analyzing, and reporting data in logfiles. TDMS files can save data in an organized way using a number of Groups and a number of Channels within a given Group. (The older TDM file format is still supported.) [Haugen] Spreadsheet Files (Excel): which are compatible to MS Excel spreadsheet files. With LabVIEW 8.6 we can write data to an Excel spreadsheet file and read data from an Excel spreadsheet file. In order to learn how to write data to files and read data from files we do a hands-on exercise with writing data to LVM files and reading data from files. I recommend this type of file because it can be easily read by several Windows Applications such as MATLAB, NotePad and Excel. 1. Writing Data to LMV file (a text formatted file) We start from Level Measurement 01.vi Open the VI Level Measurement 01.iv and save it as Level Measurement 01_write_to_lvm_file.vi In Block Diagram, add a Write to Measurement File function as follows:

Figure 1 Write to Measurement File Set the following:

Figure 2 Write to Measurement File settings 2

Then expand the Write to Measurement File icon. In Front Panel, add a Vertical Toggle Switch (you can search if you do not know where it is!). (see Figure 4) In Block Diagram, add a Merge Signals:

Figure 3 Merge Signals Right click File Name > Create a control > set a path for the LVM file (see Figure 4). Wire the remaining elements in Block Diagram properly (see Figure 5). The resulting program:

Figure 4 Front Panel 3

Figure 5 Block Diagram Save your VI. Run the program and adjust values of uin. The Time, Uin, Level in ampere and level in mm

Open the data file with NotePad, we have the following data:

Figure 6 Open the data file with NotePad

2. Reading Data from a LVM file: Open a new VI. Save it as Read Data from LVM File 01.vi. This VI is to read data from the LVM file created in the previous exercise and does not need a While Loop. Add Read From Measurement File in Block Diagram

Figure 7 Read From Measurement File We have the following Windows:

Figure 8 Configure Read from Measurement File Add a Convert from Dynamic Data

Figure 9 Setting Convert from Dynamic Data

Add the other functions (right click > Indicator) in Block Diagram and wire them properly (see Figure 10). The resulting Block Diagram:

Figure 10 Block Diagram Arrange elements in Front Panel. Save the VI. Run the program. The data that are read from the file are converted to an ordinary 2-dimensional array containing 4 columns of data (t, uin, u, y). The conversion is made by the Convert from Dynamic Data function which is on the Express / Signal Manipulation palette. This conversion function can be configured (i.e. selecting the correct data type) by double-clicking it. Four Index Array functions are used to extract each of the columns from the data and create 1 dimensional arrays, labelled Array t in s (1D), Array uin in V (1D), Array y in mA (1D) and Array y in mm (1D).

The resulting Front Panel:

Figure 11 Front Panel Conclusions At this point, the following LOs are met: Write data to LVM files Read data from LVM files Exercise Try to make programs that: Write data to a Spreadsheet (Excel) file Read data from a Spreadsheet Write data to a TDMS file Read data from a TDMS file 9

Вам также может понравиться