Create a C-type(bitfields) structure in Matlab and pass it to Matlab function block
8 次查看(过去 30 天)
显示 更早的评论
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:
- In MATLAB, we defined the same fields as bus elements (size 32).
- We created a 'Simulink.bus' with all these defined fields/elements.
- We later created a Matlab structure from bus using 'Simulink.Bus.CreateMATLABStruct' command.
- We passed this default values structure (all initialised to 0) as an input argument to a MATLAB function block.
- 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.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulink Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!