How can enumerations be included in an s-function?

17 views (last 30 days)
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

Answers (1)

Varun Bhaskar
Varun Bhaskar on 12 Aug 2015
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 Comment
Martin
Martin on 13 Aug 2015
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

Sign in to comment.

Categories

Find more on Prepare Model Inputs and Outputs in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!