WHAT IS THE PROBLEM IN MY TRY and CATCH? or How can I call a function inside a function?? CAN SOMEONE HELP?? Im working with Arduino and GUI for monitoring for my thesis..
1 view (last 30 days)
Show older comments
THE CODE BELOW WORKS: ------------------------------------------------
s=serial ('COM43', 'BaudRate',9600,'DataBits',8,'StopBits',1,'InputBufferSize',212); fopen(s); count =0;
while (1)
%data from power analyzer
%InRange,-0250.6,0010.0,-0150.2,+0.6228,220.39,0.5806
pause(0.1);
data = fgets(s);
[load3 P3 S3 Q3 PF3 V3 I3 main P S Q PF V I load2 P2 S2 Q2 PF2 V2 I2 load1 P1 S1 Q1 PF1 V1 I1] =...
strread(data,'%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s','delimiter',',');
%%%%%%GET DATA FROM PA TO MAIN GUI%%%%%%
set(handles.LP4,'String',P);
set(handles.LQ4,'String',Q);
set(handles.LV4,'String',V);
end
-------------------------------------------------
BUT WHEN I CHANGE IT TO THIS CODE BELOW... no errors but nothing happens. what is the problem with the code??
---------------------------------------
function serconnect_Callback(hObject, eventdata, handles)
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,'FlowControl','none');
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');
set(handles.serconnect, 'BackGroundColor','default');
set(handles.sercomm, 'Enable','on');
fclose(handles.serConn);
end
guidata(hObject, handles);
------------------ BELOW IS THE FUNCTION CALLED -------------------
try RxText = fscanf(handles.serConn); RxText=strtrim(RxText);
%data from Arduino
%InRange,-0250.6,0010.0,-0150.2,+0.6228,220.39,0.5806
if strcmp(RxText(1,1),'InRange')
handles.counter = handles.counter + 1;
%get Arduino data
[load3 P3 S3 Q3 PF3 V3 I3 main P S Q PF V I load2 P2 S2 Q2 PF2 V2 I2 load1 P1 S1 Q1 PF1 V1 I1] =...
strread(RxText,'%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s','delimiter',',');
%%%%%%GET DATA FROM PA TO MAIN GUI%%%%%%
set(handles.LP4,'String',P);
set(handles.LQ4,'String',Q);
set(handles.LV4,'String',V);
end
catch e
disp(e)
end
---------------- CAN SOMEONE HELP? then when I add 'InputBufferSize',212 in the the serconn still it does not work but have no errors ----------
3 Comments
Accepted Answer
Image Analyst
on 28 Feb 2013
Is RxText a 2D array? Have you considered strfind() instead of strcmp()?
More Answers (0)
See Also
Categories
Find more on Arduino Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!