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

6 views (last 30 days)
Jovanie Josol
Jovanie Josol on 3 Mar 2013
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 Comments

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!