equivalent of BytesAvailable in serialport?
34 次查看(过去 30 天)
显示 更早的评论
Hi, I am trying to migrate from `serial` to serialport interface, and having a hard time accessing BytesAvailable in `serialport`. While using serial, I could access the input buffer and get all bytes using `serial.BytesAvailable` which by default is 512. So with `fread` I get a matrix of 512 *1. However, when using `serialport` interface, NumBytesAvailable does not give me the same info.
Could anyone help me please? Thanks!
0 个评论
回答(1 个)
Poorna
2024-5-17
Hi Arthur,
It is to be noted that "BytesAvailable" and "NumBytesAvailable" behave the same way. They return the number of bytes available to read in the input buffer. When you say "I could access the input buffer and get all bytes using 'serial.BytesAvailable' which by default is 512", It is not true that the default value of the "BytesAvailable" is 512, the default value of the "BytesAvailable" property is 0. It is set to zero as soon you open the serial port by using the "fopen"' function.
It is difficult to understand what went wrong while you were using the "NumBytesAvailable" property of the "serialport" object without the actual code. Also, the "read" function is the equivalent of the "fread" function when you switch from "serial" to "serialport". Please refer to the following documentation about transitioning from "serial" to "serialport":
To know more about "serial" and "serialport", refer to the below documentation:
Hope this helps!
3 个评论
Walter Roberson
2024-5-17
serialport() objects manage the buffer internally, adjusting the size as needed.
If you only need 512 bytes out of the 8053 currently available, then
read(OBJECT, min(512,OBJECT.NumBytesAvailable))
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!