How can enumerations be included in an s-function?

조회 수: 17 (최근 30일)
Martin
Martin 2015년 8월 10일
댓글: Martin 2015년 8월 13일
I am trying to convert a Simulink/ stateflow model to a black box. Using Matlab 2015a, right clicking on the subsystem - C/C++ code - Generate s-function will do the job but with one issue. I have some datatypes defined as enumeration via an m-file in the current folder. Is there an option to include these in the s-function so I dont need those enum m-files to run the s-function?
Thanks,
Martin

답변 (1개)

Varun Bhaskar
Varun Bhaskar 2015년 8월 12일
Hello,
You can use enumerated data type in C-MEX S-Function by defining same data type with MATLAB and S-Function.
To use enumerated data type in S-Function, you need to use ssRegisterTypeFromNamedObject method to resister the data type from MATLAB/Simulink into S-Function. Sample files can be downloaded below. To execute the model, execute following command first, and then simulate the model.
>>mex enumExample.c
In this case, we use the OnOff.m enumerated data type class for the registration. More on this S-function method can be found here:
More on creating these custom data types in MATLAB can be found here:
After the type is registered, you can use the "ssSetInputPortDataType" method to set the type accordingly:
if (ssGetSimMode(S) != SS_SIMMODE_SIZES_CALL_ONLY) {
DTypeId dataTypeIdReg;
ssRegisterTypeFromNamedObject(S, "OnOff", &dataTypeIdReg);
if (dataTypeIdReg == INVALID_DTYPE_ID)
return;
ssSetInputPortDataType(S, 0, dataTypeIdReg);
}
See example enumExample.c attached to know more about using enumerate data type in C-MEX S-Function.
  댓글 수: 1
Martin
Martin 2015년 8월 13일
Hi Varun,
Thank you for your detailed response. Sorry, I am having trouble understanding the example. Also, I was not precise enough in my problem description. Maybe the following example will help.
The question is how do I convert the stateflow chart from 'enumModelExample1.slx' to an s-function in 'enumModelExample2.slx' which does not need the file for the output enum 'Status.m'.
Thanks in advance,
Martin

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Prepare Model Inputs and Outputs에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by