private void UpdateFirmwareAsyncWorker(BackgroundWorker worker, byte[] firmware)
        {
            var isSuccess = false;

            try
            {
                UpdateUI(() => UpdateStatusLabel.Text = @"Reading dataflash...");
                var dataflash = m_updater.ReadDataflash(worker);
                if (dataflash.LoadFromLdrom == false && dataflash.FirmwareVersion > 0)
                {
                    dataflash.LoadFromLdrom = true;
                    UpdateUI(() => UpdateStatusLabel.Text = @"Writing dataflash...");
                    m_updater.WriteDataflash(dataflash, worker);
                    m_updater.RestartDevice();
                    UpdateUI(() => UpdateStatusLabel.Text = @"Waiting for device after reset...");
                    Thread.Sleep(2000);
                }
                UpdateUI(() => UpdateStatusLabel.Text = @"Uploading firmware...");
                m_updater.WriteFirmware(firmware, worker);

                UpdateUI(() =>
                {
                    UpdateStatusLabel.Text = string.Empty;
                    worker.ReportProgress(0);
                });
                isSuccess = true;

                Thread.Sleep(500);
            }
            catch (Exception ex)
            {
                InfoBox.Show("An exception occured during firmware update.\n" + ex.Message);
            }
            finally
            {
                if (isSuccess)
                {
                    InfoBox.Show("Firmware successfully updated.");
                }
            }
        }
예제 #2
0
        private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            var worker   = (BackgroundWorker)sender;
            var firmware = (byte[])e.Argument;

            try
            {
                UpdateUI(() => OkButton.Enabled = CancelButton.Enabled = false);
                m_updater.StopMonitoring();

                UpdateUI(() => UpdateStatusLabel.Text = @"Reading dataflash...");
                var dataflash = m_updater.ReadDataFlash(worker);
                if (dataflash.LoadFromLdrom != true)
                {
                    dataflash.LoadFromLdrom = true;
                    UpdateUI(() => UpdateStatusLabel.Text = @"Writing dataflash...");
                    m_updater.WriteDataFlash(dataflash, worker);
                    m_updater.Reset();
                    UpdateUI(() => UpdateStatusLabel.Text = @"Waiting for device after reset...");
                    Thread.Sleep(2000);
                }
                UpdateUI(() => UpdateStatusLabel.Text = @"Uploading firmware...");
                m_updater.WriteFirmware(firmware, worker);

                Thread.Sleep(500);
                UpdateUI(() => UpdateStatusLabel.Text = string.Empty);
                InfoBox.Show("Firmware successfully updated.");
            }
            catch (Exception ex)
            {
                InfoBox.Show("An exception occured during firmware update.\n" + ex.Message);
            }
            finally
            {
                UpdateUI(() => OkButton.Enabled = CancelButton.Enabled = true);
                m_updater.StartMonitoring();
            }
        }