Saturday, September 25, 2010

Create String VI

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

  1. 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.
    Figure 1
    Figure 1 (buildstring.png)
    Use the following hints to build the front panel:
    • Right-click String 2 and select '\Codes Display from the shortcut menu. The text typed in String 2 is Volts 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 and Offset 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.

1.B) Block Diagram

  1. Build the block diagram shown in Figure 2.
    Figure 2
    Figure 2 (buildstringbd.png)
    1. BuildIcon.png Place the Build Text Express VI, located on the Functions>>Output palette, on the block diagram. This function converts Number to a string. The Build Text configuration dialog box appears.
      1. Type %Header% %Number% %Trailer% in the Text with Variables in Percents text box to create three variables. The variables appear in theConfigure Variables section.
      2. Select Number in the Variable section.
      3. In the Variable Properties section, select the Number option, set the Format to Format fractional number. Place a checkmark in the Use specified precision checkbox and set the Precision to 4. Leave the Header and Trailer variables in the default state.
      4. Click the OK button to close the dialog box.
    2. strglengthicon.png Place the String Length function, located on the Functions>>All Functions>>String palette, on the block diagram. This function returns the number of characters in Result.
    3. matchpaticon.png Place the Match Pattern function, located on the Functions>>All Functions>>String palette, on the block diagram. This function searches String 2 for a colon (:). Right-click the regular expression input, select Create>>Constant from the shortcut menu, type a colon (:), and press the <Enter> key on the numeric keypad. You also can click the Enter 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.
    4. scanfromstrgicon.png Place the Scan From String function, located on the Functions>>All Functions>>String palette, on the block diagram. This function converts the string after the colon to a numeric value.
    5. Complete the block diagram as shown in Figure 2.

1.C) Icon & Connector Pane

  1. 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
    Figure 3 (createstringconpane.png)
  2. Save the VI as Create String.vi in the C:\Exercises\LabVIEW Basics I directory. You will use this VI later in the course.

1.D) Run the VI

  1. Change the values of the front panel controls and run the VI. The VI concatenates HeaderNumber, and Trailer into Combined String and displays the string length. The VI also searches String 2 for a colon, converts the string following the colon to Number Out, and displays the index of the first character after the colon in Offset Past Match.
  2. Save and close the VI.

Content actions

GIVE FEEDBACK:

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...

Popular Projects

My Blog List

Give support

Give support
Encourage Me through Comments & Followers

Followers