matlab實時接收uart數(shù)據(jù)畫圖

matlab實時接收uart數(shù)據(jù)畫圖

ID:40157027

大小:87.89 KB

頁數(shù):4頁

時間:2019-07-23

matlab實時接收uart數(shù)據(jù)畫圖_第1頁
matlab實時接收uart數(shù)據(jù)畫圖_第2頁
matlab實時接收uart數(shù)據(jù)畫圖_第3頁
matlab實時接收uart數(shù)據(jù)畫圖_第4頁
資源描述:

《matlab實時接收uart數(shù)據(jù)畫圖》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。

1、comPortInstrcallback.m文件內(nèi)容functioncomPortInstrcallback(obj,event)%數(shù)據(jù)包協(xié)議解析部分globalRecordBuffer,ReacordValid=0;DataByteLen=17000;%中斷緩存字節(jié)長度ValidWaveLen=1000;%波形數(shù)據(jù)的長度RecordLen=17;%uartDataBuf=zeros(1,DataByteLen,'uint8');%x=zeros(2,3,'int8');uartCurDataBuf=fread(obj,DataByteLen,

2、'uint8');WaveDataBuf=zeros(1,ValidWaveLen,'uint32');%接收的數(shù)據(jù)不夠一包數(shù)據(jù)的if(ReacordValid>0)tempBuf=zero(1,ReacordValid,'uint8');fori=1:ReacordValidtempBuf(i)=RecordBuffer(i);enduartDataBuf=[tempBuf;uartCurDataBuf];%組合數(shù)組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文件修改的內(nèi)容instrcallback.m原路徑在x:ProgramFilesMATLABR2008atoolboxmatlabiofun@instrument需要在原路徑中更改文件,復(fù)制到程序目錄是不能使用的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

當前文檔最多預(yù)覽五頁,下載文檔查看全文

此文檔下載收益歸作者所有

當前文檔最多預(yù)覽五頁,下載文檔查看全文
溫馨提示:
1. 部分包含數(shù)學(xué)公式或PPT動畫的文件,查看預(yù)覽時可能會顯示錯亂或異常,文件下載后無此問題,請放心下載。
2. 本文檔由用戶上傳,版權(quán)歸屬用戶,天天文庫負責整理代發(fā)布。如果您對本文檔版權(quán)有爭議請及時聯(lián)系客服。
3. 下載前請仔細閱讀文檔內(nèi)容,確認文檔內(nèi)容符合您的需求后進行下載,若出現(xiàn)內(nèi)容與標題不符可向本站投訴處理。
4. 下載文檔時可能由于網(wǎng)絡(luò)波動等原因無法下載或下載錯誤,付費完成后未能成功下載的用戶請聯(lián)系客服處理。