-   Programming (
-   -   Hotplugging USB devices in Linux (

jobless 10-14-2008 06:46 PM

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?


jschiwal 10-14-2008 07:35 PM

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.

jobless 10-16-2008 07:34 PM

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.

All times are GMT -5. The time now is 07:19 AM.