Autocode fails without setting S-function parameters as runtime params

26 views (last 30 days)
I'm trying to integrate a MEX S-function into a model with accompanying TLC so that it 1) runs the MEX during simulation, but 2) autocodes the right C wrapper during autocoding. Everything was working fine (model simulating fine, autocoding fine) up until we had some configuration changes, and now when I attempt to autocode the model, I get an error like this:
S-function 'string_sequencer' in '[my S-function block]' does not explicitly set the number of run-time parameters using ssSetNumRunTimeParams. This compatibility diagnostic on the need for S-function upgrades can be set to none, warning, or error using the Configuration Parameters dialog
Except, in that code, I was setting the number of runtime params using ssSetNumRuntimeParams in the mdlSetWorkWidths function: I was setting it to 0. However, there are 7 tunable S-function parameters for this block. When I simply set the number of runtime parameters to 7, I get this error:
In S-function 'X/X/X_SEQUENCER/StringBasedSequencer', dialog parameter 1 has not been utilized to create any run-time parameter even though it was declared to be tunable. Each tunable dialog parameter must appear in the 'dlgParamIndices' field of at least one run-time parameter
...which begins to make it a little clearer what the issue is. The final thing I tried was to put this piece in my mdlSetWorkWidths:
char **names = ...set all of the variable names...
ssRegAllTunableParamsAsRunTimeParams(S, names);
This gets past all of the previous errors I was getting about not setting the number of runtime params, but then my TLC breaks. Specifically, I have a block that looks like this in my TLC
%function Start(block, system) Output
%assign nelements1 = LibBlockParameterSize(P1)
%assign param_width1 = nelements1[0] * nelements1[1]
%if (param_width1) > 1
%assign pp1 = LibBlockMatrixParameterBaseAddr(P1)
%else
%assign pp1 = LibBlockParameterAddr(P1, "", "", 0)
%endif
functionThatUsesP1(%<pp1>, %<param_width1>)
%endfunction
...and now that my parameters are runtime parameters, they must no longer be visible to the Start function, because I now get the error "Undefined identifier P1" when my TLC is being used for the autocode.
It seems to me that there could be a few ways out of this issue. First, if I rewind the configuration parameters such that if I set "Diagnostics -> Compatibility -> S-function upgrades needed" to "warning" or "none" instead of "error", everything autocodes and simulates just fine. The problem here is that I don't necessarily control the configuration, and changes to it will affect other systems. So, my first series of questions: how important is the first error that pops up, about not explicitly setting the number of runtime params? Is it acceptable to ignore the error via this configuration parameter, and if so, what am I trading by doing this? Why does Simulink/Coder want those tunable S-function parameters declared as runtime parameters if it works just fine without them being so? Is there some other way to set up those parameters so I won't get the error about them not being runtime params?
If I do need my S-function parameters to be runtime parameters, then what's the best way to access those parameters via TLC? I.e. since P1 is no longer visible if I set all of my tunable parameters as runtime parameters, are those parameters named something else? Thanks in advance for any insight,
Dan

Accepted Answer

Kaustubha Govind
Kaustubha Govind on 3 Apr 2013
I think ssRegAllTunableParamsAsRunTimeParams(S, names); is the right command to use in your case. To access the corresponding parameters in the TLC, use the same names that you specified in the names array to the second argument of ssRegAllTunableParamsAsRunTimeParams. For example, as several S-function demos show:
const char_T *rtParamNames[] = {"Gain"};
ssRegAllTunableParamsAsRunTimeParams(S, rtParamNames);
Corresponds to this in TLC:
%assign k = LibBlockParameter(Gain, "", "", 0)
  1 Comment
Zakarya Motea
Zakarya Motea on 25 Feb 2018
Hi Kaustubha do you have an idea on this :i am currently having the same problem as the errors mentioned up in the question regarding parameters being undefined in tlc file. if you still remember, could you please explain more on how did you solved it. how to call the right parameter names in tlc and from where to call?
regards

Sign in to comment.

More Answers (1)

Dan
Dan on 3 Apr 2013
Edited: Dan on 3 Apr 2013
You're right, I tried that solution, and it worked. I don't know why the name 'P1' in the TLC ever worked considering I didn't have a variable named 'P1'. Another mistake I was making was related to simple ignorance about tunable parameters, and not setting them properly as tunable. It seems that if you don't explicitly set your parameters as non-tunable in the MEX, they will default to tunable (or some strange undefined state), so I had to do this in my mdlInitializeSizes, to set just a single parameter tunable:
ssSetSFcnParamTunable(S,0,true);
ssSetSFcnParamTunable(S,1,false);
... other parameters set to false tunability ...
That, plus ssRegAllTunableParamsAsRunTimeParams, plus calling out the right parameter name in the TLC solved it. Thank you!
  1 Comment
Zakarya Motea
Zakarya Motea on 25 Feb 2018
Hi Dan
i am currently having the same problem as your errors regarding parameters being undefined in tlc file. if you still remember, could you please explain more on how did you solved it. how to call the right parameter names in tlc and from where to call?
regards

Sign in to comment.

Categories

Find more on Simulink Coder in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!