private void connectbutton_Click(object sender, EventArgs e) { if (connected) { MessageBox.Show("Already opened a device!", "Error"); return; } if (devicecombobox.SelectedItem == null) { MessageBox.Show("No device selected!", "Error"); return; } connected_device = devicecombobox.SelectedItem as CHDKPTPDevice; LogLine("opening device: " + connected_device.Name); try { session = new Session(connected_device); session.Connect(); } catch (Exception ex) { LogLine("exception: " + ex.Message + Environment.NewLine + ex.StackTrace.ToString()); connected = false; connected_device = null; session = null; MessageBox.Show("could not open PTP session: " + ex.Message + "\n\n" + ex.StackTrace.ToString()); return; } LogLine("connected."); connected = true; statuslabel.Text = "Connected to: " + connected_device.ToString(); }
private static CHDKPTPDevice CheckSupported(PTPDevice ptpdev) { CHDKPTPDevice dev = ptpdev as CHDKPTPDevice; if (!dev.PTPSupported) { return(dev); } try { if (!dev.Open()) { return(dev); } CHDKPTPSession 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 Session(CHDKPTPDevice dev) { _session = new CHDKPTPSession(dev); }
public CHDKPTPSession(CHDKPTPDevice dev) : base(dev) { }
private void disconnectbutton_Click(object sender, EventArgs e) { if (connected) { LogLine("closing connection..."); try { session.Disconnect(); } catch (Exception ex) { LogLine("exception: " + ex.Message + Environment.NewLine + ex.StackTrace.ToString()); } LogLine("closed."); statuslabel.Text = "Not connected"; connected_device = null; connected = false; } }