Multi-Instance usage of S-Functions (C code) in SIMULINK

孤街浪徒 提交于 2019-12-11 09:57:33

问题


I have a legacy C function in my SIMULINK model that uses some static variables in its functions. The static variables are available globally. When I reference multiple instance of my model, I get error because my S-function is not configured for that. I am getting this error message because code generation doesn't allow this.

The error message I get is the following:

The S-Function block 'ECDCTRL/PULDESC/S-Function Builder' is not supported in multi-instance Normal mode because it does not declare that it supports multiple execution instances. If the S-Function satisfies the multiple execution instances requirements, you can declare this using the SimStruct function 'ssSupportsMultipleExecInstances' in the 'mdlSetWorkWidths' method.

I am using the (MYSFUNC)_Outputs_Wrapper.c file when I build it with the auto-generated code. How can I make sure that I can use my legacy C function when using multiple references of my model? SIMULINK website suggests using ssSupportsMultipleExecInstances(SimStruct *S, bool flag) method, but it is not correct as I am not using the SimStruct header files. What is the way around?


回答1:


Use DWork vectors instead of static variables. Quoting from here:

DWork vectors have several advantages:

Provide instance-specific storage for block variables
Eliminate static and global variables


来源:https://stackoverflow.com/questions/20469428/multi-instance-usage-of-s-functions-c-code-in-simulink

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!