cdump / radiacode

Library for RadiaCode-101
MIT License
108 stars 20 forks source link

Add support for filtering by usb serial number #22

Closed ckuethe closed 10 months ago

ckuethe commented 10 months ago

rc = radiacode.RadiaCode() attaches to the first device libusb happens to discover. If you have multiple radiacode devices attached, perhaps one inside and one outside of an enclosure, you can't just do this

rc1 = radiacode.RadiaCode()
rc2 = radiacode.RadiaCode()

and trust libusb to get it right. Instead, you get an exception: USBError: [Errno 16] Resource busy

This diff adds a serial_number argument to the RadiaCode USB constructor which will then be used to attach only that device, eg. rc = radiacode.RadiaCode(serial_number="RC-102-000456") would attach to "RC-102-000456" even if "RC-103-000123" was found first.

radiacode.RadiaCode() still attaches to the first device.

radiacode.RadiaCode(serial_number="nonexistent") raises DeviceNotFound as expected.

And now you can do this too:

rc103 = radiacode.RadiaCode(serial_number="RC-103-000123")
rc102 = radiacode.RadiaCode(serial_number="RC-102-000456")