0

I'm trying to send/read data via USB, in Windows. Using the library hid\hidapi (python). It is the only one that sees\working with the Mindeo MP725 on the system.

QR Scanner Definition Example:

{'path': b'\\\\? \HID#VID_27DDD&PID_0103#6&269d9e14&1&0000#{4d1e55b2-f16f-11cf-88cb-00111111000030}\KBD', 'vendor_id': 10205, 'product_id': 259, 'serial_number': 'S/N:E608A04AB4151A4F9C8FA887B58B3D69 Rev: NBRMIAAX1', 'release_number': 259, 'manufacturer_string': '2D BarCode Scanner', 'product_string': '2D BarCode Scanner', 'usage_page': 1, 'usage': 6, 'interface_number': -1}

Example of my code:

import ctypes
import os
ctypes.CDLL(os.path.dirname(__file__) + '\hidapi.dll')
import hid

vid = 0
pid = 0
path = ''

list_device = hid.enumerate()
for i in list_device:
    if i['product_string'] == '2D BarCode Scanner':
        print(i)
        vid = i['vendor_id']
        pid = i['product_id']
        path = i['path']

with hid.Device(path=path) as h:
    h.nonblocking

    # print(f'Device manufacturer: {h.manufacturer}')
    # print(f'Product: {h.product}')
    # print(f'Serial Number: {h.serial}')

    while True:
        d = h.read(255)
        if d:
            print(d)

I get an error every time:

Traceback (most recent call last):
  File "c:\Users\user\Desktop\x64\MP725.py", line 62, in <module>
    d = h.read(255)
        ^^^^^^^^^^^
  File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\hid\init__.py", line 163, in read
    size = self.__hidcall(hidapi.hid_read, self.__dev, data, size)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\hid\init__.py", line 148, in __hidcall
    raise HIDException(err)
hid.HIDException: ReadFile: (0x00000005) Access denied.

Does anyone know how to fix this?

I examined the errors related to accessing the library itself (but I think there is no problem with this, since all other methods work fine) There is an impression that Windows itself prohibits managing the QR-scanner, as the device and the driver identifies it in the group together with keyboards and other input devices which can't be managed.

  • I took some time to read the manual and by default, this device pretends it's a keyboard. And to program it, by default you have to scan various barcodes in the manual to set different options. This whole setup is pretty common for "keyboard wedge" scanners. The scanner can also present itself as a virtual COM (serial port). The manual doesn't say which chipset they use or which driver they use. If you plug it into a Linux box, probably the driver will autoload and you can figure out which chipset they use. – bfris Dec 07 '22 at 22:46
  • You might be able to program by using the human readable text in the programming barcodes as hex codes you send to virtual COM port. The manual is unclear on this. – bfris Dec 07 '22 at 22:48
  • Update. Check out [this question](https://stackoverflow.com/q/73572097/9705687). Looks like you can send the humand readable text as a command over virtual COM port. – bfris Dec 07 '22 at 23:03
  • Yes, I understand that you can manually scan from the manual and send the settings through the COM port. But I had the opposite task: to send it coded commands, so that it switches itself to the COM port, eliminating the manual interaction. – Genius Loci Dec 08 '22 at 10:11
  • What's this line `ctypes.CDLL(os.path.dirname(__file__) + '\hidapi.dll')` purpose? – CristiFati Dec 09 '22 at 18:04

0 Answers0