Beginner: Using libgphoto2, how to find set-config-values?

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

Beginner: Using libgphoto2, how to find set-config-values?

Karmaschinken
Hello girls and guys!

I successfully installed gphoto2 and gphoto2-python and now am able to run the python samples using my camera.

Now before I switched to python, I tried a little with gphoto2-CLI, and there I have the --list-config command, which lists the values that I can use to remote control my camera or query informations.

Now these commands show up like this:

$ gphoto2 --list-config
.
.
/main/settings/reviewtime
/main/imgsettings/iso
/main/capturesettings/picturestyle
.
.

But how do I find the values within ligphoto2? Does anyone have an example how to query the camera for a list of values (or indizes) that can be read and set?

And also, does anyone know if the basic values are camera independent? I mean, when setting the aperture an a Canon 600D, will the same code also set the aperture on another Canon or even on a Nikon or so?

Thanks a lot! Any help appreciated very much!

Martin
Reply | Threaded
Open this post in threaded view
|

Re: Beginner: Using libgphoto2, how to find set-config-values?

Marcus Meissner-4
Hi,

On Sun, Dec 18, 2016 at 09:37:01AM -0700, Karmaschinken wrote:

> Hello girls and guys!
>
> I successfully installed gphoto2 and gphoto2-python and now am able to run
> the python samples using my camera.
>
> Now before I switched to python, I tried a little with gphoto2-CLI, and
> there I have the --list-config command, which lists the values that I can
> use to remote control my camera or query informations.
>
> Now these commands show up like this:
>
> $ gphoto2 --list-config
> .
> .
> /main/settings/reviewtime
> /main/imgsettings/iso
> /main/capturesettings/picturestyle
> .
> .
>
> But how do I find the values within ligphoto2? Does anyone have an example
> how to query the camera for a list of values (or indizes) that can be read
> and set?
>
> And also, does anyone know if the basic values are camera independent? I
> mean, when setting the aperture an a Canon 600D, will the same code also set
> the aperture on another Canon or even on a Nikon or so?
>
> Thanks a lot! Any help appreciated very much!

We try to keep the semantics of the values the same between camera brands. So the
values for aperture, shutterspeed, iso etc. should be same between cameras.

Which python bindings are those? They likely offer a list option.

gp_camera_list_config() is very new, and gives a flat list of the short names,
gp_camera_get_single_config() would be getting the CameraWidget of a single
value.

gp_camera_get_config() would be the older version that gets the whole configuration tree,
including the values.

Ciao, Marcus

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Gphoto-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gphoto-devel
Reply | Threaded
Open this post in threaded view
|

Re: Beginner: Using libgphoto2, how to find set-config-values?

Karmaschinken
Hello Marcus,

thanks a lot! I had some progress on how to go along with it. Actually I am really able to print out all the values.

I suppose it is hard for me to understand the structure of the libghoto2 all in all. It seems obvious what a "camera" is, but I am only starting to grasp what "context" and "widget" means. Since I am trying to write a dual-camera-script, I am already happy having managed the first steps. Is it true I can manage multiple cameras in the code while using the same "context"-object for all?

However, I still fail to set a single value. The Python binding I am using show this in the header:

# python-gphoto2 - Python interface to libgphoto2
# http://github.com/jim-easterbrook/python-gphoto2
# Copyright (C) 2014-16  Jim Easterbrook  jim@jim-easterbrook.me.uk

I suppose the new functions you mentioned are not yet implemented, since I could not call them. But I used camera.get_config(context) now, to print out the values.

If some beginners try first steps with Python, this code might help a little (see results below):

    camera_list = []
    for name, addr in context.camera_autodetect():
        camera_list.append((name, addr))
    if not camera_list:
        print('No camera detected')
        return 1
    camera_list.sort(key=lambda x: x[0])

    port_info_list = gp.PortInfoList()
    port_info_list.load()

# ADD CAMERAS TO A LIST

    cameras = []
    for index, (name, addr) in enumerate(camera_list):
        camera = gp.Camera()
        cameras.append(camera)
        print('{:d}:  {:s}  {:s}'.format(index, addr, name))
        idx = port_info_list.lookup_path(addr)
        cameras[index].set_port_info(port_info_list[idx])
        cameras[index].init(context)
        gp.gp_camera_capture_preview(camera, context)

