File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -38,7 +38,10 @@ def __init__(
3838 f"Can't open device_index { device_index } , only { len (devices )} devices found."
3939 )
4040 self ._dev = devices [device_index ]
41- self ._dev .set_configuration (1 )
41+ active_config = self ._dev .get_active_configuration ()
42+ if active_config is None or active_config .bConfigurationValue != 1 :
43+ self ._dev .set_configuration (1 )
44+
4245
4346 # Check this looks like the firmware we expect: as this is an unofficial driver,
4447 # we don't know if other versions might are out there.
@@ -63,6 +66,12 @@ def __init__(
6366 self .init (0 , bitrate , timing0 , timing1 )
6467 self .init (1 , bitrate , timing0 , timing1 )
6568
69+ def __del__ (self ):
70+ # In theory pyusb should manage this, but in order to allow a new device
71+ # object to be created later (in the same process) it seems the device needs to be reset (which
72+ # calls dispose internally)
73+ self ._dev .reset ()
74+
6675 def clear_rx_buffer (self , channel ):
6776 """Clears the device's receive buffer for the specified channel.
6877
You can’t perform that action at this time.
0 commit comments