Borrar filtros
Borrar filtros

sending over serial port

2 visualizaciones (últimos 30 días)
Josephine
Josephine el 5 de Dic. de 2013
Respondida: Walter Roberson el 5 de Dic. de 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');

Respuestas (1)

Walter Roberson
Walter Roberson el 5 de Dic. de 2013

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by