labview hw #8

3
LabVIEW HW #8 Each problem begins with a suggested descriptive name (including the .vi extension) for the solution VI that you will write. Suggested icons for use in the VI are given at the end of some problem statements. The palette locations of the cited icons are not give explicitly: these icons can be found with the aid of Quick Drop. 1. Binary Storage.vi Build a VI that stores the 2D array of Time and Displacement values produced by Waveform Simulator in a binary-formatted file named Sine Wave Data.txt. Much of the program you will write is similar to Spreadsheet Storage (OpenWriteClose), so you may want to begin by opening that VI, and then using File>>Save As… to create a new VI, which you should save in your folder for this chapter. The front panel of your new VI should look as follows: On the block diagram, implement the required three-step data storage process using the Open/Create/Replace File, Write to Binary File, and Close File icons. Wire a True Constant to Write to Binary File’s prepend array or string size? input. This selection instructs LabVIEW to begin the binary file with an eight-byte header, which records the number of rows and columns into which the data are arranged. a) Run your VI with its front-panel controls programmed as shown above. Next, find the icon (or name) for the binary-formatted Sine Wave Data.txt file that this has just created in your folder for this chapter, and determine its size (in kilobytes). If the details are not already shown, a file’s exact size can be found, using the Mac OS, by clicking on the icon (or name) and typing Command-I. In Windows, you do the same thing by right-clicking on the icon and selecting Properties. – Given the front-panel input values and binary formatting, explain why Sine Wave Data.txt has the size it does. b) Open Sine Wave Data.txt with a word processor. Offer a qualitative explanation for what you observe. Close Sine Wave Data.txt.

Upload: others

Post on 20-Apr-2022

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: LabVIEW HW #8

LabVIEW HW #8 Each problem begins with a suggested descriptive name (including the .vi extension) for the solution VI that you will write. Suggested icons for use in the VI are given at the end of some problem statements. The palette locations of the cited icons are not give explicitly: these icons can be found with the aid of QuickDrop. 1. BinaryStorage.vi Build a VI that stores the 2D array of Time and Displacement values

produced by WaveformSimulator in a binary-formatted file named SineWaveData.txt. Much of the program you will write is similar to SpreadsheetStorage(OpenWriteClose), so you may want to begin by opening that VI, and then using File>>SaveAs… to create a new VI, which you should save in your folder for this chapter. The front panel of your new VI should look as follows:

On the block diagram, implement the required three-step data storage process using the Open/Create/ReplaceFile, WritetoBinaryFile, and CloseFile icons. Wire a TrueConstant to Write to Binary File’s prependarrayorstringsize? input. This selection instructs LabVIEW to begin the binary file with an eight-byte header, which records the number of rows and columns into which the data are arranged. a) Run your VI with its front-panel controls programmed as shown above. Next, find the

icon (or name) for the binary-formatted SineWaveData.txt file that this has just created in your folder for this chapter, and determine its size (in kilobytes). If the details are not already shown, a file’s exact size can be found, using the Mac OS, by clicking on the icon (or name) and typing Command-I. In Windows, you do the same thing by right-clicking on the icon and selecting Properties. – Given the front-panel input values and binary formatting, explain why SineWaveData.txt has the size it does.

b) Open SineWaveData.txt with a word processor. Offer a qualitative explanation for what

you observe. Close SineWaveData.txt.

Page 2: LabVIEW HW #8

c) Run, instead, SpreadsheetStoragewith its front-panel controls programmed as shown above. Again, determine the size (in kilobytes) of the spreadsheet-formatted version of SineWaveData.txt. You should find that this file now is slightly larger than it was when formatted in binary (which is why binary can be preferred for large files). Given the front-panel input values, explain why SineWaveData.txt has the size it does under spreadsheet formatting.

d) By changing one parameter on the block diagram of SpreadsheetStorage, you can cause the spreadsheet-formatted version of SineWaveData.txt to be approximately twice as large as the binary-formatted version. Predict the block diagram change needed to result in this file-size doubling, then actually make the change and verify your prediction.

2. ReadBinary.vi Create a fresh, binary-formatted version of SineWaveData.txt, by running the binary-storage VI written in the problem above, but now using a (slightly different) choice of front-panel control values: here, reduce the Number of Samples to 100. [Again, in your binary-storage program, Write to Binary File’s prependarrayorstringsize? input should be wired to TRUE, so that an eight-byte informational header is inserted at the beginning of the resulting SineWaveData.txt file.] Your next task is to write a VI that reads the binary-encoded Time and Displacement data within SineWaveData.txt, and then plots these data on an XYGraph, and also displays them in a front-panel XY Cluster, as shown below.

For this program, the file path should be entered in the FilePathControl prior to running the VI; this task can be easily accomplished using the BrowseButton (the folder icon shown above, which is adjacent to the file path). Here is some guidance for writing your program: a) Retrieval of data from a file is a three-step (open, read, close) process. These three steps

are accomplished by configuring the appropriate File I/O icons as shown atop the next page. The eight-bit header at the beginning of the SineWaveData.txt file is used by

Page 3: LabVIEW HW #8

ReadFromBinaryFile to find out about the size of the data file to be read, as well as the required form (i.e., the number of rows and columns) of the data array.

b) An Empty2DDBLArrayConstant wired to the datatype input of ReadFromBinaryFile communicates the fact that the data is contained within a 2D array of double-precision floating-point numerics. That is, we’re doing this to specify the desired data type for the output data. To set it up, first place an ArrayConstant shell onto the block diagram. Then place a NumericConstant within the Array Constant shell, pop up on the Numeric Constant, and select Representation>>DBL. Finally, pop up on the Array Constant’s indexdisplay and select AddDimension. An Empty2DDBLArrayConstant icon has now been created, where the top and bottom index displays show the row and column index, respectively.

c) The 2D data array emanating from Read From Binary File’s dataoutput has two rows, where the first and second rows contain the Time and Displacement values, respectively (note that this 2D array has never been transposed, in contrast to the 2D array involved in the spreadsheet VIs that we wrote earlier). Each of these rows must be “sliced off” in preparation for plotting on an XYGraph. To accomplish this slicing operation, we use IndexArray with a NumericConstant of appropriate value wired to its top (row) index input. Leave the bottom (column) index input unwired (see the DIY Project in this chapter).

Perhaps all of this will make you appreciate Igor Pro a bit more. What you’ve needed to do in LabVIEW is quite similar to what is required with many other software packages and programming languages. In comparison, Igor Pro makes it much easier to import data that is embedded in (even fairly complex) text and headers. [Refer back to Section 8 of my Igor Pro tutorial for Data Import Basics.] – In short, I prefer different software tools for different tasks. No one package is “best” at everything.