Effacer les filtres
Effacer les filtres

How can enumerations be included in an s-function?

14 vues (au cours des 30 derniers jours)
Martin
Martin le 10 Août 2015
Commenté : Martin le 13 Août 2015
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

Réponses (1)

Varun Bhaskar
Varun Bhaskar le 12 Août 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 commentaire
Martin
Martin le 13 Août 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

Connectez-vous pour commenter.

Catégories

En savoir plus sur Block and Blockset Authoring dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by