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

MATLAB串口开关问题

[复制链接]

该用户从未签到

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

EDA365欢迎您登录!

您需要 登录 才可以下载或查看,没有帐号?注册

x
先描述下问题现象:0 X/ i9 ?  L) `8 I
        正常打开关闭一次串口后,再次打开串口提示:: E$ ]2 b& P/ D5 p" I, {6 ?
       打开失败: 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);) w- U9 \) @' H/ ~  _$ G
+ a1 W! K9 y0 V7 `8 [5 I4 n' h! x
确认该串口没有在其它程序中使用!
1 n3 Z' ?  o. F) g; u7 a  Y3 X5 y& g* |  k$ c
以下是程序代码: f6 f: c( {" Y% i8 m
1 M1 J- y3 D- {3 H: D& B+ {
set(handles.pmComPort,'String',seriallist);1 d5 l' x+ \7 w2 q
indexCom = get(handles.pmComPort,'Value');/ A  ]1 D/ @" G% v% q0 b
strCom = get(handles.pmComPort,'String');* j7 H; B" S* s7 l& n
if indexCom > 1. y# `" L# v% W- E4 G' k
    comPort = strCom(indexCom);( c( c2 ?' q8 X7 q+ X' }; ^
else
" j3 Z9 \. Q0 i- o& C$ l    comPort = strCom;   ! u- T) ^. t7 @1 i% o0 n
end! r4 Z( G! i0 `. |9 v1 \& k
s = serial(comPort);
8 A! g% R' a2 e$ Q4 ?' ]/ v; zif handles.pbOpenAndClose.String == "打开"! |. Z' ]* M+ I* v
    handles.pbOpenAndClose.String = "关闭";) l( R. K1 v7 o, S% s* A% f
    handles.pbOpenAndClose.BackgroundColor = 'g';% m7 o5 e# I. N9 ~5 ~( N) k
    fopen(s);   
7 }/ b+ Z3 p1 w+ b. R) _5 melse6 S6 A4 b2 z" F5 B4 j
    handles.pbOpenAndClose.String = "打开";* r1 Q, U" t/ `! c9 {
    handles.pbOpenAndClose.BackgroundColor = 'r';
6 d9 q5 x0 |& v& t- f    fclose(s);
( q2 o! P" {# \' c    delete(s);
, X1 X1 s/ f5 e& ^: ~) Y    clear s;
" [5 I* A  O0 }6 R% x; V6 oend
0 D4 i/ f0 m) h& S# _* M! _+ {

该用户从未签到

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

本版积分规则

关闭

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

EDA365公众号

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

GMT+8, 2025-7-27 08:33 , Processed in 0.109375 second(s), 23 queries , Gzip On.

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

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

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