sending over serial port

2 次查看(过去 30 天)
Josephine
Josephine 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