Generate Structured Text Code For Simulink Data Dictionary Defined Model Parameters
Simulink Data Dictionary (SLDD) is the preferred Model-Based-Design (MBD) data modeling and management tool. SLDD provides advantages such as data separation, logical partitioning, traceability, and so on. To achieve traceability between your generated code and model, and for code reusability and model and data sharing, use SLDD
Learning Objectives
In this tutorial, you learn how to:
Open the
plcdemo_tunable_params
model and migrate the model to use Simulink Data Dictionary (SLDD).Generate code for the model.
Requirements
Base workspace variable definition must match the variable definition in the SLDD file. If there is a mismatch, Simulink® PLC Coder™ displays an error during the code generation process.
If your model has a Data Store Memory(DSM) object, you must have a matching
Simulink.Signal
object in the SLDD file.
Workflow
Migrate the plcdemo_tunable_params
model base workspace variables to
an SLDD file for code generation:
Note
Copy the plcdemo_tunable_params
model to your current working
directory prior to starting the workflow.
Open the
plcdemo_tunable_params
model. To open the model, enter:openExample('plcdemo_tunable_params');
From the Simulink Editor Modeling tab, click Model Explorer.
Under the Model Hierarchy pane, click Base Workspace . The Contents pane displays the base workspace variables.
Right-click
K1
,K2
, andK3
. Choose theConvert to parameter object
option to convert them to theSimulink.Parameter
type.Right-click
plcdemo_tunable_params
, and then selectProperties
.Select the External Data tab.
Click New. Enter the file name as
plcdemo_tunable_params
.Click the Migrate data button. Then click Apply in response to the
Link Model to Data Dictionary
message and Migrate in response to theMigrate Data
message.Click OK.
To open the dictionary, in the Simulink Editor, click the model data badge in the bottom left corner, then click the External Data link. To inspect the contents of the dictionary, in the Model Explorer Model Hierarchy pane, under the External Data node, expand the dictionary node.
To generate code for the model, see Generate and Examine Structured Text Code.