Problems with PTP on PowerShot A800 - General Help and Assistance on using CHDK stable releases - CHDK Forum

Problems with PTP on PowerShot A800

  • 10 Replies
  • 5701 Views
Problems with PTP on PowerShot A800
« on: 08 / April / 2013, 08:51:16 »
Advertisements
Some background:
I have been using CHDK before, mostly to shoot HDR, and take timelapse series on my old PowerShot SD600. I am currently building a more advanced timelapse rig that consists of a PowerShot A800 with CHDK on, a raspberry pi, an external drive to store photos on, and an old Linksys WAP54G running DD-WRT. The basic idea is to use PTP to control the camera from the raspberry pi, and download the photos from the camera to the external drive for storage. Then to download the photos over WLAN from time to time.

Setup:
The Powershot A800 is running version "a800-100c-1.1.0-2669-full_BETA" of CHDK. Connected to the raspberry pi via USB.
The raspberry pi runs Raspbian wheezy, and connects to the camera with chdkptp r311.

I have the following two scripts:
chdkptp.sh:
Code: (shellscript) [Select]
#!/bin/sh
CHDKPTP_DIR=/path/to/chdkptp
export LD_LIBRARY_PATH=/path/to/iup:/path/to/cd
export LUA_PATH="$CHDKPTP_DIR/lua/?.lua"
"$CHDKPTP_DIR/chdkptp" "$@"
getPhotos.php:
Code: (php) [Select]
<?php

function execCommand($command) {
  
$result shell_exec($command." 2>&1");
  if (
stripos(strtolower($result), "error") !== false) {
    die(
$result);
  }
}

$initCommand "./chdkptp.sh -c -e\"luar switch_mode_usb(1)\" -e\"exec os.execute(\\\"sleep 3\\\")\" -e\"luar set_aflock(1)\"";
$photoCommand "./chdkptp.sh -c -e\"shoot\"";
$downloadCommand "./chdkptp.sh -c -e\"mdownload -overwrite=n DCIM temp\"";
$deleteCommand "./chdkptp.sh -c -e\"rm DCIM\"";

echo(
"Initializing camera ... ");
execCommand($initCommand);
echo(
"Done\n");
usleep(500000);

$nextPhoto microtime(true);

while (
true) {
  echo(
date("Y-m-d H:i:s")." Taking photo ... ");
  
$startTime microtime(true);
  
execCommand($photoCommand);
  
$elapsedTime microtime(true) - $startTime;
  echo(
"done in $elapsedTime seconds.\t\t");

  
usleep(500000);
  
shell_exec($downloadCommand);
  
usleep(500000);
  
shell_exec($deleteCommand);

  
$nextPhoto += 15;
  if (
$nextPhoto microtime(true)) {
    echo(
"Sleeping for ".($nextPhoto microtime(true))." seconds.\n");
    
time_sleep_until($nextPhoto);
  } else {
    echo(
"Not sleeping.\n");
  }
}

?>

The problem:
When i run the script getPhotos.php it works as intended at first. But after a while (1-100 images or so) the camera seems to crash. After that the camera does not respond to any interaction (PTP, pressing buttons - even the power button), and the only solution seems to be to cycle the power to the camera. This has happend after seemingly random number of images in the interval 1-100, and it seems that the downloading of the photos is the command that triggers this behavior (since, when i comment out that row "shell_exec($downloadCommand);", it works).

I have tried replacing the camera (to a PowerShot SD940) with the same result.
I have tried to use gphoto2 for downloading and deleting the photos from the camera with similar result (not the same error message, but it crashes during download and/or delete). This leads me to believe that the error is somewhere in CHDK.

Here is some output from running the getPhotos.php script:
Code: (output) [Select]
pi@raspberrypi ~/timelapse $ php -f getPhotos.php
Initializing camera ... Done
2013-04-07 13:30:40 Taking photo ... done in 5.063178062439 seconds.            Sleeping for 6.0421028137207 seconds.
2013-04-07 13:30:55 Taking photo ... done in 5.2359209060669 seconds.           Sleeping for 5.6417889595032 seconds.
2013-04-07 13:31:10 Taking photo ... done in 5.6660900115967 seconds.           Sleeping for 5.2321989536285 seconds.

[Had to cut away some rows here to make the post less than 7500 characters, but you get the idea...]

2013-04-07 13:40:40 Taking photo ... done in 5.225909948349 seconds.            Sleeping for 5.9199287891388 seconds.
2013-04-07 13:40:55 Taking photo ... done in 5.2258448600769 seconds.           unexpected return code 0x2fd
ERROR: ptp error
ERROR: Could not close session!
ERROR: no matching devices found
ERROR: not connected
Sleeping for 7.1426119804382 seconds.
2013-04-07 13:41:10 Taking photo ... ERROR: no matching devices found
ERROR: not connected

