Exercise 9.11.1
9.11.1 Block Diagram
1. Open the Temperature Control VI (Section 8.4) and save it as Temperature Logger.vi in the C:\Exercises\LabVIEW Basics I directory. You do not need to modify the front panel.
2. Open and modify the block diagram as shown in Figure 9.24. Resize the While Loop to add space at the top for the le I/O operations.
Figure 9.24
a. Place the Open/Create/Replace File VI, located on the FunctionsAll FunctionsFile I/O palette, on the block diagram. Right-click the prompt input, select Create Constant from the shortcut menu and type Enter File Name in the con-stant. Right-click the function input, select Create Constant from the shortcut menu, and click the constant with the Operating tool to select create or replace.
b. Place the Get Date/Time String function, located on the FunctionsAll FunctionsTime & Dialog palette, on the block diagram. This function returns the time, in string format, when the temperature measurement was taken. Right-click the want seconds? input, select CreateConstant from the shortcut menu, and click the
11This content is available online at <http://cnx.org/content/m12262/1.2/>.
constant with the Operating tool to change the constant from False to True. The True Boolean constant sets the function to include seconds in the string.
c. Place the Build Text Express VI, located on the FunctionsOutput palette, on the block diagram. This Express VI converts the inputs to one string. The Configure Build Text dialog box appears.
1. Type %tab%%temp%%end% in the Text with Variables in Percents text box to set up three variables; one for the tab constant, one for the temperature and one for the end of line constant. Because time uses the Beginning Text input of the Build Text Express VI, it does not need a variable.
2. Select temp in the Configure Variables section. Select the Number option, and a format of Format fractional number. The tab and end variables do not need to be formatted. You can leave them in the default state.
3. Click the OK button to close the conguration dialog box.
4. Right-click the Build Text Express VI and select View As Icon to conserve block diagram space.
d. Place a Tab constant and an End of Line constant, located on the FunctionsAll FunctionsString palette, on the block diagram.
e. Place the Write File function, located on the FunctionsAll FunctionsFile I/O palette, on the block diagram. This function writes to the
le specied by refnum.
f. Place the Close File function, located on the FunctionsAll FunctionsFile I/O palette, on the block diagram. This function closes the
le.
g. Place the Simple Error Handler VI, located on the FunctionsAll FunctionsTime & Dialog palette, on the block diagram. This VI checks the error cluster and displays a dialog box if an error occurs.
h. Complete the block diagram as shown in Figure 9.24.
3. Save the VI. You will use this VI later in the course.
9.11.2 Run the VI
1. Display the front panel and run the VI. The Enter File Name dialog box appears.
2. Type temp.txt and click the Save or OK button. The VI creates a le called temp.txt. The VI takes readings every half-second and saves the time and temperature data to a le until you click the Power switch. When the VI nishes, it closes the le.
3. Open a word processor or spreadsheet application, such as (Windows) Notepad or WordPad, (Mac OS) SimpleText, or (UNIX) Text Editor.
4. Open the temp.txt le in the word processing or spreadsheet application. The time appears in the rst column, and the temperature data appears in the second column.
5. Exit the word processor or spreadsheet application and return to LabVIEW.
6. If time permits, complete the optional steps. Otherwise, close the VI.
181
9.11.3 Optional
When using error handling in a VI, the While Loop should stop executing when an error occurs.
Complete the following steps to modify the VI so it stops when the user clicks the Power switch or an error occurs.
1. Edit the block diagram as shown in Figure 9.25.
Figure 9.25
a. Place the Unbundle by Name function, located on the FunctionsAll FunctionsCluster palette, on the block diagram. This function reads the status output from the error cluster.
b. Place the Not function and the And function, located on the FunctionsArithmetic & ComparisonExpress Boolean palette, on the block di-agram. These functions set the conditional terminal to continue while Power is True and no error occurs.
2. Save and run the VI.
3. Test the error handling by deleting the refnum wire between the Write File function and the left border of the While Loop. Right-click the refnum input of Write File and select CreateConstant.
4. Run the VI again. The VI should wait for a path, then stop immediately with an error. If error handling was not included in this VI, the VI would not report the error until the user stopped the VI.
5. If time permits, complete the challenge steps. Otherwise, close the VI. Do not save changes.
9.11.4 Challenge
1. Replace the Build Text Express VI and the Write File function with the Format Into File function.
2. Run the VI.
3. Close the VI. Do not save changes.