How to read variable buffersize every second ?

1 回表示 (過去 30 日間)
Kaan Inal
Kaan Inal 2022 年 4 月 12 日
回答済み: ag 2023 年 9 月 15 日
Hello,
i want to read the bytesavailable inside the serialport buffer every second. The bytes can vary, so i can't use a specific number of bytes to read.
Is there a possible solution for this task ?
Thanks.

回答 (1 件)

ag
ag 2023 年 9 月 15 日
Hi Kaan,
I understand that you need to read available bytes with a timeout of 1 second
To achieve this, you can use the Timeout function of the serialport object.
The below example reads 16 values of 'uint32' data in '1 second' from the 'COM3' serial port:
s = serialport("COM3",9600,"Timeout",1);
data = read(s,16,"uint32");
You can loop over the above example to achieve your task.
Please refer to the following documentation for more information,
Hope this helps!
Best Regards, Aryan Gupta

カテゴリ

Help Center および File ExchangeSerial and USB Communication についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by