Saturday, September 25, 2010

Temperature Logger VI

Summary: In this exercise, the objective is to save data to a file in a form that a spreadsheet or a word processor can access. Complete the following steps to build a VI that saves the time and current temperature to a data file.

EXERCISE 1

1.A) Block Diagram

  1. Open the Temperature Control VI 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 1. Resize the While Loop to add space at the top for the file I/O operations.
    Figure 1
    Figure 1 (templogbd.png)
    1. OpenFileIcon.png Place the Open/Create/Replace File VI, located on the Functions>>All Functions>>File I/O palette, on the block diagram. Right-click theprompt input, select Create Constant from the shortcut menu and type Enter File Name in the constant. 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.
    2. gettmdtstrgicon.png Place the Get Date/Time String function, located on the Functions>>All Functions>>Time & 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 Create>>Constant from the shortcut menu, and click the 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.
    3. BuildIcon.png Place the Build Text Express VI, located on the Functions>>Output palette, on the block diagram. This Express VI converts the inputs to one string. TheConfigure 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 configuration dialog box.
      4. Right-click the Build Text Express VI and select View As Icon to conserve block diagram space.
    4. tabicon.png eolicon.png Place a Tab constant and an End of Line constant, located on the Functions>>All Functions>>String palette, on the block diagram.
    5. WriteFileIcon.png Place the Write File function, located on the Functions>>All Functions>>File I/O palette, on the block diagram. This function writes to the file specified by refnum.
    6. CloseFileIcon.png Place the Close File function, located on the Functions>>All Functions>>File I/O palette, on the block diagram. This function closes the file.
    7. Error.png Place the Simple Error Handler VI, located on the Functions>>All Functions>>Time & Dialog palette, on the block diagram. This VI checks the error cluster and displays a dialog box if an error occurs.
    8. Complete the block diagram as shown in Figure 1.
  3. Save the VI. You will use this VI later in the course.

1.B) 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 file called temp.txt. The VI takes readings every half-second and saves the time and temperature data to a file until you click the Power switch. When the VI finishes, it closes the file.
  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 file in the word processing or spreadsheet application. The time appears in the first 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.

1.C) 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 thePower switch or an error occurs.
  1. Edit the block diagram as shown in Figure 2.
    Figure 2
    Figure 2 (templogoptbd.png)
    1. unbundle.png Place the Unbundle by Name function, located on the Functions>>All Functions>>Cluster palette, on the block diagram. This function reads the status output from the error cluster.
    2. not.png andicon.png Place the Not function and the And function, located on the Functions>>Arithmetic & Comparison>>Express Boolean palette, on the block diagram. 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 Create>>Constant.
  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.

1.D) 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.

Content actions

GIVE FEEDBACK:

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...

Popular Projects

My Blog List

Give support

Give support
Encourage Me through Comments & Followers

Followers