Problems with GUI Callback Error

1 visualizzazione (ultimi 30 giorni)
Harneel Singh Sagoo
Harneel Singh Sagoo il 10 Nov 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

Risposte (1)

Geoff Hayes
Geoff Hayes il 10 Nov 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 Commenti
Geoff Hayes
Geoff Hayes il 19 Nov 2014
So are you still experiencing errors even though you are using different ports? And are they the same errors as before?
Harneel Singh Sagoo
Harneel Singh Sagoo il 19 Nov 2014
Yes i get the same Errors when using COM6 and COM7. Could it be an issue with the Windows Device Manager and not Matlab?

Accedi per commentare.

Categorie

Scopri di più su Use COM Objects in MATLAB in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by