Problem with Callback Function / BytesAvailableFcn on GUI

5 visualizaciones (últimos 30 días)
Yassin Kim
Yassin Kim el 5 de Jul. de 2015
Comentada: Walter Roberson el 8 de Jul. de 2015
i work since 3 days only on one thing ; to be able to receive continuously bytes from device (Arduino) on GUI programme but unfortunately i have not done. The Problem is that BytesAvailableFcn cannot be called.
function togglebutton1_Callback(hObject, eventdata, handles)
stat = get(hObject,'Value'); %returns toggle state of togglebutton1
if (stat == 1)
if ~isfield(handles, 'Ser')
set(hObject, 'String','Connected');
handles.Ser = serial('COM11','BaudRate', 9600);
handles.Ser.BytesAvailableFcnMode = 'Terminator';
set (handles.Ser,'RequestToSend','off');
set (handles.Ser,'Terminator','CR');
handles.Ser.BytesAvailableFcn = {@instrcallback,handles}; % Here the Problem!
fopen(handles.Ser) ;
end
elseif (stat == 0)
if isfield(handles, 'Ser')
fclose (handles.Ser);
handles = rmfield(handles, 'Ser');
end
end
guidata(hObject, handles)
function instrcallback(obj, eventdata, handles)
set(findobj('Tag','text2'),'String','Bytes Received!') ; % Test if that function works
  3 comentarios
Yassin Kim
Yassin Kim el 6 de Jul. de 2015
Yes that's the Problem, i tried already :
get(handles.Ser,'BytesAvailableFcn')
and i got 0 I can receive Data with command
fscanf(handles.Ser)
in a loop while but i would like to use a callback function.
Yassin Kim
Yassin Kim el 6 de Jul. de 2015
Editada: Yassin Kim el 6 de Jul. de 2015
But if i use
Ser = serial('COM11','BaudRate', 9600);
Ser.BytesAvailableFcnMode = 'terminator';
Ser.BytesAvailableFcn = @instrcallback;
Ser.OutputEmptyFcn = @instrcallback;
set (Ser,'RequestToSend','off')
set (Ser,'Terminator','CR');
fopen(Ser) ;
in Command Window, i get
BytesAvailable event occurred at 18:38:36 for the object: Serial-COM11.
The Probleme is only with function instrcallback, it works when i delete it
%function instrcallback(obj, eventdata, handles)
%set(findobj('Tag','text2'),'String','Bytes Received!') ;

Iniciar sesión para comentar.

Respuestas (1)

Harsha Medikonda
Harsha Medikonda el 7 de Jul. de 2015
'instrcallback' accepts two parameters. Please refer to the following documentation link
Also,please refer to the following link for the usage of bytesavailablefcn
  1 comentario
Walter Roberson
Walter Roberson el 8 de Jul. de 2015
True, however it is only an error to specify more dummy parameters than actual arguments if one of the missing arguments is actually used.

Iniciar sesión para comentar.

Categorías

Más información sobre Instrument Control Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by