# ITERATE THRU ALL CAMERAS AND PRINT SETTINGS/VALUES

    for cameraNow in cameras:
        camera_config = camera.get_config(context)
        child_count = camera_config.count_children()

        # ITERATE THRU FIRST LEVEL ITEMS IN CONFIG AND PRINT

        for n in range(child_count):
            child = camera_config.get_child(n)
            label = '{} ({})'.format(child.get_label(), child.get_name())
            print(label)
            child_count_item = child.count_children()
           
           # ITERATE THRU SECOND LEVEL ITEMS IN CONFIG

            for o in range(child_count_item):
                child_item = child.get_child(o)
                label = '    {} ({}) ({}) '.format(child_item.get_label(), child_item.get_name(), child_item.get_value())
                print(label)

        shutterspeed = gp.check_result(gp.gp_widget_get_child_by_name(camera_config, 'shutterspeed'))
        shutterspeed.set_value("1")
        print(shutterspeed.get_name())
        print(shutterspeed.get_value())

    camera.exit(context)
    return 0

================================================
OUTPUT
================================================

0:  usb:001,013  Canon EOS 30D (PTP mode)
Camera Actions (actions)
    Synchronize camera date and time with PC (syncdatetime) (0)
    UI Lock (uilock) (2)
    PTP Opcode (opcode) (0x1001,0xparam1,0xparam2)
Camera Settings (settings)
    Camera Date and Time (datetime) (1104560018)
    Owner Name (ownername) (unknown)
    Auto Power Off (autopoweroff) (120)
    Capture Target (capturetarget) (Internal RAM)
    Capture (capture) (0)
Camera Status Information (status)
    Serial Number (serialnumber) (1530901268)
    Camera Manufacturer (manufacturer) (Canon Inc.)
    Camera Model (cameramodel) (Canon EOS 30D)
    Device Version (deviceversion) (3-1.0.6)
    Vendor Extension (vendorextension) (None)
    Camera Model (model) (2147484212)
    PTP Version (ptpversion) (256)
    DPOF Version (dpofversion) (257)
    Battery Level (batterylevel) (50%)
    Available Shots (availableshots) (90102)
Image Settings (imgsettings)
    Image Format (imageformat) (Large Fine JPEG)
    ISO Speed (iso) (100)
    WhiteBalance (whitebalance) (Tungsten)
    Color Temperature (colortemperature) (5200)
    WhiteBalance Adjust A (whitebalanceadjusta) (0)
    WhiteBalance Adjust B (whitebalanceadjustb) (0)
    WhiteBalance X A (whitebalancexa) (0)
    WhiteBalance X B (whitebalancexb) (0)
    Color Space (colorspace) (sRGB)
Capture Settings (capturesettings)
    Focus Mode (focusmode) (Manual)
    Canon Auto Exposure Mode (autoexposuremode) (Manual)
    Drive Mode (drivemode) (Single)
    Picture Style (picturestyle) (Standard)
    Aperture (aperture) (1.4)
    Shutter Speed (shutterspeed) (0.5)
    Metering Mode (meteringmode) (Evaluative)
    Bracket Mode (bracketmode) (0)
Other PTP Device Properties (other)
    Model ID (d049) (None)
shutterspeed
1

Reply | Threaded
Open this post in threaded view
|

Re: Beginner: Using libgphoto2, how to find set-config-values?

Jim Easterbrook
On 18/12/16 21:11, Karmaschinken wrote:

>
> However, I still fail to set a single value. The Python binding I am using
> show this in the header:
>
> # python-gphoto2 - Python interface to libgphoto2
> # http://github.com/jim-easterbrook/python-gphoto2
> # Copyright (C) 2014-16  Jim Easterbrook  [hidden email]
>
> I suppose the new functions you mentioned are not yet implemented, since I
> could not call them. But I used camera.get_config(context) now, to print out
> the values.

Have a look at the 'camera-config-gui.py' example. It uses
gp_camera_get_config to get the config tree, then creates a gui widget
for each config item and allows you to set values of items that aren't
read-only. The PyQt GUI stuff rather obscures the libgphoto bits though.
https://github.com/jim-easterbrook/python-gphoto2/blob/master/examples/camera-config-gui.py

--
Jim Easterbrook                 <http://www.jim-easterbrook.me.uk/>

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Gphoto-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gphoto-devel
Reply | Threaded
Open this post in threaded view
|

Re: Beginner: Using libgphoto2, how to find set-config-values?

Karmaschinken
Hello Jim! Thank you very much for your reply and for providing the Python-bindings for libgphoto2. I am very happy to be able to setup my project with your software and the great libgphoto2 from Marcus.

Unfortunately you are really right. I tried to understand what is happening in the PyQt GUI, but everything is happening in the Widgets, right?

E.g. line 154 and 155 seeem to me to be the ones that save the changed values back to the config object, right?

149    def new_value(self):
..
154        gp.check_result(gp.gp_widget_set_value(self.config, value))
155        self.config_changed()

I might dig into it and probably would manage to code my program as shown in the PyQt example, but actually I am not sure if I have to use the "Widgets"? Are these Widgets meant to be used in a GUI, or are they the prefered way to go ahead for an app running in a terminal too?

