相关疑难解决方法(0)

如何在Linux中有效地等待RS232的CTS或DSR?

目前,我正在通过以下方式读取串口的CTS和DSR信号:

bool get_cts(int fd) {
    int s;
    ioctl(fd, TIOCMGET, &s);
    return (s & TIOCM_CTS) != 0;
}
Run Code Online (Sandbox Code Playgroud)

现在我想等到get_cts()返回true.一个简单的循环不是我认为的最佳解决方案(因为它非常耗费资源).

void wait_cts(int fd) {
    while(1) {
        if(get_cts(fd)) {
             return;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

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

c c++ linux serial-port wait

5
推荐指数
1
解决办法
3102
查看次数

标签 统计

c ×1

c++ ×1

linux ×1

serial-port ×1

wait ×1