Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How is gp_camera_wait_for_event working ? #27

Closed
benoitguigal opened this issue Oct 21, 2016 · 5 comments
Closed

How is gp_camera_wait_for_event working ? #27

benoitguigal opened this issue Oct 21, 2016 · 5 comments
Labels

Comments

@benoitguigal
Copy link

I want to wait for a GP_EVENT_FILE_ADDED event. Here is my code:

gp.check_result(gp.gp_camera_wait_for_event(camera, gp.GP_EVENT_FILE_ADDED, context))

I would expect the function to wait until the event happen but instead it returns immediately (0, None)
My workaround is to create a while loop like this:

while True:
    event_type, data = gp.check_result(gp.gp_camera_wait_for_event(camera, gp.GP_EVENT_FILE_ADDED, context))
    if event_type == gp.GP_EVENT_FILE_ADDED:
        camera_file_path = data
        return camera_file_path
    time.sleep(0.1)

which is working but does not feel right. Any help would be greatly appreciated.

@jim-easterbrook
Copy link
Owner

I've not used gp_camera_wait_for_event myself so I don't know what to expect. It's probably camera and/or driver dependent. This is a question about libgphoto2 rather than about the Python interface so it might be worth asking on the gphoto2 mailing list.

@jim-easterbrook
Copy link
Owner

I've just looked at the documentation of gp_camera_wait_for_event. The second parameter is a timeout value, but you are passing gp.GP_EVENT_FILE_ADDED so your call is timing out in 2 milliseconds.

@benoitguigal
Copy link
Author

In gphoto2 version >= 2.5.6 it is possible to pass string value like 'FILEADDED' or 'CAPTURECOMPLETE' to the wait_event function.
https://github.com/gphoto/gphoto2/blob/master/NEWS. Do you think it is possible to call this underlying function instead of the function with the timeout ?

@jim-easterbrook
Copy link
Owner

jim-easterbrook commented Oct 23, 2016

python-gphoto2 is a Python interface to the libgphoto2 C library (see http://www.gphoto.org/doc/api/). It doesn't add functionality unless absolutely necessary, e.g. to use Python types. The gphoto2 command line tool is a separate entity. Its wait-event option presumably uses gp_camera_wait_for_event internally.

You can easily write your own Python function to call gp_camera_wait_for_event repeatedly until it returns the event type you want.

@benoitguigal
Copy link
Author

ok it very clear, thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants