Dynamic input buffer size of a serial communication
10 次查看(过去 30 天)
显示 更早的评论
Hi all,
I'm trying to read out data from a sensor via RS485 communication. But the problem here is that the data array send from the sensor can vary.
Is it possible to set the inputbuffer or the fread() function to a dynamic input size?
Thank you and nice greetings,
Martin
0 个评论
采纳的回答
Ameer Hamza
2020-3-12
fread() already allows specifying the number of bytes. For serial object, the input buffer size is a double value: https://www.mathworks.com/help/matlab/ref/serial-properties.html#mw_5d33f1bd-97a2-4474-b2ea-8499775ddce4 it needs to be constant. You can try using BytesAvailableFcn: https://www.mathworks.com/help/matlab/matlab_external/bytesavailablefcn.html callback function and load the data from the serial buffer to the base workspace (for example, using a global variable) every time the number of bytes in the serial buffer reaches a specified number.
However, starting from R2019b, MATLAB has introduced a function serialport: https://www.mathworks.com/help/matlab/ref/serialport.html which does not require to specify the size of the input buffer and handle it in the background.
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!