I mean, from within the code I posted above, I was able to see all the names and the values in the config object, without using widgets. Would I be able to change the values then too?

Is there any documentation available about what the libgphoto2-structures are meant to be for and how they are used? I know the API-doc, but this is just a summary of the function and data structure, without any information, what they do, or am I missing something?

I admit I am a little bit jealous when having a look at the JAVA-binding. This look so easy:

GPhoto2 camera = new GPhoto2();
camera.open();
GPhoto2Config config = new GPhoto2Config(camera);
config.readConfig();
config.setParameter("burstnumber", "5");
config.setParameter("capturetarget", "Memory card");
config.writeConfig();
camera.close();

There is no way to do it that easy within Python, no?

Thank you very much!

Martin
Reply | Threaded
Open this post in threaded view
|

Re: Beginner: Using libgphoto2, how to find set-config-values?

Jim Easterbrook
On 19/12/16 14:31, Karmaschinken wrote:
>
> Unfortunately you are really right. I tried to understand what is happening
> in the PyQt GUI, but everything is happening in the Widgets, right?

Yes, it's all a bit confusing. There are GUI widgets and camera config
"widgets" that are nodes in the config tree.

> E.g. line 154 and 155 seeem to me to be the ones that save the changed
> values back to the config object, right?
>
> 149    def new_value(self):
> ..
> 154        gp.check_result(gp.gp_widget_set_value(self.config, value))

This changes a value, but you still need to call gp_camera_set_config to
send the changes back to the camera.

> I mean, from within the code I posted above, I was able to see all the names
> and the values in the config object, without using widgets. Would I be able
> to change the values then too?

As I understand it, having got the config tree with gp_camera_get_config
you can then search for a particular node with
gp_widget_get_child_by_name, then set that node's value with
gp_widget_set_value. None of this requires a GUI - it's just a
convenient way to display the config tree. See the set-capture-target.py
example.

> Is there any documentation available about what the libgphoto2-structures
> are meant to be for and how they are used? I know the API-doc, but this is
> just a summary of the function and data structure, without any information,
> what they do, or am I missing something?

It's all I've been using - it does present a bit of a challenge at times.

> I admit I am a little bit jealous when having a look at the  JAVA-binding
> <https://github.com/angryelectron/libgphoto2-jna>  . This look so easy:
>
> GPhoto2 camera = new GPhoto2();
> camera.open();
> GPhoto2Config config = new GPhoto2Config(camera);
> config.readConfig();
> config.setParameter("burstnumber", "5");
> config.setParameter("capturetarget", "Memory card");
> config.writeConfig();
> camera.close();
>
> There is no way to do it that easy within Python, no?

