Linux 串口读取 - 我可以更改输入缓冲区的大小吗? [英] Linux serial port reading - can I change size of input buffer?

查看:132
本文介绍了Linux 串口读取 - 我可以更改输入缓冲区的大小吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 C++ 在 Ubuntu Linux 上编写一个应用程序来从串行端口读取数据.通过我的代码调用 select() 然后 ioctl(fd,FIONREAD,&bytes_avail) 来确定在最终获取数据之前有多少字节可用,它可以成功运行使用 read().

I am writing an application on Ubuntu Linux in C++ to read data from a serial port. It is working successfully by my code calling select() and then ioctl(fd,FIONREAD,&bytes_avail) to find out how many bytes are available before finally obtaining the data using read().

我的问题是:每次 select 返回数据时,可用字节数报告为 8.我猜这是在某处设置的缓冲区大小,并且 select 返回通知给缓冲区已满时的用户.

My question is this: Every time select returns with data, the number of bytes available is reported as 8. I am guessing that this is a buffer size set somewhere and that select returns notification to the user when this buffer is full.

作为开发人员,我是 Linux 新手(但对 C++ 并不陌生),我曾尝试研究(但没有成功)是否可以更改此缓冲区的大小,或者我的假设是否正确.在我的应用程序中,时间很关键,只要读取缓冲区上有新字节,我就需要收到警报.这是否可能,无需深入研究内核代码?

I am new to Linux as a developer (but not new to C++) and I have tried to research (without success) if it is possible to change the size of this buffer, or indeed if my assumptions are even true. In my application timing is critical and I need to be alerted whenever there is a new byte on the read buffer. Is this possible, without delving into kernel code?

推荐答案

您想使用串行 IOCTL TIOCSSERIAL,它允许更改接收缓冲区深度和发送缓冲区深度(以及其他内容).最大值取决于您的硬件,但如果使用 16550A,则最大缓冲区深度为 14.

You want to use the serial IOCTL TIOCSSERIAL which allows changing both receive buffer depth and send buffer depth (among other things). The maximums depend on your hardware, but if a 16550A is in play, the max buffer depth is 14.

你可以在这里找到代码

原来的链接坏了:http://www.groupsrv.com/linux/about57282.html在我写另一个或找到更好的例子之前,新的将不得不做.

The original link went bad: http://www.groupsrv.com/linux/about57282.html The new one will have to do until I write another or find a better example.

这篇关于Linux 串口读取 - 我可以更改输入缓冲区的大小吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