Main Content

Configure Model to Add C API Signals in Code Generation

Configure the model to include the C API elements for signals and parameters in the generated model code.

Open the model CapiSigsParams.

capiMdl = "CapiSigsParams";
open_system(capiMdl);

Enable C API Code Generation for Signals

To enable C API code generation for model signals:

  1. Open the Configuration Parameters dialog box.

  2. Navigate to the Code Generation > Interface pane.

  3. In the Data exchange interface > Generate C API for section, select signals.

  4. Click OK.

Configuration Parameters dialog box. The Code Generation > Interface pane is open. In the Generate C API for section, the signals box is selected.

Alternatively, enter this in the Command Window:

set_param(capiMdl,RTWCAPISignals=true)

Configure Signals as Test Points

To prevent the code generator from optimizing the signals away, configure them to be test points (see Configure Signals as Test Points):

  1. In the model, select the signals.

  2. Open the Signal tab of the Simulink® canvas.

  3. In the Monitor group, click Test Point.

CapiSigsParams model. The output signals of the Gain blocks are selected in the model canvas. The model Signal tab is selected and the Test Point toggle button in the Monitor section is selected.

Alternatively, use the capiSigsParamsHelper MATLAB® program to programmatically configure the signals as test points.

capiSigsParamsHelper("signals")

In the next step of the example, you generate model code that contains C API elements for model signals, and you write external code that can interact with it. To continue to the next step of the example, use this in the Command Window:

openExample("simulinkcoder/CapiSigsParams03Example")