/
Documentation.txt
166 lines (114 loc) · 5.83 KB
/
Documentation.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
Documentation for CHDKPTPRemote
April 29, 2011
CHDKPTPRemote is a .NET 4.0 library written in C# for working with cameras via
CHDK PTP[1,2]. It uses the LibUsbDotNet[3] library for USB communication.
At the moment of this writing the library requires a specially patched CHDK to
use the live-image functionality. This is also the reason it checks for an
"odd" CHDK PTP version (major 0x10002, minor 0).
Currently the library is build up as follows.
LibUsbDotNet -- PTP -- CHDKPTP -- CHDKPTPRemote
PTP uses LibUsbDotNet to provide a PTP interface for communicating with
devices. CHDKPTP extends PTP for support of CHDK PTP specific functionality.
Finally, CHDKPTPRemote provides a simple interface with the most basic
essential operations such as script execution and live image retrieval.
Except for LibUsbDotNet, the libraries use Exceptions when unexpected behaviour
is encountered. It is best to enclose all calls in try blocks and handle these
exceptions. Note that exceptions due to low-level problems (e.g. crashed
devices or conflicting implementations) might result in "broken" sessions.
Functions of CHDKPTPRemote.Session class
static List<CHDKPTPDevice> ListDevices(bool only_supported = true)
Returns a list of available devices. If only_supported is true, the list is
filtered such that only those devices remain that have a compatible CHDK PTP
implementation.
Session(CHDKPTPDevice dev)
Constructor for CHDKPTPRemote sessions. Does not actually initiate sessions.
void Connect()
Makes connection to camera. Must be successfully called before calling any
of the functions below.
void Disconnect()
Terminates connection to camera. After this call this function and the
following functions should no longer be called. Calling Connect again should
be fine.
object ExecuteScript(string script, bool return_string_as_byte_array = false)
Executes Lua script on camera. The functions waits until the script is done
and, if available, returns its return value. Currently supported return types
are booleans, integers and strings. String return values are interpreted as
ASCII; if not desired - because the string contains binary data, for example
- setting the return_string_as_byte_array parameter to true results in the
string being returned as is as a byte[] object.
void GetDisplayDimensions(out int width, out int height)
Sets width and height to the display dimensions of the camera. Note that
these dimensions need not correspond to the dimensions of the live images.
Typically the camera "stretches" the live image to the display dimensions
when displaying it. For example, a typical display width is 360, while live
images are often 720 pixels wide.
Bitmap GetLiveImage(Bitmap old_img = null)
Get the current live image as a Bitmap. The bitmap has uses
PixelFormat.Format24bppRgb. For efficiency one can supply a previously made
Bitmap as old_img. In this case old_img is used to copy the live image to
instead of making a new Bitmap object. Note that the supplied Bitmap should
be appropriate (w.r.t. PixelFormat and dimensions); ideally one only supplies
Bitmaps previously returned by GetLiveImage.
Bitmap GetLiveImage(out Rectangle active_area, Bitmap old_img = null)
Same as above, but also retrieves the "active area" of the live image. For
various aspect ratios the live image is typically surrounded by a black
border. The active_area indicates which part of the image contains the actual
contents.
Bitmap GetLiveOverlay(Bitmap old_img = null)
Same as GetLiveImage but for the camera's bitmap overlay. PixelFormat of
Bitmap should be Format32bppArgb.
byte[] DownloadFile(string filename)
Retrieves filename from the camera. Note that filename should contain a valid
path (i.e. one starting with "A/").
Other useful members
In determining which device to connect to one might want to use the following.
In CHDKPTP.CHDKPTPDevice:
int CHDKVersionMajor
Major version of the CHDK PTP of the camera.
int CHDKVersionMinor
Minor version of the CHDK PTP of the camera.
bool CHDKSupported
Indicates whether or the library supports this camera. N.B.: This is
determined in the call to ListDevices() that returned the device.
In CHDKPTP.CHDKPTPUtil:
static int CHDK_VERSION_MAJOR
Major version that this library supports. Can be changed in case one knows
a different version works as well.
static int CHDK_VERSION_MINOR
Minimal minor version that this library supports. Can be changed in case
one knows a different version works as well.
In PTP.PTPDevice:
bool PTPSupported
Indicates whether or not this device supports PTP.
string Name
Returns the name of the device (currently this is just the product name).
string ToString()
Returns a string identifying the device. This is just the Name plus, if
appropriate, the CHDK PTP version.
Examples
Basic usage:
using CHDKPTP
using CHDKPTPRemote
// we assume there is at least one connected and supported device
var session = new Session(Session.ListDevices()[0]);
session.Connect();
// do stuff
session.Disconnect();
Taking a picture:
session.ExecuteScript("switch_mode_usb(1)"); // switch to record mode
session.ExecuteScript("shoot()"); // take picture
Downloading image:
File.WriteAllBytes("IMG_0001.JPG",session.DownloadFile("A/DCIM/100CANON/IMG_0001.JPG"));
Draw live image:
int width,height;
session.GetDisplayDimensions(out width, out height);
Graphics g = ...;
g.DrawImage(session.GetLiveImage(),0,0,width,height);
References
1. Canon Hacker Development Kit (CHDK), http://chdk.wikia.com/
2. CHDK PTP forum thread, http://chdk.setepontos.com/index.php/topic,4338.0.html
3. LibUsbDotNet, http://libusbdotnet.sourceforge.net/
Copyright Muck van Weerdenburg 2011.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)