Search code examples
node.jsraspberry-pi3

Gphoto2 node ### An error occurred in the io-library ('Could not claim the USB device')


I am Working on Connectivity between RaspberryPi 3 and DSLR Camera (Canon 1300 D). When I run command for capture image , first time is working and when I run again I am having following issue:

An error occurred in the io-library ('Could not claim the USB device'): Could not claim interface 0 (Device or resource busy). Make sure no other program (gvfs-gphoto2-volume-monitor) or kernel module (such as sdc2xx, stv680, spca50x) is using the device and you have read/write access to the device.

Please give me solution for "How to communicate Raspberry Pi 3 with DSLR using NodeJs ?"

Code Example:

app.post('/onDemand', function(req, res) {
  GPhoto.list(function (list) {
  console.log('List:', list);
  if (list.length === 0) return;
  var camera = list[0];
  camera.takePicture({download: true,keep: true}, function (er, data) {
    fs.writeFileSync(__dirname + '/input/picture1.jpg', data);
    var filePath = "./input/picture1.jpg";
    var params = {
      Bucket: 'marzs',
      Body : fs.createReadStream(filePath),
      Key : "marzs/"+Date.now()+"_"+path.basename(filePath)
    };

    s3.putObject(params, function (err, data) {
      if (err) {
          console.log('ERROR MSG: ', err);
          res.status(500).send(err);
      } else {
          console.log('Successfully uploaded data');
          res.status(200).send({ imageURL: data.Location });
      }
      res.status(200).send({ imageURL: data.Location });
  });
  });
});

});

Thanks in Advance.

Yogesh Waghmare


Solution

  • We need to install libusb on server and run following command.

    gphoto2 --get-config=capturetarget
    gphoto2 --set-config=capturetarget=1
    gphoto2 --set-config shutterspeed=bulb
    gphoto2 --wait-event=2s --set-config eosremoterelease=Immediate --wait-event=5s --set-config eosremoterelease=Off --wait-event-and-download=5s
    

    After that we need to exit process with "process.exit();" after completion of process. and run via forever command

    now code running properly.

    Thanks & Regards, Yogesh Waghmare