How to initialize SimStruct from C code?

2 ビュー (過去 30 日間)
Asim
Asim 2013 年 3 月 11 日
回答済み: yh h 2019 年 11 月 6 日
I exported my Simulink model to C code by using "rtwsfcn.tlc". The output code for the S-Function was generated successfully.
Now I want to import this S function directly in a C project. So what I did is something like this.
SimStruct *S = (SimStruct *)malloc(sizeof(SimStruct));
mdlInitializeSizes(S); ... ...
But it gives some runtime error. Can anyone tell me the proper way to initialize SimStruct directly in C without using Matlab?

採用された回答

TAB
TAB 2013 年 3 月 11 日
編集済み: TAB 2013 年 3 月 11 日
What is your C project ? Is it a embedded project ?
s-function is matlab specific c code which uses lots of function from it library called SimStruct library. It is very difficult and unnecessary to integrate the s-function code into some user project.
Instead twsfcn.tlc, you can use ert.tlc (Embedded coder tool) to generate production quality C code which can be integrated into any custom project.
  7 件のコメント
TAB
TAB 2013 年 3 月 13 日
編集済み: TAB 2013 年 3 月 13 日
I am realy not getting what do you mean by Dimensions of the elements are different across each model.
If you are creating the instance of same structure for different models, then dimension will remain same.
Or, if you have different structure inputs for each model, then you create separate Simulink.Bus bus objects for each structure.
Code generated by simulink is fully customizable. You can go through the documentation of Simulink Coder, Embedded Coder and Simulink Coder Target Language Compiler for complete details.
PDF documentation is directly available for all registered user.
Asim
Asim 2013 年 3 月 13 日
Lets assume a very simple case. I have a simulink model that takes '2' inputs and add them to return one output.
Another model takes '3' inputs and add them together. Yet another model takes '4' inputs and add them to give one output.
So what I need is an interface that works with all these models.
Making a new Simulink.Bus object for each structure is just not an option in my case.
Thanks

サインインしてコメントする。

その他の回答 (1 件)

yh h
yh h 2019 年 11 月 6 日
where can I fined the "SimStruct"at the matlab dir?

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by