Main Content

Trace Stateflow Elements in Generated Code

To verify the generated code for your Stateflow® elements, you can trace Stateflow elements in your model to the generated code by using these types of navigation:

  • Code-to-model: Trace generated code back to the model by clicking hyperlinks in the comments or the hyperlinked line numbers, which highlights the corresponding model element in the Simulink Editor.

  • Model-to-code: Trace the model elements in the Simulink Editor to corresponding lines in generated code by right-clicking the model element and navigating to the generated code. This traceability is not supported for some Stateflow elements in Code view.

Inline Traceability for Stateflow Elements

Inline traceability refers to the line-level traceability available in the generated code. You can click the hyperlinked line numbers to trace the corresponding Stateflow elements.

This example shows how to use hyperlinks for tracing code-to-Stateflow elements:

  1. Open the example AirportConveyorBeltControlSystemExample.

    openExample('plccoder/AirportConveyorBeltControlSystemExample')
  2. Open the PLC Coder app. Click the PLC Code tab.

  3. Click Settings and navigate to the Code Generation pane.

  4. To enable report generation, select Report > Generate traceability report.

  5. Click OK.

  6. Click Generate PLC Code to initiate code and report generation. The code generation report for the top model opens in a MATLAB® web browser.

  7. In the left navigation pane, select the plcdemo_airport_conveyor.exp file.

  8. Click the hyperlink on line 65. In the Stateflow chart, the corresponding Stop_F1 state is highlighted.

    Click on the hyperlink to highlight the associated state in the Stateflow chart.

Trace States and Transitions to Code

This example shows how to trace Stateflow states and transitions to the generated code:

  1. Open the example AirportConveyorBeltControlSystemExample.

    openExample('plccoder/AirportConveyorBeltControlSystemExample')
  2. Open the PLC Coder app. Click the PLC Code tab.

  3. Click Settings and navigate to the Code Generation pane.

  4. To enable report generation, select Report > Generate traceability report.

  5. Click OK.

  6. Click Generate PLC Code to initiate code and report generation. The code generation report for the top model opens in a MATLAB web browser.

  7. In the Controller subsystem, Control block, select the Run_F1 state. In the PLC Coder tab, click Navigate to Code. The generated code for the state is highlighted in the HTML code generation report.

    Click on highlighted state and corresponding lines are highlighted in the generated code.

Related Topics