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.vi
in theC:\Exercises\LabVIEW Basics I
directory. You do not need to modify the front panel. - 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 - Place the
Open/Create/Replace File
VI, located on theFunctions>>All Functions>>File I/O
palette, on the block diagram. Right-click theprompt
input, selectCreate Constant
from the shortcut menu and typeEnter File Name
in the constant. Right-click thefunction
input, selectCreate Constant
from the shortcut menu, and click the constant with theOperating
tool to selectcreate or replace
. - Place the
Get Date/Time String
function, located on theFunctions>>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 thewant seconds?
input, selectCreate>>Constant
from the shortcut menu, and click the constant with the Operating tool to change the constant fromFalse
toTrue
. TheTrue
Boolean constant sets the function to include seconds in the string. - Place the
Build Text
Express VI, located on theFunctions>>Output
palette, on the block diagram. This Express VI converts the inputs to one string. TheConfigure Build Text
dialog box appears.- Type
%tab%%temp%%end%
in theText 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 theBeginning Text
input of theBuild Text
Express VI, it does not need a variable. - Select
temp
in theConfigure Variables
section. Select theNumber
option, and a format ofFormat fractional number
. Thetab
andend
variables do not need to be formatted. You can leave them in the default state. - Click the
OK
button to close the configuration dialog box. - Right-click the
Build Text Express VI
and selectView As Icon
to conserve block diagram space.
- Type
- Place a
Tab constant
and anEnd of Line constant
, located on theFunctions>>All Functions>>String
palette, on the block diagram. - Place the
Write File
function, located on theFunctions>>All Functions>>File I/O
palette, on the block diagram. This function writes to the file specified byrefnum
. - Place the
Close File
function, located on theFunctions>>All Functions>>File I/O
palette, on the block diagram. This function closes the file. - Place the
Simple Error Handler
VI, located on theFunctions>>All Functions>>Time & Dialog
palette, 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.
- Place the
- 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 Name
dialog box appears. - Type
temp.txt
and click theSave
orOK
button. 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 thePower
switch. 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.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. - 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 Name
function, located on theFunctions>>All Functions>>Cluster
palette, on the block diagram. This function reads the status output from the error cluster. - Place the
Not
function and theAnd
function, located on theFunctions>>Arithmetic & Comparison>>Express Boolean
palette, on the block diagram. These functions set the conditional terminal to continue whilePower
isTrue
and no error occurs.
- Place the
- Save and run the VI.
- Test the error handling by deleting the
refnum
wire between theWrite File
function and the left border of theWhile Loop
. Right-click therefnum
input ofWrite File
and 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 VI
and theWrite File
function with theFormat Into File
function. - Run the VI.
- Close the VI. Do not save changes.
No comments:
Post a Comment