How to determine the amount of buffer space for write / output remaining on the linux serial port?

You can determine how much data is readable from the serial port under Linux using ioctl. Is it possible to determine how much buffer space is left for the serial port when writing to it? In fact, I want to write a data block to the serial port, succeeding only if it can be unloaded at a time or if it will not be partitioned. Writing and reading to ports are not blocked. I do not expect this to be a UARTs buffer, but a kernel memory buffer before a UART buffer (I think).

+4
source share
3 answers

You can determine the amount of write / output.

For reading:

ioctl(device_handler, TIOCINQ, &bytes); 

For the record:

 ioctl(device_handler, TIOCOUTQ, &bytes); 

FIFO Buffer Size:

 serial_struct serinfo; memset(&serinfo, 0, sizeof(serinfo)); ioctl(device_handler, TIOCGSERIAL, &serinfo); serinfo.xmit_fifo_size; 

Regards, VA.

+3
source

The serial port is a character device, not a block device. It does not have a buffer. Character devices (such as a serial port, keyboard, mouse) write only and do not read the character. For exame, if you are listening to a series, someone writes “have a good day”, if you are not listening from the time it starts to print, you will not see the whole phrase. You will only see characters entered while listening

0
source

If you are accessing a serial port using a file descriptor, you can use select to check whenever the descriptor is ready for non-blocking writes. I do not know when this works for serial ports. I used this for TCP sockets and it worked.

0
source

Source: https://habr.com/ru/post/1443476/


All Articles