To configure initialize and step entry-point function interfaces for a rate-based model programmatically, use these functions.
Function | Description |
---|---|
addArgConf | Add step function argument configuration information for Simulink® model port to model-specific C function prototype |
attachToModel | Attach model-specific C function prototype to loaded ERT-based Simulink model |
getArgCategory | Get step function argument category for Simulink model port from model-specific C function prototype |
getArgName | Get step function argument name for Simulink model port from model-specific C function prototype |
getArgPosition | Get step function argument position for Simulink model port from model-specific C function prototype |
getArgQualifier | Get step function argument type qualifier for Simulink model port from model-specific C function prototype |
getDefaultConf | Get default configuration information for model-specific C function prototype from Simulink model to which it is attached |
getFunctionName | Get function name from model-specific C function prototype |
getNumArgs | Get number of step function arguments from model-specific C function prototype |
getPreview | Get model-specific C function prototype code previews |
RTW.configSubsystemBuild | Open UI to configure C function prototype or C++ class interface for right-click build of specified subsystem |
RTW.getFunctionSpecification | Get handle to model-specific C function prototype object |
setArgCategory | Set step function argument category for Simulink model port in model-specific C function prototype |
setArgName | Set step function argument name for Simulink model port in model-specific C function prototype |
setArgPosition | Set step function argument position for Simulink model port in model-specific C function prototype |
setArgQualifier | Set step function argument type qualifier for Simulink model port in model-specific C function prototype |
setFunctionName | Set function name in model-specific C function prototype |
Typical uses of these functions include:
Create a function interface.
Modify an existing function interface.
Create a function interface, starting with default configuration information from a model.
Reset the model function interface to the default ERT function configuration.
Create a model-specific C function interface with
, where
obj
= RTW.ModelSpecificCPrototype
returns a handle to a new, empty
function interface.obj
Add argument configuration information for your model ports by using addArgConf
.
Attach the function interface to your loaded ERT-based model by using attachToModel
.
Save your model.
Generate code by using the rtwbuild
function.
Get the handle to an existing model-specific C function interface that is attached
to your loaded ERT-based model with
.
obj
= RTW.getFunctionSpecification
(modelName
)
is a character vector
specifying the name of a loaded ERT-based model.
modelName
returns a handle to a function
interface attached to the specified model.obj
You can use other functions on the returned handle only if the test
isa(obj,'RTW.ModelSpecificCPrototype')
returns 1. If the model does
not have a function interface configuration, the function returns []
.
If the function returns a handle to an object of type RTW.FcnDefault
,
you cannot modify the existing function interface.
Use the Get
and Set
functions to test and
reset such items as the function names, argument names, argument positions, argument
categories, and argument type qualifiers.
Save your model.
Generate code by using the rtwbuild
function.
Create a model-specific C function interface by using
, where
obj
= RTW.ModelSpecificCPrototype
returns a handle to a new, empty
function interface.obj
Attach the function interface to your loaded ERT-based model by using attachToModel
.
Get default configuration information from your model by using getDefaultConf
.
Use the Get
and Set
functions to test and
reset such items as the function names, argument names, argument positions, argument
categories, and argument type qualifiers.
Save your model.
Generate code by using the rtwbuild
function.
Create an object of the ERT default function interface. Reset the model function
interface and undo custom settings by calling the RTW.FcnDefault
method,
attachToModel
:
obj = RTW.FcnDefault; obj.attachToModel(model);
model
must be a loaded ERT-based model.Do not use the same model-specific C function interface object across multiple models. If you do, changes that you make to the step and initialize functions in one model are propagated to other models, which is usually not what you want.
This example MATLAB® script configures the model function interfaces for example model
rtwdemo_counter
.
%% Open the rtwdemo_counter model rtwdemo_counter %% Select ert.tlc as the System Target File for the model set_param(gcs,'SystemTargetFile','ert.tlc') %% Create a model-specific C function prototype a=RTW.ModelSpecificCPrototype %% Add argument configuration information for Input and Output ports addArgConf(a,'Input','Pointer','inputArg','const *') addArgConf(a,'Output','Pointer','outputArg','none') %% Attach the model-specific C function prototype to the model attachToModel(a,gcs) %% Rename the initialization function setFunctionName(a,'InitFunction','init') %% Rename the step function and change some argument attributes setFunctionName(a,'StepFunction','step') setArgPosition(a,'Output',1) setArgCategory(a,'Input','Value') setArgName(a,'Input','InputArg') setArgQualifier(a,'Input','none') %% Generate code and build rtwbuild(gcs)