matlab实时接收uart数据画图

matlab实时接收uart数据画图

ID:40157027

大小:87.89 KB

页数:4页

时间:2019-07-23

matlab实时接收uart数据画图_第1页
matlab实时接收uart数据画图_第2页
matlab实时接收uart数据画图_第3页
matlab实时接收uart数据画图_第4页
资源描述:

《matlab实时接收uart数据画图》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、comPortInstrcallback.m文件内容functioncomPortInstrcallback(obj,event)%数据包协议解析部分globalRecordBuffer,ReacordValid=0;DataByteLen=17000;%中断缓存字节长度ValidWaveLen=1000;%波形数据的长度RecordLen=17;%uartDataBuf=zeros(1,DataByteLen,'uint8');%x=zeros(2,3,'int8');uartCurDataBuf=fread(obj,DataByteLen,

2、'uint8');WaveDataBuf=zeros(1,ValidWaveLen,'uint32');%接收的数据不够一包数据的if(ReacordValid>0)tempBuf=zero(1,ReacordValid,'uint8');fori=1:ReacordValidtempBuf(i)=RecordBuffer(i);enduartDataBuf=[tempBuf;uartCurDataBuf];%组合数组elseuartDataBuf=[uartCurDataBuf];endj=1;k=0;fori=1:DataByteLenif

3、(uartDataBuf(i)==255&&uartDataBuf(i+1)==255)%查找包头if(DataByteLen-i>=(RecordLen-1))WaveDataBuf(j)=65536*uartDataBuf(i+2)+256*uartDataBuf(i+3)+uartDataBuf(i+4);j=j+1;elsefork=1:(DataByteLen-i)RecordBuffer(k)=uartDataBuf(i+k);endbreak;endendendif(k>0)ReacordValid=k;elseReacordVa

4、lid=0;endplot(WaveDataBuf,'r'),gridon;Instrcallback.m文件修改的内容instrcallback.m原路径在x:ProgramFilesMATLABR2008atoolboxmatlabiofun@instrument需要在原路径中更改文件,复制到程序目录是不能使用的functioninstrcallback(obj,event)comPortInstrcallback(obj,event);%添加的代码%INSTRCALLBACKDisplayeventinformationfo

5、rtheevent.%%INSTRCALLBACK(OBJ,EVENT)displaysamessagewhichcontainsthe%typeoftheevent,thetimeoftheeventandthenameofthe%objectwhichcausedtheeventtooccur.%%Ifanerroreventoccurs,theerrormessageisalsodisplayed.%Ifapineventoccurs,thepinthatchangedvalueandthepin%valueisalsodisplayed

6、.%%INSTRCALLBACKisanexamplecallbackfunction.Usethiscallback%functionasatemplateforwritingyourowncallbackfunction.%%Example:%s=serial('COM1');%set(s,'OutputEmptyFcn',{'instrcallback'});%fopen(s);%fprintf(s,'*IDN?','async');%idn=fscanf(s);%fclose(s);%delete(s);%%MP2-24-00%Copy

7、right1999-2004TheMathWorks,Inc.%$Revision:1.4.4.3$$Date:2004/01/1620:03:49$%Defineerrormessage.error1='Type''helpinstrumentinstrcallback''foranexampleusingINSTRCALLBACK.';error1Id='MATLAB:instrument:instrcallback:invalidSyntax';switchnargincase0error(error1Id,sprintf(['This

8、functionmaynotbecalledwith0inputs.',...'Type''helpinstrumentinstrcallbac

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。