获取读取之前在串行端口上等待的字节数,Linux [英] Get the count of bytes waiting on a serial port before reading, linux

查看:77
本文介绍了获取读取之前在串行端口上等待的字节数,Linux的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Win32串行类转换为Linux(Ubuntu),此串行类的必需功能之一是窥视"串行缓冲区,以查看在读取串行端口之前串行端口上有多少字节等待.

I am converting a Win32 serial class to Linux (Ubuntu) one of the required functions of this serial class is to "peek" at the serial buffer to see how many bytes are waiting on the serial port before reading the serial port.

在这种修脚情况下,在尝试读取端口之前,我只需要知道端口上是否有任何字节.

In this pedicure situation I only need to know if there are ANY bytes on the port before attempting to read it.

在Windows中,我使用了COMSTATS,但在Linux中似乎找不到类似的功能.

In windows I used COMSTATS but I can't seem to find a similar function in Linux.

我的问题是:

在Linux上,如何读取在串行端口上等待的字节数/字符而不将其从串行端口缓冲区中删除?

On Linux How do you read the amount of BYTES/chars waiting on a serial port without removing them from the serial port buffer?

推荐答案

您需要使用ioctl

You need to use an ioctl

ioctl(serial_fd, FIONREAD, &bytes_avail);

关于该文档以及许多其他问题(规范与原始模式等),该文档非常值得阅读

This document is very much worth reading, for that and many other issues (canonical vs raw mode, etc)

http://www.cmrr.umn.edu/~strupp/serial. html

这篇关于获取读取之前在串行端口上等待的字节数,Linux的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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