|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
先描述下问题现象:6 V: _6 o# e2 ]7 F+ C) I; V1 c
正常打开关闭一次串口后,再次打开串口提示:# k" x% K' s) b6 z Y
打开失败: Cannot connect to the COM31port. Possible reasons are another application is connected to the port or the port does not exist. 出错 MSerialV1>pbOpenAndClose_Callback(line 122) fopen(s);$ T$ z" H+ Y6 M% F% a/ R
4 ~0 Q) o, W; s Q' S1 Z确认该串口没有在其它程序中使用!3 c% c7 d& H( l: _7 f
$ n5 `4 a5 F; ]9 f
以下是程序代码$ n' e1 q+ A, \0 w
2 b# D: a) r* ]+ P4 _; Z" X/ e7 H
set(handles.pmComPort,'String',seriallist);0 Y3 A3 w, l( W" e
indexCom = get(handles.pmComPort,'Value');
( [6 e X" B. BstrCom = get(handles.pmComPort,'String');
2 O# i/ E7 S+ e s" }if indexCom > 1
, m0 {2 w, W; ]1 ^ _+ @ comPort = strCom(indexCom);# D* p# E9 n: `) P
else
6 _, m2 z2 }( e/ X comPort = strCom;
' x9 E. d: \. [6 J; k+ z' M( gend
* L1 W0 Q5 Z f% ~0 W: [s = serial(comPort);
) |0 ?2 C$ A) u, B0 n3 `if handles.pbOpenAndClose.String == "打开"1 r! o0 e' r! s
handles.pbOpenAndClose.String = "关闭";
! L' W; a8 J6 Z1 o) a, @& U handles.pbOpenAndClose.BackgroundColor = 'g';, z/ w' @' g# H! X$ |
fopen(s); : l3 x1 V% D1 a& F" U& D) f
else6 ^6 t6 F K: L
handles.pbOpenAndClose.String = "打开";' S+ e+ [+ _ s+ n% z; v
handles.pbOpenAndClose.BackgroundColor = 'r';. J2 e) G: H7 j5 T- t
fclose(s);% k( |1 q6 U: I5 x+ g% X- t
delete(s);" x& L& Q7 w/ H& z
clear s;+ `) e' w, Z$ u6 B6 w: p) }$ D
end
& A+ S0 a2 n# n3 a& [ |
|