如何有效地等待CTS或RS232的DSR在Linux呢? [英] How to efficiently wait for CTS or DSR of RS232 in Linux?

查看:291
本文介绍了如何有效地等待CTS或RS232的DSR在Linux呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我读CTS和以下面的方式串行端口的DSR信号:

Currently, I'm reading the CTS and DSR signals of a serial port in the following way:

bool get_cts(int fd) {
    int s;
    ioctl(fd, TIOCMGET, &s);
    return (s & TIOCM_CTS) != 0;
}

现在我想等到 get_cts()返回true。一个简单的循环不是,我认为(因为它是极其资源密集型)的最佳解决方案。

Now I'd like to wait until get_cts() returns true. A simple loop isn't the best solution I think (as it's extremely resource-intensive).

void wait_cts(int fd) {
    while(1) {
        if(get_cts(fd)) {
             return;
        }
    }
}

有没有在Linux上使用C或C ++任何更好的解决方案? (我不能使用任何硬件流控,我并不需要在所有的串行数据线。)

Is there any better solution using C or C++ on Linux? (I cannot use any hardware flow control as I don't need the serial data lines at all.)

推荐答案

有是的ioctl TIOCMIWAIT 该块,直到一组给定的信号变化。

There is the ioctl TIOCMIWAIT which blocks until a given set of signals change.

可悲的是这个读写控制在 tty_ioctl未记录(4)页也不在 ioctl_list(4)

Sadly this ioctl is not documented in the tty_ioctl(4) page nor in ioctl_list(4).

我已经了解此读写控制在这个问题:

I have learned about this ioctl in this question:

Python的监控串口(RS-232)的握手信号

这篇关于如何有效地等待CTS或RS232的DSR在Linux呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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