Main Content

Trace Simulink Model Elements in Generated Code

To verify the generated code, Simulink® PLC Coder™ provides bidirectional traceability between the Simulink model and the generated code. For traceability, you can use either method:

  • Code-to-model: In comment lines in the generated code, the generated code displays these hyperlinks:

    • Block/subsystems names

    • Line numbers

    • Operators

    To highlight the corresponding block or subsystem in the Simulink Editor, click the hyperlinks.

  • Model-to-code: You can select a single block of a model in the Simulink Editor and navigate to the corresponding generated code.

Code-To-Model Traceability

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

  1. Open the example GeneratingStructuredTextForAFeedForwardPIDControllerExample.

    openExample('plccoder/GeneratingStructuredTextForAFeedforwardPIDControllerExample')
  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_pid_feedforward.exp file.

  8. Click the hyperlink on line 73. In the model window, the corresponding Sum block is highlighted.

    Clicking on the hyperlink highlights the associated Simulink block in the model.

Model-to-Code Traceability

This example shows how to trace model elements to their corresponding generated code:

  1. Open the example GeneratingStructuredTextForAFeedForwardPIDControllerExample.

    openExample('plccoder/GeneratingStructuredTextForAFeedforwardPIDControllerExample')
  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. Select the highlighted Sum block in the image,and in the PLC Coder tab, click Navigate to Code. The generate code for the block is highlighted in the HTML code generation report.

    Click on highlighted block and corresponding line is highlighted in the generated code.

Related Topics