How do I recompile the manually modified generated-code from Real-Time Workshop 7.3 (R2009a)?

I am generating an S-function block from a subsystem by right-clicking on the subsystem block and selecting "Real-Time Workshop > Generate S-Function...". Since the subsystem contains blocks which are dependent on the sample time, the generated S-function code will have the sample times hardcoded in it. So when I try to use this new block in different models, they fail to run.
So I plan to manually modify the generated code to make it sample time independent. However, I am unable to successfully create a MEX-file from the generated files. I believe I am not passing all the dependent files to the MEX function.

 Accepted Answer

The following instructions should help recompile the modified files successfully:
1) Use "mex -setup" to set up a compiler.
2) Generate the S-function block from your subsystem.
A sample model, sampleModel_R14SP3.mdl, which contains the subsystem "SourceSubsys" is attached.
3) Modify the generated C-code appropriately. The ssSetSampleTime macro (found in mdlInitializeSizes or mdlInitializeSampleTimes) is used to specify the period of the sample time.
The sample model generates a "SourceSubsys_sf.c" file (found in directory yourCurrentDirectory/SourceSubsys_sfcn_rtw/). The following lines were manually added to mdlOutputs function:
static int count = 0;
printf("mdlOutputs call # %d\n", count);
count++;
The modified "SourceSubsys_sf.c" is also attached.
4) Clear the MEX-file loaded into memory by executing "clear mex"
5) Execute the .bat file found in the same directory.
You can do that from the MATLAB command line by executing the following:
!SourceSubsys.bat
5) A new MEX-file will be generated.
Another model, sampleModel_R14SP3_recompiledMEX.mdl, which makes use of the generated S-function block and the newly generated MEX-file, is attached. Simulating the model will reflect the modifications made to the originally generated code.

More Answers (0)

Categories

Find more on Deployment, Integration, and Supported Hardware in Help Center and File Exchange

Products

Release

R2009a

Community Treasure Hunt

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

Start Hunting!