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

Statechart Module Tutorial Part 1: Examining a Statechart

LabVIEW 2010 Statechart Module Help

Edition Date: June 2013

Part Number: 372103F-01

»View Product Info
Download Help (Windows Only)

In Part 1 of this tutorial, you examine how LabVIEW executes a statechart and debug the statechart.

  You can complete these exercises in approximately 25 minutes.

Running the Caller VI

The first step is opening and running the caller VI, which is the VI that executes the statechart. In this example, the caller VI shows a simulated watch with stopwatch capabilities. Complete the following steps to open and run this VI.

  1. Launch LabVIEW and display the Getting Started window.
  2. Select File»Open.
  3. Browse to the labview\examples\Statechart\Tutorial\Synchronous directory and double-click Getting Started Caller VI.vi.
  4. Display the front panel of the VI and click the Run button , located on the LabVIEW toolbar.
  5. Click the Insert Battery button. Notice the watch displays the current time.
  6. Click the Mode front panel button on the left side of the watch face. Notice the watch displays 00:00:00.0.
  7. Click the Start front panel button and notice the number displayed on the watch increments. Continue pressing buttons on the front panel and notice the changes in the numbers the watch displays.
  8. Click the Quit front panel button to stop the VI.

Examining the Caller VI

The next step is examining the caller VI. Press the <Ctrl-E> keys to view the block diagram of this VI.

The statechart is synchronous. Synchronous statecharts execute one iteration at the moment the Run Statechart function receives all input data.

Launching the Statechart Editor Window

The next step is launching the Statechart Editor window. This window displays the statechart diagram that you executed in the Running the Caller VI section of this tutorial. The statechart diagram is where you place the statechart objects that comprise a statechart.

Complete the following steps to launch the Statechart Editor window.

  1. Locate the Run Statechart function on the block diagram.
  2. Right-click this function and select View»Statechart Diagram from the shortcut menu to open the Statechart Editor window, which contains the statechart diagram.

Examining the Statechart

The statechart diagram resembles the following image:

When you ran the caller VI, the statechart located the Initial pseudostate. The transition (1) that exits this pseudostate specifies which state the statechart enters first. Therefore, the statechart executed the Watch Dead state (2) first. The statechart then waited for the caller VI to send a trigger, which happened when you clicked the Insert Battery front panel button. When you clicked this button, the caller VI sent a trigger to the statechart. This trigger caused the statechart to take the transition (3) to the Watch Running state and wait for another trigger, which you sent by clicking the Mode front panel button. Each state is configured to update the text of the Time Display indicator.

Note  Because transitions go in only one direction, notice that the transition that enters the Watch Running state is separate from the transition that exits the Watch Running state.

The arrow-shaped objects in the middle of each transition are the transition nodes. The following image shows a transition node.

The blue rectangles on these nodes indicate certain information about the transition. You will create and configure a transition in Part 2 of this tutorial.

Highlighting Statechart Execution

The next step is highlighting the execution of the statechart. Complete the following steps to highlight the execution of the statechart.

  1. Run the caller VI and display the block diagram.
  2. Right-click the Run Statechart function and select Debug Statechart from the shortcut menu to display the statechart in the Statechart Debugging window.
  3. Click the Highlight Execution button , located on the toolbar of the Statechart Debugging window, to enable statechart execution highlighting.
  4. Display the front panel of the caller VI and click the Insert Battery front panel button. Watch LabVIEW highlight the transition from the Watch Dead state to the Watch Running state.
  5. Click the Mode front panel button and watch the statechart move from the Clock substate to the Timer substate.
  6. Click the Start front panel button. Watch the statechart move from the Idle substate to the Running substate.
  7. Click the Quit front panel button. Watch the statechart move to the Terminal pseudostate and stop the execution of the statechart.
  8. Click the Highlight Execution button to disable execution highlighting.

Watching Statechart Data

The next step is running the caller VI and watching how the statechart increments the Time Display indicator. Complete the following steps to view data in the Statechart Data Display window.

  1. In the Statechart Debugging window, click the Open Statechart Data Display button , located on the toolbar of this window. LabVIEW displays the Statechart Data Display window. This window shows the values of the state data, output data, and internal trigger queue.
  2. Run the caller VI.
  3. Click the Insert Battery button. The watch displays the current time.
  4. Look at the Statechart Data Display window. Notice the Time Display indicator displays the same value as the front panel indicator of the caller VI.
  5. Click the Mode front panel button. The watch displays 00.00.00.0, which means the statechart is in the Timer substate. Notice the Time Display indicator in the Statechart Data Display window also displays 00.00.00.0.
  6. Click the Mode front panel button again and notice the value of the Time Display indicator in the Statechart Data Display window displays the current time.
  7. Close the Statechart Data Display window.

Viewing the Execution of a Transition Guard

The next step is viewing the execution of a transition guard. A transition guard is LabVIEW block diagram code that determines whether the statechart takes the associated transition. The guard code must return either TRUE or FALSE. If the guard returns TRUE, the statechart takes the transition. If the guard returns FALSE, the statechart does not take the transition. Complete the following steps to view the execution of a guard.

  1. In the Statechart Debugging window, locate the guarded transition node from the Idle substate to the Running substate.
  2. Right-click this transition node and select Guard. LabVIEW displays the block diagram of the VI that corresponds to the guard.
  3. Move the cursor over the green wire that exits the IsIn? function.
  4. Click this wire to place a probe on this wire.
  5. Click the Start front panel button. The probe shows that the guard code sends FALSE to the Execute? indicator. This FALSE value means the statechart does not take the transition to the Running state.
  6. Click the Mode front panel button to transition the statechart to the Timer substate.
  7. Click the Start front panel button again. The IsIn function sends TRUE to the Execute? indicator, which means the guard returns TRUE. The statechart then takes the transition to the Running substate.
  8. Click the Quit front panel button to stop the statechart and the caller VI.
  9. Close all windows.

Summary

In this tutorial, you learned about the following tasks:

  • Opening and running a caller VI.
  • Examining a statechart.
  • Highlighting the execution of a statechart.
  • Displaying the statechart data during execution.
  • Viewing the execution of a transition guard.

Where to Go from Here

In Part 2 of this tutorial, you create and configure a new statechart.


 

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