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

MATLAB串口开关问题

[复制链接]

该用户从未签到

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

EDA365欢迎您登录!

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

x
先描述下问题现象:
% l0 G: o% v) k  `. g# s        正常打开关闭一次串口后,再次打开串口提示:" u2 `& i) i6 y) K1 x, X1 p
       打开失败: 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);9 z& Z! z# Q# E3 D

$ J/ I8 {# ^8 W: U; w* X( H确认该串口没有在其它程序中使用!. m, h1 V* }7 o
2 s1 a% g- p6 S( C( m
以下是程序代码. u$ g! U: z( D. v2 B) j5 n
$ \& [$ t. B- d6 h$ @) g2 K* y7 E
set(handles.pmComPort,'String',seriallist);( i; a& ]4 S+ b( J1 n1 J: O
indexCom = get(handles.pmComPort,'Value');
9 {1 J1 A  h6 U8 RstrCom = get(handles.pmComPort,'String');7 J2 w" X$ D5 n. a: d
if indexCom > 1
, ?+ r: o/ R1 p& g8 X- U    comPort = strCom(indexCom);. M& V3 v' o" m2 V! G
else
8 b* i5 K: K0 f, O    comPort = strCom;   
1 U" ]$ A* A# D( `2 m3 ~end0 [+ |, T, k/ o. n; ?! z
s = serial(comPort);
2 I/ A% j& b7 E& j2 a2 U# Pif handles.pbOpenAndClose.String == "打开"
. ]3 j' t" B! `6 W% o    handles.pbOpenAndClose.String = "关闭";
$ Z, a. o+ m) f    handles.pbOpenAndClose.BackgroundColor = 'g';
( B. E  j  a5 j! q. C1 T8 _, p    fopen(s);   6 ]6 H3 U6 L4 o
else; K# M3 |0 c; s, V: m; C
    handles.pbOpenAndClose.String = "打开";! O/ ~8 ], U/ G) }7 y0 p) N  R( ?3 M3 Z
    handles.pbOpenAndClose.BackgroundColor = 'r';* }; b* O* H# v2 f' E
    fclose(s);
% O4 o/ ~, m0 ^    delete(s);0 O# _1 _8 s% `: `- j8 ?6 l/ m
    clear s;
9 I) B3 x0 L# W# Pend
! S! ]( X" ~* X0 [6 T6 v8 M; p

该用户从未签到

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

本版积分规则

关闭

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

EDA365公众号

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

GMT+8, 2025-8-14 15:50 , Processed in 0.125000 second(s), 23 queries , Gzip On.

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

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

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