def _init_ruggeduinos(self): self.ruggeduinos = {} for n, dev in enumerate( usbenum.list_usb_devices( "Ruggeduino" ) ): handler = None snum = dev["ID_SERIAL_SHORT"] if snum in self._ruggeduino_id_handlers: handler = self._ruggeduino_id_handlers[snum] else: # There's no ID-specific handler, so we can query it for # its firmware version. r = ruggeduino.RuggeduinoCmdBase( dev.device_node ) ver = r.firmware_version_read() genre = ver.split(":")[0] if genre in self._ruggeduino_fwver_handlers: handler = self._ruggeduino_fwver_handlers[genre] if handler is None: raise Exception( "No handler found for ruggeduino: serial {0}, firmware '{1}'".format( snum, genre ) ) srdev = handler( dev.device_node, snum ) self.ruggeduinos[n] = srdev self.ruggeduinos[snum] = srdev
def _init_usb_devices(self, model, ctor): devs = usbenum.list_usb_devices( model ) # Devices stored in a dictionary # Each device appears twice in this dictionary: # 1. Under its serial number # 2. Under an integer key. Integers assigned by ordering # boards by serial number. srdevs = {} n = 0 for dev in devs: serialnum = dev["ID_SERIAL_SHORT"] srdev = ctor( dev.device_node, serialnum = serialnum ) srdevs[n] = srdev srdevs[ serialnum ] = srdev n += 1 return srdevs
def find_devs(): return usbenum.list_usb_devices(USB_MODEL)