필터 지우기
필터 지우기

Matlab, Arduino Communication using BytesAvailableFcn Too many input arguments

조회 수: 2 (최근 30일)
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

채택된 답변

Sean de Wolski
Sean de Wolski 2015년 2월 9일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Instrument Control Toolbox에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by