Effacer les filtres
Effacer les filtres

sending over serial port

2 vues (au cours des 30 derniers jours)
Josephine
Josephine le 5 Déc 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');

Réponses (1)

Walter Roberson
Walter Roberson le 5 Déc 2013

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by