error: incompatible types when assigning to type 'double' from type 'char *' c2_b_y = doble(c2_b_u);
10 次查看(过去 30 天)
显示 更早的评论
Hello all again;
I want to ask for your help to understand this problem. I need to make a converter from float value to string, to be send by serial transmit of my Tiva C launchpad. Im trying to make the conversion in a simulink function block using the sprintf function.
During the debug in the Code Compiler Studio it works fine.
The problem ocurrs with Matlab, that give this error:
Building with 'MinGW64 Compiler (C)'.
C:\Users\Alberto\Desktop\slprj\_sfprj\untitled\_self\sfun\src\c2_untitled.c: In function 'sf_gateway_c2_untitled':
C:\Users\Alberto\Desktop\slprj\_sfprj\untitled\_self\sfun\src\c2_untitled.c:180:10: error: incompatible types when assigning to type 'double' from type 'char *'
c2_b_y = doble(c2_b_u);
^
gmake: *** [c2_untitled.obj] Error -1
Component: Make | Category: Make error
Unable to create mex function 'untitled_sfun.mexw64' required for simulation.
This is the C code:
#include <stdio.h>
#include "dobloh.h"
double u;
char* doble(double u)
{
static char car[2000];
sprintf(car,"%.3f",u);
return car;
}
"dobloh.h" Header:
#ifndef DOBLADOR_C_
#define DOBLADOR_C_
char* doble(double u);
#endif /* DOBLADOR_C_ */
Function block code:
function y = callingDoblez(u)
%#codegen
y=0.0;
y = coder.ceval('doble',u);
I hope you can help me to understand the problem,
Thanks for your time
Regards
Alberto
0 个评论
回答(1 个)
Venkatachala Sarma
2016-5-6
Hi Alberto,
I think this summarizes all your recent queries :)
So Simulink tries to check if the model is fit for generating code before it actually generates code. To do this, Simulink generates a MEX file for your model and tries to simulate it. 'coder.ceval' is a function which works only for code generation and it has to be excluded from Simulation. So try to use the following code in the MATLAB Function block
function y = callingDoblez(u)
%#codegen
y=0.0;
if(coder.target('Rtw')
y = coder.ceval('doble',u);
end
end
This guard coder.target('Rtw') restricts 'coder.ceval' to be visible to simulation and shows it only to code generation.
I hope this resolves the issue.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!