Effacer les filtres
Effacer les filtres

equivalent of BytesAvailable in serialport?

24 vues (au cours des 30 derniers jours)
Arthur Zhang
Arthur Zhang le 2 Mai 2024
Commenté : Arthur Zhang le 17 Mai 2024
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!

Réponses (1)

Poorna
Poorna le 17 Mai 2024
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 commentaires
Walter Roberson
Walter Roberson le 17 Mai 2024
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))
Arthur Zhang
Arthur Zhang le 17 Mai 2024
Thanks Walter, I'll give it a try.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by