필터 지우기
필터 지우기

Error Dialog Box for Serial Communication

조회 수: 2 (최근 30일)
Shawn Chang
Shawn Chang 2012년 11월 14일
Hi all, is that any possible way to display the error dialog box whenever the desired port to be connected is currently not available.
Currently my code is write as following which will connect the 'COM6' directly when the button callback. I wish to write it in such a way, if the 'COM6' is currently no available, it will display an error message. Any solution to do so? Thanks you.
instrreset;
s_port=serial('COM6','BaudRate',115200,'Parity','none'...
,'DataBits',8,'FlowControl','none');
set(s_port,'InputBufferSize',11,'OutputBufferSize',11,'Timeout',1);
fopen(s_port);
fprintf(s_port,'s');
fgetl('%s',s_port);
fclose(s_port);

채택된 답변

Jan
Jan 2012년 11월 14일
Unfortunately the documentation of serial does not explain what happens, if the port cannot be opened. Therefore I guess:
try
s_port=serial('COM6','BaudRate',115200,'Parity','none', ...
'DataBits',8,'FlowControl','none');
catch
errordlg(...)
return;
end
Or:
s_port = serial('COM6','BaudRate',115200,'Parity','none', ...
'DataBits',8,'FlowControl','none');
if isempty(s_port) % or what ever, please simply test this
errordlg(...)
return;
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by