Azzera filtri
Azzera filtri

sending over serial port

2 visualizzazioni (ultimi 30 giorni)
Josephine
Josephine il 5 Dic 2013
Risposto: Walter Roberson il 5 Dic 2013
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');

Risposte (1)

Walter Roberson
Walter Roberson il 5 Dic 2013

Categorie

Scopri di più su Programming in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by