예제 #1
0
 def from_device(cls, device):
     ret = []
     for attr in ('iManufacturer', 'iProduct', 'iSerialNumber'):
         try:
             ret.append(usb_get_string(device, 255, getattr(device, attr)).strip())
         except Exception as e:
             ret.append('Unknown')
     return cls(*ret)
예제 #2
0
파일: usb.py 프로젝트: 0xD3ADB33F/lantz
 def from_device(cls, device):
     ret = []
     for attr in ('iManufacturer', 'iProduct', 'iSerialNumber'):
         try:
             ret.append(usb_get_string(device, 255, getattr(device, attr)).strip())
         except Exception as e:
             ret.append('Unknown')
     return cls(*ret)
예제 #3
0
파일: usb.py 프로젝트: jturner314/lantz
 def from_device(cls, device):
     ret = []
     for attr in ("iManufacturer", "iProduct", "iSerialNumber"):
         try:
             ret.append(usb_get_string(device, 255, getattr(device, attr)).strip())
         except Exception as e:
             ret.append("Unknown")
     return cls(*ret)
예제 #4
0
    def get_string(cls, device: UsbDevice, stridx: int) -> str:
        """Retrieve a string from the USB device, dealing with PyUSB API breaks

           :param device: USB device instance
           :param stridx: the string identifier
           :return: the string read from the USB device
        """
        if cls.UsbApi is None:
            import inspect
            args, _, _, _ = \
                inspect.signature(UsbDevice.read).parameters
            if (len(args) >= 3) and args[1] == 'length':
                cls.UsbApi = 1
            else:
                cls.UsbApi = 2
        if cls.UsbApi == 2:
            return usb_get_string(device, stridx)
        return usb_get_string(device, 64, stridx)
예제 #5
0
파일: usbtools.py 프로젝트: josmet52/myprg
    def get_string(cls, device: UsbDevice, stridx: int) -> str:
        """Retrieve a string from the USB device, dealing with PyUSB API breaks

           :param device: USB device instance
           :param stridx: the string identifier
           :return: the string read from the USB device
        """
        if cls.UsbApi is None:
            import inspect
            args, _, _, _ = \
                inspect.signature(UsbDevice.read).parameters
            if (len(args) >= 3) and args[1] == 'length':
                cls.UsbApi = 1
            else:
                cls.UsbApi = 2
        try:
            if cls.UsbApi == 2:
                return usb_get_string(device, stridx)
            return usb_get_string(device, 64, stridx)
        except UnicodeDecodeError:
            # do not abort if EEPROM data is somewhat incoherent
            return ''