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

查看:465
本文介绍了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天全站免登陆