MATLAB stops reading data

2 ビュー (過去 30 日間)
shreyas sanghvi
shreyas sanghvi 2019 年 10 月 8 日
So, I want to read data of a STM32F103RBT6 development board. I am able to receive the data though the STM for 1-2 minutes after which the communication abrubtly ends and I need to restart MATLAB to reset the communication link before I can rerun the script. Please help
Matlab code:
clc
clear
try
s=serial('COM4','BAUD',115200);
fclose(s);
fopen(s);
l=256;
p=zeros(1,l);
q=ones(1,l);
tic;
for j=1:l
z=fgets(s);
string(z);
p(1,j)=hex2dec(strtrim(z));
end
toc;
plot([1:256l],p);xlim([0 l]);drawnow
while(1)
for i=l:-1:2
p(1,i)=p(1,i-1);
end
z=fgets(s);
string(z);
p(1,1)=hex2dec(strtrim(z));
plot([1:256l],p);xlim([0 l]);drawnow
end
catch me
fclose(s);
end
fclose(s);

回答 (0 件)

製品


リリース

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by