LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-14-2008, 06:46 PM   #1
jobless
LQ Newbie
 
Registered: Sep 2008
Posts: 4

Rep: Reputation: 0
Hotplugging USB devices in Linux


Hello Guys,

I am trying to detect when a usb device is attached or detached. I am trying to find some library for Ubuntu that offers this feature. The device which is going to be attached will have an FTDI chip on it (I don't know if this information actually helps!). Can you point me to a library or some documentation which allows me to do this?

Thanks.
 
Old 10-14-2008, 07:35 PM   #2
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
You didn't mention what kind of usb device it is.

There is a libfdti but it seems to be intended for embedded devices. On the client side I don't think it would matter.

Look up documentation for Policy Kit & HAL. KDE receives messages from HAL via dbus. Udev should already create a device for you. "lshal -m" will monitor the messages sent when you insert a usb device. You can also use "udevmonitor." Is there already an .fdi file that covers it? Do you know what kernel module is used? You can insert the device while monitoring the kernel messages with "sudo tail -f /var/log/messages". You can also use "udevmonitor -env" to monitor udev and kernel environment values.

Three things to look at are:
  • Which kernel module needs to be loaded.
  • Do you need to install an .fdi file for hal to function properly with this device.
  • Do you need to add a udev rule to create the device node.

If your system uses Policy Kit, there may need to be a policy added as well, but it may be included with the .fdi file.

Last edited by jschiwal; 10-15-2008 at 05:46 AM. Reason: typo.
 
Old 10-16-2008, 07:34 PM   #3
jobless
LQ Newbie
 
Registered: Sep 2008
Posts: 4

Original Poster
Rep: Reputation: 0
More details

Thanks for the reply. The details were not clear in my previous post. Here is what I am trying to do.

The 'embedded' device I am going to attach will have an FTDI chip and has an ARM processor in it. The kernel module used when attaching the device is the ftdi_sio module. The device shows up as /dev/ttyUSB<NUM>.

I am trying to write a C program that will wait for the device to be attached and then install a program on it when it is attached. I could write an udev rule to run a program that sends a message to my program which is already running (thereby triggering it). But I was looking for some library like libusb, which provides me with some sort of blocking call to wait for a usb device to be attached to my machine. I will then look at the device string and figure out if the device attached is to be programmed or not.

As far as I can find out, libusb does not seem to be able to send an event after/or detecting hotplugging of usb devices . I am looking for a library that does.

Hope this made my question clear.

Last edited by jobless; 10-16-2008 at 07:40 PM. Reason: clarification
 
  


Reply

Tags
libusb, usb


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hotplugging and automounting removable devices? ryanreich Linux - General 4 08-06-2006 09:49 AM
USB Hotplugging and ECIADSL Tuetates Linux - Hardware 0 07-20-2005 03:42 AM
USB Hotplugging Howto? mooreted Mandriva 4 02-04-2005 11:04 AM
USB Hotplugging in LFS urk_forever Linux From Scratch 1 04-20-2004 04:36 PM
A simple question about hotplugging usb devices czechknight93 Linux - Hardware 2 04-07-2004 01:28 AM


All times are GMT -5. The time now is 01:48 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration