Problems with GUI Callback Error
이전 댓글 표시
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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
답변 (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
Harneel Singh Sagoo
2014년 11월 11일
Geoff Hayes
2014년 11월 11일
Harneel - use the paperclip button to select your file, and then press the Attach File button. As for your error message, what are you trying to read off of COM2? Is there anything already connected or using it?
Harneel Singh Sagoo
2014년 11월 11일
Geoff Hayes
2014년 11월 12일
Harneel - are the two devices actually connected on ports 5 and 7, or 1 and 2?
Harneel Singh Sagoo
2014년 11월 13일
편집: Geoff Hayes
2014년 11월 13일
Geoff Hayes
2014년 11월 13일
Based on your previous code, the above output occurs before you open the ports. Is this still the case? What happens when you call
instrfind('Type','serial','Port','COM6','Tag','');
instrfind('Type','serial','Port','COM7','Tag','');
after you have opened COM7?
Harneel Singh Sagoo
2014년 11월 17일
Harneel Singh Sagoo
2014년 11월 19일
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?
Harneel Singh Sagoo
2014년 11월 19일
카테고리
도움말 센터 및 File Exchange에서 Write COM Applications to Work with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!