BytesAvailableFcn is getting called too often
显示 更早的评论
I have a serial communication port using TCP/IP, using the tcpip routine from the instrument control toolbox. Now, I receive data via network and plot it, everything's fine. But once the remote side closes the connection and I do not receive further data, I still get tons of BytesAvailable-callbacks, tough BytesAvailable equals 0.
Before calling fread, I check the obj.BytesAvailable. If it is zero, I skip the whole routine. Nevertheless, since these are so many callbacks, matlab needs a long time to process each callback.
I figured out that this is due to the fact that I read out the entire buffer using:
results = fread(acqData, acqData.BytesAvailable/2, 'int16');
while the BytesAvailableFcnCount and InputBufferSize is set as such:
acqData = tcpip('XXX.XXX.XXX.XXX', YYYY,'NetworkRole','client','InputBufferSize',2^16);
acqData.BytesAvailableFcnMode = 'byte';
acqData.BytesAvailableFcnCount = 2^5;
I understand that if the remote side fills the buffer very fast, I will get effectively 2^10 empty callbacks per actual callback. I do not want to set the BytesAvailableFcnCount to 2^16. Also, I would not like fread to only read 2^5 bytes each time it gets called (the callback function is rather slow, so it is best to process as much data at once as possible).
Cann I change the behaviour of the BytesAvailableFcn to trigger only once? E.g. when 2^5 bytes have arrived it triggers, but then all further callbacks until the buffer is full are discarded?
Thanks!
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 TCP/IP Communication 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!