Borrar filtros
Borrar filtros

Problem with open serial port

1 visualización (últimos 30 días)
Yuval Froman
Yuval Froman el 5 de Ag. de 2019
Comentada: Walter Roberson el 5 de Ag. de 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 comentario
Walter Roberson
Walter Roberson el 5 de Ag. de 2019
After you clear s then it no longer exists as a variable so you cannot fopen it.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Specifying Target for Graphics Output en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by