private void BUT_connect_Click(object sender, EventArgs e) { if (threadrun) { threadrun = false; BUT_connect.Text = "Connect"; tracker.Close(); return; } if (tracker != null && tracker.ComPort != null && tracker.ComPort.IsOpen) { tracker.ComPort.Close(); } tracker = new ArdupilotMega.Antenna.Maestro(); try { tracker.ComPort = new SerialPort() { PortName = CMB_serialport.Text, BaudRate = int.Parse(CMB_baudrate.Text) }; } catch (Exception ex) { CustomMessageBox.Show("Bad Port settings " + ex.Message); return; } try { tracker.PanStartRange = int.Parse(TXT_panrange.Text) / 2 * -1; tracker.PanEndRange = int.Parse(TXT_panrange.Text) / 2; tracker.TrimPan = TRK_pantrim.Value; tracker.TiltStartRange = int.Parse(TXT_tiltrange.Text) / 2 * -1; tracker.TiltEndRange = int.Parse(TXT_tiltrange.Text) / 2; tracker.TrimTilt = TRK_tilttrim.Value; } catch (Exception ex) { CustomMessageBox.Show("Bad User input " + ex.Message); return; } if (tracker.Init()) { if (tracker.Setup()) { tracker.PanAndTilt(0, 0); t12 = new System.Threading.Thread(new System.Threading.ThreadStart(mainloop)) { IsBackground = true, Name = "Antenna Tracker" }; t12.Start(); } } }
private void BUT_connect_Click(object sender, EventArgs e) { saveconfig(); if (threadrun) { threadrun = false; BUT_connect.Text = Strings.Connect; tracker.Close(); foreach (Control ctl in Controls) { if (ctl.Name.StartsWith("TXT_")) ctl.Enabled = true; if (ctl.Name.StartsWith("CMB_")) ctl.Enabled = true; } BUT_find.Enabled = true; //CustomMessageBox.Show("Disconnected!"); return; } if (tracker != null && tracker.ComPort != null && tracker.ComPort.IsOpen) { tracker.ComPort.Close(); } if (CMB_interface.Text == interfaces.Maestro.ToString()) tracker = new Antenna.Maestro(); if (CMB_interface.Text == interfaces.ArduTracker.ToString()) tracker = new Antenna.ArduTracker(); if (CMB_interface.Text == interfaces.DegreeTracker.ToString()) tracker = new Antenna.DegreeTracker(); try { tracker.ComPort = new SerialPort() { PortName = CMB_serialport.Text, BaudRate = int.Parse(CMB_baudrate.Text) }; } catch (Exception ex) { CustomMessageBox.Show(Strings.ErrorConnecting + ex.Message, Strings.ERROR); return; } try { tracker.PanStartRange = int.Parse(TXT_panrange.Text) / 2 * -1; tracker.PanEndRange = int.Parse(TXT_panrange.Text) / 2; tracker.TrimPan = TRK_pantrim.Value; tracker.TiltStartRange = int.Parse(TXT_tiltrange.Text) / 2 * -1; tracker.TiltEndRange = int.Parse(TXT_tiltrange.Text) / 2; tracker.TrimTilt = TRK_tilttrim.Value; tracker.PanReverse = CHK_revpan.Checked; tracker.TiltReverse = CHK_revtilt.Checked; tracker.PanPWMRange = int.Parse(TXT_pwmrangepan.Text); tracker.TiltPWMRange = int.Parse(TXT_pwmrangetilt.Text); tracker.PanPWMCenter = int.Parse(TXT_centerpan.Text); tracker.TiltPWMCenter = int.Parse(TXT_centertilt.Text); tracker.PanSpeed = int.Parse(TXT_panspeed.Text); tracker.PanAccel = int.Parse(TXT_panaccel.Text); tracker.TiltSpeed = int.Parse(TXT_tiltspeed.Text); tracker.TiltAccel = int.Parse(TXT_tiltaccel.Text); } catch (Exception ex) { CustomMessageBox.Show(Strings.InvalidNumberEntered + ex.Message, Strings.ERROR); return; } if (tracker.Init()) { if (tracker.Setup()) { if (TXT_centerpan.Text != tracker.PanPWMCenter.ToString()) TXT_centerpan.Text = tracker.PanPWMCenter.ToString(); if (TXT_centertilt.Text != tracker.TiltPWMCenter.ToString()) TXT_centertilt.Text = tracker.TiltPWMCenter.ToString(); try { tracker.PanAndTilt(0, 0); } catch (Exception ex) { CustomMessageBox.Show("Failed to set initial pan and tilt\n" + ex.Message, Strings.ERROR); tracker.Close(); return; } foreach (Control ctl in Controls) { if(ctl.Name.StartsWith("TXT_")) ctl.Enabled = false; if (ctl.Name.StartsWith("CMB_")) ctl.Enabled = false; } //BUT_find.Enabled = false; t12 = new System.Threading.Thread(new System.Threading.ThreadStart(mainloop)) { IsBackground = true, Name = "Antenna Tracker" }; t12.Start(); } } BUT_connect.Text = "Disconnect"; }
private void BUT_connect_Click(object sender, EventArgs e) { saveconfig(); if (threadrun) { threadrun = false; BUT_connect.Text = "Connect"; tracker.Close(); foreach (Control ctl in Controls) { if (ctl.Name.StartsWith("TXT_")) { ctl.Enabled = true; } if (ctl.Name.StartsWith("CMB_")) { ctl.Enabled = true; } } BUT_find.Enabled = true; //CustomMessageBox.Show("Disconnected!"); return; } if (tracker != null && tracker.ComPort != null && tracker.ComPort.IsOpen) { tracker.ComPort.Close(); } if (CMB_interface.Text == interfaces.Maestro.ToString()) { tracker = new Antenna.Maestro(); } if (CMB_interface.Text == interfaces.ArduTracker.ToString()) { tracker = new Antenna.ArduTracker(); } if (CMB_interface.Text == interfaces.DegreeTracker.ToString()) { tracker = new Antenna.DegreeTracker(); } try { tracker.ComPort = new SerialPort() { PortName = CMB_serialport.Text, BaudRate = int.Parse(CMB_baudrate.Text) }; } catch (Exception ex) { CustomMessageBox.Show("Bad Port settings " + ex.Message, "Error"); return; } try { tracker.PanStartRange = int.Parse(TXT_panrange.Text) / 2 * -1; tracker.PanEndRange = int.Parse(TXT_panrange.Text) / 2; tracker.TrimPan = TRK_pantrim.Value; tracker.TiltStartRange = int.Parse(TXT_tiltrange.Text) / 2 * -1; tracker.TiltEndRange = int.Parse(TXT_tiltrange.Text) / 2; tracker.TrimTilt = TRK_tilttrim.Value; tracker.PanReverse = CHK_revpan.Checked; tracker.TiltReverse = CHK_revtilt.Checked; tracker.PanPWMRange = int.Parse(TXT_pwmrangepan.Text); tracker.TiltPWMRange = int.Parse(TXT_pwmrangetilt.Text); tracker.PanPWMCenter = int.Parse(TXT_centerpan.Text); tracker.TiltPWMCenter = int.Parse(TXT_centertilt.Text); tracker.PanSpeed = int.Parse(TXT_panspeed.Text); tracker.PanAccel = int.Parse(TXT_panaccel.Text); tracker.TiltSpeed = int.Parse(TXT_tiltspeed.Text); tracker.TiltAccel = int.Parse(TXT_tiltaccel.Text); } catch (Exception ex) { CustomMessageBox.Show("Bad User input " + ex.Message, "Error"); return; } if (tracker.Init()) { if (tracker.Setup()) { if (TXT_centerpan.Text != tracker.PanPWMCenter.ToString()) { TXT_centerpan.Text = tracker.PanPWMCenter.ToString(); } if (TXT_centertilt.Text != tracker.TiltPWMCenter.ToString()) { TXT_centertilt.Text = tracker.TiltPWMCenter.ToString(); } try { tracker.PanAndTilt(0, 0); } catch (Exception ex) { CustomMessageBox.Show("Failed to set initial pan and tilt\n" + ex.Message, "Error"); tracker.Close(); return; } foreach (Control ctl in Controls) { if (ctl.Name.StartsWith("TXT_")) { ctl.Enabled = false; } if (ctl.Name.StartsWith("CMB_")) { ctl.Enabled = false; } } //BUT_find.Enabled = false; t12 = new System.Threading.Thread(new System.Threading.ThreadStart(mainloop)) { IsBackground = true, Name = "Antenna Tracker" }; t12.Start(); } } BUT_connect.Text = "Disconnect"; }
private void BUT_connect_Click(object sender, EventArgs e) { saveconfig(); if (threadrun) { threadrun = false; BUT_connect.Text = "Connect"; tracker.Close(); return; } if (tracker != null && tracker.ComPort != null && tracker.ComPort.IsOpen) { tracker.ComPort.Close(); } if (CMB_interface.Text == "Maestro") tracker = new ArdupilotMega.Antenna.Maestro(); if (CMB_interface.Text == "ArduTracker") tracker = new ArdupilotMega.Antenna.ArduTracker(); try { tracker.ComPort = new SerialPort() { PortName = CMB_serialport.Text, BaudRate = int.Parse(CMB_baudrate.Text) }; } catch (Exception ex) { CustomMessageBox.Show("Bad Port settings " + ex.Message); return; } try { tracker.PanStartRange = int.Parse(TXT_panrange.Text) / 2 * -1; tracker.PanEndRange = int.Parse(TXT_panrange.Text) / 2; tracker.TrimPan = TRK_pantrim.Value; tracker.TiltStartRange = int.Parse(TXT_tiltrange.Text) / 2 * -1; tracker.TiltEndRange = int.Parse(TXT_tiltrange.Text) / 2; tracker.TrimTilt = TRK_tilttrim.Value; tracker.PanReverse = CHK_revpan.Checked; tracker.TiltReverse = CHK_revtilt.Checked; tracker.PanPWMRange = int.Parse(TXT_pwmrangepan.Text); tracker.TiltPWMRange = int.Parse(TXT_pwmrangetilt.Text); } catch (Exception ex) { CustomMessageBox.Show("Bad User input " + ex.Message); return; } if (tracker.Init()) { if (tracker.Setup()) { tracker.PanAndTilt(0, 0); t12 = new System.Threading.Thread(new System.Threading.ThreadStart(mainloop)) { IsBackground = true, Name = "Antenna Tracker" }; t12.Start(); } } BUT_connect.Text = "Disconnect"; }