From: wander.lairson <wan...@gm...> - 2011-03-15 17:04:45
|
2011/3/15 Emmanuel Blot <ebl...@gm...>: > Hi, > > I bumped into an issue when initializing a device. > The device (FTDI chip) offers up to four similar UART/serial ports, > each port is tied to a USB interface. > > I use the following piece of code: > > dev = usb.core.find(idVendor=vendor, idProduct=product) > if not dev: > raise IOError('Device not found') > for configuration in dev: > for interface in configuration: > ifnum = interface.bInterfaceNumber > if not dev.is_kernel_driver_active(ifnum): > continue > try: > print "detach %s: %s" % (dev, ifnum) > dev.detach_kernel_driver(ifnum) > except usb.core.USBError, e: > pass > dev.set_configuration() > > I need to detach *all* the interfaces from the (Linux) kernel, or I > sometime get an error (not a big deal for my use case) > I also need to call dev.set_configuration() to configure the device. > Nothing unusual I guess. > > The troubles happen when I need to open two serial ports, that is two > interfaces from the same USB device. > On the second initialization call, when dev.set_configuration() is > called for the second time, the first open interface gets in trouble: > Exception: UsbError: No such device (it may have been disconnected) > It seems set_configuration() cannot be called another time if an > interface is already being actively used. > > I don't know how to avoid calling set_configuration() more that once, > as I don't know how to identify that the USB device has already been > configured. > > Each call to usb.core.find() returns a different instance even when it > manages the same device, and I don't see any way to detect the > physical device has been already configured or not. > > Any idea? > You can use get_configuration method to check if the device is already configured. According to USB Spec, if it is not zero, it is configured. -- Best Regards, Wander Lairson Costa LCoN - Laboratório de Computação Natural - Natural Computing Laboratory (http://www.mackenzie.com.br/lcon.html) Programa de Pós-Graduação em Engenharia Elétrica (PPGEE) Faculdade de Computação e Informática (FCI) Universidade Presbiteriana Mackenzie - SP - Brazil |