private void btnAutoGps_Click2(object sender, EventArgs e) { using (ComPortFinder cpf = new ComPortFinder()) { TtUtils.ShowWaitCursor(); Values.GPSA.CloseGps(); System.Threading.Thread.Sleep(150); cpf.Find(); TtUtils.HideWaitCursor(); List<ComPortFinder.SerialDevice> devs = cpf.GetValidDevices(); if (devs.Count > 0) { DisplayDevices(devs, cpf); } else { if(MessageBox.Show("Could not locate GPS Reciever. Would you like to try finding the port using a different method? (will be slow)", "GPS Not Found", MessageBoxButtons.YesNo, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1) == DialogResult.Yes) { TtUtils.ShowWaitCursor(); Values.GPSA.CloseGps(); System.Threading.Thread.Sleep(150); cpf.FindNoThread(); TtUtils.HideWaitCursor(); if (devs.Count > 0) { DisplayDevices(devs, cpf); } else { AutoClosingMessageBox.Show("Could not locatate GPS Reciever", "GPS Not Found", 2000); } } } //AutoClosingMessageBox.Show("Could not locatate GPS Reciever", "GPS Not Found", 2000); } }
private void DisplayDevices(List<ComPortFinder.SerialDevice> devs, ComPortFinder cpf) { if (devs.Count == 1) { ComPortFinder.SerialDevice dev = devs[0]; getPortSelection(dev.Port); getBaudSelection(dev.Baud.ToString()); Values.GPSA.TestGps(Values.Settings.DeviceOptions.GpsComPort, Values.Settings.DeviceOptions.GpsBaud); Values.Settings.DeviceOptions.GpsConfigured = true; AutoClosingMessageBox.Show(String.Format("GPS set to Port: {0} with a Baud of {1}", dev.Port, dev.Baud), "GPS Found", 3000); } else { StringBuilder sb = new StringBuilder(); sb.AppendLine("Several Devices Found:\n"); foreach (ComPortFinder.SerialDevice dev in cpf.GetValidDevices()) { sb.AppendFormat("(P:{0} - B:{1}){2}\n", dev.Port, dev.Baud, Environment.NewLine); } MessageBox.Show(sb.ToString()); } }
private void btnAutoLaser_Click2(object sender, EventArgs e) { using (ComPortFinder cpf = new ComPortFinder(ComPortFinder.DeviceType.Laser)) { TtUtils.ShowWaitCursor(); cpf.Find(); TtUtils.HideWaitCursor(); List<ComPortFinder.SerialDevice> devs = cpf.GetValidDevices(); if (devs.Count > 0) { if (devs.Count == 1) { ComPortFinder.SerialDevice dev = devs[0]; getPortSelection(dev.Port); getBaudSelection(dev.Baud.ToString()); Values.LaserA.OpenLaser(Values.Settings.DeviceOptions.LaserComPort, Values.Settings.DeviceOptions.LaserBaud); AutoClosingMessageBox.Show(String.Format("Laser set to Port: {0} with a Baud of {1}", dev.Port, dev.Baud), "Laser Found", 3000); } else { StringBuilder sb = new StringBuilder(); sb.AppendLine("Several Devices Found:\n"); foreach (ComPortFinder.SerialDevice dev in cpf.GetValidDevices()) { sb.AppendFormat("(P:{0} - B:{1}){2}\n", dev.Port, dev.Baud, Environment.NewLine); } MessageBox.Show(sb.ToString()); } } else { AutoClosingMessageBox.Show("Could not locatate Laser", "Laser Not Found", 2000); } } }