假设我打开设备。
int fd,fd1;
fd_set readfds;
int maxfd;
fd = open("/dev/ttyUSB0");
if(fd<0) printf("device not available\n");//How can i Wait here until device becomes available?.. Also when it shows device not available it will just continue on doing select.
printf("device /dev/ttyUSB0 available\n");
fd1 = open("/dev/ttyUSB1");
if(fd<0) printf("device not available\n");//How can i Wait here until device becomes available?
printf("device /dev/ttyUSB1 available\n");
maxfd = MAX(fd,fd1)+1;
现在我将它们添加到 fd_set;
while(1){
FD_SET(fd,&readfds);
FD_SET(fd1,&readfds);
select(maxfd, &readfds, NULL, NULL, NULL);
if(FD_ISSET(fd,&readfds){
// Read the device. If there is nothing to read then device has been removed or something happend.
}
if(FD_ISSET(fd1,&readfds){
// Read the device. If there is nothing to read then device has been removed or something happend.
}
}
现在我如何检查设备现在可用时。说当我打开它时设备是否不可用。我如何监控它以检查它何时被插入?我不想使用 udev/libudev.h。
谢谢,