Main Content

coder.mapping.api.CodeMappingCPP

C++ 代码生成的模型数据和接口配置

自 R2021a 起

说明

代码映射对象和相关函数能够为 Simulink 模型的数据和函数配置 C++ 代码生成。对于模型数据元素,代码映射将数据元素与由存储类和存储类属性组成的配置相关联。对于函数,代码映射将入口函数与由函数自定义模板组成的配置相关联。通过为整个模型中的数据元素和函数类别指定默认配置,减少为 C++ 代码生成而准备模型的工作量。通过单独配置数据元素或函数来覆盖默认配置。对于较小的模型,您可以选择单独配置每个数据元素和函数

创建对象

当您从 Simulink® 编辑器的 App 选项卡中选择 Embedded Coder 时,如果代码映射尚不存在,该 App 将创建一个 coder.mapping.api.CodeMappingCPP 对象。该 App 基于存储在模型活动配置集对象中的代码自定义设置来创建代码映射。配置集对象可以为数据和函数指定内存段。

使用 coder.mapping.utils.createcoder.mapping.api.get 函数以编程方式访问 coder.mapping.api.CodeMappingCPP 对象。

对象函数

findGet model elements for the category of model code mappings
getClassNameGet class name of model
setClassNameSet class name of model
getClassNamespaceGet class namespace for a model
setClassNamespaceSet class namespace of model
getDataGet code mapping configuration for model data
setDataConfigure model data for C++ code generation
getFunctionGet code configuration from code mappings for model function
setFunctionSet code mapping information for model function

示例

全部折叠

打开模型 CppClassRateBased,并使用 coder.mapping.utils.create 函数为代码生成创建用于配置模型数据和函数的环境。

open_system('CppClassRateBased')
coder.mapping.utils.create('CppClassRateBased');

调用 coder.mapping.utils.create 后,通过调用在“对象函数”下列出的其他函数来配置模型接口元素的代码生成的各方面。

版本历史记录

在 R2021a 中推出