How can I define a variable in a bus as pointer ?

13 ビュー (過去 30 日間)
Antoine Bostem
Antoine Bostem 2018 年 4 月 5 日
コメント済み: bilal erol 2020 年 4 月 11 日
Hello,
I'm in some trouble with my variable definition. I have a structure that I would like to define with the Bus Editor. My structure is like :
typedef struct
{
uint16 a1;
uint16 *a2;
uint32 b1;
uint32 b2;
} structstruct;
I don't know how to define the a2 variable who is a pointer.
Could someone help me ?
Antoine

採用された回答

Mark McBroom
Mark McBroom 2018 年 4 月 29 日
編集済み: Mark McBroom 2018 年 4 月 29 日
Hi Antoine,
The idea is to use a data type that Simulink supports in place of the pointer. Since pointers are 64 bits long, use a Simulink data type that is 64 bits long. Then, in the external C code, convert the datatype used by Simulink to/form a unit16*. The best approach is to use a 64-bit integer in Simulink, since most C compilers will allow you to cast an integer to a pointer. But this requires the Fixed Point Toolbox. If you have a license for this, the set the data type of the variable to be ufix(64). If you don't have a Fixed Point license, then you can select a built-in Simulink data type that is 64 bits long, for example double or uint32[2]. C compilers won't let you cast these variables to/from a pointer, so you will need to create a temporary variable in your external code that is of type uint16* and then memcpy between the variable in the Simulink bus and the local uint16* variable.

その他の回答 (1 件)

Mark McBroom
Mark McBroom 2018 年 4 月 7 日
This is not possible in Simulink. Simulink does not support pointers. So that raises the question, why do you need a pointer in the structure? This question most often comes up when people are interfacing with external C code. If this is the case, there are some tricks you can play in Simulink that usually involve defining the type to instead by a 64-bit integer using the fixed point blockset.
  2 件のコメント
Antoine Bostem
Antoine Bostem 2018 年 4 月 9 日
Hi Mark,
Indeed, this is my case. I would like to include C code in an S-function. Could you explain me your tricks or give me a reference link ? Thank you
bilal erol
bilal erol 2020 年 4 月 11 日
have you solved your problem which is related with using pointer in simulink?

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

Community Treasure Hunt

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

Start Hunting!

Translated by