S-Functions: ssWriteRTWParamSettings in mdlRTW does not work.
Afficher commentaires plus anciens
Hey there,
I've got a problem regarding the inlining of some C S-Functions.
My S-Function expects some non tuneable parameters (e.g., "port_number"), which I try to write to the .rtw file in order to access them with my corresponding .tlc file.
My C Code looks as follows:
#define PORT_NUMBER (( uint8_T )( mxGetPr( ssGetSFcnParam( S , PORT_NUMBER_IDX ) )[ 0 ] ) + (uint8_T)1 )
static void mdlRTW(SimStruct *S)
{
if(!ssWriteRTWParamSettings (S, 1, SSWRITE_VALUE_NUM, "port_number", PORT_NUMBER))
{
return; /* An error occurred. */
}
}
I tried accessing the parameter with
%assign port_number = SFcnParamSettings.port_number
in my tlc file, but when building the model, I kept getting "unidentified identifier SFcnParamSettings".
Subsequently I searched the built .rtw file for "SFcnParamSettings", but nothing was found. Shouldn't there be a block with this title in it? For me it looks like the mdlRTW function wasn't executed correctly, but why?
And how can I check if it works?
Réponse acceptée
Plus de réponses (2)
Kaustubha Govind
le 23 Fév 2011
0 votes
I wonder if the write is failing becausing SSWRITE_VALUE_NUM requires a real_T value, but you are passing in a uint8_T value. You could try using ssWarning or ssPrintf inside your if condition to detect when ssWriteRTWParamSettings is unsuccessful.
Use SSWRITE_VALUE_DTYPE_NUM to write a SS_UINT8 type value, by passing in a void pointer to the same. See the documentation for more details.
Eike
le 24 Fév 2011
3 commentaires
Kaustubha Govind
le 24 Fév 2011
AFAIK, you only need to define MDL_RTW (as you already are) - nothing else needs to be configured.
However, I'm not sure how this code even compiles because of how you use "&PORT_NUMBER" - you can't get the address of a temporary. You need to define another variable:
#define MDL_RTW
static void mdlRTW(SimStruct *S)
{
uint8_T pn = PORT_NUMBER;
ssWriteRTWParamSettings (S, 1, SSWRITE_VALUE_DTYPE_NUM, "port_number", &pn, DTINFO(SS_UINT8, 0));
ssPrintf ("An error occured during .rtw generation!");
}
Eike
le 25 Fév 2011
Eike
le 1 Mar 2011
Catégories
En savoir plus sur Simulink Coder dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!