Company Events Academic Community Support Solutions Products & Services Contact NI MyNI

Statechart Module Tutorial Part 3: Defining Statechart Data Types

LabVIEW 2010 Statechart Module Help

Edition Date: June 2013

Part Number: 372103F-01

»View Product Info
Download Help (Windows Only)

In Part 2 of this tutorial, you created the beginnings of a statechart and learned how to find errors on the statechart diagram. In Part 3 of this tutorial, you define types of data upon which the statechart acts.

  You can complete these exercises in approximately 20 minutes.
Note  You can refer to the labview\examples\Statechart\Tutorial\Synchronous\Getting Started 3.lvsc for a completed version of the statechart you create in this part of the tutorial.

Defining the Type of Output Data

If you want the statechart to modify data, you first must define the type of data. This process involves creating the controls and/or indicators that represent the statechart data.

Complete the following steps to define the statechart output data. In Part 4 of this tutorial, you configure the statechart to modify this data.

  1. Open the My Getting Started.lvsc statechart you constructed in Part 2 of this tutorial. You also can navigate to the labview\examples\Statechart\Tutorial\Synchronous directory and open Getting Started 2.lvsc for a completed statechart from Part 2 of this tutorial.
  2. In the Project Explorer window, double-click the Outputs.ctl item. LabVIEW displays the Control Editor window for this type definition.
  3. Notice the numeric control Numeric inside the Outputs cluster. Right-click this control and select Change to Indicator from the shortcut menu to change this control to a numeric indicator.
  4. Right-click the Numeric indicator and select Replace»Express»Text Indicators»String Indicator from the shortcut menu. This action replaces the numeric indicator with a string indicator.
  5. Double-click the String label and enter Time Display as the new label.
  6. Press the <Ctrl-S> keys to save this type definition.
  7. Close the Control Editor window to return to the Project Explorer window.

Defining the Type of State Data

You also define state data, which differs from output data. State data is accessible only from the statechart, whereas output data also is accessible from a VI that calls the statechart. Use state data to define data types that other VIs do not need to access.

Complete the following steps to define the statechart state data. You modify this data in Part 4 of this tutorial.

  1. In the Project Explorer window, double-click the StateData.ctl item.
  2. Double-click the Data label and enter Timer as the new label.
  3. Right-click the Timer control and select Representation»Unsigned Long from the shortcut menu.
  4. Expand the StateData cluster by dragging the bottom-right corner down and to the right.
  5. Move the cursor over the border of the Timer control until the cursor changes to the Positioning tool.
  6. Press the <Ctrl> key and click and drag the cursor below the Timer numeric control to create a copy of the control.
  7. Label this new control Clock.
  8. Press the <Ctrl-S> keys to save this type definition.
  9. Close the Control Editor window to return to the Project Explorer window.

Generating Code for the Statechart

The next step is generating code for the statechart. This code is contained in a single Run Statechart function that you place on the block diagram of the caller VI. Complete the following steps to generate code for this statechart.

  1. Display the Statechart Editor window for the My Getting Started Statechart.lvsc statechart that you constructed in Part 2 of this tutorial. You can display the Statechart Editor window by double-clicking the Diagram.vi item in the Project Explorer window for the statechart.
  2. Click the Generate Code button , which is located on the toolbar of this window. LabVIEW displays a dialog box indicating the status of the code generation progress.
Note  You also can generate code by right-clicking the .lvsc file in the Project Explorer window and selecting Generate Code from the shortcut menu.

Configuring the Caller VI

The next step is configuring a caller VI to execute and send triggers to the statechart. This VI contains the Run Statechart function that you must link to the statechart. Complete the following steps to link the Run Statechart function to the statechart.

  1. In the Statechart Editor window, select File»Open.
  2. Browse to the labview\examples\Statechart\Tutorial\Synchronous directory and double-click Getting Started Caller VI (Unlinked).vi.
  3. Display the block diagram of this VI. All the wires are broken because the Run Statechart function is not linked to a statechart.
  4. Locate the Run Statechart function. This function executes the statechart when you run the caller VI.
  5. Right-click this function and select Link to Statechart from the shortcut menu. LabVIEW prompts you for a .lvsc file to which the function can link.
  6. Click the Browse button and navigate to the directory that contains the My Getting Started Statechart.lvsc file.
  7. Click the OK button. Notice the wires to and from this function now are intact.
  8. Select File»Save As and save the caller VI as Getting Started Caller VI Linked.vi.
  9. Press the <Ctrl-R> keys to run the caller VI. Click the front panel buttons and notice the Time Display indicator does not change value. You configure the statechart to change the value of the Time Display indicator in Part 4 of this tutorial.
  10. Click the Quit button to stop the VI.
  11. Save and close the caller VI.
Note  The inputs and triggers wired to the Run Statechart function are not linked to the My Getting Started Statechart.lvsc file. The Getting Started Caller VI (Unlinked).vi does not reflect any changes you make to the inputs or triggers in the My Getting Started Statechart.lvsc code.

Summary

In this tutorial, you learned about the following tasks:

  • Defining types of data that the statechart can modify.
  • Generating code for the statechart.
  • Linking the Run Statechart function to a statechart.

Where to Go from Here

In Part 4 of this tutorial, you add regions and substates to the statechart.


 

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
Add Comments 1 2 3 4 5 submit