필터 지우기
필터 지우기

Reading from COM port for 2 days

조회 수: 2 (최근 30일)
naser moravej
naser moravej 2022년 11월 27일
답변: chrisw23 2022년 11월 28일
Hello everyone,
I have an instrument which continuously sends data over serial port (I use an USB to TTL) with baud rate 460800. Currently I can capture its data for about 6 hours (the target PC has 4GB of ram). This period of time doesn't satisfy my requirement. I'm tring to read from serial port for 2 days (or more). Perhaps this limition is because of the amount of system's ram. Is there any way to save data directly to the hard disk to eliminate this limition?
This is my code. The code suppose to infinitely read from serial port util the USB to TTL get upluged.
packet_length = 816;
numT = 100000
rawData1D = zeros(1, numT * packet_length);
s = serial('COM22','BaudRate',460800,'timeout', 10);
s.InputBufferSize = 242400000;
fopen(s);
C = 1;
a = 0;
while 1
a = fread(s,packet_length);
if size(a,1) < packet_length
break;
end
rawData1D(packet_length * C + 1: packet_length * (C + 1)) = a;
C = C + 1
end
fclose(s);
Thanks for your suggestion.

답변 (1개)

chrisw23
chrisw23 2022년 11월 28일
I suggest to use event based communication. Reading a fixed packet length may lead to a buffer over-/underrun due to asynchronous write and read operations.
read this Serial Events

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by