フィルターのクリア

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 Center および File ExchangeSpecifying 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