Create a C-type(bitfields) structure in Matlab and pass it to Matlab function block

8 ビュー (過去 30 日間)
Shalaka
Shalaka 2025 年 6 月 24 日
コメント済み: Shalaka 2025 年 6 月 24 日
Hello team,
We need to access a C-function in Matlab. We are using 'MATLAB function block' for the same. This C function returns structure object (of structure datatype).
T_SftyReason Sfty_GetReason(void)
{
return SftyValues.SftyInfo.SReason;
}
The corresponding structure definition (of size 32 bits) in C-code is:
typedef struct TAG_SftyReason
{
uint8_T Err1 : 1; /**< Error 1*/
uint8_T Err2 : 1; /**< Error 2*/
..
..
..
..
uint8_T Reserved : 4; /**< @brief Bits used to achieve alignment */
} T_SftyReason;
In order to access this function in Matlab (using matlab function), we need to create the same structure in matlab and pass its object inorder to get the expected result available in Matlab.
Tried out:
In order to achieve mentioned goal, we have already tried out this solution:
  1. In MATLAB, we defined the same fields as bus elements (size 32).
  2. We created a 'Simulink.bus' with all these defined fields/elements.
  3. We later created a Matlab structure from bus using 'Simulink.Bus.CreateMATLABStruct' command.
  4. We passed this default values structure (all initialised to 0) as an input argument to a MATLAB function block.
  5. Later we have called the C-function inside MATLAB function block to receive output from C-function in same datatype as 'Simulink.bus'.
We are currently facing build issues for this approach during complete project build. The generated code for above model gives error as "error: conversion to non-scalar type requested".
We assume that there is some mismatch with the structure definitions in MATLAB workspace verses the C-type. Request you to please guide us to resolve this issue on priority.
  2 件のコメント
Shalaka
Shalaka 2025 年 6 月 24 日
Hello Walter, thank you for sharing the reference.
However, I am working on the Outputs of the Matlab function block. The specified link suggests that the 'storage class: Bitfield' is available for Parameters only. Please guide me if there is any other approach to work with the output from the Function block in Simulink.

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

回答 (0 件)

カテゴリ

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

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by