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
- Open the Temperature Control VI and save it as
Temperature Logger.viin theC:\Exercises\LabVIEW Basics Idirectory. You do not need to modify the front panel. - Open and modify the block diagram as shown in Figure 1. Resize the
While Loopto add space at the top for the file I/O operations.Figure 1 Place the
Open/Create/Replace FileVI, located on theFunctions>>All Functions>>File I/Opalette, on the block diagram. Right-click thepromptinput, selectCreate Constantfrom the shortcut menu and typeEnter File Namein the constant. Right-click thefunctioninput, selectCreate Constantfrom the shortcut menu, and click the constant with theOperatingtool to selectcreate or replace.Place the
Get Date/Time Stringfunction, located on theFunctions>>All Functions>>Time & Dialogpalette, on the block diagram. This function returns the time, in string format, when the temperature measurement was taken. Right-click thewant seconds?input, selectCreate>>Constantfrom the shortcut menu, and click the constant with the Operating tool to change the constant fromFalsetoTrue. TheTrueBoolean constant sets the function to include seconds in the string.Place the
Build TextExpress VI, located on theFunctions>>Outputpalette, on the block diagram. This Express VI converts the inputs to one string. TheConfigure Build Textdialog box appears.- Type
%tab%%temp%%end%in theText with Variables in Percentstext 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 theBeginning Textinput of theBuild TextExpress VI, it does not need a variable. - Select
tempin theConfigure Variablessection. Select theNumberoption, and a format ofFormat fractional number. Thetabandendvariables do not need to be formatted. You can leave them in the default state. - Click the
OKbutton to close the configuration dialog box. - Right-click the
Build Text Express VIand selectView As Iconto conserve block diagram space.
- Type
Place a
Tab constantand anEnd of Line constant, located on theFunctions>>All Functions>>Stringpalette, on the block diagram.Place the
Write Filefunction, located on theFunctions>>All Functions>>File I/Opalette, on the block diagram. This function writes to the file specified byrefnum.Place the
Close Filefunction, located on theFunctions>>All Functions>>File I/Opalette, on the block diagram. This function closes the file.Place the
Simple Error HandlerVI, located on theFunctions>>All Functions>>Time & Dialogpalette, on the block diagram. This VI checks the error cluster and displays a dialog box if an error occurs.- Complete the block diagram as shown in Figure 1.
- Save the VI. You will use this VI later in the course.
1.B) Run the VI
- Display the front panel and run the VI. The
Enter File Namedialog box appears. - Type
temp.txtand click theSaveorOKbutton. The VI creates a file calledtemp.txt. The VI takes readings every half-second and saves the time and temperature data to a file until you click thePowerswitch. When the VI finishes, it closes the file. - Open a word processor or spreadsheet application, such as (Windows) Notepad or WordPad, (Mac OS) SimpleText, or (UNIX) Text Editor.
- Open the
temp.txtfile in the word processing or spreadsheet application. The time appears in the first column, and the temperature data appears in the second column. - Exit the word processor or spreadsheet application and return to LabVIEW.
- 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.- Edit the block diagram as shown in Figure 2.
Figure 2 Place the
Unbundle by Namefunction, located on theFunctions>>All Functions>>Clusterpalette, on the block diagram. This function reads the status output from the error cluster.Place the
Notfunction and theAndfunction, located on theFunctions>>Arithmetic & Comparison>>Express Booleanpalette, on the block diagram. These functions set the conditional terminal to continue whilePowerisTrueand no error occurs.
- Save and run the VI.
- Test the error handling by deleting the
refnumwire between theWrite Filefunction and the left border of theWhile Loop. Right-click therefnuminput ofWrite Fileand selectCreate>>Constant. - 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.
- If time permits, complete the challenge steps. Otherwise, close the VI. Do not save changes.
1.D) Challenge
- Replace the
Build Text Express VIand theWrite Filefunction with theFormat Into Filefunction. - Run the VI.
- Close the VI. Do not save changes.
No comments:
Post a Comment