我正在使用termios API来读取/写入串行接口中配置的设备。我正在使用的代码如下:
//打开串行接口const char * device =“/ dev / ttyS0”;int fd = …
虽然 O_NONBLOCK 在开放时添加, fcntl(fd, F_SETFL, 0) 在下面调用,相当于阻止模式。
O_NONBLOCK
fcntl(fd, F_SETFL, 0)
fd = open(device, O_RDWR | O_NOCTTY | O_NONBLOCK); fcntl(fd, F_SETFL, 0); // The O_NONBLOCK flag is overwritten
如果串口上没有数据,则会被阻塞。