2

I'm trying to make a PTP (Picture Transfer Protocol) library with a primary focus on mobile devices. The end goal is to create an app (with Xamarin or something similar) that works on Windows 10 (Phone), Android and iOS that uses PTP to communicate with cameras. The primary goals is to do PTP over IP (for wireless control and remote shooting), but while I'm at it I'd like to add support for PTP over USB so it's also possible to connect to an USB connected camera.

I've found mfptp which seems to do this, but it uses the .NET Micro Framework and a third party USB library. I doubt this is portable to a .NET Portable Class Library.

I've also found this question about a .NET MTP/PTP wrapper, but the links in that aren't that promising either. The most promising thing I've found so far is the WPD API but that seems pretty much focused to the Windows Desktop, and would require using COM to boot.

The real question is, is there some way to do this reliably in a cross-platform way? And if not, is there an alternative to the .NET WPD Wrapper on GitHub?

Community
  • 1
  • 1
Xudonax
  • 429
  • 4
  • 17
  • 2
    USB (and anything that involves hardware access) doesn't seem like something that could be easily implemented in a cross-platform manner. – Jason Jun 06 '15 at 16:35
  • @Jason I was expecting as much, to be honest :) – Xudonax Jun 06 '15 at 22:07

1 Answers1

0

I have been doing some investigation on PTP/IP using sockets. Once you connect to the camera as an access point you can send commands to the camera. PTP/IP follows the PTP commands and you have to follow an initialization procedure. You need two sockets, one for commands and another for events. I have been able to initialize the connection but not issue commands, the first one I was trying to do was the GetDeviceInfo. I found this link which helped get started.

http://www.cipa.jp/ptp-ip/documents_e/CIPA_DC-005_Whitepaper_ENG.pdf

This is how I sent the InitCMD using a socket in C#

// Length, 4  
// Type, 4  
// Initiator GUID, 16  
// Friendly Name, variable  
// Protocol Version, 4  
byte[] type = BitConverter.GetBytes(1);  
Guid g = Guid.NewGuid();  
byte[] guid = g.ToByteArray();  
byte[] host = Encoding.UTF8.GetBytes("HostName\0");  
byte[] version = BitConverter.GetBytes(1 << 16);  
int len = 4 + type.Length + guid.Length + host.Length + version.Length;  
byte[] length = BitConverter.GetBytes(len);  

byte[] data = length.Concat(type).Concat(guid).Concat(host).Concat(version).ToArray();  

s.Send(data);  

byte[] responseLen = new byte[4];  
int recvLen = s.Receive(responseLen, 4, SocketFlags.None);  
len = BitConverter.ToInt32(responseLen, 0) - 4;  

byte[] responseData = new byte[len];  
recvLen = s.Receive(responseData, len, SocketFlags.None);  
chris
  • 51
  • 8