Return Array Pointer with ceval

6 次查看(过去 30 天)
DKalale
DKalale 2017-11-10
回答: Mark McBroom 2017-11-12
I am trying to pass 6 integer values out of a C Function into a variable in Simulink. I am trying this by trying to return a pointer to a fixed size array out of a C Function using the ceval function. I am having trouble with the ceval settings.
My C function is something like...
int * read_variable(void)
{
/*Static Variable for Counters */
Static int var[6];
/*Read and Assign to Array*/
var[0] = 10U;
var[1] = 11U;
var[2] = 12U;
var[3] = 13U;
var[4] = 14U;
var[5] = 15U;
/* Return point to the array */
return var;
}
What do I need in ceval to get this to work? Below is what I am starting with, but I am hoping someone else has already figured this out.
function var = read
var = int32(zeros(6,1));
var = coder.ceval('read_variable',coder.wref(var));
end

回答(1 个)

Mark McBroom
Mark McBroom 2017-11-12
As described in the help , coder.ceval() can only return a scalar value. In order to return a vector, you will need to change your C function to have var[6] as an argument rather than a return and then remove the assignment to coder.ceval, since the C function is now a void function. MATLAB code should look like this.
coder.ceval('read_variable',coder.wref(var));

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by