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:
Open the example
GeneratingStructuredTextForAFeedForwardPIDControllerExample
.openExample('plccoder/GeneratingStructuredTextForAFeedforwardPIDControllerExample')
Open the PLC Coder app. Click the PLC Code tab.
Click Settings and navigate to the Code Generation pane.
To enable report generation, select Report > Generate traceability report.
Click OK.
Click Generate PLC Code to initiate code and report generation. The code generation report for the top model opens in a MATLAB® web browser.
In the left navigation pane, select the
plcdemo_pid_feedforward.exp
file.Click the hyperlink on line 73. In the model window, the corresponding
Sum
block is highlighted.
Model-to-Code Traceability
This example shows how to trace model elements to their corresponding generated code:
Open the example
GeneratingStructuredTextForAFeedForwardPIDControllerExample
.openExample('plccoder/GeneratingStructuredTextForAFeedforwardPIDControllerExample')
Open the PLC Coder app. Click the PLC Code tab.
Click Settings and navigate to the Code Generation pane.
To enable report generation, select Report > Generate traceability report.
Click OK.
Click Generate PLC Code to initiate code and report generation. The code generation report for the top model opens in a MATLAB web browser.
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.