Filter löschen
Filter löschen

Matlab, Arduino Communication using BytesAvailableFcn Too many input arguments

2 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Sean de Wolski
Sean de Wolski am 9 Feb. 2015
Using the string syntax for mycallback doesn't allow you to change the inputs. You'll probably want something like this
s.BytesAvailableFcn =@(~,~)mycallbacktest(s};
Now we ignore (~) the two default arguments given by every callback function (why you're getting the error), and pass in s, what your function needs.

Weitere Antworten (0)

Kategorien

Mehr zu Instrument Control Toolbox finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by