Include C-code in Simulink with pointers within a structure

20 次查看(过去 30 天)
i would like to integrate a structure which contains pointers into simulink like
typedef struct {
uint16_t id;
uint16_t *value;
} Queueitem_t;
pointers that are declared alone work like
extern uint16_t * var;
Does anyone have any idea how i do it. when running "Simulink.importExternalCTypes("headerfile")" i always get an error message -> Invalid use of operator.

回答(1 个)

Varun
Varun 2023-9-15
Hi Roman,
I understand that you are trying to create Simulink.Bus” object using the function “Simulink.importExternalCTypes to a C header file which consists of a struct which has a data type of pointer.
According to MATLAB R2023a, pointer data types are not supported in Simulink, that is why you are getting the above error while creating Simulink.Bus object.
However, you can follow an alternative approach to achieve similar functionalities of the pointer data type.
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/from 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, then 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.
Please refer to this MATLAB Answers post to learn more:
Hope this helps.

类别

Help CenterFile Exchange 中查找有关 Simulink 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by