Python PyUSB NotImplemented Error dev.write(), dev.read(), dev.ctrl_transfer()

26 Views Asked by At

I try to communicate with an NFC Reader ID CPR30+ from FEIG that is connected to via USB to my Windows10 Laptop. I installed the device driver and with PyUSB I can detect the device with idVendor, idProduct. I use a valid backend with libusb 1.0. But I cannot talk to the device i.e. the methods read, write and ctrl_transfer won't work. I receive NotImplemented error, even though these methods are defined in the Device class of the usb.core module. Accessing the property "manufacturer" and the method set_configuration() also result in this error: Exception has occurred: NotImplementedError Operation not supported or unimplemented on this platform What am I doing wrong and how can I correct it?

What I tried was: I changed the path of the libusb dll. I tried using pywinusb.hid but that also didn't work. I checked whether the device works. Result: The communication works with the NFC Reader when using the Demo Program on Windows, the driver is installed correctly. The stackoverflow search did not help so far. I looked at the drivermanual, but there is no explicit support for Python, only for Java, C#, C++ and SWIFT. Do I have to write a backend for the NFC Reader, i.e. my own dll that interfaces the Reader and PyUSB?

Here's the code with some results:

    #example from https://github.com/walac/pyusb/blob/master/docs/tutorial.rst
    import usb.core
    import usb.util
    import usb.backend.libusb1

    usb_backend = r"C:\Users\...\AppData\Local\Programs\Python\Python312\DLLs\libusb-1.0.dll"

    backend = usb.backend.libusb1.get_backend(find_library=lambda x: usb_backend)
    dev     = usb.core.find(idVendor = 0xab1, idProduct = 0x3)
    if dev == None:
        print("No device found")
    else:
        print(f'Type dev: {type(dev)}') #<class 'usb.core.Device'>
        print("Listing Devices")
        print("###############\n")
        print("".join(hex(dev.idVendor))) #stdout: 0xab1, OK
        print("".join(hex(dev.idProduct))) #stdout: 0x3, OK
        #print(usb_device.backend) #stdout: <usb.backend.libusb1._LibUSB object ..., OK

        #print("".join(hex(usb_device.manufacturer))) #NotImplemented Error ??
        #print(usb_device.set_configuration()) #NotImplemented Error ??

        #https://stackoverflow.com/questions/70371707/how-to-write-to-control-endpoint-with-pyusb
        dev.ctrl_transfer(
        0xA1,  # REQUEST_TYPE_CLASS | RECIPIENT_INTERFACE | ENDPOINT_IN
        1,     # GET_REPORT
        0x200, # "Vendor" Descriptor Type + 0 Descriptor Index
        0,     # USB interface № 0
        64     # max reply size
        )        #NotImplemented Error ??

        endpoint_in = dev[0][(0,0)][0] #endpoint in has the correct value
        endpoint_out = dev[0][(0,0)][1]  #endpoint out has the correct value
        #endpoint_out.write( "version".encode() + bytes([0]) ) #NotImplemented Error ??
        #buffer = dev.read(endpoint_in.bEndpointAddress, 64, 1000).tobytes() #NotImplemented Error ??

with print(dev) I get the output:

DEVICE ID 0ab1:0003 on Bus 002 Address 043 =================
 bLength                :   0x12 (18 bytes)
 bDescriptorType        :    0x1 Device
 bcdUSB                 :  0x110 USB 1.1
 bDeviceClass           :    0x0 Specified at interface
 bDeviceSubClass        :    0x0
 bDeviceProtocol        :    0x0
 bMaxPacketSize0        :   0x40 (64 bytes)
 idVendor               : 0x0ab1
 idProduct              : 0x0003
 bcdDevice              :  0x101 Device 1.01
 iManufacturer          :    0x4 Error Accessing String
 iProduct               :    0x2 Error Accessing String
 iSerialNumber          :    0x1 Error Accessing String
 bNumConfigurations     :    0x1
  CONFIGURATION 1: 500 mA ==================================
   bLength              :    0x9 (9 bytes)
   bDescriptorType      :    0x2 Configuration
   wTotalLength         :   0x20 (32 bytes)
   bNumInterfaces       :    0x1
   bConfigurationValue  :    0x1
   iConfiguration       :    0x0
   bmAttributes         :   0x80 Bus Powered
   bMaxPower            :   0xfa (500 mA)
    INTERFACE 0: Vendor Specific ===========================
     bLength            :    0x9 (9 bytes)
     bDescriptorType    :    0x4 Interface
     bInterfaceNumber   :    0x0
     bAlternateSetting  :    0x0
     bNumEndpoints      :    0x2
     bInterfaceClass    :   0xff Vendor Specific
     bInterfaceSubClass :   0xff
     bInterfaceProtocol :    0x0
     iInterface         :    0x6 Error Accessing String
      ENDPOINT 0x81: Bulk IN ===============================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x81 IN
       bmAttributes     :    0x2 Bulk
       wMaxPacketSize   :   0x40 (64 bytes)
       bInterval        :    0x0
      ENDPOINT 0x2: Bulk OUT ===============================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :    0x2 OUT
       bmAttributes     :    0x2 Bulk
       wMaxPacketSize   :   0x40 (64 bytes)
       bInterval        :    0x0
0

There are 0 best solutions below