private void Instance_DeviceChanged(MainV2.WM_DEVICECHANGE_enum cause) { if (cause != MainV2.WM_DEVICECHANGE_enum.DBT_DEVICEARRIVAL) { return; } Parallel.ForEach(SerialPort.GetPortNames(), port => //Task.Run(delegate { px4uploader.Uploader up; try { up = new px4uploader.Uploader(port, 115200); } catch (Exception ex) { //System.Threading.Thread.Sleep(50); Console.WriteLine(ex.Message); return; } try { up.identify(); log.InfoFormat("Found board type {0} boardrev {1} bl rev {2} fwmax {3} on {4}", up.board_type, up.board_rev, up.bl_rev, up.fw_maxsize, port); detectedport = port; up.close(); } catch (Exception) { Console.WriteLine("Not There.."); //Console.WriteLine(ex.Message); up.close(); } }); }
void deviceChanged(MainV2.WM_DEVICECHANGE_enum cause) { GPSDevice gpsModule = getDevice(); if ((gpsModule != null)) { if (_Available == false) { _Available = true; if (CustomMessageBox.Show("A GPS module was detected on your system. Would you like to use it to set your tracker home location?", "Tracker Home", MessageBoxButtons.YesNo) == DialogResult.Yes) { GPSPosition pos = gpsModule.GetCoordinates(); double alt = getGEAlt(pos.Lat, pos.Lng); Host.comPort.MAV.cs.TrackerLocation = new PointLatLngAlt(pos.Lat, pos.Lng, alt, "Tracker Home"); } } } else if (_Available == true) { _Available = false; } }