LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-14-2010, 03:39 PM   #1
R00ts
Member
 
Registered: Mar 2004
Location: Austin TX, USA
Distribution: Ubuntu 11.10, Fedora 16
Posts: 547

Rep: Reputation: 30
Question Best method for programmatically detecting a USB device?


Hi everyone. I have a USB modem and a large C++ application that needs to detect whether that device is present or not. I was hoping to get advice for what the best method to do so would be. The only solution I've thought of is to parse the output of lsusb and look for the vendor and product ID of my device, but that seems a little hack-ish and inefficient.


Is there a command or program that I can provide it a vendor/product ID for a USB device and it can tell me whether or not such a device is present in the system? Or another, better way to detect the device than parsing the lsusb output that I've been thinking? Thanks.
 
Old 12-14-2010, 11:49 PM   #2
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 676

Rep: Reputation: 137Reputation: 137
Quote:
Originally Posted by R00ts View Post
Hi everyone. I have a USB modem and a large C++ application that needs to detect whether that device is present or not. I was hoping to get advice for what the best method to do so would be. The only solution I've thought of is to parse the output of lsusb and look for the vendor and product ID of my device, but that seems a little hack-ish and inefficient.


Is there a command or program that I can provide it a vendor/product ID for a USB device and it can tell me whether or not such a device is present in the system? Or another, better way to detect the device than parsing the lsusb output that I've been thinking? Thanks.
At least on Fedora/RedHat you can use udev (and run custom rule for your USB modem) to create device with a name you like. Then your application should only open device with known name.
 
Old 12-15-2010, 09:36 AM   #3
R00ts
Member
 
Registered: Mar 2004
Location: Austin TX, USA
Distribution: Ubuntu 11.10, Fedora 16
Posts: 547

Original Poster
Rep: Reputation: 30
Thanks. I took a brief look at udev and it seems to be something that runs when a device is connected/disconnected, which isn't quite what I'm looking for. But I've only skimmed the surface so I'll keep investigating. I also realized yesterday that the driver for this modem creates a device file at /dev/tty***USBModem, so I may just decide to check for the existence of that file to determine if the USB device is plugged in or not.

(FYI, this application is on an embedded system that won't be changed/reconfigured on site)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
USB drive not working properly, read only device? (USB key storage device) Arodef Linux - Hardware 14 01-01-2010 07:32 AM
Method to determine if a device is a usb device (RHEL5 / RHEL6) mholden64 Linux - Kernel 4 08-15-2009 07:45 PM
probe method on bus and device driver not being called kunice Linux - Hardware 0 02-24-2008 11:47 AM
snd-usb-audio not detecting my device ekoome Linux - Kernel 1 07-15-2007 01:19 PM
Problem in Detecting USB Mass storage device LN85 Linux - Kernel 5 07-03-2007 11:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration