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.
Temperature Logger.vi in the
C:\Exercises\LabVIEW Basics I
directory. You do not need to modify the front panel.
While Loop to
add space at the top for the file I/O operations.
![]() |
Open/Create/Replace File
VI, located on the Functions>>All
Functions>>File 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
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.
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.
Build Text Express
VI, located on the
Functions>>Output palette, on the block
diagram. This Express VI converts the inputs to one
string. The Configure Build Text dialog
box appears.
%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.
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.
OK button to close the
configuration dialog box.
Build Text Express
VI and select View As Icon
to conserve block diagram space.
Tab
constant and an End
of Line constant, located on the
Functions>>All Functions>>String
palette, on the block diagram.
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.
Close File
function, located on the Functions>>All
Functions>>File I/O palette, on the block
diagram. This function closes the file.
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.
Enter
File Name dialog box appears.
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.
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.
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.
![]() |
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.
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.
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.
Build Text Express VI and the
Write File function with the Format
Into File function.
"A full introductory course on programming with LabVIEW."