Create Data Objects for Code Generation with Data Object Wizard
To specify code generation options for signal lines, block parameters, and states in a model, you can use data objects that you store in a workspace or data dictionary. For basic information about data objects, see Data Objects.
You can use the Data Object Wizard to create data objects for:
New or existing models that do not use data objects.
Existing models to which you have added signal lines or blocks.
This example shows how to use the Data Object Wizard to create and configure data objects for code generation from the built-in package
Create Data Objects
Open the example model
The model creates numeric variables in the base workspace. Blocks in the model use these variables to set parameter values (such as the Gain parameter of a Gain block). Some of the signals and block states in the model have explicit names, such as
On the Modeling tab, under Design, click Data Object Wizard.
In the Data Object Wizard, click Find. The wizard proposes the creation of
Simulink.Parameter objects to replace the variables and the creation of
Simulink.Signal objects to represent the signals and states.
The wizard finds only signals, parameters, data stores, and states whose storage class is set to
Auto. For example, if you use the Signal Properties dialog box to specify a storage class other than
Auto for a signal line, the wizard does not propose a data object.
Click Select All.
Click Create. The data objects appear in the base workspace.
For detailed information about the options that you can choose in the Data Object Wizard, see Create Data Objects for a Model Using Data Object Wizard.
Set Storage Class for Data Objects
Storage classes determine how the generated code uses variables to represent signals, parameters, and states. For data objects from the built-in package
Simulink, the default storage class is
Auto. To specify storage classes for the new data objects, use the Model Explorer.
Open the Model Explorer.
In the Model Hierarchy pane, select Base Workspace.
In the Contents pane, from the drop-down list Column View, select
Select all of the new data objects. For example, select the object
input1, hold Shift, and select the object
Set the property
StorageClass for all of the data objects to
ExportToFile. To change the storage class for all of the selected objects, in the StorageClass column, click any of the objects. In the drop-down list, select
ExportToFile. The change that you make propagates to all of the selected objects.
HeaderFile property for all of the objects as
In the model, set Configuration Parameters > Code Generation > System target file to
ert.tlc. With this setting, the code generator honors storage classes such as
Generate and Inspect Code
Generate code from the model.
### Starting build procedure for: rtwdemo_configinterface tf = logical 0 tf = logical 0 ### Successful completion of code generation for: rtwdemo_configinterface Build Summary Top model targets built: Model Action Rebuild Reason ============================================================================================ rtwdemo_configinterface Code generated. Code generation information file does not exist. 1 of 1 models built (0 models already up to date) Build duration: 0h 0m 37.772s
In the code generation report, view the generated file
myExportedHdrFile.h. The file contains
extern declarations for the global variables that correspond to the data objects.
/* Exported data declaration */ /* Declaration for custom storage class: ExportToFile */ extern real_T X;
View the file
rtwdemo_configinterface.c. The file contains the definitions for the global variables. The code assigns numeric values for the variables that correspond to parameter objects.
/* Exported data definition */ /* Definition for custom storage class: ExportToFile */ real_T X;