vpelletier / python-libusb1

Python ctype-based wrapper around libusb1
GNU Lesser General Public License v2.1
168 stars 65 forks source link

How to get data from a USB device #52

Closed serj053 closed 4 years ago

serj053 commented 4 years ago

The method getDeviceList (usb1) shows the presence of the device and it really is (bladeRF), but the method openByVendorIDAndProductID (usb1, 0x2cf0, 0x5246) returns None and the device remains not available. No errors. What is the reason for this behavior and how to access the USB device. OS Windows 7

```

import usb1 con = usb1.USBContext() con.getDeviceList(usb1) [<usb1.USBDevice object at 0x02A084D0>, <usb1.USBDevice object at 0x02A08670>, <usb1.USBDevice object at 0x02A08690>, <usb1.USBDevice object at 0x02A08830>, <usb1.USBDevice object at 0x02A08A50>, <usb1.USBDevice object at 0x02A08B70>, <usb1.USBDevice object at 0x02A08C50>] handl = con.openByVendorIDAndProductID(usb1, 0x2cf0, 0x5246) print(handl) None

vpelletier commented 4 years ago
handl = con.openByVendorIDAndProductID(usb1, 0x2cf0, 0x5246)

You should not be passing usb1 as an argument here.

That method's signature is:

    def openByVendorIDAndProductID(
            self, vendor_id, product_id,
            skip_on_access_error=False, skip_on_error=False):

self being automatically set by python when calling on an instance (con), you are actually passing these parameters:

handl = con.openByVendorIDAndProductID(
    # self=con is implicit
    vendor_id=usb1,
    product_id=0x2cf0,
    skip_on_access_error=0x5246,
)

No vendor_id (integer) equals usb1, so nothing is found and None is returned.

serj053 commented 4 years ago

Thank you, everything worked out! Move on.

serj053 commented 4 years ago

If it is not difficult for you to explain please, there is a class USB Device() which has parameters;

serj053 commented 4 years ago

Sorry I'm one minute late..

vpelletier commented 4 years ago

"device_p "-? (what does this mean), "can_load_configuration=True" ? what does this mean).

Classes which have such arguments are not meant to be instanciated from outside of the usb1 module (as should be said in their docstring). You can get instances of such classes by calling some methods on instances you already have: from a USBContext instance you get a USBDevice instance, then by opening it you get a USBDeviceHandle instance, and so on.