[英]Linux serial port reading - can I change size of input buffer?
I am writing an application on Ubuntu Linux in C++ to read data from a serial port. 我正在用C ++编写Ubuntu Linux上的应用程序来从串口读取数据。 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()
然后ioctl(fd,FIONREAD,&bytes_avail)
成功地工作ioctl(fd,FIONREAD,&bytes_avail)
以找出在最终使用read()
获取数据之前可用的字节数。
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. 我的问题是:每次
select
返回数据时,可用的字节数报告为8.我猜这是一个缓冲区大小设置在某处,当这个缓冲区已满时,select会向用户返回通知。
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. 我不熟悉Linux作为开发人员(但不是C ++的新手),我试图研究(没有成功)是否可以改变这个缓冲区的大小,或者确实如果我的假设是真的。 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?
这可能,而不深入研究内核代码?
You want to use the serial IOCTL TIOCSSERIAL
which allows changing both receive buffer depth and send buffer depth (among other things). 您希望使用串行IOCTL
TIOCSSERIAL
,它允许更改接收缓冲区深度和发送缓冲区深度(以及其他内容)。 The maximums depend on your hardware, but if a 16550A is in play, the max buffer depth is 14. 最大值取决于您的硬件,但如果正在使用16550A,则最大缓冲区深度为14。
You can find code that does something similar to what you want to do here 你可以找到的代码,做类似的事情你想做的事在这里
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. 最初的链接变坏了: http : //www.groupsrv.com/linux/about57282.html新的链接必须要做,直到我写另一个或找到一个更好的例子。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.