private void UpgradeFirmware()
 {
     Application.DoEvents();
     try
     {
         WDS_MainProg.frameWin().DisablePlugAndPlay();
         progressDlg.Show(this);
         _ioph.terminate();
         Thread.Sleep(100);
         ADTRecord adtRecord = _ioph.getAdtRecord();
         FirmwareDownloadResult stoppedWithError = new IO_FD_Main(adtRecord).DownloadFirmware(_latestFirmware, new UpdateFirmwareCallback(firmwareUpdateCallback), null);
         if (stoppedWithError == FirmwareDownloadResult.OK)
         {
             IOPortAddress.HIDAddress hidAddr = adtRecord.PortAddress.hidAddr;
             FormWait wait = new FormWait(hidAddr.VID, hidAddr.PID, hidAddr.Serial, false, 0x1388, 100) {
                 Text = "Enumerating Application..."
             };
             if (wait.ShowDialog() != DialogResult.OK)
             {
                 firmwareUpdateCallback(0, true, "There was an error trying to reenumerate in application mode.", MessageBoxButtons.OK);
                 stoppedWithError = FirmwareDownloadResult.StoppedWithError;
             }
             adtRecord.PortAddress.handle = DDI_HID.instance().open(adtRecord, ' ');
             ADTManager.instance().addADTRecord(adtRecord);
         }
         _ioph = new IOPH_DCP(adtRecord, this);
         _ioph.initialize();
         createCloseWindowController();
         progressDlg.Close();
         WDS_MainProg.frameWin().RestorePlugAndPlay();
         if (stoppedWithError != FirmwareDownloadResult.OK)
         {
             _log.Warn("RF_To_USB_Network_Demo: Mainboard firmware download failed");
             _ioph.terminate();
             base.Close();
         }
     }
     catch
     {
         _log.Warn("RF_To_USB_Network_Demo: Mainboard firmware download failed");
         _ioph.terminate();
         base.Close();
     }
 }
Exemple #2
0
        public FirmwareDownloadResult DownloadFirmware(string firmwarePath, UpdateFirmwareCallback callback, Difference[] fwChanges)
        {
            FormWait wait;
            StreamReader reader = new StreamReader(firmwarePath);
            ArrayList firmware = new ArrayList();
            try
            {
                while (reader.Peek() >= 0)
                {
                    string str = reader.ReadLine().Trim();
                    if ((str.Length > 0) && (str[0] != ';'))
                    {
                        firmware.Add(str);
                    }
                }
            }
            catch
            {
                callback(0, true, "There was an error while reading in the firmware file.", MessageBoxButtons.OK);
                return FirmwareDownloadResult.StoppedWithError;
            }
            finally
            {
                reader.Close();
            }
            if (firmware.Count < 2)
            {
                callback(0, true, "There was an error while reading in the firmware file.", MessageBoxButtons.OK);
                return FirmwareDownloadResult.StoppedWithError;
            }
            ushort vID = this._adtRecord.PortAddress.hidAddr.VID;
            ushort pID = this._adtRecord.PortAddress.hidAddr.PID;
            string serial = this._adtRecord.PortAddress.hidAddr.Serial;
            WDS_MainProg.frameWin().DisablePlugAndPlay();
            if (!this._adtRecord.DeviceInfo.BootloaderMode)
            {
                if (!this.EnterBootloadMode())
                {
                    callback(0, true, "There was an error trying to enter booload mode.", MessageBoxButtons.OK);
                    WDS_MainProg.frameWin().RestorePlugAndPlay();
                    return FirmwareDownloadResult.StoppedWithError;
                }
                ADTManager.instance().removeADTRecord(this._adtRecord);
                this._ddi.close(this._adtRecord.PortAddress.handle);
                Thread.Sleep(100);
                wait = new FormWait(vID, pID, serial, true, 0x1388, 100) {
                    Text = "Enumerating Bootloader..."
                };
                if (wait.ShowDialog() != DialogResult.OK)
                {
                    callback(0, true, "There was an error trying to reenumerate in bootload mode.", MessageBoxButtons.OK);
                    WDS_MainProg.frameWin().RestorePlugAndPlay();
                    return FirmwareDownloadResult.StoppedWithError;
                }
            }
            else
            {
                this._ddi.close(this._adtRecord.PortAddress.handle);
                ADTManager.instance().removeADTRecord(this._adtRecord);
            }
            FDResult result2 = this.WriteFirmwareToDevice(firmware, callback, vID, pID, serial, firmwarePath);
            wait = new FormWait(vID, pID, serial, false, 0x1388, 100) {
                Text = "Enumerating Device..."
            };
            if (wait.ShowDialog() == DialogResult.OK)
            {
                this._adtRecord.PortAddress.handle = DDI_HID.instance().open(this._adtRecord, ' ');
                this._adtRecord.DeviceInfo = this._adtRecord.PortAddress.handle.HIDhnd.hnd.ADT.DeviceInfo;
            }
            WDS_MainProg.frameWin().RestorePlugAndPlay();
            switch (result2)
            {
                case FDResult.OK:
                    return FirmwareDownloadResult.OK;

                case FDResult.Error:
                    return FirmwareDownloadResult.StoppedWithError;

                case FDResult.FatalError:
                    return FirmwareDownloadResult.StoppedWithFatalError;
            }
            return FirmwareDownloadResult.StoppedWithError;
        }