pi@raspberrypi ~/timelapse $ php -f getPhotos.php
Initializing camera ... ERROR: no matching devices found
ERROR: not connected
ERROR: not connected
And a similar run using gphoto2 to download the images:
Code: (output) [Select]
pi@raspberrypi ~/timelapse $ php -f getPhotos.php
Initializing camera ... Done
2013-04-07 13:48:59 Taking photo ... done in 5.1752691268921 seconds.           Downloading 'IMG_0541.JPG' from folder '/store_00010001/DCIM/100___04'...

*** Error ***
PTP I/O error

*** Error ***
An error occurred in the io-library ('Unspecified error'): The supplied vendor or product id (0x0,0x0) is not valid.
*** Error (-1: 'Unspecified error') ***
The change to the getPhotos.php script to use gphoto2 is to use the following definitions instead of the original ones:
Code: (php) [Select]
$downloadCommand = "cd temp && gphoto2 -P";
$deleteCommand = "gphoto2 -DR";
So, for my final questions:
Am I doing something wrong, that can cause this error?
Or is this indeed a bug in CHDK? (Is it known, and is there a plan to fix it?)

*

Online reyalp

  • ******
  • 13438
Re: Problems with PTP on PowerShot A800
« Reply #1 on: 08 / April / 2013, 13:44:23 »
So, for my final questions:
Am I doing something wrong, that can cause this error?
Or is this indeed a bug in CHDK? (Is it known, and is there a plan to fix it?)
In theory any crash is a bug, but there are some known issues.

If you can get a romlog from the camera http://chdk.wikia.com/wiki/Debugging#Camera_crash_logs_.28romlog.29 that may help us understand what's going wrong.

There is one known issue that can happen if you try to download too soon after the shot was taken. The romlog will tell us if you are hitting this.

There is another crash that can happen happen in PTP on cameras without CAM_FIRMWARE_MEMINFO defined. If you use the 1.2 trunk, it's defined for all cameras.

I've also had weirdness / failed connections when the camera goes into powersave mode. I haven't really worked out exactly what happens, if you get it early pressing a button wakes it up but sometimes the connection dies. In any case, I'd suggest setting the "disable lcd off" CHDK option to "always".

If you use chdkptp r330, you can use the "rec" cli command to switch modes. This won't switch modes if the camera is already in the correct mode. Calling switch_mode_usb() to a mode you are already in can cause crashes or other weird behavior.
Don't forget what the H stands for.

Re: Problems with PTP on PowerShot A800
« Reply #2 on: 09 / April / 2013, 13:15:48 »
If you can get a romlog from the camera http://chdk.wikia.com/wiki/Debugging#Camera_crash_logs_.28romlog.29 that may help us understand what's going wrong.

I made another run, and got a slightly different output: (return code 0x2ff instead of 0x2fd)
Code: (output) [Select]
2013-04-07 15:03:08 Taking photo ... done in 5.1647598743439 seconds.           Sleeping for 5.8731100559235 seconds.
2013-04-07 15:03:23 Taking photo ... done in 5.1146519184113 seconds.           unexpected return code 0x2ff
ERROR: ptp error
ERROR: Could not close session!
open_camera_dev:usb_ptp_device_reset(): Connection timed out
usb_ptp_get_device_status(): Connection timed out
ERROR: connection failed
ERROR: not connected
Not sleeping.
2013-04-07 15:03:56 Taking photo ... ERROR: connection failed
ERROR: not connected
open_camera_dev: ptp_opensession failed 0x2ff
Device status OK
open_camera_dev: ptp_opensession 2 failed: 0x2ff

When i got the romlog, the time in the log said it was from more than a day ago. So it seems that this error does not trigger the dump. I will attach the romlog anyways

*

Online reyalp

  • ******
  • 13438
Re: Problems with PTP on PowerShot A800
« Reply #3 on: 09 / April / 2013, 16:16:26 »
When i got the romlog, the time in the log said it was from more than a day ago. So it seems that this error does not trigger the dump. I will attach the romlog anyways
Yeah, this romlog is a dryos kernel panic. Not one I'd expect from any of the known issues I mentioned earlier so likely unrelated.

Reading your original post again, it sounds like the camera hangs rather than crashing, so no romlog is expected. If the camera crashes properly, it should hang for a few seconds and then shut down without retracting the lens.

0x2ff and 0x2fd are internal ptpcam error codes:
Code: [Select]
#define PTP_ERROR_IO 0x02FF
#define PTP_ERROR_RESP_EXPECTED 0x02FD
Both mean that communication failed, and I would expect the difference only has to do with where in the transaction it failed, so it probably doesn't tell us much.

