问题描述
我的SIMULINK模型中有一个旧版C函数,该函数在其函数中使用一些静态变量。静态变量全局可用。当我引用模型的多个实例时,出现错误,因为未为此配置S函数。我收到此错误消息是因为代码生成不允许这样做。
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:
使用自动生成的代码构建文件时,我正在使用(MYSFUNC)_Outputs_Wrapper.c
文件。使用模型的多个引用时,如何确保可以使用旧版C函数? SIMULINK网站建议使用 ssSupportsMultipleExecInstances(SimStruct * S,bool flag)
方法,但这是不正确的,因为我没有使用 SimStruct
头文件。怎么回事?
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?
推荐答案
使用DWork向量代替静态变量。引用自:
Use DWork vectors instead of static variables. Quoting from here:
Provide instance-specific storage for block variables
Eliminate static and global variables
这篇关于SIMULINK中S功能(C代码)的多实例用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!