ReQuestion: passing information/parameters from Simulink to embedded code generated
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I'm developing inline s-function driver block. I have created the .c .tlc and .mex32 files.
These blocks have a mask with 4 parameters, and I want to pass parameters to the files generated by RTW tool, but when I try to generate the code I have this error:
Error using ==> rtwgen Error in mdlRTW of S-function myModel/model_DI'. This function wrote 0 run-time parameters where as it has registered 4 run-time parameters.
I try to do so:
In my driver, at the top of my .c I have this:
#define param1(S) (mxGetScalar(ssGetSFcnParam(S,1)))
#define param2(S) (mxGetScalar(ssGetSFcnParam(S,2)))
#define param3(S) (mxGetScalar(ssGetSFcnParam(S,3)))
Then this is the MdlRTW function:
#define MDL_RTW
static void mdlRTW(SimStruct *S) {
uint8_T Numparam1, Numparam2, Numparam3;
Numparam1=(uint8_T)param1(S);
if( Numparam1<0 Numparam1>15 )
{
sprintf(msg,"Número incorrecto de Numparam1 %d", Numparam1);
ssSetErrorStatus(S,msg); return;
}
Numparam2=(uint8_T)param2(S);
if( Numparam2<0 Numparam2>15 )
{
sprintf(msg,"Número incorrecto de Numparam2 %d", Numparam2);
ssSetErrorStatus(S,msg); return;
}
Numparam3=(uint8_T)param3(S);
if( Numparam3<0 Numparam3>1 )
{
sprintf(msg,"Número incorrecto de Numparam3 %d", Numparam3);
ssSetErrorStatus(S,msg); return; }
// Write out the parameters for this block.
if (!ssWriteRTWParamSettings(S, 3, SSWRITE_VALUE_DTYPE_NUM, "Numparam1", &Numparam1, DTINFO (SS_UINT8, COMPLEX_NO), SSWRITE_VALUE_DTYPE_NUM, "Numparam2", &Numparam2, DTINFO (SS_UINT8, COMPLEX_NO), SSWRITE_VALUE_DTYPE_NUM, "Numparam3", &Numparam3, DTINFO (SS_UINT8, COMPLEX_NO)))
{
sprintf(msg,"Error al pasar parametros de la mascara a model.rtw");
ssSetErrorStatus(S,msg);
return; // An error occurred which will be reported by SL } }
And then, to pick in my .tlc I have:
%%Function: mdlOutputs ========================================================
%function Outputs(block, system) Output /* %<Type> Block: %<Name> */
{
%assign Numparam1= CAST( "Number",SFcnParamSettings.Numparam1)
%assign Numparam2= CAST( "Number",SFcnParamSettings.Numparam2)
%assign Numparam3= CAST( "Number",SFcnParamSettings.Numparam3)
...
0 comentarios
Respuesta aceptada
Kaustubha Govind
el 14 de Nov. de 2011
As the documentation suggests, ssWriteRTWParamSettings is needed to write the values of nontunable parameters to the model.rtw file. Since you seem to have already registered your parameters as tunable, you don't have to define the mdlRTW() method at all, because these are automatically written to model.rtw for you. Examine the model.rtw file (ensure that "Retain .rtw file" under Code Generation>Debug is checked before you attempt to generate code from the model - the model.rtw file will be generated to the same folder where the model.c files are generated). The parameters values are written against the name you registered for each of them in the 4th argument to ssRegDlgParamAsRunTimeParam.
3 comentarios
Kaustubha Govind
el 16 de Nov. de 2011
Please type "sfcndemo_runtime" at the MATLAB prompt to see an example of S-function with run-time parameters and their corresponding TLCs. Hopefully this will help you achieve what you need.
Más respuestas (0)
Ver también
Categorías
Más información sobre Embedded Coder en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!