openant icon indicating copy to clipboard operation
openant copied to clipboard

Device remains in use after manager is stopped

Open jonnylamb opened this issue 9 years ago • 5 comments

I get usb.core.USBError: [Errno 16] Resource busy when creating another ant.fs.manager.Application instance using the same device:

With this test script I get the following traceback. https://gist.github.com/jonnylamb/a794c732bff1e1883d1a

Traceback (most recent call last):
  File "/tmp/garmin.py", line 34, in <module>
    b = GarminTest()
  File "/home/jonny/src/openant/ant/fs/manager.py", line 104, in __init__
    self._node = Node()
  File "/home/jonny/src/openant/ant/easy/node.py", line 56, in __init__
    self.ant = Ant()
  File "/home/jonny/src/openant/ant/base/ant.py", line 68, in __init__
    self._driver.open()
  File "/home/jonny/src/openant/ant/base/driver.py", line 185, in open
    dev.set_configuration()
  File "/home/jonny/src/pyusb/usb/core.py", line 559, in set_configuration
    self._ctx.managed_set_configuration(self, configuration)
  File "/home/jonny/src/pyusb/usb/core.py", line 92, in managed_set_configuration
    self.backend.set_configuration(self.handle, cfg.bConfigurationValue)
  File "/home/jonny/src/pyusb/usb/backend/libusb1.py", line 724, in set_configuration
    _check(self.lib.libusb_set_configuration(dev_handle.handle, config_value))
  File "/home/jonny/src/pyusb/usb/backend/libusb1.py", line 554, in _check
    raise USBError(_str_error[ret], ret, _libusb_errno[ret])
usb.core.USBError: [Errno 16] Resource busy

jonnylamb avatar Aug 06 '15 23:08 jonnylamb

Yes, this is intended. The Application class takes hold of this in the init function. Might be able to work around this by using del on the first object before creating a new one. But only one Application object is intended to be used during the liftetime of the program. That doesn't stop one from using multiple channels and similar of course.

Tigge avatar Aug 12 '15 13:08 Tigge

del a before creating b does not work.

How do you suggest I create another connection in the same process after the first one has disconnected then?

jonnylamb avatar Aug 12 '15 13:08 jonnylamb

Yeah, that is a good question - and something I haven't tried yet. I'll experiment a bit with this and see if I can find a good solution for this.

Tigge avatar Aug 12 '15 16:08 Tigge

Thanks, would be incredible to get a good solution to this.

Relatedly, after swapping the dev.set_configuration() and dev.reset() calls in ant/base/driver.py I found I could make multiple Application instances (to the same device) but only after receiving a Resource busy exception first, as quoted above.

jonnylamb avatar Aug 12 '15 16:08 jonnylamb

I expect the main solution here will be gracely close the channel.

Will be possible with Pull #54.

Also see examples for this.

drkingpo avatar Oct 21 '20 18:10 drkingpo