def _set_name(self): try: manufacturer = util.get_string(self.dev, 256, self.dev.iManufacturer) product = util.get_string(self.dev, 256, self.dev.iProduct) return ("%s - %s") % (manufacturer, product) except ValueError as e: _logger.warning(e) return _('Unknow keyboard or scanner')
def _set_name(self): try: manufacturer = util.get_string(self.dev, self.dev.iManufacturer) product = util.get_string(self.dev, self.dev.iProduct) return ("%s - %s") % (manufacturer, product) except ValueError as e: _logger.warning(e) return _('Unknown input device')
def listPrinters(self): printers = core.find(find_all=True) # , bDeviceClass=7) for printer in printers: print printer.bDeviceClass try: print util.get_string(printer, 256, 3) except: print 'dispositivo oculto'
def _set_name(self): try: manufacturer = util.get_string(self.dev, self.dev.iManufacturer) product = util.get_string(self.dev, self.dev.iProduct) return re.sub(r"[^\w \-+/*&]", '', "%s - %s" % (manufacturer, product)) except ValueError as e: _logger.warning(e) return _('Unknown input device')
def _try_get_string(dev, index, langid = None, default_str_i0 = "", default_access_error = "Error Accessing String"): """ try to get a string, but return a string no matter what """ if index == 0 : string = default_str_i0 else: try: if langid is None: string = util.get_string(dev, index) else: string = util.get_string(dev, index, langid) except : string = default_access_error return string
def usbData(log_file): # find USB devices dev = usb.core.find(find_all=True) with open(log_file, 'a', encoding='utf-8') as out_file: out_file.write("\n ******* NEW CYCLE *******\n") # loop through devices, printing USB data for cfg in dev: # sys.stdout.write('Hexadecimal VendorID=' + hex(cfg.idVendor) + ' & ProductID=' + hex(cfg.idProduct) + '\n\n') #print("Decimal VendorID= " + str(cfg.idVendor)) #print("ProductID: " + str(cfg.idProduct)) out_file.write("VendorID: " + hex(cfg.idVendor) + "\n") out_file.write("ProductID: " + hex(cfg.idProduct) + "\n") out_file.write("device speed: " + getSpeedString(hex(cfg.speed)) + "\n") out_file.write("device bus: " + str(cfg.bus) + "\n") out_file.write("device address: " + str(cfg.address) + "\n") out_file.write("device port: " + str(cfg.port_number) + "\n") out_file.write("device class: " + getClassString(hex(cfg.bDeviceClass)) + "\n") out_file.write("device sub class: " + str(cfg.bDeviceSubClass) + "\n") out_file.write("bcd device: " + str(cfg.bcdDevice) + "\n") try: out_file.write( "Manufacturer: " + str(util.get_string(cfg, cfg.iManufacturer, None)) + "\n") except: out_file.write("Manufacturer: " + "NONE\n") out_file.write( "______________________________________________________\n") out_file.close()
def deviceName_match(dev): if hasattr(dev, "product"): if dev.product == deviceName: return True else: from usb.util import get_string product = get_string(dev, 64, dev.iProduct) if product == deviceName: return True
def manufacturer(self): """ Return the USB device's manufacturer string descriptor. This property will cause some USB traffic the first time it is accessed and cache the resulting value for future use. """ if self._manufacturer is None: self._manufacturer = util.get_string(self, self.iManufacturer) return self._manufacturer
def serial_number(self): """ Return the USB device's serial number string descriptor This property will cause some USB traffic the first time it is accessed and cache the resulting value for future use. """ if self._serial_number is None: self._serial_number = util.get_string(self, self.iSerialNumber) return self._serial_number
def product(self): """ Return the USB device's product string descriptor. This property will cause some USB traffic the first time it is accessed and cache the resulting value for future use. """ if self._product is None: self._product = util.get_string(self, self.iProduct) return self._product
def getString(self, index, length, langid = None): r"""Retrieve the string descriptor specified by index and langid from a device. Arguments: index: index of descriptor in the device. length: number of bytes of the string langid: Language ID. If it is omittedi, will be used the first language. """ return util.get_string(self.dev, length, index, langid).encode('ascii')
def getString(self, index, length, langid = None): r"""Retrieve the string descriptor specified by index and langid from a device. Arguments: index: index of descriptor in the device. length: number of bytes of the string (ignored) langid: Language ID. If it is omittedi, will be used the first language. """ return util.get_string(self.dev, index, langid).encode('ascii')
def serial_number(self): return util.get_string(self, 1000, self.iSerialNumber)
def product(self): return util.get_string(self, 1000, self.iProduct)
def manufacturer(self): return util.get_string(self, 1000, self.iManufacturer)
def get_string(self, num): return get_string(self.__dev, num)
def get_index_from_serial(self, serial): for dev in self.devices: if serial == int(get_string(dev, dev.iSerialNumber), 16): self.index = dev.id return (self.index) return (None)
answer = classDict.get(str(classId)) if answer is None: answer = classId return answer # find USB devices dev = usb.core.find(find_all=True) # loop through devices, printing USB data for cfg in dev: # sys.stdout.write('Hexadecimal VendorID=' + hex(cfg.idVendor) + ' & ProductID=' + hex(cfg.idProduct) + '\n\n') #print("Decimal VendorID= " + str(cfg.idVendor)) #print("ProductID: " + str(cfg.idProduct)) print("VendorID: " + hex(cfg.idVendor)) print("ProductID: " + hex(cfg.idProduct)) print("device speed: " + str(cfg.speed)) print("device bus: " + str(cfg.bus)) print("device address: " + str(cfg.address)) print("device port: " + str(cfg.port_number)) print("device class: " + getClassString(hex(cfg.bDeviceClass))) print("device sub class: " + str(cfg.bDeviceSubClass)) print("bcd device: " + str(cfg.bcdDevice)) try: print("Manufacturer: " + str(util.get_string(cfg, cfg.iManufacturer, None))) except: print("Manufacturer: " + "NONE") print("______________________________________________________\n")
def get_string(self, num): print("getstr", num, get_string(self.__dev, num)) return get_string(self.__dev, num)
help='Reset the device before switching') parser.add_argument("-s", "--secure", dest="secure", action="store_true", help='Check after switching') args = parser.parse_args() dlist = devicelist(0x0d50, 0x0008, args.ledonly, args.relaisonly, args.reset) if args.debug: print('Found', len(dlist.devices), 'devices') count = 0 for dev in dlist.devices: if args.debug: print('Device #'+str(count) +': Type='+type_string(dev.idProduct) +': Version='+str(dev.bcdDevice) +': SNumber='+str(int(get_string(dev, dev.iSerialNumber), 16)) ) count += 1 if args.snumber: devindex = dlist.get_index_from_serial(args.snumber) if devindex is None: print('No device with serial number', args.snumber) exit() if args.debug: print('Old switch setting:', dlist.get_switch()) if args.action == 1: dlist.set_switch(True) elif args.action == 0:
def __getName(self,pen): """ Get pen's name for user displaying """ name = (util.get_string(dev=pen,length=20,index=1))+" "+(util.get_string(dev=pen,length=20,index=2)) return name