Problems with GUI Callback Error
3 次查看(过去 30 天)
显示 更早的评论
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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 个评论
回答(1 个)
Geoff Hayes
2014-11-10
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 个评论
Geoff Hayes
2014-11-19
So are you still experiencing errors even though you are using different ports? And are they the same errors as before?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Use COM Objects in MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!