Why do I get "Error using tlc_c" when using a Matlab Function in Simulink?
Show older comments
Hello,
I'm currently trying to use simulink and RT_Mag to get 2 devices (Gumstix Overo) to discuss over RS232.
The messages I'm trying to send/receive are made of multiple data with a string of character "data1;data2...;dataN\n\r" in char8.
Without any Matlab functions, everything works great. But when I try to use some to recover each data individually and use them as real numbers, or to put some numbers in a new string to send it back, I get several errors. The two functions work great on Matlab (I tested them before implementing them in Simulink), but when I launch my Simulink program I get these errors:
"
Code generation assertion 'typeReplaced.getMatrixSize() == typeReplacing.getMatrixSize()' failed in '.\rtwcg_utils\rtwcg_dataconnector.cpp:510'
[ 0] 0x204ecffb C:\Program Files\MATLAB\R2011b\bin\win32\rtwcg.dll+00315387 ( RTWCG::DataConnector::replace+000283 )
[ 1] 0x204ee8c0 C:\Program Files\MATLAB\R2011b\bin\win32\rtwcg.dll+00321728 ( RTWCG::RTWCGConnectBlockData+000512 )
[ 2] 0x204eeb83 C:\Program Files\MATLAB\R2011b\bin\win32\rtwcg.dll+00322435 ( RTWCG::RTWCGConnectBlockData+000067 )
[ 3] 0x2054efa8 C:\Program Files\MATLAB\R2011b\bin\win32\rtwcg.dll+00716712 ( RTWCG::RTWFcnConst::OptimizeAndEmitCode+001816 )
[ 4] 0x2051085d C:\Program Files\MATLAB\R2011b\bin\win32\rtwcg.dll+00460893 ( RTWCG::RTWCGModule::OptimizeAndEmitCode+000125 )
[ 5] 0x1e7f9ecd C:\Program Files\MATLAB\R2011b\bin\win32\libmwsimulink.dll+08298189 ( BlockSetCheckVarDimsInputEmpty+066381 )
[ 6] 0x1e7f6f97 C:\Program Files\MATLAB\R2011b\bin\win32\libmwsimulink.dll+08286103 ( BlockSetCheckVarDimsInputEmpty+054295 )
[ 7] 0x1e84aa02 C:\Program Files\MATLAB\R2011b\bin\win32\libmwsimulink.dll+08628738 ( sleGetRTWBlockForSLBlock+262210 )
[ 8] 0x1e84af9f C:\Program Files\MATLAB\R2011b\bin\win32\libmwsimulink.dll+08630175 ( sleGetRTWBlockForSLBlock+263647 )
[ 9] 0x1e33b9c5 C:\Program Files\MATLAB\R2011b\bin\win32\libmwsimulink.dll+03324357 ( ArrayToSLObject+481685 )
[ 10] 0x7f63ea8c C:\Program Files\MATLAB\R2011b\bin\win32\m_dispatcher.dll+00060044 ( mdLogging::log_function_exit+000108 )
[ 11] 0x7f63e561 C:\Program Files\MATLAB\R2011b\bin\win32\m_dispatcher.dll+00058721 ( Mfunction_handle::dispatch+000401 )
[ 12] 0x7b99ac96 C:\Program Files\MATLAB\R2011b\bin\win32\m_interpreter.dll+00502934 ( inDestroyWS+247110 )
[ 13] 0x7b997c71 C:\Program Files\MATLAB\R2011b\bin\win32\m_interpreter.dll+00490609 ( inDestroyWS+234785 )
[ 14] 0x7b9a6807 C:\Program Files\MATLAB\R2011b\bin\win32\m_interpreter.dll+00550919 ( inDestroyWS+295095 )
[ 15] 0x7b9a6922 C:\Program Files\MATLAB\R2011b\bin\win32\m_interpreter.dll+00551202 ( inDestroyWS+295378 )
### Build procedure for model: 'COM_Rs232_test' aborted due to an error.
Error using tlc_c (line 174)
Errors occurred during parsing of MATLAB function 'GUMSTIX/MATLAB Function3'(#61)
Error in RTW.makertw/make_rtw (line 281)
buildResult = tlc_c(h,...
Error in make_rtw (line 22)
buildResult = h.make_rtw(varargin{:});
Error in GenereFullCOM (line 99)
make_rtw; % generation of ert_code from the selected model
Error in GenereCOM (line 66)
GenereFullCOM(['COM_' ComModelName], MinSampleTime, Gumstix);
% generates the sources files to needed to build the application
Error in init_Rs232_test (line 24)
GenereCOM(ComModelName, ComMinSampleTime);
"
My functions work as follow:
"
function ordres = PWM2Orders(PWM_moteur1,sens1,PWM_moteur2,sens2,PWM_moteur3,sens3,PWM_moteur4,sens4,PWM_servo1,PWM_servo2,PWM_servo3,PWM_servo4,PWM_servo5,PWM_servo6)
%PWMtoOrders prepares the orders to send via the RS232 thread
% Apparently Simulink MatlabFunctions cannot have char8 data as output so
% it is necessary to cast...
coder.extrinsic('sprintf');
ordres = uint8(zeros(1,89));
strordres = sprintf('%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d\n\r',PWM_moteur1,sens1,PWM_moteur2,sens2,PWM_moteur3,sens3,PWM_moteur4,sens4,PWM_servo1,PWM_servo2,PWM_servo3,PWM_servo4,PWM_servo5,PWM_servo6);
ordres = cast(strordres,'uint8');
end
"
I already tried the 3 compilers proposed to me by mex -setup.
Finnally I work with MATLAB R2011b.
Thanks in advance!
Matthieu
EDIT:
The errors send me to this:
Error using tlc_c (line 174) :
[sfcnsCell, buildInfo, modelrefInfo] = ...
rtwgen(modelName, ...
'PostponeTerm', 'off', ...
'WriteDataRefs', 'on', ...
'CaseSensitivity','on',...
'Language', 'C', ...
'OutputDirectory',buildDir, ...
'MdlRefBuildArgs',iMdlRefBuildArgs);
Error in RTW.makertw/make_rtw (line 281) :
buildResult = tlc_c(h,...
h.ModelName, ...
h.RTWRoot, ...
h.SystemTargetFilename, ...
dispOpts, ...
h.BuildDirectory, ...
gensettings.CodeFormat,...
h.MdlRefBuildArgs, ...
anchorDir, checksum);
Error in make_rtw (line 22):
buildResult = h.make_rtw(varargin{:});
And the others just call the precedent one.
7 Comments
Ryan Livingston
on 19 Aug 2014
There should be some more error information available aside from "Errors occurred during parsing of MATLAB function...". You should be able to see the location in your MATLAB code where the error is being reported. Can you post those errors?
Matthieu Muschinowski
on 20 Aug 2014
Edited: Matthieu Muschinowski
on 20 Aug 2014
Ryan Livingston
on 20 Aug 2014
Thanks. The fact that the error "Error occurred during parsing..." is present means that an error was detecting when inspecting your MATLAB code. We need the error from processing the MATLAB code to determine what is wrong. Can you just paste everything that shows up?
There should also be a blue link that takes you to a line in your MATLAB code. There should also be further messages about what the software thinks is wrong with your MATLAB code. This:
shows how to view the errors in more detail.
Matthieu Muschinowski
on 20 Aug 2014
Ryan Livingston
on 20 Aug 2014
Edited: Ryan Livingston
on 20 Aug 2014
Ahh, thanks! Different kind of error from what I was initially expecting. So that's why you don't have any links.
Just a guess, but looking at the code in the MATLAB Function Block, it seems that the output of sprintf is not preallocated. When using an extrinsic function one must preallocate the output to tell Simulink about its size, type and complexness:
coder.extrinsic('foo');
y = zeros(1,2);
y = foo(x);
In your case, you could try something like:
strordres = blanks(1,89); %adjust size as necessary
strordres = sprintf(...);
ordres = cast(strordres, 'uint8');
describes this process in more detail.
Ryan Livingston
on 20 Aug 2014
If my previous suggestion doesn't help, getting in touch with MathWorks Technical Support is typically the best route for this type of issue:
Matthieu Muschinowski
on 20 Aug 2014
Answers (0)
Categories
Find more on COM Component Integration in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!