Summary: In this exercise, the objective is to write data to a file. Complete the following steps to build a VI that concatenates a message string, a numeric value, and a unit string to a file. In another exercise, you will build a VI that reads the file and displays its contents.
EXERCISE 1
1.A) Front Panel
- Open a blank VI and build the front panel shown in Figure 1.
Figure 1 - Place a path indicator located on the
Controls>>Text Indicators
palette on the front panel. This indicator displays the path for the data file you create. - Right-click the
String to Write
control and selectVisible Items>>Scrollbar
from the shortcut menu to display a scrollbar.
- Place a path indicator located on the
1.B) Block Diagram
- Build the block diagram shown in Figure 2.
Figure 2 - Place the
Create String VI
from the previous exercise on the block diagram. SelectFunctions>>All Functions>>Select a VI
and navigate toC:\Exercises\LabVIEW Basics I\Create String.vi
. This subVI concatenates the three input strings to one combined string. - Place the
Open/Create/Replace File
VI, located on theFunctions>>All Functions>>File I/O
palette, on the block diagram. This VI displays a dialog box to open or create a file. Right-click theprompt
input, selectCreate>>Constant
from the shortcut menu, and typeEnter Filename
in the constant. When the VI runs, a file navigation dialog box appears withEnter Filename
as the title of the window. Right-click thefunction
input, selectCreate>>Constant
from the shortcut menu, and click the constant with theOperating
tool to selectcreate or replace
. - Place the
Write File
function, located on theFunctions>>All Functions>>File I/O
palette, on the block diagram. This function writes the concatenated strings to the file. - 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 function checks the error cluster and displays a dialog box if an error occurs. - Complete the block diagram as shown in Figure 2.
- Place the
- Save the VI as
File Writer.vi
in theC:\Exercises\LabVIEW Basics I
directory.
1.C) Run the VI
- Enter values in the front panel controls and run the VI. An
Enter Filename
dialog box appears. - Type
demofile.txt
and click theSave
orOK
button to save the file. The VI writes theString to Write
,Numeric to Write
, andUnit to Write
values to the file. - Close the VI.
No comments:
Post a Comment