|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
先描述下问题现象:
% l0 G: o% v) k `. g# s 正常打开关闭一次串口后,再次打开串口提示:" u2 `& i) i6 y) K1 x, X1 p
打开失败: 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);9 z& Z! z# Q# E3 D
$ J/ I8 {# ^8 W: U; w* X( H确认该串口没有在其它程序中使用!. m, h1 V* }7 o
2 s1 a% g- p6 S( C( m
以下是程序代码. u$ g! U: z( D. v2 B) j5 n
$ \& [$ t. B- d6 h$ @) g2 K* y7 E
set(handles.pmComPort,'String',seriallist);( i; a& ]4 S+ b( J1 n1 J: O
indexCom = get(handles.pmComPort,'Value');
9 {1 J1 A h6 U8 RstrCom = get(handles.pmComPort,'String');7 J2 w" X$ D5 n. a: d
if indexCom > 1
, ?+ r: o/ R1 p& g8 X- U comPort = strCom(indexCom);. M& V3 v' o" m2 V! G
else
8 b* i5 K: K0 f, O comPort = strCom;
1 U" ]$ A* A# D( `2 m3 ~end0 [+ |, T, k/ o. n; ?! z
s = serial(comPort);
2 I/ A% j& b7 E& j2 a2 U# Pif handles.pbOpenAndClose.String == "打开"
. ]3 j' t" B! `6 W% o handles.pbOpenAndClose.String = "关闭";
$ Z, a. o+ m) f handles.pbOpenAndClose.BackgroundColor = 'g';
( B. E j a5 j! q. C1 T8 _, p fopen(s); 6 ]6 H3 U6 L4 o
else; K# M3 |0 c; s, V: m; C
handles.pbOpenAndClose.String = "打开";! O/ ~8 ], U/ G) }7 y0 p) N R( ?3 M3 Z
handles.pbOpenAndClose.BackgroundColor = 'r';* }; b* O* H# v2 f' E
fclose(s);
% O4 o/ ~, m0 ^ delete(s);0 O# _1 _8 s% `: `- j8 ?6 l/ m
clear s;
9 I) B3 x0 L# W# Pend
! S! ]( X" ~* X0 [6 T6 v8 M; p |
|