Using a C Union datatypes as an input/Output for a S-function on Simulink

13 ビュー (過去 30 日間)
Ali
Ali 2022 年 12 月 28 日
コメント済み: Ali 2023 年 1 月 2 日
Hello,
I have a C program which uses struct and union defined in a header. What i want to do is use this program in Simulink for that i used the legacy code tool to create a Sfunction but, i still have a problem with the unions which are part of some structures used as input and output of the program and Simulink won't import them. I am asking here if there is any workaround for using Unions with Simulink or if there are exemple available.
If there are available solutions it would help a lot.

採用された回答

Mark McBroom
Mark McBroom 2023 年 1 月 1 日
Simulink does not support unions. However, you can work around this by treating the union as a Simulink.Bus data object with DataScope of "Imported" and Header file is the name of the hand-written header file defining the structs and unions. https://www.mathworks.com/help/simulink/slref/simulink.bus.html# This approach treats each field of the union as different memory locations during simulation and therefore is only valid if the SImulink model reads and writes to just one of the union fields. If you attempt to write to one union field and then read from another, you will not get the expected result during simulation.
Hope this helps
Mark.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSimulink Functions についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by