GUI Serial Communication Edittext
2 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
I have the following Code in my GUI and I'm hoping for some help:
% --- Executes on button press in Connect.
function Connect_Callback(hObject, eventdata, handles)
% hObject handle to Connect (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%suchen der verfügbaren Ports,...
%rausfinden in for-Schleife welches Port...
%die geüwnschte Eigenschaft (offen) besitzt...
%und verbinde Arduino mit diesem Port
handles =guidata (hObject);
h=instrfindall;
for i= 1:length(h)
fopen('COM'+string(i))
end
h=instrfindall;
str=string(h.name(find(cell2mat(h.BytesAvailable))))
fclose('all');
fopen(str);
% --- Executes on button press in Disconnect.
function Disconnect_Callback(hObject, eventdata, handles)
% hObject handle to Disconnect (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
fclose('all');
function Portname_Callback(hObject, eventdata, handles)
% hObject handle to Portname (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Portname as text
% str2double(get(hObject,'String')) returns contents of Portname as a double
% --- Executes during object creation, after setting all properties.
function Portname_CreateFcn(hObject, eventdata, handles)
% hObject handle to Portname (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Connection_Status_Callback(hObject, eventdata, handles)
% hObject handle to Connection_Status (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Connection_Status as text
% str2double(get(hObject,'String')) returns contents of Connection_Status as a double
% --- Executes during object creation, after setting all properties.
function Connection_Status_CreateFcn(hObject, eventdata, handles)
% hObject handle to Connection_Status (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
If I press the connect button I want to connect my Arduino to a COM-Port ( hope that my code is right referring to that)
In the next step I want to display the Port-Name my ARduino is connected to in the Edittext (Portname), do I have to use a handles-command, because if I straight use display(str) there is no name displayed in my edittext.
To stop the connection I simply used the command fclose('all') hope this is right, if not please correct me.
3 个评论
Geoff Hayes
2017-10-20
Tobias - you will need to read the info on connecting to the Arduino (from the above link) to see what you will need to connect to this device. Or watch this YouTube post at How to Interface Arduino with MATLAB.
How are you determining the port name by which you will connect to the Arduino? However that is, let's call it the local variable portname, it will be a string that you can then populate in your text control as shown above.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 MATLAB Support Package for Arduino Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!