private void Instance_DeviceChanged(MainV2.WM_DEVICECHANGE_enum cause)
        {
            if (cause != MainV2.WM_DEVICECHANGE_enum.DBT_DEVICEARRIVAL)
            {
                return;
            }

            if (flashdone == true)
            {
                return;
            }

            Task.Run(() =>
            {
                Parallel.ForEach(SerialPort.GetPortNames(), port =>
                {
                    px4uploader.Uploader up;

                    try
                    {
                        // time to appear
                        Thread.Sleep(20);
                        up = new px4uploader.Uploader(port, 115200);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        return;
                    }

                    try
                    {
                        up.identify();
                        var msg = String.Format("Found board type {0} brdrev {1} blrev {2} fwmax {3} chip {5:X} chipdes {6} on {4}", up.board_type,
                                                up.board_rev, up.bl_rev, up.fw_maxsize, port, up.chip, up.chip_desc);
                        log.Info(msg);

                        up.close();

                        this.InvokeIfRequired(() => lbl_status.Text = msg);
                        detectedport    = port;
                        detectedboardid = up.board_type;
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Not There..");
                        up.close();
                    }
                });
            });
        }
Exemplo n.º 2
0
        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
                {
                    // time to appear
                    Thread.Sleep(20);
                    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} brdrev {1} blrev {2} fwmax {3} chip {5:X} chipdes {6} on {4}", up.board_type,
                                   up.board_rev, up.bl_rev, up.fw_maxsize, port, up.chip, up.chip_desc);

                    detectedport = port;

                    up.close();
                }
                catch (Exception)
                {
                    Console.WriteLine("Not There..");
                    //Console.WriteLine(ex.Message);
                    up.close();
                }
            });
        }
Exemplo n.º 3
0
        public void Deactivate()
        {
            MainV2.instance.DeviceChanged -= Instance_DeviceChanged;

            // try reboot device on screen close.
            if (!String.IsNullOrEmpty(detectedport))
            {
                try
                {
                    px4uploader.Uploader up = new px4uploader.Uploader(detectedport, 115200);
                    up.__reboot();
                    up.close();
                } catch { }
            }
        }