Configure Model to Generate C API Code for Block Parameters
This example shows how to configure the model to include the C API for block parameters in the generated code.
Open the model CapiConfigDemo.
capiMdl = "CapiConfigDemo";
open_system(capiMdl);Enable C API Generation for Parameters
To enable C API code generation for parameters:
- Open the Configuration Parameters dialog box. 
- Navigate to the Code Generation > Interface pane. 
- In the Data exchange interface > Generate C API for section, select parameters. 
- Click OK. 

Alternatively, enter this in the Command Window:
set_param(capiMdl,RTWCAPIParams=true)
Specify Default Parameter Behavior as Tunable
To prevent optimizing away block parameters, specify the default parameter behavior as Tunable (see Default parameter behavior).
- Open the Configuration Parameters dialog box. 
- Navigate to the Code Generation > Optimization pane. 
- From the Default parameter behavior list, select - Tunable.
- Click OK. 

Alternatively, enter this in the Command Window:
set_param(capiMdl,DefaultParameterBehavior="Tunable")Generate Model Code
Use the slbuild command to generate code from your model. Use evalc to suppress the output of the slbuild command.
evalc("slbuild(capiMdl,GenerateCodeOnly=true)");Verify That Block Parameters Are Included in C API
The C API structure array that corresponds to block parameters is rtBlockParameters. To view the instantiation code for this structure, examine the generated C API source file CapiConfigDemo_capi.c (located in the folder CapiConfigDemo_grt_rtw).
This is the instantiation code for the structure in this file:
static const rtwCAPI_BlockParameters rtBlockParameters[] = {
  /* addrMapIndex, blockPath,
   * paramName, dataTypeIndex, dimIndex, fixPtIdx
   */
  { 0, TARGET_STRING("CapiConfigDemo/unitDelay1"),
    TARGET_STRING("InitialCondition"), 0, 0, 0 },
  { 1, TARGET_STRING("CapiConfigDemo/unitDelay2"),
    TARGET_STRING("InitialCondition"), 0, 0, 0 },
  {
    0, (NULL), (NULL), 0, 0, 0
  }
};