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

MATLAB串口开关问题

[复制链接]

该用户从未签到

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

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

该用户从未签到

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

本版积分规则

关闭

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

EDA365公众号

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

GMT+8, 2025-11-5 17:30 , Processed in 0.156250 second(s), 23 queries , Gzip On.

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

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

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