How to set the output port type in dependence on an parameter - S Function

1 次查看(过去 30 天)
Hello,
i'm trying to write an S-Function which allows to set the output port type dependence on one of the parameter? What i already tried:
static void mdlOutputs(SimStruct *S, int_T tid)
{
DTypeId y0DataType = ssGetSFcnParam(S,2);
switch(y0DataType)
{
case SS_INT8:
{
int8_T *pY0 = (int8_T *)ssGetOutputPortSignal(S,0);
pY0[0] = 0;
break;
}
case SS_UINT8:
{
uint8_T *pY0 = (uint8_T *)ssGetOutputPortSignal(S,0);
pY0[0] = 13;
break;
}
default:
{
uint8_T *pY0 = (uint8_T *)ssGetOutputPortSignal(S,0);
pY0[0] = 7;
}
}
}
I can compile it and run the corresponding simulink model, but it doesn't work. Can me tell anyone why?
Regards V.Sadiku
  3 个评论
Valmir Sadiku
Valmir Sadiku 2013-5-10
Simulink sets the output port type to 'double' and the attached display shows a strange value -> 3.953e-323). The parameter in the mask are set to"uint8", so i expected that simulink will set this one as output type. Maybe i have to do it another way, but i'm at a loss with this Problem.
Valmir Sadiku
Valmir Sadiku 2013-5-10
编辑:Valmir Sadiku 2013-5-10
If i try to do this in this way:
static void mdlInitializeSizes(SimStruct *S)
{
......
...
ssSetOutputPortDataType(S, 0, ssGetSFcnParam(S,2));
....
}
After recompiling it works without any error message, but if i run that corresponding simulink model it will give the following error in the Matlab command window:
Attempt to use invalid data type id -5373248
And the Simulink model freezes, and i have to restart matlab.

请先登录,再进行评论。

回答(1 个)

William James
William James 2013-6-3
hello,
i met the problem as you ! if you resolved it ,please tell me how to set the output type .
thank you with Hz
  1 个评论
Kaustubha Govind
Kaustubha Govind 2013-6-3
Do you validate the value entered for the parameter is a valid datatype ID before configuring it as the output datatype in mdlInitializeSizes?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Simulink Coder 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by