Return Array Pointer with ceval

5 views (last 30 days)
DKalale
DKalale on 10 Nov 2017
Answered: Mark McBroom on 12 Nov 2017
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

Answers (1)

Mark McBroom
Mark McBroom on 12 Nov 2017
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));

Categories

Find more on Simulink Coder in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!