如何在生成的代码中加入C函数调用

8 Ansichten (letzte 30 Tage)
Vico Wu
Vico Wu am 13 Apr. 2022
Beantwortet: mark li am 13 Apr. 2022
我想要搭建一个simulink模型,我查了资料可以通过matlab function 调用的形式加入c代码,但是我的c代码是API的.a文件关联的文件很多,我想在生成的代码中 某个位置直接包含我想要调用的函数体,不用去解析API的库文件,不用去考虑他的实现 只要在相应位置有这段代码就可以
例如 api 中有一个函数叫 in_cfg(uint16 a,uin16 b,uint16 c),我只要 生成的代码的某个逻辑位置有 in_cfg(a,b,c);

Antworten (1)

mark li
mark li am 13 Apr. 2022
你好!你可以开配置中添加API,具体是model setting (Ctrl+E)->Simulation Target, 填写.c和.h。
代码生成也许要嵌进去,model setting (Ctrl+E)->Code Genaration->Custom Code填写.c和.h。
之后你用statflow调用即可,stateflow需要选择C语言
可以参考这个例子https://ww2.mathworks.cn/help/stateflow/ug/calling-c-functions-in-actions.html?searchHighlight=stateflow%20call%20c%20function&s_tid=srchtitle_stateflow%20call%20c%20function_3

Kategorien

Mehr zu 代码生成 finden Sie in Help Center und File Exchange

Produkte


Version

R2015b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!