How is the camera connected to the raspberry pi? The pi has very limited power on USB, and this could cause flaky behavior. If it's using a non-powered USB hub, you might try connecting directly or using a powered hub. The camera itself draws very little power so should be OK without a powered hub but if there's other stuff attached it could be an issue.

You also might try looking at the kernel log on the pi around the time the hang happens.

If you have a PC you can run the equivalent commands from, that would also be a good test to see if it's something specific to the pi.
Don't forget what the H stands for.


Re: Problems with PTP on PowerShot A800
« Reply #4 on: 10 / April / 2013, 12:42:59 »
There is another crash that can happen happen in PTP on cameras without CAM_FIRMWARE_MEMINFO defined. If you use the 1.2 trunk, it's defined for all cameras.

I've also had weirdness / failed connections when the camera goes into powersave mode. I haven't really worked out exactly what happens, if you get it early pressing a button wakes it up but sometimes the connection dies. In any case, I'd suggest setting the "disable lcd off" CHDK option to "always".

If you use chdkptp r330, you can use the "rec" cli command to switch modes. This won't switch modes if the camera is already in the correct mode. Calling switch_mode_usb() to a mode you are already in can cause crashes or other weird behavior.

I updated the CHDK version to a800-100c-1.2.0-2692-full_BETA from http://mighty-hoernsche.de/trunk/, set the "disable lcd off" to "always", switched to chdkptp r330 and started using the command "rec" instead of "switch_mode_usb()", and also made the script sleep 1 second after the shot before downloading it.

I still have the same problem.

How is the camera connected to the raspberry pi? The pi has very limited power on USB, and this could cause flaky behavior. If it's using a non-powered USB hub, you might try connecting directly or using a powered hub. The camera itself draws very little power so should be OK without a powered hub but if there's other stuff attached it could be an issue.

You also might try looking at the kernel log on the pi around the time the hang happens.

If you have a PC you can run the equivalent commands from, that would also be a good test to see if it's something specific to the pi.

The camera is connected by a USB-A to USB-Mini cable (no hubs), and the camera is powered by a battery eliminator providing 3.1V/1A. The pi is powered by an adapter providing 5V/1A. Also connected to USB on the pi is a flashdrive (not a mechanical disk).

Will try to look at the kernel log, and also run the same code from a PC... Will post back the results here within a few days at least.

Re: Problems with PTP on PowerShot A800
« Reply #5 on: 10 / April / 2013, 17:30:45 »
I just executed the same script from a Windows 7 PC with chdkptp-r330-win32. First thing i noticed was that after every command the script executed windows made that sound of "hardware disconnected". Strange.

The result however was the same, after 60 photos this happened:
Code: (output) [Select]
2013-04-10 23:20:55 Taking photo ... done in 7.7266809940338 seconds.           unexpected return code 0x2ff
ERROR: ptp error
ERROR: Could not close session!

This time the camera shut off following the error, and i got a ROMLOG that seems to be related. Se the attached file.

*

Online reyalp

  • ******
  • 13438
Re: Problems with PTP on PowerShot A800
« Reply #6 on: 10 / April / 2013, 22:47:27 »
I just executed the same script from a Windows 7 PC with chdkptp-r330-win32. First thing i noticed was that after every command the script executed windows made that sound of "hardware disconnected". Strange.
This is normal, when you disconnect chdkptp the connection is reset.
Quote
This time the camera shut off following the error, and i got a ROMLOG that seems to be related. Se the attached file.
This is a invalid memory access in one of the ptp tasks, probably in chdk code. Unfortunately, I don't have the files to get much more than that from an autobuild. If you are able to reproduce it again with the attached build, I may be able to get more useful information.
Don't forget what the H stands for.

Re: Problems with PTP on PowerShot A800
« Reply #7 on: 11 / April / 2013, 13:23:59 »
If you are able to reproduce it again with the attached build, I may be able to get more useful information.

I loaded the version you attached, and took over 400 images with no problem. So I'm going to put the rig up tonight hoping that it will work bug-free :) Will report back in a few days or so.


Re: Problems with PTP on PowerShot A800
« Reply #8 on: 15 / April / 2013, 09:43:43 »
Checked on the camera now, and I got the same error this time :( And the romlog is the same that I have already posted (meaning no log was saved I guess?)

Re: Problems with PTP on PowerShot A800
« Reply #9 on: 15 / April / 2013, 09:46:17 »
Checked on the camera now, and I got the same error this time :( And the romlog is the same that I have already posted (meaning no log was saved I guess?)
This might be a stupid question but did you go through the CHDK menu to the Debug menu and select "Save ROM crash log" again ?
Ported :   A1200    SD940   G10    Powershot N    G16

 

Related Topics