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

MATLAB串口开关问题

[复制链接]

该用户从未签到

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

EDA365欢迎您登录!

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

x
先描述下问题现象:
9 b! S2 M+ D5 E        正常打开关闭一次串口后,再次打开串口提示:+ T2 `5 Z" W: k0 Z" ]$ U* L
       打开失败: 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);# r" c+ D0 L' Y/ p! j" }7 U/ }2 T
. A. O& K3 y1 R  T$ S
确认该串口没有在其它程序中使用!
: L! O( `& j; {  O( ~2 {
  {& ]' m2 o$ y; d6 K* n以下是程序代码2 z& w) _+ B# {& R3 v# @' i, J
. H. ?# m* d8 A7 \: `: c# @9 ?0 ^: g
set(handles.pmComPort,'String',seriallist);
/ I  i% ~8 k+ H4 H8 PindexCom = get(handles.pmComPort,'Value');
' h5 m/ j! g6 R; R  u3 m/ wstrCom = get(handles.pmComPort,'String');" [$ C" d2 T/ _2 R1 t
if indexCom > 1' `$ d+ \+ \* K& F
    comPort = strCom(indexCom);
  f% v& E4 }6 z  [, a6 o8 Velse# H# K. R; F& Z( f, T3 c6 V
    comPort = strCom;   
2 J$ z, W9 L# Eend3 i* ^9 e/ h  T1 \7 a/ T  u
s = serial(comPort);
) n: d" C5 d. H5 }5 h  iif handles.pbOpenAndClose.String == "打开"+ {2 W! A5 j' C+ l1 w* T
    handles.pbOpenAndClose.String = "关闭";
- C" E* g" R: v3 L- z: I5 ^    handles.pbOpenAndClose.BackgroundColor = 'g';2 k" S5 g( B7 O8 v
    fopen(s);   $ S" _0 f6 V) N3 |
else  r7 j  R9 S* Z
    handles.pbOpenAndClose.String = "打开";
, q' D# }# [/ B: s    handles.pbOpenAndClose.BackgroundColor = 'r';8 |) j0 o$ ~: c" ^( s/ \3 A
    fclose(s);
- N2 J0 O5 v8 @, n, t    delete(s);
' o) Q* h/ P# K) X' V0 B; d/ h" o    clear s;( @/ T0 ~% A: n# L
end5 l- M5 J& \/ ^% l+ j

该用户从未签到

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

本版积分规则

关闭

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

EDA365公众号

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

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

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

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

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