Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8806941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:15:04+00:00 2026-06-14T02:15:04+00:00

Say I open Devices. int fd,fd1; fd_set readfds; int maxfd; fd = open(/dev/ttyUSB0); if(fd<0)

  • 0

Say I open Devices.

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;

Now I add them to 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.

}


}

Now how can i check the device when it is available now. Say if device is not available when i opened it. How can i monitor it to check when it has been plugged?. I don’t want to use udev/libudev.h.

Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T02:15:06+00:00Added an answer on June 14, 2026 at 2:15 am

    Common way is to try writing to device some data and reading response back. If response is expected then it means device is connected, otherwise it is not.

    For example when scanning COM port on which modem is connected one should write "ATE0\r" to COM port and get back modem response "OK". This means modem is connected to that COM port.

    Same idea applies to USB devices. Only protocol is more complex and request/response data may be more complex from device to device.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If you open a web page that is not mobile-specific at all, say, http://dogpile.com
I'm trying to watch a process and wait for a certain pattern, say: open
Say I open a file in vim. I start on line 1 column 1
Say I open Chrome and hop into the javascript console. If I run localStorage.setItem('test',
Example: say I want to open a file. If I get a FileNotFoundException ,
I'm trying to open a file in a Java program (say Program.java ) using
If a MySQL database connection is already open from a script (say PHP ),
Let's say I have the following code, file1 = open(myfile,w) #Write to file1... #Open
If you open Settings -> General -> About , it'll say Bob's iPhone at
I have one device which sends data on COM port say on COM13. Now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.