Problems with GUI Callback Error
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Harneel Singh Sagoo
el 10 de Nov. de 2014
Comentada: Harneel Singh Sagoo
el 19 de Nov. de 2014
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Error produced once pressing the button "verbinden"
>> versuchsstand
Serial Port Object : Serial-COM1
Communication Settings
Port: COM1
BaudRate: 9600
Terminator: 'LF'
Communication State
Status: closed
RecordStatus: off
Read/Write State
TransferStatus: idle
BytesAvailable: 0
ValuesReceived: 0
ValuesSent: 0
Serial Port Object : Serial-COM2
Communication Settings
Port: COM2
BaudRate: 9600
Terminator: 'LF'
Communication State
Status: closed
RecordStatus: off
Read/Write State
TransferStatus: idle
BytesAvailable: 0
ValuesReceived: 0
ValuesSent: 0
Error using serial/fopen (line 72)
Open failed: Port: COM2 is not available. No ports are available.
Use INSTRFIND to determine if other instrument objects are connected to the requested device.
Error in versuchsstand>verbinden_Callback (line 98)
fopen(steuerung);
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in versuchsstand (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)versuchsstand('verbinden_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
0 comentarios
Respuestas (1)
Geoff Hayes
el 10 de Nov. de 2014
Harneel - rather than pasting the m file in your question, just attach it to your question using the paperclip button. Or just copy and paste the verbinden_Callback callback. There is nothing wrong with the callback but there is a problem with the serial port as it seems to still be available even though you have closed it. You may have to delete it as described at a similar question http://www.mathworks.com/matlabcentral/answers/9509-serial-port-is-not-available-in-gui-but-it-actually-available-in-my-pc. Try changing your code to the following
function verbinden_Callback(hObject, eventdata, handles)
% Kraftmesser initialisieren
kraftmesser = instrfind('Type','serial','Port','COM1','Tag','');
if ~isempty(kraftmesser)
fclose(kraftmesser);
delete(kraftmesser);
end
kraftmesser = serial('COM1');
% Steuerung initialisieren
steuerung = instrfind('Type','serial','Port','COM2','Tag','');
if ~isempty(steuerung)
fclose(steuerung);
delete(steuerung);
end
steuerung = serial('COM2');
fopen(steuerung);
fwrite(steuerung,'#1g=+1/r');
fclose(steuerung);
What happens when you now run your GUI? Also review your code for the COM1 serial port. It isn't clear why you need it since you never actually try to write anything to it.
10 comentarios
Geoff Hayes
el 19 de Nov. de 2014
So are you still experiencing errors even though you are using different ports? And are they the same errors as before?
Ver también
Categorías
Más información sobre MATLAB Mobile Fundamentals en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!