Menu

Home

Wander Lairson Xiaofan Chen

PyUSB provides USB access on the Python language.
Please go to github page for more details. Discussion here will be ignored by the admins.
https://github.com/pyusb/pyusb


Project Members:


Discussion

  • laurent

    laurent - 2014-09-15

    Dear Wanders,
    I need your help for pyusb use.
    I use ,for my python program, libusb library on a windows pc.
    I have two identical spectrometers with idVendor = 0x2457, idProduct =0x1022. I am using bus and address, but I do not know how to write the code to differentiate them. eg dev = usb.core.find (idVendor = 0x2457, idProduct =0x1022)
    dev = usb.core.find (= \. \ libusb0-0001--0x2457-0x1022)
    thanking you in advance.
    laurent

     
    • Wander Lairson

      Wander Lairson - 2014-09-16

      2014-09-15 7:19 GMT-03:00 laurent lorenz7791@users.sf.net:

      Dear Wanders,
      I need your help for pyusb use.
      I use ,for my python program, libusb library on a windows pc.
      I have two identical spectrometers with idVendor = 0x2457, idProduct
      =0x1022. I am using bus and address, but I do not know how to write the code
      to differentiate them. eg dev = usb.core.find (idVendor = 0x2457, idProduct
      =0x1022)
      dev = usb.core.find (= . \ libusb0-0001--0x2457-0x1022)
      thanking you in advance.
      laurent

      Hi,

      There were a recent discussion in PyUSB mailing list on this topic [1].

      [1] http://comments.gmane.org/gmane.comp.python.pyusb.user/1730

      --
      Best Regards,
      Wander Lairson Costa

       
  • Edward Chu

    Edward Chu - 2023-11-15

    Dear Wander and team,

    I need your help for pyusb. I want to be able to send
    control transfers to usb devices, but this fails for
    devices that aren't HID devices, such as a hub or camera.
    I want to describe the problem with the following example:

    import usb.core
    import usb.util
    import usb.control
    usbdev = usb.core.find(idVendor=0x05e3, idProduct=0x0610)   #Targus hub
    print(usbdev)
    usbdev = usb.core.find(idVendor=0x413c, idProduct=0x2112)   #Dell keyboard
    print(usbdev)
    

    output:

    DEVICE ID 05e3:0610 on Bus 002 Address 002 =================
     bLength                :   0x12 (18 bytes)
     bDescriptorType        :    0x1 Device
     bcdUSB                 :  0x200 USB 2.0
     bDeviceClass           :    0x9 Hub
     bDeviceSubClass        :    0x0
     bDeviceProtocol        :    0x2
     bMaxPacketSize0        :   0x40 (64 bytes)
     idVendor               : 0x05e3
     idProduct              : 0x0610
     bcdDevice              : 0x4143 Device 65.43
     iManufacturer          :    0x1 Error Accessing String
     iProduct               :    0x2 Error Accessing String
     iSerialNumber          :    0x0
     bNumConfigurations     :    0x1
    ...
    DEVICE ID 413c:2112 on Bus 002 Address 001 =================
     bLength                :   0x12 (18 bytes)
     bDescriptorType        :    0x1 Device
     bcdUSB                 :  0x110 USB 1.1
     bDeviceClass           :    0x0 Specified at interface
     bDeviceSubClass        :    0x0
     bDeviceProtocol        :    0x0
     bMaxPacketSize0        :    0x8 (8 bytes)
     idVendor               : 0x413c
     idProduct              : 0x2112
     bcdDevice              :  0x107 Device 1.07
     iManufacturer          :    0x1 DELL
     iProduct               :    0x2 Dell USB Wired Multimedia Keyboard
     iSerialNumber          :    0x0
     bNumConfigurations     :    0x1
    

    The print function for the hub info fails in getting the strings for
    iManufacturer and iProduct, while the print function for the keyboard
    succeeds. The try-except block in _try_get_string in core.py fails
    when it calls util.get_string, which in turn fails in the try-except
    block in langids when it calls util.get_langids, which in turn fails
    when it calls ctrl_transfer in get_descriptor in control.py which
    then fails in managed_open, which then fails in open_device in
    libusb1.py when it calls init for _DeviceHandle which fails in
    _check(_lib.libusb_open(self.devid, byref(self.handle))), which
    returns -12 (the value for LIBUSB_ERROR_NOT_SUPPORTED). Since
    ctrl_transfer fails in get_descriptor, it also fails when I try to
    use ctrl_transfer for anything else.

     
  • Tormod Volden

    Tormod Volden - 2023-11-15

    You may also try here : https://github.com/pyusb/pyusb/discussions
    In any case, you will have to provide more context and info on versions, OS, drivers etc.

     
  • Edward Chu

    Edward Chu - 2023-11-15

    Thanks for the link. I found in: https://github.com/pyusb/pyusb/discussions/419 a response from jonasmalacofilho that provides the link: https://github.com/libusb/libusb/wiki/Windows#How_to_use_libusb_on_Windows that states: "If your target device is not HID, and your device is not using WinUSB driver, you must install a driver before you can communicate with it using libusb. Currently, this means installing one of Microsoft's WinUSB, libusb-win32 or libusbK drivers." This does appear to describe the behavior I see. Since I see that you have edited this page, you may already be aware of this. While Zadig appears to work by installing the WinUSB driver, it's not clear what other side effects may happen.

     
  • Edward Chu

    Edward Chu - 2023-11-22

    In the module libusb1.py the call to _lib.libusb_open passes
    two 64 bit ints, the first is a device ID (devid) and the
    second is the address of a pointer which the open call should
    return the address of a device handle object (_DeviceHandle).
    The name of the dll called is 'C:\WINDOWS\system32\libusb-1.0.dll'
    found in _lib._name and it is this call that fails if the
    device ID is for a non HID device.

     
  • Xiaofan Chen

    Xiaofan Chen - 2023-11-22

    Please go to pyusb discussion and not to discuss issues here. Thanks.
    https://github.com/pyusb/pyusb/discussions

     

Log in to post a comment.