MATLAB Answers

How to call C custom variable or constant in Simulink Model

8 ビュー (過去 30 日間)
Mirko
Mirko 2020 年 4 月 30 日
コメント済み: Mark McBroom 2020 年 5 月 4 日
Good evening,
I'm looking for a method to call a variable or constant defined in a custom C code inside a simulink model.
I already use several functions with C Caller both in the model and in Stateflow.
Can someone help me?

  0 件のコメント

Sign in to comment.

回答 (1 件)

Mark McBroom
Mark McBroom 2020 年 5 月 4 日
not sure what you mean by "call", but one solution would be to put the variable inside a C function that simply returns the constant. Then use C Caller block to call this new C function.
Thanks.
Mark.

  2 件のコメント

Mirko
Mirko 2020 年 5 月 4 日
Hi Mark, thanks for the reply.
The idea you suggested to me is feasible, but I thought there was a different method to use a constant defined in the Header directly as a constant without having to use a function. Within stateflow this is possible just use in any formula the name of the variable defined in the .h file. Is there a Simulink block that allows me to do this? Could the Data Store Memory be useful?
Thanks
Mirko
Mark McBroom
Mark McBroom 2020 年 5 月 4 日
If you want to hvae the external C file declare and define the variable, you can have the generated code use that external definition. This can be done by creating a Simulink.Parameter data object, and then setting it's storage class to be "Imported Extern". This will allow you to use the constant in Simulink, but the declaration and definition are done in an external, hand written C file.
This link to the doc gives more details:
Thanks.
Mark.

Sign in to comment.

製品


リリース

R2020a

Translated by