找回密码
 注册
关于网站域名变更的通知
查看: 547|回复: 1
打印 上一主题 下一主题

MATLAB串口开关问题

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2020-8-4 14:33 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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' }' {

该用户从未签到

2#
发表于 2020-8-4 15:51 | 只看该作者
试试过程中用指令能否正常退出串口,关闭串口
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

推荐内容上一条 /1 下一条

EDA365公众号

关于我们|手机版|EDA365电子论坛网 ( 粤ICP备18020198号-1 )

GMT+8, 2025-11-24 21:46 , Processed in 0.156250 second(s), 23 queries , Gzip On.

深圳市墨知创新科技有限公司

地址:深圳市南山区科技生态园2栋A座805 电话:19926409050

快速回复 返回顶部 返回列表