Custom data types for S-function parameters

3 次查看(过去 30 天)
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!

采纳的回答

Mark McBroom
Mark McBroom 2020-6-7
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 个评论
db1024
db1024 2020-6-9
Thanks Mark. I got it working by following the example
openExample('simulink/IntegrateCFcnArgsAreStructuresExample')
from your posted link.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Coder 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by