Trích:
Nguyên văn bởi luckyboy150488
mình cũng đang làm đề tài vẽ đồ thị dữ liệu nhận từ rs232 bạn nào có tài liệu share cho t với.t xin cám ơn
|
Bạn dùng thử code này xem sao:
---my code---
serialObj=serial('COM1','baudrate',9600,'Timeout', 2);
serialObj.BytesAvailableFcnMode='byte';
serialObj.BytesAvailableFcnCount=2;
serialObj.BytesAvailableFcn={@mycallback,handles};
......
......
function mycallback(hObject, eventdata, handles)
tframe=2; %width of the oscilloscope screen
global ia count t tocold samples
if isempty(count)
count=1;
end
try
x=fread(handles.serialObj,2,'uint8');
ia(count)=x(1)*256+x(2); %x=[quotient reminder]
samples(count)=count;
catch e
errordlg(e.message);
end
count=count+1;
set(handles.plot1,'xdata',samples,'ydata',ia);
set(handles.axes1,'xlim',[0 count]...
,'ylim',[min(ia)-1 max(ia)+1]);
Hoặc trong file .txt ở dưới, đổi nó lại thành .m ha(tại mình up ko đc). Bạn về chỉnh sửa cho hợp với mình.