Matlab, Arduino Communication using BytesAvailableFcn Too many input arguments
Afficher commentaires plus anciens
Hey,
I'm having some Problems with the Serial Communication from Matlab to an Arduino.
It's supposed to be asynchronus read Operation (input from user) so I am using the 'BytesAvaiableFcn'.
Problem is I always get an Errormsg:
??? Error using ==>
mycallbacktest
Too many input arguments.
Error in ==> instrcb at 36
feval(val{1}, obj,
eventStruct,
val{2:end});
Warning: The BytesAvailableFcn
is being disabled. To enable the
callback property
either connect to the hardware
with FOPEN or set the
BytesAvailableFcn property.
My Matlab code for initalizing the serial Port is:
s = serial('com5');
set(s, 'BaudRate', 38400,'InputBufferSize', 1024, 'OutputBufferSize', 1024,'timeout',100);
s.BytesAvailableFcnMode = 'byte';
s.BytesAvailableFcnCount = 3;
s.BytesAvailableFcn ={'mycallbacktest',s};
fopen(s);
pause;
To test my callback function I got this code
function [] = mycallbacktest(s)
ardudata = fscan(s);
%set buttons
butsym{1,1} = '!';
butsym{1,2} = '?';
if strcmp(ardudata(1),butsym{1,1})
disp('case1')
elseif strcmp(ardudata(1),butsym{1,2})
disp('case2')
else
disp('case3')
% led_num = str2num(ardudata);
pause(1)
end
The Data from the Arduino:
case 1:
!!!
case 2:
???
case 3:
end of line char
XXX
in case 3 I get a new line Char and in the next line a 3 digit number in the range from 001-090
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur MATLAB Support Package for Arduino Hardware dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!