您在這裡

Reading From Files

26 七月, 2019 - 09:47
Available under Creative Commons-ShareAlike 4.0 International License. Download for free at http://cnx.org/contents/5b6e61df-b830-48cb-9764-94696cb47c80@1.3

The signal.dat file created in the previous example will be used to read data from a file. As in the previous example, select the File Dialog, Open/Create File, Read from Binary File and Close File functions.

media/image19.png
Figure 11.19 Operators to Read Files 

Create constants by right clicking on the operation (0:open) and access (0:read/write) terminals of the Open/Create File operation. Set the constants toopen andread-only respectively (see Figure Figure 11.20).

media/image20.png
Figure 11.20 Set to Open and Read-Only  

Similar to creating arrays, drop an array constant in the G diagram, drop a numeric constant onto the array constant and set the data type representation to double. Wire this array constant to the data type terminal of the Read from Binary File function as shown in Figure Figure 11.21 .

media/image21.png
Figure 11.21 Data Type to Read 

In the Front Panel window, drop a Waveform Graph.

media/image22.png
Figure 11.22 Graph for Data to be Read  

With the data type specified, wire thedata terminal of the Read from Binary File function to the Waveform Graph terminal as shown in Figure Figure 11.23 .

media/image23.png
Figure 11.23 Data to be Read  

Complete the program by wiring refnum and error terminals of the Open/Create File, Read from Binary File and Close File functions as shown in Figure Figure 11.24 .

media/image24.png
Figure 11.24 Read Binary Data G Program 

When this program is executed, a fle dialog box appears. Select the signal.dat file and click OK.

media/image25.png
Figure 11.25 Select Binary File to Read From  

The binary data in signal.dat is read and plotted in a Waveform Graph. The result is shown in Figure Figure 11.26.

media/image26.png
Figure 11.26 Read Data Graphed