Wikia

CHDK Wiki

Changes: PTP Extension

Edit

Back to page

m (LibUSB Driver for Windows)
(ptpcam)
 
(20 intermediate revisions by 7 users not shown)
Line 3: Line 3:
 
Most cameras support some basic operations over PTP, but often only in a limited fashion. For example, downloading of files can be limited to just JPEG files.
 
Most cameras support some basic operations over PTP, but often only in a limited fashion. For example, downloading of files can be limited to just JPEG files.
   
The PTP extension for CHDK discussed in this article is does not alter the standard operations but adds new CHDK-specific operations instead. This is due to the complexity involved in altering or complete overwriting the standard operations. It also means that special tools are required to access this new functionality.
+
The PTP extension for CHDK discussed in this article does not alter the standard operations but adds new CHDK-specific operations instead. This is due to the complexity involved in altering or complete overwriting the standard operations. It also means that special tools are required to access this new functionality.
  +
  +
If you want simple control over the camera without USB a protocol connection (for example, using a micro-controller or RC equipment) see [[USB Remote]].
   
 
The CHDK extension was first added to the CHDK trunk in [http://tools.assembla.com/chdk/changeset/957 changeset 957], and has been enabled for all cameras since [http://tools.assembla.com/chdk/changeset/1116 changeset 1116]
 
The CHDK extension was first added to the CHDK trunk in [http://tools.assembla.com/chdk/changeset/957 changeset 957], and has been enabled for all cameras since [http://tools.assembla.com/chdk/changeset/1116 changeset 1116]
Line 14: Line 14:
 
Files can be uploaded to and downloaded from any part of the file system.
 
Files can be uploaded to and downloaded from any part of the file system.
 
===Script execution===
 
===Script execution===
The PTP interface allows execution of lua scripts sent over PTP. In general, any scripting function available to normal CHDK scripts can be executed remotely. There are some additional functions specific to PTP, described in [[Lua/PTP Scripting]].
+
The PTP interface allows execution of lua scripts sent over PTP. In general, any scripting function available to normal CHDK scripts can be executed remotely. See [[CHDK Scripting Cross Reference Page]] for a list of CHDK script functions. There are some additional functions specific to PTP, described in [[Lua/PTP Scripting]].
   
 
Some of the features available using Lua scripts include
 
Some of the features available using Lua scripts include
Line 27: Line 27:
   
 
===Remote display===
 
===Remote display===
In CHDK 1.1 support has been added for streaming the contents of the camera LCD display over PTP. (revision 1921 and later)
+
CHDK 1.1 add support streaming the contents of the camera LCD display over PTP. (revision 1921 and later)
  +
  +
===Remote shooting===
  +
CHDK 1.2 added support for saving images directly over USB, without saving on the SD card. This is supported for raw and DNG on all cameras, and for jpeg on some cameras. For raw and DNGs capturing a subset of rows from the raw framebuffer is also supported.
   
 
===Debugging features===
 
===Debugging features===
Line 36: Line 36:
 
All the client applications below require [http://sourceforge.net/apps/trac/libusb-win32/wiki libusb-win32] driver on Windows:
 
All the client applications below require [http://sourceforge.net/apps/trac/libusb-win32/wiki libusb-win32] driver on Windows:
 
* It is available for Windows 2000, Windows XP 32 Bit, Windows Vista 32/64 Bit, Windows 7 32/64 Bit.
 
* It is available for Windows 2000, Windows XP 32 Bit, Windows Vista 32/64 Bit, Windows 7 32/64 Bit.
* It must be installed as a Device Driver, NOT a Filter Driver.
+
* Windows 8 users should read the following guide: [http://www.craftedge.com/tutorials/driver_install_windows8/driver_install_win8.html How to install an unsigned driver on Windows 8]
* It will break your ability to download photos through Windows built-in Wizard, but don't worry you can do it through PTP instead using one of the client applications below.
+
* A [http://chdk.setepontos.com/index.php?topic=6231.msg106526#msg106526 useful note] for Windows 8.1 users, refers to [http://zadig.akeo.ie/ this] site.
  +
* It should be installed as an INF Driver, NOT a Filter Driver.
  +
* It will most likely break your ability to download photos through Windows built-in Wizard, but you can still download files using the client applications below.
   
 
To install libusb-win32 on Windows:
 
To install libusb-win32 on Windows:
Line 50: Line 50:
 
* It should appear in Device Manager as libusb-win32 devices > Canon Digital Camera
 
* It should appear in Device Manager as libusb-win32 devices > Canon Digital Camera
 
* No PC reboot is needed
 
* No PC reboot is needed
  +
  +
'''NOTES'''
  +
* The installed INF driver is specific to the selected model. If you use more than one camera model with CHDK PTP clients, you may need to install an INF driver for each one.
  +
* Depending on the camera, the INF driver installation may be specific to the particular physical USB port. In this case, plugging the camera into a different port will allow you to access the camera using normal windows software. This probably applies to older cameras (vxworks?)
  +
* You may be able to get the filter driver to work on some OSes (XP) but the INF driver is strongly recommended.
   
 
== Client applications ==
 
== Client applications ==
Line 55: Line 60:
   
 
===ptpcam===
 
===ptpcam===
: If you are new to ptpcam check out ptpcamgui below. More advanced users may wish to use ptpcam.
+
'''Download''':
  +
: 1) download and install libusb (see install instructions above)
  +
: 2) go [http://forum.chdk-treff.de/viewtopic.php?f=7&t=2122 here] (German CHDK forum topic on the development of ptpcam with CHDK extensions)
  +
: 3) download ptpcam_Vx.x.zip at the end of the first message.
   
: '''Download''':
+
The version of ptpcam available in the forum link has CHDK extensions added to communicate to the CHDK code on your camera. This is a derivative of the official ptpcam available at http://libptp.sourceforge.net/ (the CHDK extensions are not included in the official version of ptpcam).
::: 1) download and install libusb (see install instructions above)
 
::: 2) go [http://forum.chdk-treff.de/viewtopic.php?f=7&t=2122 here] (German CHDK forum topic on the development of ptpcam with CHDK extensions)
 
::: 3) download ptpcam_Vx.x.zip at the end of the first message.
 
   
: Note that [http://en.wikipedia.org/wiki/Picture_Transfer_Protocol PTP] is simply a protocol for communicating with your camera and is available on many cameras not just Canon. The version of ptpcam available in the forum link has CHDK extensions added to communicate to the CHDK code on your camera. This is a derivative of the opensource ptpcam available at http://libptp.sourceforge.net/ (this source code doesn't include CHDK extensions, also note: no compiled executable is available at the sourceforge link).
+
If you are comfortable writing batch scripts (or perl/python/... scripts) for your PC, ptpcam can be used to download jpg files and upload lua scripts and execute CHDK lua scripts on your camera all while your camera is carefully lined up on your subject and mounted to a tripod (when, for most Canon cameras, removing the memory card is not possible).
   
: If you are comfortable writing batch scripts (or perl/python/... scripts) for your PC, ptpcam can be used to download jpg files and upload lua scripts and execute CHDK lua scripts on your camera all while your camera is carefully lined up on your subject and mounted to a tripod (when, for most Canon cameras, removing the memory card is not possible).
+
Keep in mind the fact that commands sent to your camera via ptpcam will take more time to complete than it takes for ptpcam to return control to your script. So make sure that after you issue a'' ptpcam --chdk="blah blah"'' command, that you have inserted a delay in your (batch file, perl, ...) script running on your PC to give the camera time to finish its business before you go poking the camera again.
   
: Keep in mind the fact that commands sent to your camera via ptpcam will take more time to complete than it takes for ptpcam to return control to your script. So make sure that after you issue a'' ptpcam --chdk="blah blah"'' command, that you have inserted a delay in your (batch file, perl, ...) script running on your PC to give the camera time to finish its business before you go poking the camera again.
+
See [[PTP Extension/ptpcam Examples]] for some examples.
   
: To give yourself access to the same functionality as ptpcamgui create the file A/CHDK/LUALIB/lptpgui.lua with the text from below. This is a copy of what ptpcamgui copies to your SD card to enable many of its functions. If you want the latest version, you will find this on your memory card after using ptpcamgui to download files from your camera.
+
A version of ptpcam is maintained in the [http://tools.assembla.com/chdkde/browser/trunk/tools/ptpcam chdkde source tree], with builds available from the [http://forum.chdk-treff.de/viewtopic.php?f=7&t=2122 chdkde forum] (download ptpcam_Vx.x.zip). The ptpcam executable may be built for Windows or Linux.
   
<code>-- lptpgui.lua -- store this file in CHDK/LUALIB
+
===ptpCamGui===
+
[[ptpCamGui]] is a graphical front end for ptpcam. Builds are available from the [http://forum.chdk-treff.de/viewtopic.php?f=7&t=2207 chdkde forum] It's also part of [[CHDK Shell]].
lptpgui = {}
 
 
lptpgui.version=120
 
 
-- begin -- DCIM Download --
 
local function getfileson(path,hfile)
 
local fd,c,s,fpath,stat,i,tc,ts=os.listdir(path),0,0
 
if fd~=nil and #fd>0 then
 
for i=1, #fd do
 
fpath=path .. "/" .. fd[i]
 
stat=os.stat(fpath)
 
if stat~=nil then
 
if stat.is_dir==true then
 
if fd[i]~="CANONMSC" then
 
tc,ts=getfileson(fpath,hfile)
 
c=c+tc
 
s=s+ts
 
end
 
elseif stat.is_file==true then
 
hfile:write(path .. "/" .. "|" .. fd[i] .. "|" .. os.date("%Y%m%d%H%M%S", stat.mtime) .. "\n")
 
s=s+(stat.size-1)/4096+1
 
c=c+1
 
end
 
end
 
end
 
end
 
return c,s
 
end
 
 
local function getdcimfiles()
 
local fn,count,size,tc,ts="A/ptpgui.txt",0,0
 
local file=io.open(fn,"wb")
 
if file then
 
tc,ts=getfileson("A/DCIM",file)
 
count=count+tc
 
size=size+ts
 
file:close()
 
end
 
if count>0 then size=(size-1)/256+1 else size=0 end
 
return count .. "\n" .. fn .. "\n" .. size
 
end
 
 
function lptpgui.dcimdl()
 
return getdcimfiles()
 
end
 
-- end -- DCIM Download --
 
 
-- begin -- GetCamMode --
 
function lptpgui.getcammode()
 
modemap=require("GEN/modelist")
 
capmode=require("capmode")
 
mode=""
 
for i=1, #modemap do
 
if capmode.valid(modemap[i]) then mode=mode..modemap[i].."|" end
 
end
 
return mode
 
end
 
-- end -- GetCamMode --
 
 
-- begin -- GetCamInfo --
 
function lptpgui.getcaminfo()
 
info=""
 
info=info..get_vbatt().."|"..get_config_value(8).."|"..get_config_value(9).."|"..get_free_disk_space()
 
return info
 
end
 
-- end -- GetCamInfo --
 
 
-- begin -- ExecLuaString --
 
local function init_defaultvars(tvars)
 
if type(tvars)=="table" then
 
for var,val in pairs(tvars) do rawset(_G,var,val) end
 
end
 
end
 
local function gui_print(...)
 
local str=""
 
for i=1,select("#",...) do
 
if str~="" then str=str.." " end
 
str=str..tostring(select(i,...))
 
end
 
write_usb_msg(str)
 
cam_print(...)
 
end
 
function lptpgui.exec_luastring(script,tvars)
 
init_defaultvars(tvars)
 
script=string.gsub(script,"\002","\n")
 
script=string.gsub(script,"\003","]]")
 
cam_print=print
 
print=gui_print
 
func,merr=loadstring(script)
 
if func==nil then
 
print(merr)
 
else
 
func()
 
end
 
end
 
-- end -- ExecLuaString --
 
 
-- begin -- ExecLuaFile --
 
function lptpgui.exec_luafile(filename,tvars)
 
init_defaultvars(tvars)
 
cam_print=print
 
print=gui_print
 
func,merr=loadfile(filename)
 
if func==nil then
 
print(merr)
 
else
 
func()
 
end
 
end
 
-- end -- ExecLuaFile --
 
 
return lptpgui
 
 
</code>
 
   
:Note the redefine of print before your script runs in the ''exec_luafile'' code above. This allows your print commands to also be seen by your (batch file, perl,...) script running on the PC. The output can be fetched using the ''ptpcam --chdk="getm"'' command (see perl script below for an example). This print output stays in memory on your camera until you perform a ''getm'' so if you don't plan on reading the messages using ''getm'' you may want to add ''if cam_print==nil then cam_print=print end'' and use ''cam_print'' in your scripts instead to avoid a possible memory over-use issue.
+
A forum thread including descriptions can you find [http://chdk.setepontos.com/index.php?topic=6285.0 here].
   
:The following is the help given from the command line of ptpcam and ptpcam --chdk, '''followed by some examples''' showing some common tasks you will likely want to do.
+
The source code for the frontend and the DLL is available on the [https://www.assembla.com/spaces/rudi_space/trac_subversion_tool ptpCamGui assembla project].
<code>
 
C:\ptpcam_V2.0>ptpcam -h
 
USAGE: ptpcam [OPTION]
 
 
Options:
 
--bus=BUS-NUMBER USB bus number
 
--dev=DEV-NUMBER USB assigned device number
 
-r, --reset Reset the device
 
-l, --list-devices List all PTP devices
 
-i, --info Show device info
 
-o, --list-operations List supported operations
 
-p, --list-properties List all PTP device properties
 
(e.g. focus mode, focus distance, etc.)
 
-s, --show-property=NUMBER Display property details (or set its value,
 
if used in conjunction with --val)
 
--set-property=NUMBER Set property value (--val required)
 
--set=PROP-NAME Set property by name (abbreviations allowed)
 
--val=VALUE Property value (numeric for --set-property and
 
string or numeric for --set)
 
--show-all-properties Show all properties values
 
--show-unknown-properties Show unknown properties values
 
-L, --list-files List all files
 
-g, --get-file=HANDLE Get file by given handler
 
-G, --get-all-files Get all files
 
--overwrite Force file overwrite while savingto disk
 
-d, --delete-object=HANDLE Delete object (file) by given handle
 
-D, --delete-all-files Delete all files form camera
 
-c, --capture Initiate capture
 
--nikon-ic, --nic Initiate Nikon Direct Capture (no download!)
 
--nikon-dc, --ndc Initiate Nikon Direct Capture and download
 
--loop-capture=N Perform N times capture/get/delete
 
-f, --force Talk to non PTP devices
 
-v, --verbose Be verbose (print more debug)
 
-h, --help Print this help message
 
--chdk[=command] CHDK mode. Interactive shell unless optional
 
command is given. Run interactive shell and
 
press 'h' for a list of commands.
 
 
C:\ptpcam_V2.0>
 
 
C:\ptpcam_V2.0>ptpcam --chdk
 
<conn> h
 
q quit quit program
 
h help list commands
 
r reset reconnect to camera
 
version get CHDK PTP version (ptpcam and camera)
 
shutdown shutdown camera (soft)
 
reboot reboot camera
 
reboot <filename> reboot camera using specified firmware update
 
reboot-fi2 reboot camera using default firmware update
 
m memory <address> get byte at address
 
m memory <address>-<address> get bytes at given range
 
m memory <address> <num> get num bytes at given address
 
set <address> <long> set long value at address
 
c call <address> <arg1> ... call function at address with given arguments
 
upload <local> <remote> upload local file to camera
 
download <remote> <local> download file from camera
 
mode <val> set mode (0=playback,1=record)
 
lua <code> execute lua code
 
luar <code> execute "return <code>" and retreive result
 
script-support show supported script interfaces
 
script-status show script execution and message status
 
getm get messages / return values from script
 
putm <message> send <message> to running script
 
 
<conn> #======================= '''EXAMPLES''' ===========================
 
<conn>
 
<conn> #----- generate the file list -------------------------------
 
<conn> #the following will call CHDK/LUALIB/lptpgui.lua and will
 
<conn> #create a file called A/ptpgui.txt on your SD card that contains
 
<conn> #a complete list of jpg files on your camera including path names
 
<conn> #and date and time of creation (change false to true if you have gps)
 
<conn> luar require("lptpgui").dcimdl(false)
 
script:1
 
1:ret:'420
 
A/ptpgui.txt
 
712'
 
<conn>
 
<conn> #----- download the file list, download a file --------------
 
<conn> #download the file list generated above
 
<conn> download A/ptpgui.txt fileList.txt
 
<conn> #now that you have complete path info you can easily download
 
<conn> #only the image you require
 
<conn> download A/DCIM/101___07/IMG_0419.JPG img.jpg
 
<conn>
 
<conn> #----- upload your CHDK LUA script --------------------------
 
<conn> #after you tweak your script, you can upload it to your camera
 
<conn> upload myRevisedScript.lua A/CHDK/SCRIPTS/myRevisedScript.lua
 
<conn>
 
<conn> #----- run your CHDK LUA script on your camera --------------
 
<conn> #put your camera into record mode
 
<conn> mode 1
 
<conn> #then run your scipt with params 0,1,2,3
 
<conn> lua require('lptpgui').exec_luafile(<nowiki>[[</nowiki>A/CHDK/SCRIPTs/myRevisedScript.lua<nowiki>]]</nowiki>,{0,1,2,3})
 
</code>
 
   
:The following (activestate 5.10) perl script will download the last N files from your camera.
+
ptpCamGui is only available for Windows.
   
<code> <nowiki>
+
English translation of instructions for using can be found [http://chdk.setepontos.com/index.php?topic=6285.msg64905#msg64905 here]. Note that despite coming from a German site, both English and German languages are supported in the same .exe and are set automatically (based on your Windows installation language setting).
#!perl
 
#---------------------------------------------------------------------------
 
# Fetches last N files (based on date/time of pic) from camera. (montana123)
 
#---------------------------------------------------------------------------
 
my $numFilesToGet=5;
 
#---------------------------------------------------------------------------
 
   
printf("\n Fetching file list. \n");
+
First time users note that the big red camera icon is used both to enter camera mode and to shoot (when radio buttons to right select "Photo").
my @fileListResponse = `ptpcam --chdk="luar require('lptpgui').dcimdl(false)"`;
 
sleep 2;
 
my @downLoadResponse = `ptpcam --chdk="download A/ptpgui.txt fileList.txt"`;
 
sleep 2;
 
   
printf("\n Fetching last $numFilesToGet files.\n");
+
==chdkptp==
open FH, "<fileList.txt" or die $!; my @fileList=<FH>; close FH;
+
chdkptp is a client created specifically for controlling CHDK cameras. It provides CLI and optional GUI based on [http://www.tecgraf.puc-rio.br/iup/ IUP].
my $lastFile = $#fileList;
 
my $firstFile = $lastFile-($numFilesToGet-1);
 
   
for ($i=$firstFile;$i<=$lastFile;$i++) {
+
chdkptp also provides a Lua API for the CHDK protocol on the PC. Because the GUI and CLI are also implemented in Lua, this makes chdkptp easy to extend and enables end users to implement complex interactions with code on the camera.
($path,$name,$datetime,$junk)=split(/\|/,$fileList[$i]);
 
#printf("$path-$name-$datetime-$junk\n");
 
$result=`ptpcam --chdk="download $path$name $name"`;
 
printf (" > $path - $name result= $result\n");
 
sleep 2;
 
}
 
   
printf("\n --\nAll done.\nHit ENTER to quit."); $response=<stdin>; exit (0);
+
CHDK 1.1 remote display and CHDK 1.2 remote capture are supported.
</nowiki> </code>
 
   
  +
Source and builds are available on the [http://www.assembla.com/wiki/show/chdkptp chdkptp assembla project]. A [http://chdk.setepontos.com/index.php?topic=6231.0 thread] in the chdk forum is available for support and discussion.
   
:The following (activestate 5.10) perl script will (optionally) upload your CHDK LUA script to your camera and (optionally) run it.
+
Build instructions are available in [http://trac.assembla.com/chdkptp/browser/trunk/README.TXT README.TXT] in the source. Usage information is available in [http://trac.assembla.com/chdkptp/browser/trunk/USAGE.TXT USAGE.TXT]
   
<code> <nowiki>
+
chdkptp is currently considered pre-alpha because functionality and APIs are subject to change. However, the snapshot builds are generally stable and suitable for everyday use.
#!perl
 
#---------------------------------------------------------------------------
 
# Optionally upload/run script to/on camera (montana123)
 
#---------------------------------------------------------------------------
 
my $myScript="myRevisedScript.lua";
 
my $upload=0;
 
my $run=1;
 
#---------------------------------------------------------------------------
 
   
if ($upload) {
+
The chdkptp code is based on the CHDK fork of ptpcam, but it does not use the same commands or command line options.
printf("\n Uploading $myScript script to camera. \n");
 
my @upLoadResponse = `ptpcam --chdk="upload $myScript A/CHDK/SCRIPTS/$myScript"`;
 
}
 
   
if ($run) {
+
==Platforms==
if ($upload) { sleep 3; }
 
$scriptMessage = `ptpcam --chdk="getm"`; #discard existing messages
 
sleep 1;
 
printf("\n Running $myScript script on camera.\n");
 
my $modeResponse = `ptpcam --chdk="mode 1"`;
 
sleep 3;
 
my $scriptResponse = `ptpcam --chdk="lua require('lptpgui').exec_luafile([[A/CHDK/SCRIPTS/$myScript]])"`;
 
printf(" > launch response= $scriptResponse\n");
 
my $wait=100;
 
while ($wait) {
 
sleep 3;
 
$scriptStatus = `ptpcam --chdk="script-status"`;
 
($junk,$run,$msg)=split(/\s+/,$scriptStatus);
 
printf(" > status: $run - $msg\n");
 
$wait--; if ($run =~ /no/) {$wait=0;}
 
}
 
if ($msg =~ /yes/) {
 
sleep 1;
 
$scriptMessage = `ptpcam --chdk="getm"`;
 
printf("\n Output From Script PRINT command(s):\n\n$scriptMessage\n --\n");
 
}
 
sleep 1;
 
my $modeResponse = `ptpcam --chdk="mode 0"`;
 
}
 
   
printf("\n All done.\n Hit ENTER to quit."); $response=<stdin>; exit(0);
+
chdkptp is compatible with MS Windows, OSX and Linux on x86
</nowiki> </code>
+
===Additional Platforms===
   
:The source code as well as the original proposal consist of both a patch for the SVN trunk and a patch for the <tt>ptpcam</tt> program. The latter adds the option <tt>--chdk</tt> which starts an interactive prompt to communicate with the connected camera. A version of ptpcam is maintained in the [http://tools.assembla.com/chdkde/browser/trunk/tools/ptpcam chdkde source tree], with builds available from the [http://forum.chdk-treff.de/viewtopic.php?f=7&t=2122 chdkde forum] (download ptpcam_Vx.x.zip). The ptpcam executable may be built for Windows or Linux.
+
In addition standard desktop environments, chdkptp builds are also available for the [http://www.raspberrypi.org/ raspberry pi] SBC.
:
+
====Work is also on its way to get as least the CHDKPTP CLI running on an ODroid XU board and a BeagleBone Black====
  +
Helping out to make that a reality is apprcated, more inf on
   
===ptpCamGui===
+
*[[Getting_CHDKPTP_on_oDroidXU_to_work|CHDKPTP on oDroidXU]]
: ptpCamGui is a graphical front end for ptpcam. Builds are available from the [http://forum.chdk-treff.de/viewtopic.php?f=7&t=2207 chdkde forum] It's also part of [[CHDK Shell]].
+
and
+
*[[Getting_CHDKPTP_on_BeagleBone_Black_to_work|CHDKPTP on BeagleBone Black]]
: A forum thread including descriptions can you find [http://chdk.setepontos.com/index.php?topic=6285.0 here].
 
 
: The source code for the frontend and the DLL is available on the [https://www.assembla.com/spaces/rudi_space/trac_subversion_tool ptpCamGui assembla project].
 
 
: ptpCamGui is only available for Windows.
 
 
: English translation of instructions for using can be found [http://chdk.setepontos.com/index.php?topic=6285.msg64905#msg64905 here]. Note that despite coming from a German site, both English and German languages are supported in the same .exe and are set automatically (based on your Windows installation language setting).
 
 
: First time users note that the big red camera icon is used both to enter camera mode and to shoot (when radio buttons to right select "Photo").
 
 
===chdkptp===
 
 
: An under development client. Considered pre-alpha because functionality and APIs are subject to change. However, the snapshot builds are usable for most common operations.
 
 
: CHDK 1.1 remote display is supported.
 
 
: >Source and builds can be found on the [http://www.assembla.com/wiki/show/chdkptp chdkptp assembla project]. A [http://chdk.setepontos.com/index.php?topic=6231.0 thread] in the chdk forum is available for discussion.
 
 
: chdkptp provides a lua API to the CHDK protocol on the PC. A CLI and optional GUI based on [http://www.tecgraf.puc-rio.br/iup/ IUP] are implemented in Lua. This allows easy customization, and enables end users to quickly implement complex interactions with code on the camera.
 
 
: chdkptp is compatible with windows and linux.
 
 
===<code>chdkcam (historical)</code>===
 
: <code><tt>CHDKCAM</tt> is a Windows program that provides a graphical interface to the camera and also allows live streaming of the camera's screen. The <tt>CHDKCAM</tt> binaries should also be compatible with the adapted <tt>ptpcam</tt> from the original source. </code>
 
   
: <code>CHDKCAM is only compatible with early development versions of the protocol, it is not compatible with the current CHDK or CHDKDE builds.</code>
+
====Arch Linux====
  +
chdkptp package is available from [https://aur.archlinux.org/ AUR], see [https://aur.archlinux.org/packages/chdkptp-svn/ package page].
   
 
== Usage notes ==
 
== Usage notes ==
Line 112: Line 118:
 
=== Windows ===
 
=== Windows ===
   
In order to get <tt>CHDKCAM</tt> or <tt>ptpcam</tt> to work properly you might need to disable the "Canon Camera Access Library" service (or, if that doesn't work, the "WIA" service).
+
In order to get CHDK clients to work properly you might need to disable the "Canon Camera Access Library" service (or, if that doesn't work, the "WIA" service).
   
 
=== Linux ===
 
=== Linux ===
   
Make sure you've got access to USB; in some cases this means switching to root (or changing permissions).
+
Make sure you've got access to USB; in some cases this means switching to root (or changing permissions). Some information can be found in this post: http://chdk.setepontos.com/index.php?topic=6231.msg89252#msg89252
   
== Development details ==
+
If your distro's default configuration accesses the camera on connect, this may put the camera in a state where some functionality (such as switching to shooting mode) is not available, or prevent CHDK clients from accessing the camera.
 
''Also see the [http://www.mweerden.net/chdk_ptp.html original documentation] and the [http://chdk.setepontos.com/index.php/topic,4338.0.html forum thread].''
 
   
 
== FAQ ==
 
== FAQ ==
Line 129: Line 135:
 
:* On many DryOS cameras, post_levent_to_ui(4484) will also unlock the keys.
 
:* On many DryOS cameras, post_levent_to_ui(4484) will also unlock the keys.
   
  +
== Development history ==
  +
The original PTP Extension was contributed by mweerden. At [http://github.com/mweerden/CHDK/tree/ptp mweerden's github] one can find the original sources as well as a follow-up attempt at a minimal version for inclusion in the SVN trunk. The proposal version, with some minor modifications, has been included in CHDK trunk since [http://tools.assembla.com/chdk/changeset/957 changeset 957].
  +
ewavr made additional contributions, including the first "live view" functionality and GUI client. You can find files related to this work on [http://ewavr.nm.ru/chdk/for_test/ ewavr's site].
   
=== Adding support for another camera/firmware version (historical) ===
+
The full history can be found in the [http://chdk.setepontos.com/index.php?topic=4338.0 PTP development thread] on the forum.
'''note''' the following is for historical reference only. PTP is implemented in all complete CHDK ports now.
 
As with CHDK itself it is usually a good idea to base your efforts on the sources of a similar camera. The essential steps to get any CHDK PTP support are as follows.
 
 
* Find the add_ptp_handler function for your firmware.
 
* Make sure init_chdk_ptp is started as a task.
 
 
This should enable you to connect with <tt>ptpcam --chdk</tt> and download/upload files, read/write memory and execute remote functions as well as Lua code.
 
 
Next you probably want to find a way to switch the camera to record mode (and back to playback mode). How to do this depends on the camera, so you probably need to check your reference source for this.
 
 
Finally you might want to add specific functions like those needed for <tt>CHDKCAM</tt>.
 
 
== Functionality Comparison (historical) ==
 
 
The various variants (original source, <tt>CHDKCAM</tt>, [http://chdk.setepontos.com/index.php/topic,4338.msg48083.html#msg48083 proposal for addition to trunk]) of the CHDK PTP extension support the following functionality.
 
 
{| cellspacing="5"
 
!
 
!current trunk
 
!original
 
!<tt>CHDKCAM</tt>
 
!proposal
 
|-
 
| file upload/download || x || x || x || x
 
|-
 
| memory read/write || x|| x || x ||x
 
|-
 
| remote function calls || x || x || x || x
 
|-
 
| mode switching || L || x || x ||
 
|-
 
| Lua code execution || x || x || x || x
 
|-
 
| retrieval of props and params || L || x || x ||
 
|-
 
| camera shutdown/reboot || L || x || ||
 
|-
 
| directory reading || L || || x ||
 
|-
 
| script output retrieval || L<sup>1</sup> || || x ||
 
|-
 
| video settings || || || x ||
 
|-
 
| versioning || x || || || x
 
|}
 
 
L=functionality available using Lua
 
 
<sup>1</sup> script error messages are returned and scripts can send arbitrary data, but console output is not returned.
 
 
Note that the proposal has much less extensions as the idea is to keep CHDK PTP as small as possible and provide the rest of the functionality (e.g. mode switching, shutdown/reboot) via scripting.
 
 
== Availability (historical versions) ==
 
The proposal version, with some minor modifications, has been included in CHDK trunk since [http://tools.assembla.com/chdk/changeset/957 changeset 957]
 
 
At [http://github.com/mweerden/CHDK/tree/ptp mweerden's github] one can find the original sources as well as a follow-up attempt at a minimal version for inclusion in the SVN trunk. At [http://ewavr.nm.ru/chdk/for_test/ ewavr's site] you can find his <tt>CHDKCAM</tt> program and binaries for various firmwares.
 
 
Below is an overview of the currently supported firmwares. Here "cc" means there is a <tt>CHDKCAM</tt> version, "mg" it's supported in mweerden's code, "(b)" that there is a binary, "(s)" that it's in the source and "(p)" that there is a patch.
 
{| cellspacing="5"
 
| A480 || 1.00b || cc (b)
 
|-
 
| A540 || 1.00b || [http://chdk.setepontos.com/index.php/topic,4338.msg44963.html#msg44963 cc (p)]
 
|-
 
| A570 || 1.00e || [http://chdk.setepontos.com/index.php/topic,4338.msg54270.html#msg54270 mg (bp)]
 
|-
 
| || 1.01a || [http://chdk.setepontos.com/index.php/topic,4338.msg54270.html#msg54270 mg (bp)]
 
|-
 
| A590 || 1.00e || cc (b)
 
|-
 
| || 1.01b || cc (b)
 
|-
 
| A610 || 1.00d || cc (b)
 
|-
 
| || 1.00e || cc (b)
 
|-
 
| || 1.00f || cc (b)
 
|-
 
| A650 || 1.00d || [http://chdk.setepontos.com/index.php/topic,4338.msg48534.html#msg48534 SVN (p)]
 
|-
 
| A710 || 1.00a || cc (b)
 
|-
 
| A720 || 1.00c || cc (b)
 
|-
 
| G11 || 1.00j || [http://chdk.setepontos.com/index.php/topic,4338.msg54620.html#msg54620 stubs]
 
|-
 
| IXUS700IS/SD500 || 1.01a || cc (b)
 
|-
 
| IXUS870IS/SD880 || 1.01a || mg (s)
 
|-
 
| SX1 || 2.01a || cc (b)
 
|-
 
| SX10 || 1.01a || cc (b)
 
|-
 
| || 1.02b || cc (b)
 
|-
 
| SX200IS || 1.00c || cc (b)
 
|}
 
 
[[Category:Development]]
 
[[Category:Development]]
 
[[Category:PTP Extension]]
 
[[Category:PTP Extension]]

Latest revision as of 14:27, July 12, 2014

The Picture Transfer Protocol (PTP) facilitates remote operations on a camera connected computer. Typical operations are uploading/downloading photos and remote captures.

Most cameras support some basic operations over PTP, but often only in a limited fashion. For example, downloading of files can be limited to just JPEG files.

The PTP extension for CHDK discussed in this article does not alter the standard operations but adds new CHDK-specific operations instead. This is due to the complexity involved in altering or complete overwriting the standard operations. It also means that special tools are required to access this new functionality.

If you want simple control over the camera without USB a protocol connection (for example, using a micro-controller or RC equipment) see USB Remote.

The CHDK extension was first added to the CHDK trunk in changeset 957, and has been enabled for all cameras since changeset 1116

Related forum thread: [1]

Functionality Edit

An overview of the functionality available through the PTP interface is described below. The specific functionality and usage depends on which client application you use. The canonical reference to the CHDK PTP protocol is core/ptp.h in the CHDK source tree.

File transferEdit

Files can be uploaded to and downloaded from any part of the file system.

Script executionEdit

The PTP interface allows execution of lua scripts sent over PTP. In general, any scripting function available to normal CHDK scripts can be executed remotely. See CHDK Scripting Cross Reference Page for a list of CHDK script functions. There are some additional functions specific to PTP, described in Lua/PTP Scripting.

Some of the features available using Lua scripts include

  • Switch to and from record mode
  • Switch recording modes, e.g. Av, Tv, Video
  • Adjust exposure parameters, focus, zoom etc.
  • Shoot pictures or video
  • Manipulate Canon menus and settings with simulated key presses
  • List, create and delete files and directories
  • Return values from script, send and receive arbitrary messages between the camera and PC
  • Shutdown or reboot the camera

Remote displayEdit

CHDK 1.1 add support streaming the contents of the camera LCD display over PTP. (revision 1921 and later)

Remote shootingEdit

CHDK 1.2 added support for saving images directly over USB, without saving on the SD card. This is supported for raw and DNG on all cameras, and for jpeg on some cameras. For raw and DNGs capturing a subset of rows from the raw framebuffer is also supported.

Debugging featuresEdit

  • Read and write camera memory
  • call arbitrary camera functions

LibUSB Driver for Windows Edit

All the client applications below require libusb-win32 driver on Windows:

  • It is available for Windows 2000, Windows XP 32 Bit, Windows Vista 32/64 Bit, Windows 7 32/64 Bit.
  • Windows 8 users should read the following guide: How to install an unsigned driver on Windows 8
  • A useful note for Windows 8.1 users, refers to this site.
  • It should be installed as an INF Driver, NOT a Filter Driver.
  • It will most likely break your ability to download photos through Windows built-in Wizard, but you can still download files using the client applications below.

To install libusb-win32 on Windows:

  • Download the latest binary release from here
  • Extract archive
  • Connect camera via USB and turn on in Play mode
  • Let Windows install its built-in driver if not already installed
  • Run \bin\inf-wizard.exe from extracted archive
  • Select your camera from the list of attached USB devices
  • Hit Next and save the resulting INF file to a new folder
  • Hit Install Now...
  • It should appear in Device Manager as libusb-win32 devices > Canon Digital Camera
  • No PC reboot is needed

NOTES

  • The installed INF driver is specific to the selected model. If you use more than one camera model with CHDK PTP clients, you may need to install an INF driver for each one.
  • Depending on the camera, the INF driver installation may be specific to the particular physical USB port. In this case, plugging the camera into a different port will allow you to access the camera using normal windows software. This probably applies to older cameras (vxworks?)
  • You may be able to get the filter driver to work on some OSes (XP) but the INF driver is strongly recommended.

Client applications Edit

As described above, a client program compatible that implements the CHDK protocol is required to access these features

ptpcamEdit

Download:

1) download and install libusb (see install instructions above)
2) go here (German CHDK forum topic on the development of ptpcam with CHDK extensions)
3) download ptpcam_Vx.x.zip at the end of the first message.

The version of ptpcam available in the forum link has CHDK extensions added to communicate to the CHDK code on your camera. This is a derivative of the official ptpcam available at http://libptp.sourceforge.net/ (the CHDK extensions are not included in the official version of ptpcam).

If you are comfortable writing batch scripts (or perl/python/... scripts) for your PC, ptpcam can be used to download jpg files and upload lua scripts and execute CHDK lua scripts on your camera all while your camera is carefully lined up on your subject and mounted to a tripod (when, for most Canon cameras, removing the memory card is not possible).

Keep in mind the fact that commands sent to your camera via ptpcam will take more time to complete than it takes for ptpcam to return control to your script. So make sure that after you issue a ptpcam --chdk="blah blah" command, that you have inserted a delay in your (batch file, perl, ...) script running on your PC to give the camera time to finish its business before you go poking the camera again.

See PTP Extension/ptpcam Examples for some examples.

A version of ptpcam is maintained in the chdkde source tree, with builds available from the chdkde forum (download ptpcam_Vx.x.zip). The ptpcam executable may be built for Windows or Linux.

ptpCamGuiEdit

ptpCamGui is a graphical front end for ptpcam. Builds are available from the chdkde forum It's also part of CHDK Shell.

A forum thread including descriptions can you find here.

The source code for the frontend and the DLL is available on the ptpCamGui assembla project.

ptpCamGui is only available for Windows.

English translation of instructions for using can be found here. Note that despite coming from a German site, both English and German languages are supported in the same .exe and are set automatically (based on your Windows installation language setting).

First time users note that the big red camera icon is used both to enter camera mode and to shoot (when radio buttons to right select "Photo").

chdkptpEdit

chdkptp is a client created specifically for controlling CHDK cameras. It provides CLI and optional GUI based on IUP.

chdkptp also provides a Lua API for the CHDK protocol on the PC. Because the GUI and CLI are also implemented in Lua, this makes chdkptp easy to extend and enables end users to implement complex interactions with code on the camera.

CHDK 1.1 remote display and CHDK 1.2 remote capture are supported.

Source and builds are available on the chdkptp assembla project. A thread in the chdk forum is available for support and discussion.

Build instructions are available in README.TXT in the source. Usage information is available in USAGE.TXT

chdkptp is currently considered pre-alpha because functionality and APIs are subject to change. However, the snapshot builds are generally stable and suitable for everyday use.

The chdkptp code is based on the CHDK fork of ptpcam, but it does not use the same commands or command line options.

PlatformsEdit

chdkptp is compatible with MS Windows, OSX and Linux on x86

Additional PlatformsEdit

In addition standard desktop environments, chdkptp builds are also available for the raspberry pi SBC.

Work is also on its way to get as least the CHDKPTP CLI running on an ODroid XU board and a BeagleBone BlackEdit

Helping out to make that a reality is apprcated, more inf on

and

Arch LinuxEdit

chdkptp package is available from AUR, see package page.

Usage notes Edit

Windows Edit

In order to get CHDK clients to work properly you might need to disable the "Canon Camera Access Library" service (or, if that doesn't work, the "WIA" service).

Linux Edit

Make sure you've got access to USB; in some cases this means switching to root (or changing permissions). Some information can be found in this post: http://chdk.setepontos.com/index.php?topic=6231.msg89252#msg89252

If your distro's default configuration accesses the camera on connect, this may put the camera in a state where some functionality (such as switching to shooting mode) is not available, or prevent CHDK clients from accessing the camera.

FAQ Edit

  • Download/upload fails with code 0x2ff or the camera crashes when you try to transfer a file
Perhaps you didn't correctly specify the file on the camera. Always use the full path and start with a capitalised 'A'. For example: "download A/DCIM/100CANON/IMG_1234.jpg test.jpg"
note this mainly applies to ptpcam, chdkptp corrects the names for you.
  • The canon firmware does not recognize key presses (real or from script) when PTP is connected
There are two known workarounds:
  • Switch to record mode using switch_mode_usb script function. Keys will still be enabled if you switch back to play.
  • On many DryOS cameras, post_levent_to_ui(4484) will also unlock the keys.

Development history Edit

The original PTP Extension was contributed by mweerden. At mweerden's github one can find the original sources as well as a follow-up attempt at a minimal version for inclusion in the SVN trunk. The proposal version, with some minor modifications, has been included in CHDK trunk since changeset 957. ewavr made additional contributions, including the first "live view" functionality and GUI client. You can find files related to this work on ewavr's site.

The full history can be found in the PTP development thread on the forum.

Around Wikia's network

Random Wiki