Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the count of bytes waiting on a serial port before reading

I have a custom made device with which I send/receive data trough the serial port. I was wondering if there is any function I can use to get the count of bytes waiting to be read from the serial port?

I want only a windows api solution, if there exists one. It seems a trivial task and I don't want to use external components.

like image 402
opc0de Avatar asked Nov 25 '25 09:11

opc0de


2 Answers

ClearCommError should fill in a COMSTAT (TComStat record) having a 'cbInQue' member specifying unread number of bytes received on the port.

like image 174
Sertac Akyuz Avatar answered Nov 26 '25 22:11

Sertac Akyuz


I use TComPort. Although you can use WinAPi calls, they are tricky and TComPort takes care of the boring stuff. It is very light and free and you can use the TComport.InputCount function which from the help:

 Returns the number of bytes in input buffer.

function InputCount: Integer;

Description
Call InputCount function to get the number of bytes in input buffer.
like image 25
Brian Frost Avatar answered Nov 26 '25 22:11

Brian Frost



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!