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