필터 지우기
필터 지우기

sending over serial port

조회 수: 2 (최근 30일)
Josephine
Josephine 2013년 12월 5일
답변: Walter Roberson 2013년 12월 5일
hi i am trying make a gui that will send data over serial port. my gui looks like this. it selects an copen port from the popup menu. when the connect button is pressed, it will connect. when the send button is pressed, it sends the data.
for now, the connect pushbutton works and so it will connect. but the send button will generate an error.
my code is somehow like this:
function connectbutton_Callback(hObject, eventdata, handles)
if strcmp(get(handles.connectbutton,'String'),'Connect')
serPortn = get(handles.popupmenu1, 'Value');
if serPortn == 1
errordlg('Select valid COM port');
else
serList = get(handles.popupmenu1,'String');
serPort = serList{serPortn};
serConn = serial(serPort, 'TimeOut', 1, ...
'BaudRate', str2num(get(handles.baudrate, 'String')));
try
fopen(serConn);
set(handles.sendbutton, 'Enable', 'On');
set(handles.connectbutton,'String','Disconnect')
catch e
errordlg(e.message);
end
end
else
set(handles.sendbutton, 'Enable', 'Off');
set(connectbutton, 'String','Connect')
fclose(serConn);
end
guidata(hObject, handles);
function sendbutton_Callback(hObject, eventdata, handles)
fprintf(serConn, 'E:\matlab workspace\gui\image.bmp');
out = fread(serConn, comPort.BytesAvailable,'uint8');
the error here is:
Undefined function or variable 'serConn'.
Error in mygui>sendbutton_Callback (line 101) fprintf(serConn, 'E:\matlab workspace\gui\image.bmp');

답변 (1개)

Walter Roberson
Walter Roberson 2013년 12월 5일

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by