jim-easterbrook / python-gphoto2

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

Can not set datetime on Canon EOS 1200D #147

Closed jensanjo closed 1 year ago

jensanjo commented 1 year ago

I am trying to set the date and time on a Canon EOS 1200D using this program:

import time
import gphoto2 as gp

camera = gp.Camera()
camera.init()
config = camera.get_config()
OK, date_config = gp.gp_widget_get_child_by_name(config, 'datetime') 
assert(OK == gp.GP_OK)
now = int(time.time())
date_config.set_value(now)
camera.set_config(config)
camera.exit()

There is no error message, but the datetime is not changed. If a do the same using gphoto2 it works

LANG=C gphoto2 --set-config datetime=now
jim-easterbrook commented 1 year ago

I don't think you'll get any error messages unless you use gp.use_python_logging() to get gphoto2 error messages sent to Python's logging system.

Setting camera clocks seems to be very make & model dependent. See the set-camera-clock.py example - it works for my Cannon cameras but I can't promise it works on others. The datetimeutc config uses int(time.time()), the syncdatetime config takes the value 1, and the datetime config takes an int or str representation of the time depending on the widget type.

jensanjo commented 1 year ago

If I use set-camera-clock.py the resulting time is off by 3600 sec. It uses the syncdatetime config. I think the 3600 sec offset is a timezone issue (I am in Europe/Amsterdam). Because the syncdatetime config does not work for me, I need the datetime config. That works when I use gphoto2, but not with python-gphoto2 2.3.4. Any ideas?

I added logging to the test script:

import gphoto2 as gp
import logging

# setup python logging
logging.basicConfig(
        format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
callback_obj = gp.check_result(gp.use_python_logging())    

# try to set the camera datetime
camera = gp.Camera()
camera.init()
config = camera.get_config()
OK, date_config = gp.gp_widget_get_child_by_name(config, 'datetime') 
assert(OK == gp.GP_OK)
now = int(time.time())
date_config.set_value(now)
camera.set_config(config)
assert(now == date_config.get_value())  # the datetime config is properly set
camera.exit()

But the output does not seem relevant:

WARNING: gphoto2: (gp_port_usb_close [libusb.c:309]) Invalid parameters: 'port && port->pl->dh' is NULL/FALSE.
jim-easterbrook commented 1 year ago

If you look at set-camera-clock.py you'll see it uses the datetimeutc config for my Canon EOS 100D - I expect you need to do the same with your Canon.

jensanjo commented 1 year ago

Thanks! That works. I have to add the utc offset (3600 or 7200 seconds depending on daylight saving) to the datetimeutc value to get a correct datetime.