Summary: In this exercise, the objective is to use the Build String, Match Pattern, Scan from String, and String Length functions. Complete the following steps to build a VI that converts a numeric value to a string, concatenates the string to other strings to form a single output string, and determines the output string length. The VI also matches a pattern in a string and converts the remaining string to a numeric value.
EXERCISE 1
1.A) Front Panel
- Open a blank VI and build the front panel shown in Figure 1. Do not add labels for the comments; they are shown for informational purposes only.Use the following hints to build the front panel:
Figure 1 - Right-click
String 2
and select '\
'Codes Display
from the shortcut menu. The text typed inString 2
isVolts DC: +1.26E+1
. As shown using Codes display in the front panel above, there are two spaces after the colon (\s\s
), and the text ends with a carriage return (\r\n
). You may see only a\r
or a\n
for the carriage return. - Change
String Length
andOffset Past Match
to 32-bit signed integer (I32) representation. - After entering text in the controls, select
Operate>>Make Current Values Default
to set the text as the default values of these controls.
- Right-click
1.B) Block Diagram
- Build the block diagram shown in Figure 2.
Figure 2 - Place the
Build Text Express VI
, located on theFunctions>>Output
palette, on the block diagram. This function convertsNumber
to a string. The Build Text configuration dialog box appears.- Type
%Header% %Number% %Trailer%
in theText with Variables in Percents
text box to create three variables. The variables appear in theConfigure Variables
section. - Select
Number
in theVariable
section. - In the
Variable Properties
section, select theNumber
option, set theFormat
toFormat fractional number
. Place a checkmark in theUse specified precision
checkbox and set thePrecision
to4
. Leave theHeader
andTrailer
variables in the default state. - Click the
OK
button to close the dialog box.
- Type
- Place the
String Length
function, located on theFunctions>>All Functions>>String
palette, on the block diagram. This function returns the number of characters inResult
. - Place the
Match Pattern
function, located on theFunctions>>All Functions>>String
palette, on the block diagram. This function searchesString 2
for a colon (:
). Right-click theregular expression
input, selectCreate>>Constant
from the shortcut menu, type a colon (:
), and press the<Enter>
key on the numeric keypad. You also can click theEnter
button on the toolbar to complete the entry. Do not use the<Enter>
key on the main keyboard because in this case it adds the return character to the search expression. - Place the
Scan From String
function, located on theFunctions>>All Functions>>String
palette, on the block diagram. This function converts the string after the colon to a numeric value. - Complete the block diagram as shown in Figure 2.
- Place the
1.C) Icon & Connector Pane
- Display the front panel and create an icon and connector pane so you can use this VI as a subVI later in this course. Refer to the lesson on Modular Programming for more information about creating icons and connector panes.
Figure 3 - Save the VI as
Create String.vi
in theC:\Exercises\LabVIEW Basics I
directory. You will use this VI later in the course.
1.D) Run the VI
- Change the values of the front panel controls and run the VI. The VI concatenates
Header
,Number
, andTrailer
intoCombined String
and displays the string length. The VI also searchesString 2
for a colon, converts the string following the colon toNumber Out
, and displays the index of the first character after the colon inOffset Past Match
. - Save and close the VI.
No comments:
Post a Comment