在 Windows 10 系统上使用扫描仪读取条形码 QR



我已经通过USB将条形码/QR码扫描仪连接到我的Windows 10 PC。扫描程序已在系统上注册。

现在我想编写一个python应用程序来使用扫描仪读取条形码和QR码。

然而我无法读取代码,结果我得到了一个对象。

我必须做什么,出了什么问题???

可以从扫描仪访问完整的参数。

#importing modules
import usb
import usb.core
import usb.util
import usb.backend.libusb1
#device vid / pid
VID = 0x2010 
PID = 0x7638
#access the device registry
backend = usb.backend.libusb1.get_backend(find_library=lambda X: "C:ProgramDataAnaconda3libusbamd64")
#some tries to get parameters / informations about the device
usb_error = usb.USBError('USB-Error', error_code='error', errno=None)
dev = usb.core.find(idVendor=VID, idProduct=PID)
dev.set_configuration()
if not dev:
    raise ValueError ("USB device not found")
    exit(1)
config = dev.configurations
cfg = dev.get_active_configuration()
intf = cfg[(0,0)]
ep = usb.util.find_descriptor(
    intf,
    custom_match = lambda e: usb.util.endpoint_direction(e.bEndpointAddress) == usb.util.ENDPOINT_IN)
ep_adr = ep.bEndpointAddress
dev.backend.open_device
adress = dev.address
manufaktur = dev.manufacturer
conf2 = dev.bNumConfigurations
dev_descriptor = dev.bDescriptorType
ser_num = dev.serial_number
busses = usb.busses()
for bus in busses:
    devices = bus.devices
    for dev in devices:
        print ("Device:", dev.filename)
        print ("  idVendor: %d (0x%04x)" % (dev.idVendor, dev.idVendor))
        print ("  idProduct: %d (0x%04x)" % (dev.idProduct, dev.idProduct))
print('cfg: ', str(cfg))
print('Manufacturer: ', str(manufaktur))
print('Serial Number', str(ser_num))
print('EP: ', ep)
print('Descriptor: ', dev_descriptor)
the actual result:
Device: 
  idVendor: 8208 (0x2010)
  idProduct: 30264 (0x7638)
cfg:    CONFIGURATION 1: 400 mA ==================================
   bLength              :    0x9 (9 bytes)
   bDescriptorType      :    0x2 Configuration
   wTotalLength         :   0x22 (34 bytes)
   bNumInterfaces       :    0x1
   bConfigurationValue  :    0x1
   iConfiguration       :    0x0 
   bmAttributes         :   0x80 Bus Powered
   bMaxPower            :   0xc8 (400 mA)
    INTERFACE 0: Human Interface Device ====================
     bLength            :    0x9 (9 bytes)
     bDescriptorType    :    0x4 Interface
     bInterfaceNumber   :    0x0
     bAlternateSetting  :    0x0
     bNumEndpoints      :    0x1
     bInterfaceClass    :    0x3 Human Interface Device
     bInterfaceSubClass :    0x1
     bInterfaceProtocol :    0x1
     iInterface         :    0x0 
      ENDPOINT 0x83: Interrupt IN ==========================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x83 IN
       bmAttributes     :    0x3 Interrupt
       wMaxPacketSize   :    0x8 (8 bytes)
       bInterval        :    0x1
Manufacturer:  USBKey Chip
Serial Number 202730041341
EP:        ENDPOINT 0x83: Interrupt IN ==========================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x83 IN
       bmAttributes     :    0x3 Interrupt
       wMaxPacketSize   :    0x8 (8 bytes)
       bInterval        :    0x1
Descriptor:  1

您获得的对象必须是具有结果扫描输出的字符串。尝试扫描到主机...

您拥有的扫描仪仅模拟 USB 键盘作为输出。扫描仪内部的所有软件都是扫描图像的结果一串字节。

您要做的是使用 libusb 直接与 USB 硬件对话,这只会为您提供模拟的 HID 键盘。

如果要破解,则需要对扫描板或扫描config images进行jtag,以触发设备上的配置更改。

通过USB连接的条形码扫描仪就像Windows 10中的标准输入设备(如键盘)一样。在记事本中打开的文本文件上扫描条形码时,扫描的数字将显示在文本文件中,就像在键盘上打字一样。

因此,为了在Windows 10中读取Python39 shell或文件,使用python代码"input("scan Barcode:")"并扫描。我从扫描仪设备获得了扫描的数字。

C:ProjectPython39>python
Python 3.9.0 (tags/v3.9.0:9cf6752, Oct  5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>>
>>> input("scan Barcode: ")
scan Barcode: 88H-1010UB-0TV
'88H-1010UB-0TV'
>>>
>>> myBarCodeId = input("Scan barCode please ...")
Scan barCode please ...TARNLK002563
>>>
>>> print(myBarCodeId)
TARNLK002563
>>>
>>> mibar=input("scan me please n")
scan me please
88H-1010UB-0TV
>>>
>>> print(mibar)
88H-1010UB-0TV
>>>

最新更新