Custom data types for S-function parameters
6 次查看(过去 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!
0 个评论
采纳的回答
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Block and Blockset Authoring 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!