资源简介

用matlab的m语言编写的可从串口直接读取数据并显示为波形图的程序,仅供参考,数据传送格式请自行探索。

资源截图

代码片段和文件信息

clc;
bufsize=6;  
circle_times=2;
display_num=100;
doc=‘mydata1‘;
com=‘COM6‘;
baudrate=9600;
timeout=600;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
obj=serial(com);   
m=zeros(1display_num);
n=zeros(1display_num);
l=zeros(1display_num);
d=zeros(circle_timesdisplay_num);
e=zeros(circle_timesdisplay_num);
f=zeros(circle_timesdisplay_num);
fopen(obj);                
set(obj‘BaudRate‘baudrate‘timeout‘timeout‘DataBits‘8‘StopBits‘1‘Parity‘‘none‘‘FlowControl‘‘none‘);                 
wind_sum=0;
temp_sum=0;
humid_sum=0;
for i=1:circle_times
    for j=1:display_num
        data=fread(objbufsize)‘;
        a=double(data(1)*2^8+data(2))/10;
        b=double(data(3)*2^8+data(4))/10;
        c=double(data(5)*2^8+data(6))/100;
        m(j)=a;
        n(j)=b;
        l(j)=c;
   

评论

共有 条评论