jim-easterbrook / python-gphoto2

Python interface to libgphoto2
GNU Lesser General Public License v3.0
359 stars 59 forks source link

Reading PTP event failed when using capture-image.py (sony alpha a6000) #100

Closed gadoo2020 closed 4 years ago

gadoo2020 commented 4 years ago

ubuntu 18.04 LTS Python 2.7.17 i installed python-gphoto2 from https://github.com/jim-easterbrook/python-gphoto2

when i tried to capture image from my sony camera this error appears :

WARNING: gphoto2: (ptp_usb_event [usb.c:587]) Reading PTP event failed: Timeout reading from or writing to the port (-10) WARNING: gphoto2: (ptp_usb_event [usb.c:587]) Reading PTP event failed: Timeout reading from or writing to the port (-10) WARNING: gphoto2: (ptp_usb_event [usb.c:587]) Reading PTP event failed: Timeout reading from or writing to the port (-10) WARNING: gphoto2: (ptp_usb_event [usb.c:587]) Reading PTP event failed: Timeout reading from or writing to the port (-10) WARNING: gphoto2: (ptp_usb_event [usb.c:587]) Reading PTP event failed: Timeout reading from or writing to the port (-10) WARNING: gphoto2: (ptp_usb_event [usb.c:587]) Reading PTP event failed: Timeout reading from or writing to the port (-10) WARNING: gphoto2: (ptp_usb_event [usb.c:587]) Reading PTP event failed: Timeout reading from or writing to the port (-10) WARNING: gphoto2: (ptp_usb_event [usb.c:587]) Reading PTP event failed: Timeout reading from or writing to the port (-10) WARNING: gphoto2: (ptp_usb_event [usb.c:587]) Reading PTP event failed: Timeout reading from or writing to the port (-10) WARNING: gphoto2: (ptp_usb_event [usb.c:587]) Reading PTP event failed: Timeout reading from or writing to the port (-10) WARNING: gphoto2: (ptp_usb_event [usb.c:587]) Reading PTP event failed: Timeout reading from or writing to the port (-10)

jim-easterbrook commented 4 years ago

Does it actually work, i.e. is a picture taken? Libgphoto2 tends to produce a lot of warnings even when working correctly in my experience. I don't think this is a problem with the Python interface itself, so perhaps you should ask on the gphoto mailing list. Someone there might have the same camera model.

gadoo2020 commented 4 years ago

no picture taken automatically but when i take picture by manual method while the code is running ,the code work and image is previewed

jim-easterbrook commented 4 years ago

Sorry I can't help. I don't have a Sony camera and don't know how they work with libgphoto2.

pdeman commented 4 years ago

first of all, keep in mind that the sony camera needs to be set in ptp or mtp mode. by default they connect as usb storage, and you have to go through the menu on the sony to set it in ptp or mtp mode. I have similar problem with a sony alpha7r4. it works with libgphoto2 but not with phython gphoto2.

self.logger.info("trigger capture")  
retval=gphoto2.gp_camera_trigger_capture(self.camera,self.context)
self.logger.info("image captured") 
eventtype=0
while eventtype != gphoto2.GP_EVENT_FILE_ADDED: 
      error,eventtype,file_path = gphoto2.gp_camera_wait_for_event(self.camera,20,self.context)

it never goes out of the while. no gp_event_file_added so I can't get the path of the image.

jim-easterbrook commented 4 years ago

The gp_camera_trigger_capture and gp_camera_capture functions are different. With gp_camera_capture you don't need to wait for the event as the path should be returned by the function. When you say it works with libgphoto2 do you mean with the gphoto2 program? Python-gphoto2 is simply a wrapper round libgphoto2. The gphoto2 sources are public, so you might be able to find out what it's doing differently to make capture work.

pdeman commented 4 years ago

I mean libgphoto2. it does trigger or capture, but I have a problem "Reading PTP event failed: Timeout reading from or writing to the port (-10)". I doesn't return the path, and it may be a problem for the python wrapper ?

jim-easterbrook commented 4 years ago

Can you post your working C code that's using libgphoto2? It must be doing something different.

pdeman commented 4 years ago

https://github.com/gphoto/libgphoto2/issues/471

jim-easterbrook commented 4 years ago

My reading of that says you can trigger a capture using gp_camera_trigger_capture but not get the file name, in C and in Python. I'm not seeing any failing that's specific to the Python interface.

pdeman commented 4 years ago

but with any other brand the same code trigger the capture and gives me the file path.

jim-easterbrook commented 4 years ago

Yes, it's definitely a camera-specific problem. The capture-image.py example works with the cameras I have (Canon compact and DSLR).

pdeman commented 4 years ago

with the sony, capture-image.py trigger the capture but never ends.

jim-easterbrook commented 4 years ago

Yes, it calls gp_camera_capture which, I assume, waits for the file added event that never comes.

jim-easterbrook commented 4 years ago

It seems from the gphoto2 mailing lists that the Sony 6000 is problematical. https://sourceforge.net/p/gphoto/mailman/search/?q=sony+6000

jim-easterbrook commented 4 years ago

@gadoo2020 Sorry this has drifted off topic rather. I suggest you look at some of the mailing list discussions to see what may be possible with your camera.