Debugging Applications Built with LabVIEW Statechart Module
Overview
Any software application inevitably contains bugs during the development cycle. To correct these software defects, developers need access to powerful debugging tools they can use to be more efficient and dig into the detailed operations of their applications. With the NI LabVIEW Statechart Module, developers have tools and techniques to effectively debug their designs.
Table of Contents
Enabling Statechart Debugging
The first step to debugging statecharts is to ensure that debugging is enabled.
1. From the Project Explorer window, right-click the statechart and select Properties.

2. Under the Category pane, select Statechart Code Generation.

3. In the Debugging drop-down box, select Enabled. Debugging is available only when you are generating statecharts for desktop or real-time environments. To debug statecharts on field-programmable gate arrays (FPGAs) or embedded hardware, target the statechart for a desktop PC to ensure the logic is correct.

4. At this point, you may need to regenerate the statechart code.

Setting Breakpoints
As with debugging any LabVIEW application, you can use breakpoints and probes to find programming errors. You can set breakpoints in two ways: on the statechart diagram or within a state or transition.
The following steps show how to set a breakpoint on the statechart diagram.
1. Right-click the Run Statechart.vi linked to your statechart. Select Debug Statechart.

2. The statechart diagram now appears in a debugging window. Right-click a transition or a wire and select Set Breakpoint.

3. Use the Single Step buttons to navigate through the code.

You set breakpoints within states similarly to the way you set breakpoints in typical LabVIEW applications.
1. Open the statechart diagram.
2. Right-click on a state and select Configure State⦠Alternatively, right-click on a transition and select Configure Transitionā¦
3. Once configuring a state or transition, right-click a wire and select Set Breakpoint. Breakpoints and probes work identically within statechart code as they do within other LabVIEW applications.

Using highlight execution and statechart display data
Highlight execution can be a useful tool for determining which state your statechart is running in.
1. From your LabVIEW application, right-click the Run Statechart.vi and select Debug Statechart.
2. Click the Highlight Execution button. Run the VI. The state of execution is highlighted in each iteration.

3. Set the breakpoints again while the VI is running if you wish.

Another feature you may want to use while debugging statecharts is the watch values feature. This displays the output values, the internal state data of the statechart, and the internal trigger queue. You can access it through the following steps.
1. Run the caller VI.
2. Right-click the Run Statechart.vi and select Debug Statechart.
3. Click on the Open Statechart Data Display.


Additionally, you can create custom statechart display windows to allow more customization of the window.
1. From the Project Explorer window, expand the statechart.
2. Open CustomDataDisplay.vi.
3. Modify this watch window if you wish. You can customize it to include additional information that you are interested in observing during the execution of your program.
4. To access this watch window when the VI is running, debug the statechart and select Open Statechart Custom Display.


Summary
Statecharts provide a high level of abstraction for developing complex applications. This abstraction does not, however, come at the cost of being able to debug applications. LabVIEW provides techniques to efficiently debug statechart applications and eliminate bugs from software development.
For more information on the LabVIEW Statechart Module, visit ni.com/statechart.
Reader Comments | Submit a comment »
Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).
