|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
先描述下问题现象:
2 X( F3 S$ X9 H- i; B5 v4 X/ K 正常打开关闭一次串口后,再次打开串口提示:
& F2 c1 p- [" \! D* L8 | 打开失败: 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);# j/ Y; h3 H/ b7 [, o
+ l/ t1 M* v! J8 J' _
确认该串口没有在其它程序中使用!0 }( O [5 X3 e: I( h: g3 z# ~
( T, x+ K( ^, |+ x" Y以下是程序代码# H8 e1 R3 e+ H, b5 x
( M% m" V* S( q- n
set(handles.pmComPort,'String',seriallist);
& {7 }8 l u& ^" x$ U" AindexCom = get(handles.pmComPort,'Value');
% I7 ? y, f& x' f0 `strCom = get(handles.pmComPort,'String');
& Q- }- [2 Z x( j/ @if indexCom > 1: ~$ n( M6 a$ k9 x( r' a
comPort = strCom(indexCom);
7 }0 _6 u) L( X- Delse8 m2 }, b; I5 o& w
comPort = strCom; 5 T8 D1 i" L/ G
end
?& j0 i$ D) Z m1 g. ~6 ps = serial(comPort);
) Z" n7 V) l; M( T0 N2 C6 R7 C% |if handles.pbOpenAndClose.String == "打开"( @7 c: P0 D/ n
handles.pbOpenAndClose.String = "关闭";" m7 o7 Z; y' ` P
handles.pbOpenAndClose.BackgroundColor = 'g';
* r0 {/ y% i" q" _% E; T+ x fopen(s); * V5 s- r3 Q$ n
else5 `) A) E+ V) n( V: D$ b# C5 v
handles.pbOpenAndClose.String = "打开";
8 {5 v1 M/ `8 e3 N) n& b handles.pbOpenAndClose.BackgroundColor = 'r';( g: A2 Z( i# c! |+ p
fclose(s);4 t1 }$ n3 t6 ^. a1 X1 A9 V3 T
delete(s);& t# b/ d7 |; }; y8 k+ p
clear s;
$ N# k% [* r. F1 C" E# x) ^0 }end
' C* D' z( G+ P, V3 G/ X; O* E$ {/ A, P |
|