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 2and select '\'Codes Displayfrom the shortcut menu. The text typed inString 2isVolts 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\ror a\nfor the carriage return. - Change
String LengthandOffset Past Matchto 32-bit signed integer (I32) representation. - After entering text in the controls, select
Operate>>Make Current Values Defaultto 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>>Outputpalette, on the block diagram. This function convertsNumberto a string. The Build Text configuration dialog box appears.- Type
%Header% %Number% %Trailer%in theText with Variables in Percentstext box to create three variables. The variables appear in theConfigure Variablessection. - Select
Numberin theVariablesection. - In the
Variable Propertiessection, select theNumberoption, set theFormattoFormat fractional number. Place a checkmark in theUse specified precisioncheckbox and set thePrecisionto4. Leave theHeaderandTrailervariables in the default state. - Click the
OKbutton to close the dialog box.
- Type
Place the
String Lengthfunction, located on theFunctions>>All Functions>>Stringpalette, on the block diagram. This function returns the number of characters inResult.Place the
Match Patternfunction, located on theFunctions>>All Functions>>Stringpalette, on the block diagram. This function searchesString 2for a colon (:). Right-click theregular expressioninput, selectCreate>>Constantfrom the shortcut menu, type a colon (:), and press the<Enter>key on the numeric keypad. You also can click theEnterbutton 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 Stringfunction, located on theFunctions>>All Functions>>Stringpalette, 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.
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.viin theC:\Exercises\LabVIEW Basics Idirectory. 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, andTrailerintoCombined Stringand displays the string length. The VI also searchesString 2for 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