Skip to content

Instantly share code, notes, and snippets.

@wmakeev
Last active December 29, 2018 15:10
Show Gist options
  • Save wmakeev/33176a2a7c08615ecfbf95bb7e830e6f to your computer and use it in GitHub Desktop.
Save wmakeev/33176a2a7c08615ecfbf95bb7e830e6f to your computer and use it in GitHub Desktop.
Digital camera control #canon #nikon #photo #gphoto #camera
@wmakeev
Copy link
Author

wmakeev commented Jul 27, 2018

Ищу способ управления камерой Canon 1200D через Raspberry PI.
Родной SDK Canon поддерживает только Mac и Win.
Понял, что есть другой вариант для Linux - gPhoto.

@wmakeev
Copy link
Author

wmakeev commented Aug 2, 2018

gPhoto2

Пока Pi в пути, пробую настроить работу на Mac'е с бывалой камерой Nikon D50.

  • Установил модуль node-gphoto2
  • Установил все необходимые модули (см. раздел Prerequisites)

Пробую следующий код:

'use strict'

const gphoto2 = require('gphoto2')

const GPhoto = new gphoto2.GPhoto2()

const getAsyncCaller = camera => (method, ...args) => new Promise((resolve, reject) => {
  camera[method](...args, (err, data) => {
    if (err) return reject(err)
    resolve(data)
  })
})

GPhoto.setLogLevel(1)
GPhoto.on('log', (level, domain, msg) => {
  console.log(domain, msg)
})

GPhoto.list(async list => {
  if (list.length === 0) {
    console.log('No camera found')
  }

  let camera = list[0]
  let cameraAsync = getAsyncCaller(camera)

  console.log(`Camera '${camera.model}' found`)

  await cameraAsync('setConfigValue', 'capturetarget', 1)
})

Система камеру видит, но при попытке записать настройки получаю ошибку Could not claim the USB device.

Camera 'Nikon D50 (PTP mode)' found
gp_libusb1_open [libusb1.c:424] 'libusb_claim_interface (port->pl->dh, port->settings.usb.interface)' failed: Access denied (insufficient permissions) (-3)
gp_port_set_error [gphoto2-port.c:1190] Could not claim interface 0 (Operation timed out). Make sure no other program (MacOS PTPCamera service) or kernel module (such as sdc2xx, stv680, spca50x) is using the device and you have read/write access to the device.

Решил проверить напрямую через командную строку

> brew install gphoto2
> gphoto2 --summary

Аналогичная ошибка.

*** Error ***
An error occurred in the io-library ('Could not claim the USB device'): Could not claim interface 0 (No such file or directory). Make sure no other program (MacOS PTPCamera service) or kernel module (such as sdc2xx, stv680, spca50x) is using the device and you have read/write access to the device.
*** Error (-53: 'Could not claim the USB device') ***

For debugging messages, please use the --debug option.
Debugging messages may help finding a solution to your problem.
If you intend to send any error or debug messages to the gphoto
developer mailing list <[email protected]>, please run
gphoto2 as follows:

    env LANG=C gphoto2 --debug --debug-logfile=my-logfile.txt --summary

Please make sure there is sufficient quoting around the arguments.

Читаю, что нужно установить права доступа к USB, по этой ссылке читаем как.

@wmakeev
Copy link
Author

wmakeev commented Dec 29, 2018

Дело не в правах доступа, а как указано в сообщении в процессах, занимающих порты.
На mac'е, к примеру, после подключения камеры, порт занимает процесс PTPCamera.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment