Problem with Callback Function / BytesAvailableFcn on GUI
이전 댓글 표시
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
Walter Roberson
2015년 7월 6일
You did not say what difficulty you are encountering. Is the callback not being invoked? Have you tried
get(handles.Ser,'BytesAvailableFcn')
to be sure that it has been set to what you want?
Yassin Kim
2015년 7월 6일
Yassin Kim
2015년 7월 6일
편집: Yassin Kim
2015년 7월 6일
답변 (1개)
Harsha Medikonda
2015년 7월 7일
0 개 추천
'instrcallback' accepts two parameters. Please refer to the following documentation link
Also,please refer to the following link for the usage of bytesavailablefcn
댓글 수: 1
Walter Roberson
2015년 7월 8일
True, however it is only an error to specify more dummy parameters than actual arguments if one of the missing arguments is actually used.
카테고리
도움말 센터 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!