Problem with serial port communication

2 次查看(过去 30 天)
Hi,
I'm interfacing ALtera MAX10 fpga development kit with Matlab and trying to acquire data continuously. I can send command to the fpga board through Matlab regarding how many samples of data I want to capture (Also I'm increasing the buffer size according to the number of samples to be captured). Till 30000 samples I am getting the data correctly. Whenever I'm increasing the sample count to 50000, Matlab is throwing an error that the buffer size cannot be increased to this amount. I want to acquire data continuously say for 5 minutes ( corresponding to 300,000 samples ). Can anyone please kindly help me resolve this issue ? Note that baud rate is set to 115200 bps.
Thanks, Swarnava Pramanik

采纳的回答

Walter Roberson
Walter Roberson 2016-6-15
Use a BytesAvailableFcn callback to save the data from time to time.
  14 个评论
Swarnava Pramanik
Swarnava Pramanik 2016-6-18
Hi Walter,
Could you please kindly help me in another problem. I'm able to continuously get the data from my fpga board and at the same time I'm processing my data. It's happening so that my board is sending suppose 12000 samples but I'm only able to receive 11770 samples (losing around 300 samples corresponding to 0.3 seconds of data ). I'm attaching my code also
function store_plot_data(serialObject,event,chunk)
strRecv = fscanf(serialObject, '%s', chunk);
if( strcmp(strRecv(end), ',') == 1)
data_draw = [ data_draw dataStringTail strRecv ];
dataStringTail = [];
elseif( ( isempty(dataStringTail) == 0 ) && ( strcmp(strRecv(end), ',') == 0))
lastCommaIndex = max(strfind(strRecv,','));
% dataStringTail = strRecv(lastCommaIndex : end);
data_draw = [data_draw dataStringTail strRecv];
dataStringTail = [];
else
lastCommaIndex = max(strfind(strRecv,','));
dataStringTail = strRecv(lastCommaIndex : end);
data_draw = [data_draw strRecv(1 : lastCommaIndex - 1)];
end
end
Please note that "data_draw", "dataStringTail" are global variables.
Thanks,
Swarnava Pramanik
Swarnava Pramanik 2016-6-26
Hi Walter,
The callback function to the BytesAvailableFcn occurs only when the number of bytes specified by the BytesAvailableFcnCount is available in the input buffer. Suppose if the input buffer doesn't have the number of bytes specified by the BytesAvailableFcnCount property then the callback function is not executed. This is why I'm loosing some sample. Is there anyway to get around this ?
Thanks,

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by