问题描述
您可以使用ioctl确定在Linux下可从串行端口读取多少数据。是否可以确定在写入串行端口时还有多少缓冲区空间?实际上,我想将数据块写入串行端口,仅在一次可以卸载所有数据时才成功,或者如果必须分块则失败。对端口的写入和读取是非阻塞的。我不希望这是UART缓冲区,但是内核存储缓冲区要在UART缓冲区之前(我想)。
You can determine how much data is available to read from a serial port under linux using an ioctl. Is it possible to determine how much buffer space remains for the serial port when writing to it? Effectively I want to write a block of data to a serial port, succeeding only if it can all be offloaded in one go, or failing if it would have to be chunked. The writes and reads to the ports are non-blocking. I'm not expecting this to be the UARTs buffer, but the kernels memory buffer ahead of the UARTs buffer (I guess).
推荐答案
您可以确定写入/输出的数量。
You can determine the amount of write/output.
要读取:
ioctl(device_handler, TIOCINQ, &bytes);
要写:
ioctl(device_handler, TIOCOUTQ, &bytes);
FIFO缓冲区的大小:
Size of FIFO buffer:
serial_struct serinfo;
memset(&serinfo, 0, sizeof(serinfo));
ioctl(device_handler, TIOCGSERIAL, &serinfo);
serinfo.xmit_fifo_size;
致谢,
VA。
Regards,VA.
这篇关于如何确定linux串行端口上剩余的写/输出缓冲区空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!