Custom data types for S-function parameters

10 views (last 30 days)
Hello,
I would like to use a custom data type (Simulink.Bus object) for a S-function paramter in a custom S-function. The documentation states that custom data types can be used for S-function parameters [1]:
To register a custom data type recognizable by Simulink, the S-function mdlInitializeSizes routine must register the data type, using ssRegisterTypeFromNamedObject.
For example, the following code placed at the beginning of mdlInitializeSizes defines a custom data type from a Simulink.AliasType object named u8 in the MATLAB® workspace. The example then assigns the custom data type to the first output port.
int id1;
ssRegisterTypeFromNamedObject(S, "u8", &id1);
ssSetOutputPortDataType(S, 0, id1);
In addition, you can use the identifier id1 to assign this data type to S-function parameters, DWork vectors, and input ports.
The code snippet in the above-quoted documentation works for output ports (and in a similar way for input ports). Unfortunately, I was not able to use custom data types for S-functions parameters. I simply could not find a corresponding SimStruct functions, like ssSetParameterDataType, in the documentation.
Could somebody poinpoint me to the corresponding entry in the documentation or provide me a brief code snippet?
Thank you!

Accepted Answer

Mark McBroom
Mark McBroom on 7 Jun 2020
The easiest way to do this is to use the legacy_code tool to create the s-function for you. You will have to create a dummy c-function that takes as inputs and/outputs C structures with the same layout as your bus, but then legacy_code will genearte all of the C code you need to not only register the custom data type, but also how to access elements in the bus. This is very tricky to do by hand and much easier with legacy_code tool.
Thanks.
Mark.
  1 Comment
db1024
db1024 on 9 Jun 2020
Thanks Mark. I got it working by following the example
openExample('simulink/IntegrateCFcnArgsAreStructuresExample')
from your posted link.

Sign in to comment.

More Answers (0)

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!