How to use try catch and call a function (e.g @myfunc)??

FUNCTION IN A PUSH BUTTON - CONNECT -----------------------------------------------------------
function serconnect_Callback(hObject, eventdata, handles)
global serConn
if strcmp(get(hObject,'String'),'CONNECT')
serPortn = get(handles.sercomm, 'Value');
if serPortn == 1
errordlg('Select valid COM port');
else
serList = get(handles.sercomm,'String');
serPort = serList{serPortn};
serConn = serial(serPort,'BaudRate',9600,'DataBits',8,'StopBits',1,'InputBufferSize',55 );
set(serConn, 'ReadAsyncMode', 'continuous');
try
fopen(serConn);
handles.serConn = serConn;
set(handles.serconnect, 'String','DISCONNECT');
set(handles.sercomm, 'Enable','off');
set(serConn, 'BytesAvailableFcn', {@myfunc,handles});
catch e
errordlg(e.message);
end
end
else
set(hObject, 'String','CONNECT');
fclose(handles.serConn);
end
guidata(hObject, handles);
------------------------------------------------------
MY FUNCTION:
________________________________________________________
function myfunc(hObject, eventdata, handles)
global serConn
try RxText = fscanf(handles.serConn); RxText = strtrim(RxText);
[InRange,power,va,var,pf,volt,current,id]=strread(RxText,'%s%s%s%s%s%s%s%s','delimiter',',');
if strcmp(id,'B')
set(handles.P1,'String',power);
set(handles.Q1,'String',var);
set(handles.V1,'String',volt);
end
if strcmp(id,'C')
set(handles.P2,'String',power);
set(handles.Q2,'String',var);
set(handles.V2,'String',volt);
end
if strcmp(id,'D')
set(handles.P3,'String',power);
set(handles.Q3,'String',var);
set(handles.V3,'String',volt);
end
if strcmp(id,'A')
set(handles.P4,'String',power);
set(handles.Q4,'String',var);
set(handles.V4,'String',volt);
end
catch e disp(e) end
PROBLEM: No errors are encountered but nothing happens. WHAT IS WRONG WITH THE CALLING OF @myfunc or TRY and CATCH??

4 commentaires

Have you used the debugger to step through your code ?
I have no idea what is a debugger. can you help me with that? try and catch work. I think it is at @myfunc. it does not execute @myfunc..
thanks for this. le me try this.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Interactive Control and Callbacks dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by