3
說我打開設備。通過打開和讀取檢測可用設備
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。
感謝,
「我不想使用'udev/libudev.h'」。 - 爲什麼不? –
嗯,我需要使它在沒有使用庫的情況下工作。謝謝, – demic0de