MATLAB Answers

Custom data types for S-function parameters

5 ビュー (過去 30 日間)
db1024 2020 年 6 月 4 日
コメント済み: db1024 2020 年 6 月 9 日
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 件のコメント

Sign in to comment.


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.

  1 件のコメント

db1024 2020 年 6 月 9 日
Thanks Mark. I got it working by following the example
from your posted link.

Sign in to comment.

その他の回答 (0 件)

Translated by