问题
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