使用 C Function 模块集成 C/C++ 代码
在 Simulink® 模型中集成并调用外部 C/C++ 代码
使用 C Function 模块从您的模型调用外部 C/C++ 代码。使用 C Function 模块可以:
编写 C 代码来预处理数据以调用 C 函数。同样,您可以在调用 C 函数后编写 C 代码来对数据进行后处理。
为仿真和代码生成指定不同代码。
调用在外部代码中定义的多个 C 函数。
初始化并使用模块中缓存的持久数据。
分配和取消分配内存。
要通过在您的 Simulink 模型中配置自定义代码源来开始使用,请参阅Specify and Configure Custom C/C++ Code。
要调用简单的 C 代码,请使用 C Caller 模块。要将使用 C 代码的动态系统集成到您的 Simulink 模型中,请使用 S-Function 模块。
模块
C Function | Integrate and call external C/C++ code from a Simulink model (自 R2020a 起) |
对象
SymbolSpec | Query and configure C Function block data symbols (自 R2020a 起) |
Symbol | C Function block data symbol (自 R2020a 起) |
模型设置
主题
- Specify and Configure Custom C/C++ Code
Specify custom C/C++ headers, source files, and libraries, and configure custom code settings for your Simulink model.
- Integrate External C/C++ Code into Simulink Using C Function Blocks
Integrate and modify external C Code using C Function blocks.
- Modify States of a C Function Block Using Persistent Symbols
- Change Values of Signals Using C Function Block and Buses
- Access Elements of a Matrix Using Output Code in a C Function Block
- Use External Functions with Matrix Input in a C Function Block
- Define an Alias Type in a C Function Block
- Use Inherited Sizes in a C Function Block
- Use Enumerated Data in a C Function Block
- Interface with C++ Classes Using C Function Block
Use C Function block to interface directly with C++ classes defined in custom code.
- Debug Custom C/C++ Code
Debug custom C/C++ code from within Simulink.