Passing parameters for C-Mex S-functions returns only Zero(0)

Hello community,
Currently, I'm troubling around with S-function parameters in Simulink. The S-function are all written in C. I wanted to pass parameters to the S-function, but the passed arguments are always just zero. I don't understand this behavior and nearly rewrote the example given in foogain from the help context.
Here's what I did so far:
  • I defined the retrieving function in the header of the S-function C-code:
#define FLAG mxGetPr(ssGetSFcnParam(S,0))[0]
  • In the mdlOutputs I just wrote a ssPrintf for debug purposes like this:
ssPrintf( "This is the flag: %d", FLAG ); // the flag parameter is -2 though, the ssPrintf will show zero(0) as output ...
Could you please give me some advice what the problem could be? Thanks in advance.

Réponses (2)

Kaustubha Govind
Kaustubha Govind le 24 Fév 2011
Could you try %f instead of %d? In this case, FLAG is of type double, but you are using a format specifier that is meant for integers.
Hm, this was indeed the error for my problem. A cast like (int) could avoid that dangerous behavior, too:
ssPrintf( "This is the flag: %d", (int)FLAG );
Thank you Kaustubha.

Catégories

En savoir plus sur Simulink Coder dans Centre d'aide et File Exchange

Produits

Question posée :

Rob
le 24 Fév 2011

Community Treasure Hunt

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

Start Hunting!

Translated by