I am converting a Win32 serial class to Linux (Ubuntu) one of the required functions of this serial class is to "peek" at the serial buffer to see how many bytes are waiting on the serial port before reading the serial port.
In this pedicure situation I only need to know if there are ANY bytes on the port before attempting to read it.
In windows I used COMSTATS but I can't seem to find a similar function in Linux.
My question is:
On Linux How do you read the amount of BYTES/chars waiting on a serial port without removing them from the serial port buffer?
You need to use an ioctl
ioctl(serial_fd, FIONREAD, &bytes_avail);
This document is very much worth reading, for that and many other issues (canonical vs raw mode, etc)
http://www.cmrr.umn.edu/~strupp/serial.html
In C language you can ask this with an ioctl :
int bytes_avaiable;
ioctl(serial_file_descriptor, FIONREAD, &bytes_available);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With