Controlling Properties using PTP/IP on Canon EOS Cameras
With the PTP/IP communication established as described in the last post, this article explains how to poll update events and start taking control of properties like ISO, shutter speed, and aperture.
Canon EOS PTP/IP Properties
Canon uses vendor-specific codes to reference properties. The following list shows the props I have come across so far, although there is much more to discover.
0xd101
: Aperture0xd102
: Shutter Speed0xd103
: ISO0xd10a
: White Balance0xd11c
: Capture Destination0xd1b0
: Live View Output
Polling Property Updates
Despite the PTP/IP specification including a dedicated event channel, Canon uses a custom GetEventData
operation to poll camera events.
From analyzing the communication between my Canon 70D and the EOS Utility app, I found that Canon issues the command five times a second to keep the UI in sync with the camera.
GetEventData Operation
The GetEventData
request is a PTP operation with a data phase to transmit the event data accumulated on the camera.
When asking the camera for event data for the first time, the camera responds with a massive response packet (e. g. the Canon 70D sends 11324 bytes
). Subsequent responses only contain events that have occurred since the last query.
To poll for event data, follow this sequence:
The host issues an operation request using operation code 0x9116.
Instead of a simple operation response, the camera answers with a Start Data Packet, which includes a property signalling the total number of bytes to be transmitted.
Afterwards, the camera sends an end data packet containing the event data payload. The following example shows a single Property Changed event after I adjusted the shutter speed to 1/125 of a second.
Each event data payload ends with a segment of eight bytes and an event code of zero. Without any updates, the event data consists only of this end marker.
Value Changed Event
With the event data polling mechanism established, we can now look at two essential event types. The first is the ValueChanged
event (0xc189), which informs the host that a property value has changed.
The following example shows the event data after I altered the ISO to ISO 400.
Allowed Values Changed Event
Whenever a property’s list of allowed values changes, the camera notifies the host using an AllowedValuesChanged
event (0xc18a). For example, when switching to a lens that supports different aperture values, the camera sends an event similar to the one below.
If you alter a setting on the camera that renders a property unsupported, the camera emits an AllowedValuesChanged
event with an empty list. For example, when changing the exposure mode from manual to aperture priority, the allowed values list for the shutter speed contains no entry.
Set Property Value
Canon EOS cameras provide a SetPropValue
(0x9110) operation for altering property values. This operation request consists of three packets since the host transmits the payload in the data phase.
Therefore, the packet sequence is similar to the GetEventData
operation, but the data phase direction is from host to camera this time.
Start the SetPropValue
operation by sending an operation request packet with the data flag set to 0x02
to indicate the host will proceed with a data packet.
Continue with a StartDataPacket
and set the totalDataLength
parameter to the total payload size in bytes.
Finish the operation with an EndDataPacket
containing the actual data payload. The example below shows how to change the shutter speed to 1/50th of a second.
When the SetPropValue
operation succeeds, the camera responds with an okay (0x2001) operation response.
Now that you know about the crucial property operations, you can start taking control of your Canon EOS camera.
Your best bet to reverse engineer property values is changing the property on the camera and analyzing the change events simultaneously. To give you a head start, I’d recommend looking at the value mappings I discovered while implementing the PTP/IP protocol for my CineRemote app.