How can enumerations be included in an s-function?
조회 수: 17 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
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.
참고 항목
카테고리
Help Center 및 File 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!