Effacer les filtres
Effacer les filtres

Problem with open serial port

1 vue (au cours des 30 derniers jours)
Yuval Froman
Yuval Froman le 5 Août 2019
Commenté : Walter Roberson le 5 Août 2019
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 commentaire
Walter Roberson
Walter Roberson le 5 Août 2019
After you clear s then it no longer exists as a variable so you cannot fopen it.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Specifying Target for Graphics Output dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by