@@ -30,32 +30,33 @@ def product_id(self):
3030 return self ._dev .idProduct
3131
3232 def open (self ):
33- # Check if there is a kernel driver controlling the device
33+ # Try to get the active configuration...
34+ config = None
3435 try :
35- if self ._dev .is_kernel_driver_active (0 ):
36- # Detach the kernel driver
37- self ._dev .detach_kernel_driver (0 )
38- except NotImplementedError :
39- # In windows, is_kernel_driver_active and detach_kernel_driver are
40- # not implemented
41- pass
42-
43- # Configure the device. If already configured, this acts as a reset
44- try :
45- self ._dev .set_configuration ()
36+ config = self ._dev .get_active_configuration ()
4637 except NotImplementedError :
4738 # In windows, set_configuration is not implemented for devices not
4839 # running the correct driver, that should be WinUSB
4940 raise WrongDriverException ()
5041
51- # Find the Bluetooth interface...
42+ # Find the Bluetooth interface of the usb device ...
5243 self ._interface_bt = usb .util .find_descriptor (
53- self . _dev . get_active_configuration () ,
44+ config ,
5445 bInterfaceClass = usb .CLASS_WIRELESS_CONTROLLER ,
5546 bInterfaceSubClass = usb .SUBCLASS_RF_CONTROLLER ,
5647 bInterfaceProtocol = usb .PROTOCOL_BLUETOOTH_PRIMARY_CONTROLLER ,
5748 )
5849
50+ # Check if there is a kernel driver controlling the interface
51+ try :
52+ if self ._dev .is_kernel_driver_active (self ._interface_bt .bInterfaceNumber ):
53+ # Detach the kernel driver
54+ self ._dev .detach_kernel_driver (self ._interface_bt .bInterfaceNumber )
55+ except NotImplementedError :
56+ # In windows, is_kernel_driver_active and detach_kernel_driver are
57+ # not implemented
58+ pass
59+
5960 # Claim the interface
6061 usb .util .claim_interface (self ._dev , self ._interface_bt .bInterfaceNumber )
6162
@@ -84,12 +85,12 @@ def open(self):
8485 def close (self ):
8586 # Release the claimed interface
8687 if hasattr (self , "_interface_bt" ) and self ._interface_bt is not None :
87- usb .util .release_interface (self ._dev , self ._interface_bt )
88+ usb .util .release_interface (self ._dev , self ._interface_bt . bInterfaceNumber )
8889
8990 # Reattach the kernel driver
9091 try :
91- if self ._dev .is_kernel_driver_active (0 ) is False :
92- self ._dev .attach_kernel_driver (0 )
92+ if self ._dev .is_kernel_driver_active (self . _interface_bt . bInterfaceNumber ) is False :
93+ self ._dev .attach_kernel_driver (self . _interface_bt . bInterfaceNumber )
9394 except NotImplementedError :
9495 # In windows, is_kernel_driver_active and detach_kernel_driver are
9596 # not implemented
0 commit comments