I've deliberately kept my Python interface as close as is reasonable to
the C original, so they can share documentation.  (-:  It also means I'm
not prescribing how it should be used. A higher level interface can be
easier to use but less flexible.

The equivalent of your Java might look like this:

config = gp_camera_get_config(camera, context)
node = gp_widget_get_child_by_name(config, "burstnumber")
gp_widget_set_value(node, 5)
node = gp_widget_get_child_by_name(config, "capturetarget")
gp_widget_set_value(node, 0)
gp_camera_set_config(camera, context)

--
Jim Easterbrook                 <http://www.jim-easterbrook.me.uk/>

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/intel
_______________________________________________
Gphoto-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gphoto-devel
Reply | Threaded
Open this post in threaded view
|

Re: Beginner: Using libgphoto2, how to find set-config-values?

Karmaschinken
Hmmmm... For sure it's me and my very basic skills in C and Python, but I can't make it work

I can't make your code run, it throws an error:

TypeError: in method 'gp_widget_get_child_by_name', argument 1 of type 'CameraWidget *'

This is the code I tried, had to change it a little!?

        config = gp.gp_camera_get_config(camera, context)
        node = gp.gp_widget_get_child_by_name(config, "burstnumber")
        gp.gp_widget_set_value(node, 5)
        node = gp.gp_widget_get_child_by_name(config, "capturetarget")
        gp.gp_widget_set_value(node, 0)
        gp.gp_camera_set_config(camera, context)

What am I doing wrong here? Thanks for your help.

Best regards. Martin.
Reply | Threaded
Open this post in threaded view
|

Re: Beginner: Using libgphoto2, how to find set-config-values?

Karmaschinken
Once again! Thank you Jim, thank you Marcus!

I am starting to understand how it works! At least I managed to get all options listed now and also to set the values. That's all what I wanted for now. Now I have to try if it works with two cameras at once, but since I already managed to shoot to cameras and download the images, I am convinced I will get that working too.

Thanks a lot!

Have a nice Christmas time! Best regards. Martin

Reply | Threaded
Open this post in threaded view
|

Re: Beginner: Using libgphoto2, how to find set-config-values?

Jim Easterbrook
In reply to this post by Karmaschinken
On 19/12/16 19:30, Karmaschinken wrote:

> Hmmmm... For sure it's me and my very basic skills in C and Python, but I
> can't make it work
>
> I can't make your code run, it throws an error:
>
> TypeError: in method 'gp_widget_get_child_by_name', argument 1 of type
> 'CameraWidget *'
>
> This is the code I tried, had to change it a little!?
>
>         config = gp.gp_camera_get_config(camera, context)
>         node = gp.gp_widget_get_child_by_name(config, "burstnumber")
>         gp.gp_widget_set_value(node, 5)
>         node = gp.gp_widget_get_child_by_name(config, "capturetarget")
>         gp.gp_widget_set_value(node, 0)
>         gp.gp_camera_set_config(camera, context)
>
> What am I doing wrong here? Thanks for your help.

Sorry, I was very sloppy and omitted all the error checking code.
gp.gp_camera_get_config actually returns a tuple of two values - the
error code and the config value. This tuple is not an acceptable
argument to gp_widget_get_child_by_name. (I also omitted the config
parameter to gp_camera_set_config.)

The "object oriented" versions of the functions are generally easier to use:

     config = camera.get_config(context)
     node = config.get_child_by_name("burstnumber")
     node.set_value(5)
     node = config.get_child_by_name("capturetarget")
     node.set_value(0)
     camera.set_config(config, context)

--
Jim Easterbrook                 <http://www.jim-easterbrook.me.uk/>

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/intel
_______________________________________________
Gphoto-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gphoto-devel
Reply | Threaded
Open this post in threaded view
|

Re: Beginner: Using libgphoto2, how to find set-config-values?

Karmaschinken
This post was updated on .
Jim , thanks again!

The camera is under control! I would be very happy, if I would not have these very sad news on the radio. I'm in Berlin, and so is my girl friend. It is so unbelievable sad.

Thanks again and best wishes.
Reply | Threaded
Open this post in threaded view
|

Re: Beginner: Using libgphoto2, how to find set-config-values?

Jim Easterbrook
In reply to this post by Karmaschinken
On 18/12/16 21:11, Karmaschinken wrote:
>
> I suppose the new functions you mentioned are not yet implemented, since I
> could not call them. But I used camera.get_config(context) now, to print out
> the values.

I think I should explain why my Python bindings do not currently have
the gp_camera_get_single_config() function.

I use a tool called SWIG (see http://swig.org/) to generate C source
from the libgphoto2 header files on my computer, currently version
2.5.8. When a user installs python-gphoto2 this C source is compiled and
linked with the version of libgphoto2 installed on the user's computer
to make a Python extension. If the user has a newer version with
additional functions such as gp_camera_get_single_config() these won't
be usable as they are not in the SWIG generated C source. Everything
else should work correctly though.

If the user has an older version of libgphoto2 that is missing any of
the functions expected by the SWIG generated C source then I expect the
compilation or linking would fail. I haven't received any reports of
this, but sometimes people don't report problems with software, they
just give up and use something else.

I would like to be able to make the new functions available from Python,
but I need to be very careful to maintain compatibility with earlier
versions.
--
Jim Easterbrook                 <http://www.jim-easterbrook.me.uk/>

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/intel
_______________________________________________
Gphoto-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gphoto-devel
Reply | Threaded
Open this post in threaded view
|

Re: Beginner: Using libgphoto2, how to find set-config-values?

Jim Easterbrook
On 20/12/16 11:33, Jim Easterbrook wrote:
>
> I would like to be able to make the new functions available from Python,
> but I need to be very careful to maintain compatibility with earlier
> versions.

OK, I think I've found a way of doing this. I've released a new version
of python-gphoto2 that includes the gp_camera_get_single_config(),
gp_camera_set_single_config() and gp_camera_list_config() functions if
it's installed on a machine with libgphoto2 v1.5.10 or later. With
earlier versions of libgphoto2 those functions exist but will fail when
called.

I'd welcome any feedback from python-gphoto2 users who try this new version.
--
Jim Easterbrook                 <http://www.jim-easterbrook.me.uk/>

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/intel
_______________________________________________
Gphoto-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gphoto-devel
Reply | Threaded
Open this post in threaded view
|

Re: Beginner: Using libgphoto2, how to find set-config-values?

Karmaschinken
Jim, thank you very much! I will test at soon as I am back home!

Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: Beginner: Using libgphoto2, how to find set-config-values?

Karmaschinken
Hello Jim,

I managed to use your Python Bindings for my 5D Mk II. Now there is one thing I need some help:

I would like to trigger the camera with a cable-remote while being in LiveView. Now everytime I call "gp.check_result(gp.gp_camera_exit(camera, context))" LiveView is being ended. Is there any chance to avoid this behaviour?