MATLAB: How to access the signals and parameters of referenced models using C-API in Real-Time Workshop 6.2 (R14SP2)

simulink coder

I want to be able to access the signals and parameters of referenced models using C-API.

Best Answer

The ability to access the signals and parameters of referenced models using C-API is not available in Real-Time Workshop 6.2 (R14SP2).
To work around this issue:
For a top model (e.g. mymodel.mdl) and all its sub models (e.g. mymodel_refmod.mdl),
1) Open the Configuration Parameters > Data Import/Export pane.
2) Select the checkbox “States“.
3) Provide an appropriate variable for storing states, e.g. “xout”.
4) Select "C-API" on the Interface pane Generate GRT code for the top model (mymodel.mdl).
In the generated file mymodel.c, you would see the childMMI array is initialized in the mymodel_initialize function:
void mymodel_initialize(boolean_T firstTime) {
...
rtwCAPI_SetChildMMI(mymodel_M->DataMapInfo.mmi, 0, &(mymodel_refmod_M->DataMapInfo.mmi));
...
}
where mymodel_refmod_M->DataMapInfo.mmi is the child MMI corresponding to the referenced model in mymodel.mdl.
Note that the file mymodel_capi.c remains unchanged. The initialization is done in mymodel_initialize() function in mymodel.c