Git Product home page Git Product logo

Comments (12)

jonoboy9 avatar jonoboy9 commented on June 1, 2024

I did try:
pip install libusb.
Then copied libusb-1.0.dll from site-packages\libusb_platform_windows\x64 to c:\windows\system32.
So ran:
from ptpy import PTPy
camera = PTPy()
I get the following error:
Traceback (most recent call last):
File "", line 1, in
File "D:\Python38\lib\site-packages\ptpy_init_.py", line 109, in new
plain_camera = plain(device=device)
File "D:\Python38\lib\site-packages\ptpy\ptp.py", line 712, in init
super(PTP, self).init(*args, **kwargs)
File "D:\Python38\lib\site-packages\ptpy\transports\usb.py", line 93, in init
self.__acquire_camera(devs)
File "D:\Python38\lib\site-packages\ptpy\transports\usb.py", line 126, in __acquire_camera
for _ in self.__available_cameras(devs):
File "D:\Python38\lib\site-packages\ptpy\transports\usb.py", line 114, in __available_cameras
for dev in devs:
File "D:\Python38\lib\site-packages\usb\core.py", line 1249, in device_iter
if _interop._all(tests) and (custom_match is None or custom_match(d)):
File "D:\Python38\lib\site-packages\ptpy\transports\usb.py", line 47, in call
for cfg in device:
File "D:\Python38\lib\site-packages\usb\core.py", line 1094, in iter
yield Configuration(self, i)
File "D:\Python38\lib\site-packages\usb\core.py", line 584, in init
desc = backend.get_configuration_descriptor(
File "D:\Python38\lib\site-packages\usb\backend\libusb1.py", line 755, in get_configuration_descriptor
_check(self.lib.libusb_get_config_descriptor(
File "D:\Python38\lib\site-packages\usb\backend\libusb1.py", line 595, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 2] Entity not found
I really appreciate some help. Thanks

from sequoia-ptpy.

manmoi01 avatar manmoi01 commented on June 1, 2024

Hi
I solved a similar problem by installing the github master version which indicates that it is version 0.3.3, which corrects a bug in the usb transport with python 3

#27 (comment)

from sequoia-ptpy.

jonoboy9 avatar jonoboy9 commented on June 1, 2024

Hi,
I have downloaded the latest varsion 0.3.3 and still get the same error.
I have been digging around a little

In \site-packages\usb\core.py there is a method called find which calls: def device_iter(**kwargs)
This is a generator calling: for dev in backend.enumerate_devices().
This in turn calls site-packages\usb\backend\libusb1.py _LibUSB.enumerate_devices which in returns an iterable class _DevIterator(self.ctx) as follows:

_DevIterator(_objfinalizer.AutoFinalizedObject): 
    def __init__(self, ctx):
        self.dev_list = POINTER(c_void_p)()
        self.num_devs = _check(_lib.libusb_get_device_list(
                                ctx,
                                byref(self.dev_list))
                            )
        print("self.num_devs   "); print(self.num_devs)

When I connect the camera: self.num_devs goes from 4->5 which shows that the camera is connected correctly.

While iterating through the devices, the traceback is at the line:
if _interop._all(tests) and (custom_match is None or custom_match(d)): in device_iter in site-packages\usb\core.py

In the _DevIterator.__iter__ function I print out the iteration. When an instance of the _Device class is created, the devid is printed out.
For the first and second devices the expression _interop._all(tests) and (custom_match is None or custom_match(d)) returns False and so nothing is yielded
Its on the 3rd device it goes wrong. I would appreciate any suggestion what to look for. Many thanks.

_DevIterator.__iter__ i= 0
libusb1 _Device.devid = 1880973620544

_DevIterator.__iter__ i= 1
libusb1 _Device.devid = 1880973618848

_DevIterator.__iter__ i= 2
libusb1 _Device.devid = 1880973615456

Traceback (most recent call last):
File "", line 1, in
File "D:\Python38\sequoia-ptpy-master\ptpy\__init__.py", line 111, in __new__
plain_camera = plain(device=device)
File "D:\Python38\sequoia-ptpy-master\ptpy\ptp.py", line 720, in __init__
super(PTP, self).__init__(*args, **kwargs)
File "D:\Python38\sequoia-ptpy-master\ptpy\transports\usb.py", line 92, in __init__
self.__acquire_camera(devs)
File "D:\Python38\sequoia-ptpy-master\ptpy\transports\usb.py", line 127, in __acquire_camera
for _ in self.__available_cameras(devs):
File "D:\Python38\sequoia-ptpy-master\ptpy\transports\usb.py", line 114, in __available_cameras
for dev in devs:
File "D:\Python38\lib\site-packages\usb\core.py", line 1256, in device_iter
if _interop._all(tests) and (custom_match is None or custom_match(d)):
File "D:\Python38\sequoia-ptpy-master\ptpy\transports\usb.py", line 47, in __call__
for cfg in device:
File "D:\Python38\lib\site-packages\usb\core.py", line 1094, in __iter__
yield Configuration(self, i)
File "D:\Python38\lib\site-packages\usb\core.py", line 584, in __init__
desc = backend.get_configuration_descriptor(
File "D:\Python38\lib\site-packages\usb\backend\libusb1.py", line 759, in get_configuration_descriptor
_check(self.lib.libusb_get_config_descriptor(
File "D:\Python38\lib\site-packages\usb\backend\libusb1.py", line 595, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 2] Entity not found

When I attach my Nikon Camera D40X, in the Windows Device Manager, there is listed Portable Devices -> D40X.
Under details under Hardware IDs I see
Device USB\VID_04B0&PID_0418\7440864
Also under details:
Manufacture Nikon
Friendly name D40X

Now I did see somewhere to do the following:
python
>>> import usb.core
>>> dev = usb.core.find(idVendor=0x04B0, idProduct=0x0418)
If I print out dev, I get as below. Note I get:
iManufacturer : 0x1 Error Accessing String
iProduct : 0x2 Error Accessing String
iSerialNumber : 0x3 Error Accessing String
Now if >>>> dev.set_configuration(), I get the following error message:
File "", line 1, in
File "D:\Python38\lib\site-packages\usb\core.py", line 869, in set_configuration
self._ctx.managed_set_configuration(self, configuration)
File "D:\Python38\lib\site-packages\usb\core.py", line 102, in wrapper
return f(self, *args, **kwargs)
File "D:\Python38\lib\site-packages\usb\core.py", line 148, in managed_set_configuration
self.backend.set_configuration(self.handle, cfg.bConfigurationValue)
File "D:\Python38\lib\site-packages\usb\backend\libusb1.py", line 798, in set_configuration
_check(self.lib.libusb_set_configuration(dev_handle.handle, config_value))
File "D:\Python38\lib\site-packages\usb\backend\libusb1.py", line 595, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 2] Entity not found

Print out of dev:
DEVICE ID 04b0:0418 on Bus 001 Address 004 =================
bLength : 0x12 (18 bytes)
bDescriptorType : 0x1 Device
bcdUSB : 0x200 USB 2.0
bDeviceClass : 0x0 Specified at interface
bDeviceSubClass : 0x0
bDeviceProtocol : 0x0
bMaxPacketSize0 : 0x40 (64 bytes)
idVendor : 0x04b0
idProduct : 0x0418
bcdDevice : 0x100 Device 1.0
iManufacturer : 0x1 Error Accessing String
iProduct : 0x2 Error Accessing String
iSerialNumber : 0x3 Error Accessing String
bNumConfigurations : 0x1
CONFIGURATION 1: 2 mA ====================================
bLength : 0x9 (9 bytes)
bDescriptorType : 0x2 Configuration
wTotalLength : 0x27 (39 bytes)
bNumInterfaces : 0x1
bConfigurationValue : 0x1
iConfiguration : 0x0
bmAttributes : 0xc0 Self Powered
bMaxPower : 0x1 (2 mA)
INTERFACE 0: Image =====================================
bLength : 0x9 (9 bytes)
bDescriptorType : 0x4 Interface
bInterfaceNumber : 0x0
bAlternateSetting : 0x0
bNumEndpoints : 0x3
bInterfaceClass : 0x6 Image
bInterfaceSubClass : 0x1
bInterfaceProtocol : 0x1
iInterface : 0x0
ENDPOINT 0x81: Bulk IN ===============================
bLength : 0x7 (7 bytes)
bDescriptorType : 0x5 Endpoint
bEndpointAddress : 0x81 IN
bmAttributes : 0x2 Bulk
wMaxPacketSize : 0x200 (512 bytes)
bInterval : 0x0
ENDPOINT 0x2: Bulk OUT ===============================
bLength : 0x7 (7 bytes)
bDescriptorType : 0x5 Endpoint
bEndpointAddress : 0x2 OUT
bmAttributes : 0x2 Bulk
wMaxPacketSize : 0x200 (512 bytes)
bInterval : 0x0
ENDPOINT 0x83: Interrupt IN ==========================
bLength : 0x7 (7 bytes)
bDescriptorType : 0x5 Endpoint
bEndpointAddress : 0x83 IN
bmAttributes : 0x3 Interrupt
wMaxPacketSize : 0x8 (8 bytes)
bInterval : 0x9

from sequoia-ptpy.

manmoi01 avatar manmoi01 commented on June 1, 2024

hi

In my case the camera (nikon d7200) only worked when with zdiag I installed the libusbK library.

Under Windows, install libusb or libusb-win32 using zadig.

from sequoia-ptpy.

jonoboy9 avatar jonoboy9 commented on June 1, 2024

@manmoi01 I apologise if I am asking a stupid question. I am trying to understand the device driver stack.
You mentioned installing, the libusbK, libusb or libusb-win32 using Zadig.
Which of these is the device driver for the camera, ie that which is seen in the device manager for the camera?
So on your system did you replace the current device driver with one of these.
According to Zadig, my current driver is WUDFWpdMtp
Also, as I already have libusb0.dll and libusb-1.0.dll do I need to install libusb or libusb-win32?
Many thanks for your help.

from sequoia-ptpy.

manmoi01 avatar manmoi01 commented on June 1, 2024

@jonoboy9 Hi, pyusb use libusbK, libusb or libusb-win32 for communicate with usb device, Zadig rewrite the controller of specific device, the problem is another programs maybe cannot connect anymore with the camera.

WUDFWpdMtp is the controller of Microsoft for PTP, that is the controller that use windows, but pyusb cannot use this controller to connect with a camera.

from sequoia-ptpy.

domenzain avatar domenzain commented on June 1, 2024

@jonoboy9, you will need to replace the Windows driver with libusbK using Zadig.
Keep the original driver around in case you want to get the previous behaviour back (Windows supports MTP for file transfers).

Admittedly using libusb under Windows is a bit complicated.

from sequoia-ptpy.

jonoboy9 avatar jonoboy9 commented on June 1, 2024

@manmoi01 Hi, When you installed libusbk drivers using Zadig for your Nikon camera, did you select
"Install Driver" or "Install WCID Driver".
Then to use the libusbk driver, did you write an equivalent of libusbk.py to call the libusbk.dll. I understand from the comments in the PYUSB homepage, it should not be necessary to have an equivalent libusbk.py. I really appreciate just a brief explainatio, what else, even if I have to write something, what I must do to pick up the libusbk libraries.

from sequoia-ptpy.

manmoi01 avatar manmoi01 commented on June 1, 2024

@jonoboy9 Hi, yes you need install libusbk driver when the camera is connected to computer after this pyusb can connect to camera, Zadig change the driver is device specific and only affect the camera that you connect.

from sequoia-ptpy.

domenzain avatar domenzain commented on June 1, 2024

@jonoboy9 pyusb works out of the box with libusbK drivers installed. No need to create any bindings by yourself.

from sequoia-ptpy.

jonoboy9 avatar jonoboy9 commented on June 1, 2024

@manmoi01 @domenzain May I say thank you both. libusbk has helped. I have been able to take pictures. Just 2 questions:

  1. After with c.session(): cpt = c.initiate_capture() should I do a terminate_open_capture. What does this do?
    2)What function do I call to say, get and set shutter speeds?

Now that I have got working code, I have gone back to have a look at the problems I had when using libusb1. Using libusb1, I did successfully get the number of usb devices and even open the camera device. I also could get some info, but not any string data such as manufacturer and product name. Where it all goes wrong is when I wanted to get the langid. To do this, in core.py, Device.ctrl_transfer, it calls lib.libusb_control_transfer which returns -5. Any thoughts?
Also what is interesting, just before the call to the backend, there is this comment:

#Thanks to Johannes Stezenbach to point me out that we need to claim the recipient interface
    recipient = bmRequestType & 3
    rqtype = bmRequestType & (3 << 5)
    if recipient == util.CTRL_RECIPIENT_INTERFACE and rqtype != util.CTRL_TYPE_VENDOR:
            interface_number = wIndex & 0xff
            self._ctx.managed_claim_interface(self, interface_number)

Using either libusbk or the libusb1, managed_claim_interface is NOT called.

from sequoia-ptpy.

domenzain avatar domenzain commented on June 1, 2024

@jonoboy9 The exact details will depend on the camera manufacturer's implementation. Most will only support the StartCapture command. You can perform a GetDeviceInfo even outside a PTP session. And this command will let you know what the camera supports (commands, events, ...).

About the pyUSB issues, you will be able to get better information there:
https://github.com/pyusb/pyusb
You can declare the environment constant for detailed pyUSB logging to understand what it going on.

from sequoia-ptpy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.