Exploring the PTP/IP Protocol

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: Aperture
  • 0xd102: Shutter Speed
  • 0xd103: ISO
  • 0xd10a: White Balance
  • 0xd11c: Capture Destination
  • 0xd1b0: 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:

1
Issue Operation Request

The host issues an operation request using operation code 0x9116.

GetEventData Request
12
00
00
00
06
00
00
00
01
00
00
00
16
91
1f
00
00
00
Offset
Type
Description
0
Uint32
Length: 18 bytes
4
Uint32
Packet Type: Operation Request (0x06)
8
Uint32
Data Phase: No Data
12
Uint16
Operation: GetEventData (0x9116)
14
Uint32
Transaction Id: 31
2
Process Start Data Packet

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.

Start Data Packet
14
00
00
00
09
00
00
00
1f
00
00
00
18
00
00
00
00
00
00
00
Offset
Type
Description
0
Uint32
Length: 20 bytes
4
Uint32
Packet Type: Start Data Packet (0x09)
8
Uint32
Transaction Id: 31
12
Uint64
Total Data Length: 24 bytes
3
Process End Data Packet

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.

End Data Packet
24
00
00
00
0c
00
00
00
1f
00
00
00
10
00
00
00
89
c1
00
00
02
d1
00
00
70
00
00
00
08
00
00
00
00
00
00
00
Offset
Type
Description
0
Uint32
Length: 36 bytes
4
Uint32
Packet Type: End Data Packet (0x0c)
8
Uint32
Transaction Id: 31
12
Uint32
Event Length: 16 bytes
16
Uint32
Event Type: Property Changed (0xc189)
20
Uint32
Property Code: Shutter Speed (0xd102)
24
Uint32
Property Value: 1/125 s (0x70)
28
Uint32
Event Length: 8 bytes
32
Uint32
Event Type: End Marker

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.

ISO changed to 400
10
00
00
00
89
c1
00
00
03
d1
00
00
58
00
00
00
Offset
Type
Description
0
Uint32
Event Length: 16 bytes
4
Uint32
Event Type: Property Changed (0xc189)
8
Uint32
Property Code: ISO (0xd103)
12
Uint32
Property Value: ISO 400 (0x58)

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.

Allowed Aperture Values Changed
64
00
00
00
8a
c1
00
00
01
d1
00
00
03
00
00
00
14
00
00
00
15
00
00
00
18
00
00
00
1b
00
00
00
1d
00
00
00
20
00
00
00
23
00
00
00
25
00
00
00
28
00
00
00
2b
00
00
00
2d
00
00
00
30
00
00
00
33
00
00
00
35
00
00
00
38
00
00
00
3b
00
00
00
3d
00
00
00
40
00
00
00
43
00
00
00
45
00
00
00
48
00
00
00
Offset
Type
Description
0
Uint32
Event Length: 100 bytes
4
Uint32
Event Type: Allowed Values Changed (0xc18a)
8
Uint32
Property Code: Aperture (0xd101)
12
Uint32
Unknown Value
16
Uint32
Allowed Values Count: 20
20
Uint32[]
Allowed Values List: f1.8 (0x15), ..., f16 (0x48)

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.

1
Send Operation Request

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.

SetPropValue Operation
12
00
00
00
06
00
00
00
02
00
00
00
10
91
18
00
00
00
Offset
Type
Description
0
Uint32
Length: 18 bytes
4
Uint32
Packet Type: Operation Request (0x06)
8
Uint32
Data Phase: With Data
12
Uint16
Operation: SetPropValue (0x9110)
14
Uint32
Transaction Id: 24
2
Send Start Data Packet

Continue with a StartDataPacket and set the totalDataLength parameter to the total payload size in bytes.

Start Data Packet
14
00
00
00
09
00
00
00
18
00
00
00
0c
00
00
00
00
00
00
00
Offset
Type
Description
0
Uint32
Length: 20 bytes
4
Uint32
Packet Type: Start Data Packet (0x09)
8
Uint32
Transaction Id: 24
12
Uint64
Total Data Length: 12 bytes
3
Send End Data Packet

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.

End Data Packet
18
00
00
00
0c
00
00
00
18
00
00
00
0c
00
00
00
02
d1
00
00
65
00
00
00
Offset
Type
Description
0
Uint32
Length: 24 bytes
4
Uint32
Packet Type: End Data Packet (0x0c)
8
Uint32
Transaction Id: 24
12
Uint32
Payload Length: 12 bytes
16
Uint32
Property Code: Shutter Speed (0xd102)
20
Uint32
Property Value: 1/50s (0x65)

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.