After you clear s then it no longer exists as a variable so you cannot fopen it.
Problem with open serial port
1 次查看(过去 30 天)
显示 更早的评论
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
回答(0 个)
另请参阅
类别
在 Help Center 和 File 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!