public PTPCommunication(PTPDevice dev) { _device = dev; reqres = new PTPReqRes(); reqres.data = new byte[484]; ptpdata = new PTPData(); ptpdata.data = new byte[500]; p_reqres = Marshal.AllocHGlobal(Marshal.SizeOf(reqres)); p_ptpdata = Marshal.AllocHGlobal(Marshal.SizeOf(ptpdata)); ResetAll(); }
public PTPCommunication(PTPDevice dev) { this.device = dev; this.reqres = new PTPReqRes(); this.reqres.data = new byte[484]; this.ptpdata = new PTPData(); this.ptpdata.data = new byte[500]; this.p_reqres = Marshal.AllocHGlobal(Marshal.SizeOf(this.reqres)); this.p_ptpdata = Marshal.AllocHGlobal(Marshal.SizeOf(this.ptpdata)); this.ResetAll(); }
private static CHDKPTPDevice CheckSupported(PTPDevice ptpdev) { var dev = ptpdev as CHDKPTPDevice; if (!dev.PTPSupported) { return dev; } try { if (!dev.Open()) { return dev; } var sess = new CHDKPTPSession(dev); sess.OpenSession(); if (sess.CHDK_Version(out dev.CHDKVersionMajor, out dev.CHDKVersionMinor)) { if (dev.CHDKVersionMajor == CHDK_VERSION_MAJOR && dev.CHDKVersionMinor >= CHDK_VERSION_MINOR) { CHDK_ScriptSupport flags; sess.CHDK_ScriptSupport(out flags); if (flags.HasFlag(CHDK_ScriptSupport.PTP_CHDK_SCRIPT_SUPPORT_LUA)) { dev.CHDKSupported = true; } } sess.CloseSession(); } } catch (PTPException) { // make sure CHDKSupported has not already been set dev.CHDKSupported = false; } finally { if (dev.IsOpen) { dev.Close(); } } return dev; }
public static List <PTPDevice> FindDevices(bool only_supported = true, Func <UsbDevice, PTPDevice> constr = null) { List <PTPDevice> l = new List <PTPDevice>(); if (constr == null) { constr = x => new PTPDevice(x); } foreach (UsbRegistry reg in UsbDevice.AllDevices) { UsbDevice dev; if (reg.Open(out dev)) { PTPDevice ptpdev = constr(dev); for (int i = 0; i < dev.Configs.Count; i++) { UsbConfigInfo config_info = dev.Configs[i]; foreach (UsbInterfaceInfo interface_info in config_info.InterfaceInfoList) { if (interface_info.Descriptor.Class == ClassCodeType.Ptp) { bool rid_set = false; bool wid_set = false; foreach (UsbEndpointInfo endpoint_info in interface_info.EndpointInfoList) { // BULK and assumed MaxPacketSize if ((endpoint_info.Descriptor.Attributes & 0x03) != 0x02 || endpoint_info.Descriptor.MaxPacketSize != 512) { continue; } if ((endpoint_info.Descriptor.EndpointID & 0x80) == 0) { ptpdev.WriterEndpointID = (WriteEndpointID)endpoint_info.Descriptor.EndpointID; wid_set = true; } else { ptpdev.ReaderEndpointID = (ReadEndpointID)endpoint_info.Descriptor.EndpointID; rid_set = true; } } if (rid_set && wid_set) { ptpdev.ConfigurationID = config_info.Descriptor.ConfigID; ptpdev.InterfaceID = interface_info.Descriptor.InterfaceID; ptpdev.PTPSupported = true; break; } } if (ptpdev.PTPSupported) { break; } } } if (!only_supported || ptpdev.PTPSupported) { l.Add(ptpdev); } dev.Close(); // always close so we don't have a list of open but unused devices } } return(l); }