Skip to content

Commit

Permalink
Add support for filtering by usb serial number (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
ckuethe authored Dec 11, 2023
1 parent 391c755 commit bb0a1db
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
9 changes: 7 additions & 2 deletions radiacode/radiacode.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ def spectrum_channel_to_energy(channel_number: int, a0: float, a1: float, a2: fl
class RadiaCode:
_connection: Union[Bluetooth, Usb]

def __init__(self, bluetooth_mac: Optional[str] = None, ignore_firmware_compatibility_check: bool = False):
def __init__(
self,
bluetooth_mac: Optional[str] = None,
serial_number: Optional[str] = None,
ignore_firmware_compatibility_check: bool = False,
):
self._seq = 0
if bluetooth_mac is not None:
self._connection = Bluetooth(bluetooth_mac)
else:
self._connection = Usb()
self._connection = Usb(serial_number=serial_number)

# init
self.execute(b'\x07\x00', b'\x01\xff\x12\xff')
Expand Down
12 changes: 10 additions & 2 deletions radiacode/transports/usb.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@ def __init__(self, message=None):


class Usb:
def __init__(self, timeout_ms=3000):
self._device = usb.core.find(idVendor=0x483, idProduct=0xF123)
def __init__(self, serial_number=None, timeout_ms=3000):
_vid = 0x0483
_pid = 0xF123

if serial_number:
self._device = usb.core.find(idVendor=_vid, idProduct=_pid, serial_number=serial_number)
else:
# usb.core.find(..., serial_number=None) will attempt to match against a value of None,
# rather than ignoring it as a match condition.
self._device = usb.core.find(idVendor=_vid, idProduct=_pid)
self._timeout_ms = timeout_ms
if self._device is None:
raise DeviceNotFound
Expand Down

0 comments on commit bb0a1db

Please sign in to comment.