필터 지우기
필터 지우기

Problem with open serial port

조회 수: 1 (최근 30일)
Yuval Froman
Yuval Froman 2019년 8월 5일
댓글: Walter Roberson 2019년 8월 5일
Hi,
I am doing a project and i need to recieve data from microcontroller.
I opened a new GUI file in Matlab, but when i get to open the serial port i get this error:
"Error while evaluating UIControl Callback"
Somone have an idea what can be the problem?
Thanks.
This is my code: The problem is in case 3:
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes1);
cla;
s = serial('COM4','baudrate',9600,'Terminator','CR','StopBits',1);
popup_sel_index = get(handles.popupmenu1, 'Value');
switch popup_sel_index
case 1
plot(rand(5));
case 2
plot(sin(1:0.01:25.99));
case 3
fclose(s);
delete(s);
clear s;
fopen(s);
fprintf(s,'Telemeter@');
distance = str2double(fscanf(s,'%s'));
%a = '5';
str = get(handles.text1,'String');
set(handles.text1,'String',[str distance]);
fclose(s);
end
  댓글 수: 1
Walter Roberson
Walter Roberson 2019년 8월 5일
After you clear s then it no longer exists as a variable so you cannot fopen it.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by