python - the problem about detecting usb device -


i need detect usb device when had been plugged , unplugged, , write python programme dbus.

but odd device mounted 3 times @ least when plugged or unplugged

the monitor code following:

            device = dbus.interface(self.bus.get_object("org.freedesktop.hal", udi),                                     "org.freedesktop.hal.device")              self.notify_message(device.getproperty("info.udi")) 

then catch output when try insert usb device(eg. keyboard)

mon jul  4 03:47:31 2011    /org/freedesktop/hal/devices/usb_device_413c_2003_noserial  mon jul  4 03:47:31 2011    /org/freedesktop/hal/devices/usb_device_413c_2003_noserial_if0  mon jul  4 03:47:31 2011    /org/freedesktop/hal/devices/usb_device_413c_2003_noserial_if0_logicaldev_input 

so, notify shows 3 times everytime plugged or unplugged how show once notification?

i not familiar dbus, @ device names getting:

usb_device_413c_2003_noserial usb_device_413c_2003_noserial_if0 usb_device_413c_2003_noserial_if0_logicaldev_input 

the first device represents usb device whole. second device represents interface 0 of said device. third device represents endpoint or other feature of interface 0 may or may not specified in device's descriptors.

you 3 different logical devices though plugged in 1 physical device. sort of thing important people implement composite usb devices.

to answer question, though: if want notified once, in notification handler function should filter out notifications don't care looking @ device name string , deciding whether care event or not. example, might decide don't care devices if0 in name pseudo code be:

def notificationhandler(notification)   if notification.name not contain `if0`     pass notification higher level code   end end 

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -