175

matlab串口禁用bytesavailablefcn

我在matlab上用串口读取stm32发送给电脑的数据,设置为缓冲区接收到32个字节就进入回调函数,但是弹出这个警告:The BytesAvailableFcn is being disabled. To enable the callback property either connect to the hardware with FOPEN or set the BytesAvailableFcn property.而且提示pause(5)这行代码有问题,不知道该怎么解决

clear;
clear s;
clc;

try
    s=serial('com5');
catch
    error('cant serial');
end
set(s,'BaudRate',115200,'ByteOrder','littleEndian','DataBits',8, ...
    'Parity','none','StopBits',1,'FlowControl','none');
set(s,'timeout',1);
s.inputbuffersize=10240000;   %设置串口接收缓冲区
s.OutputBufferSize=10240000;
s.BytesAvailableFcnMode = 'byte';
s.BytesAvailableFcnCount = 32;
s.BytesAvailableFcn  = @callback1;

fopen(s);

pause(5);
fclose(s);
delete(s);
clear s;
close all;
查看全部
weixin_44849612
weixin_44849612
2019/10/07 16:21
  • c++
  • c语言
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复