目前,我正在通过以下方式读取串口的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++有没有更好的解决方案?(我不能使用任何硬件流控制,因为我根本不需要串行数据线.)