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 void post_disconnect() { statuslabel.Text = "Not connected"; connected_device = null; connect_button.Visible = true; disconnectbutton.Visible = false; connected = scriptcontrol.Connected = picturecontrol.Connected = false; }
protected override void OnClosed(EventArgs e) { base.OnClosed(e); if (session != null) { session.Disconnect(); connected_device = null; connected = scriptcontrol.Connected = picturecontrol.Connected = false; } }
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; } }
public Session(CHDKPTPDevice dev) { _session = new CHDKPTPSession(dev); }