Include C-code in Simulink with pointers within a structure

조회 수: 23 (최근 30일)
Roman Reiter
Roman Reiter 2022년 8월 31일
답변: Varun 2023년 9월 15일
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