To use enumerated data types from custom C/C++ code in Simulink model do the following:
1. Create a MATLAB class defining the ENUM in exactly the same way as the ENUM definition in the HEADER file of custom/legacy code.
2. Call the custom C header file with the ENUM definition in the MATLAB class for handshaking.
3. Use this ENUM type in the Output Signal Data Type of the source block.
4. Use Legacy Code Tool as in the attached RunMe script to create wrapper S-function.
When changing ENUM definitions:
- Change both the C header file and the MATLAB class.
- Make sure you do "clear classes" in MATLAB so that Simulink picks up the new definitions.
Demo Content:
1. The C source code "myCode.c" with enumerated data.
2. The C header file "myCode.h"
3. The MATLAB file "OnOff.m" That contains the MATLAB class definition.
4. The MATLAB file "RunMe.m"
5. Simulink model "TMWDemo.mdl" using the generated S-function block
Running the DEMO:
1. Run the RunMe.m script to create custom S-function.
2. Run TMWDemo.mdl model.
Best Answer