Ejemplo n.º 1
0
        public void upload(Firmware fw)
        {
            this.port.ReadTimeout = 1000; // 1 sec

            //Make sure we are doing the right thing
            if (self.board_type != fw.board_id)
            {
                if (!(self.board_type == 33 && fw.board_id == 9))
                {
                    throw new Exception("Firmware not suitable for this board");
                }
            }

            if (self.fw_maxsize < fw.image_size)
            {
                throw new Exception("Firmware image is too large for this board");
            }

            print("erase...");
            self.__erase();

            print("program...");
            self.__program(fw);

            print("verify...");
            if (self.bl_rev == 2)
            {
                self.__verify_v2(fw);
            }
            else
            {
                self.__verify_v3(fw);
            }

            print("done, rebooting.");
            self.__reboot();
            try
            {
                self.port.Close();
            }
            catch { }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// upload to vrbrain standalone
        /// </summary>
        /// <param name="filename"></param>
        public bool UploadVRBRAIN(string filename)
        {
            px4uploader.Uploader up;
            updateProgress(0, "Reading Hex File");
            px4uploader.Firmware fw;
            try
            {
                fw = px4uploader.Firmware.ProcessFirmware(filename);
            }
            catch (Exception ex)
            {
                CustomMessageBox.Show(Strings.ErrorFirmwareFile + "\n\n" + ex.ToString(), Strings.ERROR);
                return(false);
            }

            try
            {
                // check if we are seeing heartbeats
                MainV2.comPort.BaseStream.Open();
                MainV2.comPort.giveComport = true;
                BoardDetect.boards board = BoardDetect.DetectBoard(MainV2.comPortName);

                if (MainV2.comPort.getHeartBeat().Length > 0)
                {
                    MainV2.comPort.doReboot(true);
                    MainV2.comPort.Close();

                    //specific action for VRBRAIN4 board that needs to be manually disconnected before uploading
                    if (board == BoardDetect.boards.vrbrainv40)
                    {
                        CustomMessageBox.Show("VRBRAIN 4 detected. Please unplug the board, and then press OK and plug back in.\n");
                    }
                }
                else
                {
                    MainV2.comPort.BaseStream.Close();
                    CustomMessageBox.Show("Please unplug the board, and then press OK and plug back in.\nMission Planner will look for 30 seconds to find the board");
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                CustomMessageBox.Show("Please unplug the board, and then press OK and plug back in.\nMission Planner will look for 30 seconds to find the board");
            }

            DateTime DEADLINE = DateTime.Now.AddSeconds(30);

            updateProgress(0, "Scanning comports");

            while (DateTime.Now < DEADLINE)
            {
                string[] allports = SerialPort.GetPortNames();

                foreach (string port in allports)
                {
                    log.Info(DateTime.Now.Millisecond + " Trying Port " + port);

                    updateProgress(-1, "Connecting");

                    try
                    {
                        up = new px4uploader.Uploader(port, 115200);
                    }
                    catch (Exception ex)
                    {
                        //System.Threading.Thread.Sleep(50);
                        Console.WriteLine(ex.Message);
                        continue;
                    }

                    try
                    {
                        up.identify();
                        updateProgress(-1, "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);
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Not There..");
                        //Console.WriteLine(ex.Message);
                        up.close();
                        continue;
                    }

                    up.skipotp = true;

                    try
                    {
                        up.currentChecksum(fw);
                    }
                    catch
                    {
                        up.__reboot();
                        up.close();
                        CustomMessageBox.Show("No need to upload. already on the board");
                        return(true);
                    }

                    try
                    {
                        up.ProgressEvent += new px4uploader.Uploader.ProgressEventHandler(up_ProgressEvent);
                        up.LogEvent      += new px4uploader.Uploader.LogEventHandler(up_LogEvent);

                        updateProgress(0, "Upload");
                        up.upload(fw);
                        updateProgress(100, "Upload Done");
                    }
                    catch (Exception ex)
                    {
                        updateProgress(0, "ERROR: " + ex.Message);
                        log.Info(ex);
                        Console.WriteLine(ex.ToString());
                        return(false);
                    }
                    finally
                    {
                        up.close();
                    }

                    if (up.board_type == 1140 || up.board_type == 1145 || up.board_type == 1150 || up.board_type == 1151 || up.board_type == 1152 || up.board_type == 1210 || up.board_type == 1351 || up.board_type == 1352 || up.board_type == 1411 || up.board_type == 1520)
                    {//VR boards have no tone alarm
                        if (up.board_type == 1140)
                        {
                            CustomMessageBox.Show("Upload complete! Please unplug and reconnect board.");
                        }
                        else
                        {
                            CustomMessageBox.Show("Upload complete!");
                        }
                    }
                    else
                    {
                        // wait for IO firmware upgrade and boot to a mavlink state
                        CustomMessageBox.Show("Please wait for the musical tones to finish before clicking OK");
                    }
                    return(true);
                }
            }

            updateProgress(0, "ERROR: No Response from board");
            return(false);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// upload to vrbrain standalone
        /// </summary>
        /// <param name="filename"></param>
        public bool UploadVRBRAIN(string filename, BoardDetect.boards board)
        {
            px4uploader.Uploader up;
            updateProgress(0, "Reading Hex File");
            px4uploader.Firmware fw;
            try
            {
                fw = px4uploader.Firmware.ProcessFirmware(filename);
            }
            catch (Exception ex)
            {
                CustomMessageBox.Show(Strings.ErrorFirmwareFile + "\n\n" + ex.ToString(), Strings.ERROR);
                return false;
            }

            try
            {
                // check if we are seeing heartbeats
                MainV2.comPort.BaseStream.Open();
                MainV2.comPort.giveComport = true;

                if (MainV2.comPort.getHeartBeat().Length > 0)
                {
                    MainV2.comPort.doReboot(true);
                    MainV2.comPort.Close();

                    //specific action for VRBRAIN4 board that needs to be manually disconnected before uploading
                    if (board == BoardDetect.boards.vrbrainv40)
                    {
                        CustomMessageBox.Show(
                            "VRBRAIN 4 detected. Please unplug the board, and then press OK and plug back in.\n");
                    }
                }
                else
                {
                    MainV2.comPort.BaseStream.Close();
                    CustomMessageBox.Show(Strings.PleaseUnplugTheBoardAnd);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                CustomMessageBox.Show(Strings.PleaseUnplugTheBoardAnd);
            }

            DateTime DEADLINE = DateTime.Now.AddSeconds(30);

            updateProgress(0, "Scanning comports");

            while (DateTime.Now < DEADLINE)
            {
                string[] allports = SerialPort.GetPortNames();

                foreach (string port in allports)
                {
                    log.Info(DateTime.Now.Millisecond + " Trying Port " + port);

                    updateProgress(-1, "Connecting");

                    try
                    {
                        up = new px4uploader.Uploader(port, 115200);
                    }
                    catch (Exception ex)
                    {
                        //System.Threading.Thread.Sleep(50);
                        Console.WriteLine(ex.Message);
                        continue;
                    }

                    try
                    {
                        up.identify();
                        updateProgress(-1, "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);
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Not There..");
                        //Console.WriteLine(ex.Message);
                        up.close();
                        continue;
                    }

                    up.skipotp = true;

                    try
                    {
                        up.currentChecksum(fw);
                    }
                    catch
                    {
                        up.__reboot();
                        up.close();
                        CustomMessageBox.Show(Strings.NoNeedToUpload);
                        return true;
                    }

                    try
                    {
                        up.ProgressEvent += new px4uploader.Uploader.ProgressEventHandler(up_ProgressEvent);
                        up.LogEvent += new px4uploader.Uploader.LogEventHandler(up_LogEvent);

                        updateProgress(0, "Upload");
                        up.upload(fw);
                        updateProgress(100, "Upload Done");
                    }
                    catch (Exception ex)
                    {
                        updateProgress(0, "ERROR: " + ex.Message);
                        log.Info(ex);
                        Console.WriteLine(ex.ToString());
                        return false;
                    }
                    finally
                    {
                        up.close();
                    }

                    if (up.board_type == 1140 || up.board_type == 1145 || up.board_type == 1150 || up.board_type == 1151 ||
                        up.board_type == 1152 || up.board_type == 1210 || up.board_type == 1351 || up.board_type == 1352 ||
                        up.board_type == 1411 || up.board_type == 1520)
                    {
            //VR boards have no tone alarm
                        if (up.board_type == 1140)
                            CustomMessageBox.Show("Upload complete! Please unplug and reconnect board.");
                        else
                            CustomMessageBox.Show("Upload complete!");
                    }
                    else
                    {
                        // wait for IO firmware upgrade and boot to a mavlink state
                        CustomMessageBox.Show(Strings.PleaseWaitForTheMusicalTones);
                    }
                    return true;
                }
            }

            updateProgress(0, "ERROR: No Response from board");
            return false;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// upload to px4 standalone
        /// </summary>
        /// <param name="filename"></param>
        public bool UploadPX4(string filename)
        {
            Uploader up;
            updateProgress(0, "Reading Hex File");
            px4uploader.Firmware fw;
            try
            {
                fw = px4uploader.Firmware.ProcessFirmware(filename);
            }
            catch (Exception ex)
            {
                CustomMessageBox.Show("Error loading firmware file\n\n" + ex.ToString(), "Error");
                return false;
            }

            try
            {
                // check if we are seeing heartbeats
                MainV2.comPort.BaseStream.Open();
                MainV2.comPort.giveComport = true;

                if (MainV2.comPort.getHeartBeat().Length > 0)
                {
                    MainV2.comPort.doReboot(true);
                    MainV2.comPort.Close();
                }
                else
                {
                    MainV2.comPort.BaseStream.Close();
                    CustomMessageBox.Show("Please unplug the board, and then press OK and plug back in.\nMission Planner will look for 30 seconds to find the board");
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                CustomMessageBox.Show("Please unplug the board, and then press OK and plug back in.\nMission Planner will look for 30 seconds to find the board");
            }

            DateTime DEADLINE = DateTime.Now.AddSeconds(30);

            updateProgress(0, "Scanning comports");

            while (DateTime.Now < DEADLINE)
            {
                string[] allports = SerialPort.GetPortNames();

                foreach (string port in allports)
                {
                    log.Info(DateTime.Now.Millisecond + " Trying Port " + port);

                    updateProgress(-1, "Connecting");

                    try
                    {
                        up = new Uploader(port, 115200);
                    }
                    catch (Exception ex)
                    {
                        //System.Threading.Thread.Sleep(50);
                        Console.WriteLine(ex.Message);
                        continue;
                    }

                    try
                    {
                        up.identify();
                        updateProgress(-1, "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);
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Not There..");
                        //Console.WriteLine(ex.Message);
                        up.close();
                        continue;
                    }

                    try
                    {
                        up.currentChecksum(fw);
                    }
                    catch
                    {
                        up.__reboot();
                        up.close();
                        CustomMessageBox.Show("No need to upload. already on the board");
                        return true;
                    }

                    try
                    {
                        up.ProgressEvent += new Uploader.ProgressEventHandler(up_ProgressEvent);
                        up.LogEvent += new Uploader.LogEventHandler(up_LogEvent);

                        updateProgress(0, "Upload");
                        up.upload(fw);
                        updateProgress(100, "Upload Done");
                    }
                    catch (Exception ex)
                    {
                        updateProgress(0, "ERROR: " + ex.Message);
                        log.Info(ex);
                        Console.WriteLine(ex.ToString());
                        return false;
                    }
                    finally
                    {
                        up.close();
                    }

                    // wait for IO firmware upgrade and boot to a mavlink state
                    CustomMessageBox.Show("Please wait for the musical tones to finish before clicking OK");

                    return true;
                }
            }

            updateProgress(0, "ERROR: No Responce from board");
            return false;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// upload to px4 standalone
        /// </summary>
        /// <param name="filename"></param>
        public bool UploadPX4(string filename)
        {
            Uploader up;
            updateProgress(0, "Reading Hex File");
            px4uploader.Firmware fw;
            try
            {
                fw = px4uploader.Firmware.ProcessFirmware(filename);
            }
            catch (Exception ex)
            {
                CustomMessageBox.Show(Strings.ErrorFirmwareFile + "\n\n" + ex.ToString(), Strings.ERROR);
                return false;
            }

            try
            {
                // check if we are seeing heartbeats
                MainV2.comPort.BaseStream.Open();
                MainV2.comPort.giveComport = true;
                BoardDetect.boards board = BoardDetect.DetectBoard(MainV2.comPortName);

                if (MainV2.comPort.getHeartBeat().Length > 0)
                {
                    MainV2.comPort.doReboot(true);
                    MainV2.comPort.Close();

                    //specific action for VRBRAIN4 board that needs to be manually disconnected before uploading
                    if (board == BoardDetect.boards.vrbrainv40)
                    {
                        CustomMessageBox.Show("VRBRAIN 4 detected. Please unplug the board then press OK and plug back in.\n");
                    }
                }
                else
                {
                    MainV2.comPort.BaseStream.Close();
                    CustomMessageBox.Show("Please unplug the board, and then press OK and plug back in.\nMission Planner will look for 30 seconds to find the board");
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                CustomMessageBox.Show("Please unplug the board, and then press OK and plug back in.\nMission Planner will look for 30 seconds to find the board");
            }

            DateTime DEADLINE = DateTime.Now.AddSeconds(30);

            updateProgress(0, "Scanning comports");

            while (DateTime.Now < DEADLINE)
            {
                string[] allports = SerialPort.GetPortNames();

                foreach (string port in allports)
                {
                    log.Info(DateTime.Now.Millisecond + " Trying Port " + port);

                    updateProgress(-1, "Connecting");

                    try
                    {
                        up = new Uploader(port, 115200);
                    }
                    catch (Exception ex)
                    {
                        //System.Threading.Thread.Sleep(50);
                        Console.WriteLine(ex.Message);
                        continue;
                    }

                    try
                    {
                        up.identify();
                        updateProgress(-1, "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);

                        up.ProgressEvent += new Uploader.ProgressEventHandler(up_ProgressEvent);
                        up.LogEvent += new Uploader.LogEventHandler(up_LogEvent);
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Not There..");
                        //Console.WriteLine(ex.Message);
                        up.close();
                        continue;
                    }

                    // test if pausing here stops - System.TimeoutException: The write timed out.
                    System.Threading.Thread.Sleep(500);

                    try
                    {
                        up.verifyotp();

                        if (up.libre)
                        {
                            MissionPlanner.Utilities.Tracking.AddEvent("FWUpload", "verifyotp", "libre", "");
                        }
                        else 
                        {
                            MissionPlanner.Utilities.Tracking.AddEvent("FWUpload", "verifyotp", "Pass", "");
                        }
                    }
                    catch (Org.BouncyCastle.Security.InvalidKeyException ex) 
                    {
                        MissionPlanner.Utilities.Tracking.AddEvent("FWUpload", "verifyotp","InvalidKeyException","");
                        log.Error(ex);
                        CustomMessageBox.Show("You are using unsupported hardware.\nThis board does not contain a valid certificate of authenticity.\nPlease contact your hardware vendor about signing your hardware.", "Invalid Cert"); 
                        up.skipotp = true;
                    }
                    catch (FormatException ex)
                    {
                        MissionPlanner.Utilities.Tracking.AddEvent("FWUpload", "verifyotp", "FormatException", "");
                        log.Error(ex);
                        CustomMessageBox.Show("You are using unsupported hardware.\nThis board does not contain a valid certificate of authenticity.\nPlease contact your hardware vendor about signing your hardware.", "Invalid Cert");
                        up.skipotp = true;
                    }
                    catch (IOException ex) 
                    {
                        MissionPlanner.Utilities.Tracking.AddEvent("FWUpload", "verifyotp", "IOException", "");
                        log.Error(ex);
                        CustomMessageBox.Show("lost communication with the board.", "lost comms");
                        up.close();
                        return false;
                    }
                    catch (TimeoutException ex)
                    {
                        MissionPlanner.Utilities.Tracking.AddEvent("FWUpload", "verifyotp", "TimeoutException", "");
                        log.Error(ex);
                        CustomMessageBox.Show("lost communication with the board.", "lost comms");
                        up.close();
                        return false;
                    }
                    catch (Exception ex)
                    {
                        MissionPlanner.Utilities.Tracking.AddEvent("FWUpload", "verifyotp", "Exception", "");
                        log.Error(ex);
                        CustomMessageBox.Show("lost communication with the board. " + ex.ToString(), "lost comms");
                        up.close();
                        return false;
                    }

                    try
                    {
                        up.currentChecksum(fw);
                    }
                    catch (IOException ex)
                    {
                        log.Error(ex);
                        CustomMessageBox.Show("lost communication with the board.", "lost comms");
                        up.close();
                        return false;
                    }
                    catch
                    {
                        up.__reboot();
                        up.close();
                        CustomMessageBox.Show("No need to upload. already on the board");
                        return true;
                    }

                    try
                    {
                        updateProgress(0, "Upload");
                        up.upload(fw);
                        updateProgress(100, "Upload Done");
                    }
                    catch (Exception ex)
                    {
                        updateProgress(0, "ERROR: " + ex.Message);
                        log.Info(ex);
                        Console.WriteLine(ex.ToString());
                        return false;
                    }
                    finally
                    {
                        up.close();
                    }

                    // wait for IO firmware upgrade and boot to a mavlink state
                    CustomMessageBox.Show("Please wait for the musical tones to finish before clicking OK");

                    return true;
                }
            }

            updateProgress(0, "ERROR: No Response from board");
            return false;
        }
Ejemplo n.º 6
0
        private void FWUpload(object?a)
        {
            try
            {
                Tuple <int, string> passin = (Tuple <int, string>)a;
                var index     = passin.Item1;
                var portname  = passin.Item2;
                var tryupload = true;

                lock (ports)
                    if (ports.Contains(portname))
                    {
                        tryupload = false;
                    }

                if (tryupload)
                {
                    var      fw = Firmware.ProcessFirmware(_args[0]);
                    Uploader up = null;
                    try
                    {
                        up = new px4uploader.Uploader(new SerialPort(portname, 115200));
                    }
                    catch
                    {
                    }

                    if (up != null)
                    {
                        up.ProgressEvent += completed =>
                        {
                            /* this.BeginInvoke(new Action(() =>
                             * {
                             *   textBox1.AppendText(portname + " " + (int)completed + "\r\n");
                             * }));*/
                        };

                        bool flashit    = false;
                        bool validcomms = false;
                        try
                        {
                            up.identify();
                            validcomms = true;
                            up.currentChecksum(fw);
                            flashit = true;
                        }
                        catch (Exception ex)
                        {
                            AppendLine(ex.Message);
                        }

                        if (flashit)
                        {
                            this.BeginInvoke(new Action(() => { textBox1.AppendText(portname + " Flashing fw\r\n"); }));
                            up.upload(fw);
                        }
                        else
                        {
                            this.BeginInvoke(new Action(() => { textBox1.AppendText(portname + " reboot\r\n"); }));
                            up.__reboot();
                        }

                        lock (ports)
                            ports.Add(portname);
                        up.close();
                        this.BeginInvoke(new Action(() => { textBox1.AppendText(portname + " Done fw\r\n"); }));
                        if (validcomms)
                        {
                            return;
                        }
                    }
                }

                var mav = new MAVLinkInterface();
                mav.BaseStream = new SerialPort((string)portname, 115200);
                var bldone = false;
                mav.OnPacketReceived += (sender, message) =>
                {
                    if (message.msgid == (ulong)MAVLink.MAVLINK_MSG_ID.STATUSTEXT)
                    {
                        if (ASCIIEncoding.ASCII.GetString(message.ToStructure <MAVLink.mavlink_statustext_t>().text).Trim().Contains("Bootloader up-to-date") ||
                            ASCIIEncoding.ASCII.GetString(message.ToStructure <MAVLink.mavlink_statustext_t>().text).Trim().Contains("Flash OK"))
                        {
                            bldone = true;
                        }
                        DisplayText(message);
                    }
                };
                try
                {
                    mav.BaseStream.Open();

                    mav.getHeartBeat();

                    mav.doCommand(MAVLink.MAV_CMD.FLASH_BOOTLOADER, 0, 0, 0, 0, 290876, 0, 0, false);

                    mav.getHeartBeat();
                    if (!bldone)
                    {
                        mav.getHeartBeat();
                    }
                    if (!bldone)
                    {
                        mav.getHeartBeat();
                    }
                    if (!bldone)
                    {
                        mav.getHeartBeat();
                    }
                    if (!bldone)
                    {
                        mav.getHeartBeat();
                    }
                    if (!bldone)
                    {
                        mav.getHeartBeat();
                    }
                    if (!bldone)
                    {
                        mav.getHeartBeat();
                    }
                    if (!bldone)
                    {
                        mav.getHeartBeat();
                    }
                    if (!bldone)
                    {
                        mav.getHeartBeat();
                    }

                    mav.Close();


                    this.BeginInvoke(new Action(() =>
                    {
                        textBox1.AppendText(portname + " Done bl " + (bldone ? "OK" : "FAIL") + "\r\n");
                    }));
                }
                catch (Exception ex)
                {
                    AppendLine(ex.Message);
                }
            }
            catch (Exception ex)
            {
                AppendLine(ex.Message);
            }
        }
Ejemplo n.º 7
0
        private void FWUpload(object a)
        {
            Tuple <int, string> passin = (Tuple <int, string>)a;
            var index    = passin.Item1;
            var portname = passin.Item2;

            Console.WriteLine("Thread start for " + portname);
            try
            {
                if (!portstatus.ContainsKey(portname))
                {
                    portstatus[portname] = "";
                }

                {
                    Uploader up = null;
                    try
                    {
                        up = new px4uploader.Uploader(new SerialPort(portname, 115200));
                    }
                    catch
                    {
                    }

                    if (up != null)
                    {
                        up.ProgressEvent += completed =>
                        {
                            /* this.BeginInvoke(new Action(() =>
                             * {
                             *   textBox1.AppendText(portname + " " + (int)completed + "\r\n");
                             * }));*/
                        };

                        bool     flashit    = false;
                        bool     validcomms = false;
                        Firmware fw         = null;
                        try
                        {
                            up.identify();
                            validcomms            = true;
                            portstatus[portname] += "BL ";
                            UpdateTextBox();
                            fw = Firmware.ProcessFirmware(_args[0]);
                            up.currentChecksum(fw);

                            fw.board_id = up.board_type;

                            flashit = true;
                            portstatus[portname] += "CS ";
                            UpdateTextBox();
                        }
                        catch (Exception ex)
                        {
                            if (ex.Message.Contains("Same Firmware"))
                            {
                                portstatus[portname] += "BLUPD OK ";
                            }
                            else
                            {
                                portstatus[portname] += "BLEX ";
                            }
                            UpdateTextBox();
                        }

                        if (flashit)
                        {
                            DateTime ts = DateTime.Now;
                            up.ProgressEvent += completed =>
                            {
                                if (ts.Second != DateTime.Now.Second)
                                {
                                    Console.WriteLine("{0}: {1}", portname, completed);
                                    ts = DateTime.Now;
                                }
                            };
                            up.upload(fw);
                            portstatus[portname] += "BLUPD OK ";
                            UpdateTextBox();
                        }
                        else
                        {
                            up.__reboot();
                            UpdateTextBox();
                        }

                        up.close();

                        if (validcomms)
                        {
                            return;
                        }
                    }
                }

                var ports = getPortByVPidInt(txt_vid.Text, txt_pid.Text, txt_int.Text);
                if (!ports.Contains(portname))
                {
                    portstatus[portname] += "NOTML OK ";
                    UpdateTextBox();
                    return;
                }

                var mav = new MAVLinkInterface();
                mav.BaseStream = new SerialPort((string)portname, 115200);
                var bldone = false;
                mav.OnPacketReceived += (sender, message) =>
                {
                    if (message.msgid == (ulong)MAVLink.MAVLINK_MSG_ID.STATUSTEXT)
                    {
                        if (ASCIIEncoding.ASCII.GetString(message.ToStructure <MAVLink.mavlink_statustext_t>().text).Trim().Contains("Bootloader up-to-date") ||
                            ASCIIEncoding.ASCII.GetString(message.ToStructure <MAVLink.mavlink_statustext_t>().text).Trim().Contains("Flash OK"))
                        {
                            bldone = true;

                            portstatus[portname] += ASCIIEncoding.ASCII
                                                    .GetString(message.ToStructure <MAVLink.mavlink_statustext_t>().text).Trim()
                                                    .TrimEnd(new char[] { '\0', '\r', '\n' });
                            UpdateTextBox();
                        }
                        //DisplayText(message);
                    }
                };
                try
                {
                    mav.BaseStream.Open();

                    mav.getHeartBeat();

                    mav.doCommand(MAVLink.MAV_CMD.FLASH_BOOTLOADER, 0, 0, 0, 0, 290876, 0, 0, false);

                    mav.getHeartBeat();
                    if (!bldone)
                    {
                        mav.getHeartBeat();
                    }
                    if (!bldone)
                    {
                        mav.getHeartBeat();
                    }
                    if (!bldone)
                    {
                        mav.getHeartBeat();
                    }
                    if (!bldone)
                    {
                        mav.getHeartBeat();
                    }
                    if (!bldone)
                    {
                        mav.getHeartBeat();
                    }
                    if (!bldone)
                    {
                        mav.getHeartBeat();
                    }
                    if (!bldone)
                    {
                        mav.getHeartBeat();
                    }
                    if (!bldone)
                    {
                        mav.getHeartBeat();
                    }

                    mav.Close();


                    if (bldone)
                    {
                        portstatus[portname] += "MLBLUPD OK";
                    }

                    UpdateTextBox();
                }
                catch (Exception ex)
                {
                    portstatus[portname] += "MLEX ";

                    UpdateTextBox();
                }
            }
            catch (Exception ex)
            {
                portstatus[portname] += "EX!! ";

                UpdateTextBox();
            }

            UpdateTextBox();
        }