デバイスを開くとします。
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 を使用したくありません。
ありがとう、