|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
先描述下问题现象:
9 b! S2 M+ D5 E 正常打开关闭一次串口后,再次打开串口提示:+ T2 `5 Z" W: k0 Z" ]$ U* L
打开失败: 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);# r" c+ D0 L' Y/ p! j" }7 U/ }2 T
. A. O& K3 y1 R T$ S
确认该串口没有在其它程序中使用!
: L! O( `& j; { O( ~2 {
{& ]' m2 o$ y; d6 K* n以下是程序代码2 z& w) _+ B# {& R3 v# @' i, J
. H. ?# m* d8 A7 \: `: c# @9 ?0 ^: g
set(handles.pmComPort,'String',seriallist);
/ I i% ~8 k+ H4 H8 PindexCom = get(handles.pmComPort,'Value');
' h5 m/ j! g6 R; R u3 m/ wstrCom = get(handles.pmComPort,'String');" [$ C" d2 T/ _2 R1 t
if indexCom > 1' `$ d+ \+ \* K& F
comPort = strCom(indexCom);
f% v& E4 }6 z [, a6 o8 Velse# H# K. R; F& Z( f, T3 c6 V
comPort = strCom;
2 J$ z, W9 L# Eend3 i* ^9 e/ h T1 \7 a/ T u
s = serial(comPort);
) n: d" C5 d. H5 }5 h iif handles.pbOpenAndClose.String == "打开"+ {2 W! A5 j' C+ l1 w* T
handles.pbOpenAndClose.String = "关闭";
- C" E* g" R: v3 L- z: I5 ^ handles.pbOpenAndClose.BackgroundColor = 'g';2 k" S5 g( B7 O8 v
fopen(s); $ S" _0 f6 V) N3 |
else r7 j R9 S* Z
handles.pbOpenAndClose.String = "打开";
, q' D# }# [/ B: s handles.pbOpenAndClose.BackgroundColor = 'r';8 |) j0 o$ ~: c" ^( s/ \3 A
fclose(s);
- N2 J0 O5 v8 @, n, t delete(s);
' o) Q* h/ P# K) X' V0 B; d/ h" o clear s;( @/ T0 ~% A: n# L
end5 l- M5 J& \/ ^% l+ j
|
|