Main Content

Access C API Model Maps

Two C API maps serve as the gateway to using the generated C API code. These are structure containers through which you access C API elements.

  • The main map serves as a gateway for obtaining real-time information about model elements.

  • The static model map serves a gateway for obtaining metadata about model elements.

Obtain Access to C API Maps Example

This is an example C language function that accesses the model information maps. The example shows how to use the direct data structures access, and how to use the predefined get-functions and macros.

The example code is also provided as standalone code (see Standalone C Code for Accessing C API Maps Example) so that you can copy it more easily.

C Code for Accessing C API Maps Example

DescriptionSample C Code with Direct Data Structure AccessSample C Code with Macros and Get-Functions
Include the generated model header so you can access the real-time model object and the get-functions used to access the maps.
# include "AccessCapiDemoMdl.h"
# include "accessCapiExternalCode.h"
# include <stdio.h>
# include "AccessCapiDemoMdl.h"
# include "accessCapiExternalCode.h"
# include <stdio.h>
Declare the variables to use for storing the map objects.
const rtwCAPI_ModelMappingInfo *mainCapiMap;
const rtwCAPI_ModelMappingStaticInfo *capiStaticMap;
const rtwCAPI_ModelMappingInfo *mainCapiMap;
const rtwCAPI_ModelMappingStaticInfo *capiStaticMap;
Obtain pointers to the main and static C API maps.
void accessModelInfoMaps()
{
  mainCapiMap = 
      &AccessCapiDemoMdl_M->DataMapInfo.mmi;

  capiStaticMap = 
      mainCapiMap->staticMap;
void accessModelInfoMaps()
{
  mainCapiMap = 
      &rtmGetDataMapInfo(AccessCapiDemoMdl_M).mmi;

  capiStaticMap =
      AccessCapiDemoMdl_GetCAPIStaticMap();
Print a notification announcing you obtained the maps.
  printf("Obtained the main and static C API maps.\n");
}
  printf("Obtained the main and static C API maps.\n");
}

Here is a schematic illustration of the map structure that is accessed by the code in the example:

Standalone C Code for Accessing C API Maps Example

 Ready-to-Copy Standalone C Code

Related Topics