Search code examples
pythonraspberry-piusblibusb

"Unknown Error" when calling set_configuration from PyUSB


I'm using a simpler version of StormLauncher (https://github.com/nmilford/stormLauncher) to call a Thunder USB Missile Launcher from a Raspberry Pi. Once I hooked it up to a powered USB hub it worked.

Twice.

Now when I call it, I get:

Traceback (most recent call last):File "launcherFire.py", line 15, in <module>
turret.set_configuration()


File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 559, in set_configuration
    self._ctx.managed_set_configuration(self, configuration)
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 92, in managed_set_configuration
    self.backend.set_configuration(self.handle, cfg.bConfigurationValue)
  File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 741, in set_configuration
    _check(self.lib.libusb_set_configuration(dev_handle.handle, config_value))
  File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 571, in _check
    raise USBError(_str_error[ret], ret, _libusb_errno[ret])
usb.core.USBError: [Errno None] Unknown error

I've tried unplugging and plugging it back again, which seemed to work here but it hasn't changed anything.

Here is my code:

import usb.core


turret = usb.core.find(idVendor=0x2123, idProduct=0x1010)


if turret is None:
    raise ValueError('Launcher not found.')

try:
    turret.detach_kernel_driver(0)
except Exception, e:
    pass # already unregistered    

turret.set_configuration()

turret.ctrl_transfer(0x21, 0x09, 0, 0, [0x02, 0x10, 0x00,0x00,0x00,0x00,0x00,0x00])

Any hints on what to try, either software or hardware wise, would be great.

Update: It appears to have been a hardware failure on the USB launcher itself. I replaced it and the exact same code runs fine (although humorously this launcher also has a broken motor, but at least the air trigger still operates).


Solution

  • It was a hardware failure. A new launcher worked as expected with the same code.