|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
先描述下问题现象:
; s1 ^7 p$ @0 |9 x( H, A$ j4 k5 o 正常打开关闭一次串口后,再次打开串口提示:2 ?! z, j( Q8 ~1 j' y5 C1 [
打开失败: 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);6 A! j& b8 n' n1 w$ J
/ p; L; z# ]/ W确认该串口没有在其它程序中使用!# @+ }$ A( G+ S s$ `$ d1 O* u7 I+ e
; [1 x$ _5 n7 B) A) {3 [0 O! T3 O4 g以下是程序代码
& a3 k ?+ b6 |0 A4 o' |5 q s& ]5 K( w8 l9 O& Z3 H- X) o8 x3 J! c. A
set(handles.pmComPort,'String',seriallist);
" K3 ?, {8 Q; c! W1 O* j( IindexCom = get(handles.pmComPort,'Value');
. i& j h! {6 W& Q: OstrCom = get(handles.pmComPort,'String');
" j" n1 P- V; z8 uif indexCom > 1: A; x! s$ }$ I8 l
comPort = strCom(indexCom);, O, L% J- Z* _4 `$ V& V4 r
else1 m* J9 C( |/ _6 k# j
comPort = strCom;
* C) Q0 T. ^/ F% l' ~end
& K; u$ D" Y% }. H& O6 m* Y4 ?8 D! Rs = serial(comPort);6 h! ?) ^5 K4 u5 N# b
if handles.pbOpenAndClose.String == "打开"
0 m' H$ g0 z; h: m# B+ P! E5 W handles.pbOpenAndClose.String = "关闭";1 l8 q4 Z7 E# G% o" M
handles.pbOpenAndClose.BackgroundColor = 'g';
5 A5 O6 a4 n X3 f fopen(s);
5 ^; O0 s! |% L' Felse
0 k8 _' {; n8 H4 J6 D handles.pbOpenAndClose.String = "打开";% W* a! T* u% z* O9 r# S
handles.pbOpenAndClose.BackgroundColor = 'r';# i1 k$ [0 ?1 X" `
fclose(s);9 u/ b7 n( K& C' W: s& f. y5 w
delete(s);: o) ~/ w% Y9 X. Z {
clear s;# d$ O, D) X' ?2 Q
end+ A: g" f7 ]& O, J
|
|