필터 지우기
필터 지우기

Custom data types for S-function parameters

조회 수: 3 (최근 30일)
db1024
db1024 2020년 6월 4일
댓글: db1024 2020년 6월 9일
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