資源簡介
可以使用matlab代碼打開、關閉串口,讀取串口數據,可以處理串口錯誤信息,自定義帶有數據幀封裝與解析算法,支持多通道繪制波形。純代碼實現。
代碼片段和文件信息
clc;
clearvars;
close?all;
%?fclose(instrfind);
dataRate?=?5;
timeDatabuf?=?0.2;
timeWinLength?=?20;
plotWinLength?=?dataRate?*?timeWinLength?;
groupNum?=?7;
frameLength?=?13;
frameHead?=?‘#S‘;
frameEnd?=?‘E*‘;
serialPort?=?serial(‘COM3‘‘BaudRate‘9600);
serialPort.InputBufferSize?=?frameLength?*?groupNum?*?dataRate?*?timeDatabuf;
serialPort.Timeout?=?6000;
dataBufferSize?=?serialPort.InputBufferSize;
try
????fopen(serialPort);
catch?err
????fclose(instrfind);
????pause(0.1);
????fopen(serialPort);
end
strChecker?=?blanks(2);
strBuffer?=?blanks(frameLength?-?4?+?1);
dispBuffer?=?zeros(9plotWinLength);
tAxes?=?-plotWinLength;
x?=?tAxes?:?1?:?tAxes?+?plotWinLength?-?1;
t?=?x?./?dataRate;
channelNum?=?1;
iStr?=?1;
iStrBuf?=?1;
dotNum?=?0;
pause(0.1);
try
????[strcountmsg]?=?fgetl(serialPort);
????disp(str);
%?????str?=?fgetl(serialPort);
catch?
????disp(‘1\n\r‘);
end
figure(‘Position‘[20500550400]);
hold?on;
grid?on;
grid?minor;
while?i
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????3532??2017-03-23?15:51??RS232.m
-----------?---------??----------?-----??----
?????????????????3532????????????????????1
- 上一篇:Matlab做有限元分析
- 下一篇:matlab 邊緣圖像檢測 幾種算法GUI界面
評論
共有 條評論