|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
先描述下问题现象:/ T- H9 r. }9 t) B' w! v- N4 X3 v4 P5 o h
正常打开关闭一次串口后,再次打开串口提示:& ?$ |/ [( C8 g( P: O
打开失败: 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);5 p9 Y2 v# I' I& F3 }! {, U8 z+ x
3 @4 p( u7 r, ?. K确认该串口没有在其它程序中使用!: [& R, l9 j! y2 Q" N
. {6 k) e7 n6 J6 D+ u) x
以下是程序代码
, x" y. |, h6 u! ^& Y
7 ^/ ]! |1 k) E1 ^, ^. j/ x8 Bset(handles.pmComPort,'String',seriallist);
! m+ N' f2 q3 B. L; R# xindexCom = get(handles.pmComPort,'Value');+ l- H0 a' e: I6 n& w( v
strCom = get(handles.pmComPort,'String');% Q+ Y; d* n* w% O; N- O. _! ]% r
if indexCom > 1
; h. B) H: O7 F; l, p: @/ g. o comPort = strCom(indexCom);. ?. F: g6 Q! h* g
else
/ B8 p0 g6 N+ D0 j/ c( c comPort = strCom;
) H" [; r. }8 u1 l' @6 n& W& Rend
3 T, `5 p- [# A) ^: v% ~s = serial(comPort);' ^: P/ W/ @. V: x
if handles.pbOpenAndClose.String == "打开"
' [) ~6 @4 ?0 e' K7 i. @ handles.pbOpenAndClose.String = "关闭";
+ y: V ^9 o0 u% W6 m4 g1 q6 I handles.pbOpenAndClose.BackgroundColor = 'g';
7 z* @8 @2 B5 o+ D2 z+ N fopen(s); + a3 R' g! z9 O) m( X
else
G' y% K% w: _9 U handles.pbOpenAndClose.String = "打开";
+ Y0 y9 U6 m/ ?* F9 n handles.pbOpenAndClose.BackgroundColor = 'r';% X! w2 o) Q/ @- Z6 E5 s1 ?; U3 ]
fclose(s);9 N3 k$ @6 \: I& \) L4 a0 ~* I, }
delete(s);
: A( ]4 u- ?2 G- ~. E clear s;5 O. r& P$ H) b& ]; O' c
end' J# e, z) l1 ~- M1 ]
|
|