|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
先描述下问题现象:
' V4 `' e% R, e) J5 H% T _- `- M* _ 正常打开关闭一次串口后,再次打开串口提示:
* g" |7 E7 ~& n- e 打开失败: 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);
/ j4 ^/ s4 d& I1 I3 c- @2 {: x1 s; e. _
确认该串口没有在其它程序中使用!, a$ T6 t& b: |6 B, v
- G& W6 N9 \! B' R以下是程序代码
+ T4 n0 {# n8 l3 J3 L
+ A8 t M: f- k8 X" p) Iset(handles.pmComPort,'String',seriallist); f# U3 I' ]( d3 a6 r
indexCom = get(handles.pmComPort,'Value');
( c2 d/ u( r8 Q7 J6 M5 ZstrCom = get(handles.pmComPort,'String');- Z5 ?' B) q: y O8 j% I. C
if indexCom > 1& h( z( \* Z5 k) a5 \
comPort = strCom(indexCom);& o" V4 S- a% F7 t
else, _; w3 ?. |. K
comPort = strCom;
- }7 j; z7 v" X/ ~ M m5 |end+ @' S4 C- [) P7 T8 I
s = serial(comPort);
7 W# Z7 `4 b2 I7 a1 Z; Vif handles.pbOpenAndClose.String == "打开"
: m( b/ J x: F" {0 B i; K handles.pbOpenAndClose.String = "关闭";) W" G; W* O6 T
handles.pbOpenAndClose.BackgroundColor = 'g';3 M+ `" H& q ] |$ v3 l
fopen(s); & K& Y! Y1 H$ G. @ M% j
else
3 k6 H) G# d# i# T/ ]" F+ \ handles.pbOpenAndClose.String = "打开";
" t1 B& S# [) ~% n( U1 q0 `& B handles.pbOpenAndClose.BackgroundColor = 'r';9 L: j6 T7 Q, c
fclose(s);( g y+ U$ x$ Z- Q
delete(s);. R. @- G- {) j2 w8 d; ^+ _! e9 H
clear s;
. X* V8 B/ G: ^' Q3 ?end
# H6 C1 ^5 z, I% T' }' { |
|