private void IsConnectedTimer_Tick(object sender, EventArgs e) { Ping(); if (IsConnectedTimer.Interval.Seconds > 1) { IsConnectedTimer.Stop(); IsConnectedTimer.Interval = new TimeSpan(0, 0, 1); IsConnectedTimer.Start(); } }
protected void ResetButtonHandler() { // If the User clicked the Reset button on the Device Configuration page, // then we should stop the connection polling to allow the User to choose // a different peripheral on the same device. if (DeviceModel.IsSerial) { IsConnectedTimer.Stop(); } if (DeviceModel.IsUsbHid) { AutoConnectUSBDevice = false; } Reset(); }
private async Task Update(UpdaterViewModel updaterModel, IProgress <blfwkdll.Updater.UpdaterOperationProgressData> progress, CancellationToken token = new CancellationToken()) { #if (TEST_WINDOW_LOGIC) blfwkdll.Updater.UpdaterOperationProgressData dummyOpData = new blfwkdll.Updater.UpdaterOperationProgressData(new blfwkdll.Updater.UpdaterEnum(0, "Updating...")); dummyOpData.Tasks.Add(new blfwkdll.Updater.UpdaterTask(new blfwkdll.Updater.UpdaterEnum(0, "Erasing..."), 0, 100)); dummyOpData.Tasks.Add(new blfwkdll.Updater.UpdaterTask(new blfwkdll.Updater.UpdaterEnum(1, "Writing..."), 0, 100)); for (int j = 0; j < dummyOpData.Tasks.Count; ++j) { dummyOpData.CurrentTaskIndex = j; if (progress != null) { progress.Report(dummyOpData); } for (UInt32 i = 10; i <= dummyOpData.Tasks[j].Total; i += 10) { dummyOpData.Tasks[j].CurrentPosition = i; if (progress != null) { progress.Report(dummyOpData); } await Task.Delay(TimeSpan.FromSeconds(.1), token).ConfigureAwait(false); if (j == 1 && i == 20) { throw new Exception("The updater threw an error."); } } } #else Updater.setCallback(UpdaterProgress); await Task.Run(() => { try { if (DeviceModel.IsSerial) { IsConnectedTimer.Stop(); } if (InSecurity) { if (UnlockWithBackdoorKey == true) { Updater.unlockWithKey(BackdoorKey); } else if (FlashEraseAllUnsecure == true) { Updater.eraseAllUnsecure(); } Status = "Unlocked"; } //Updater.flashFirmware(ImageFileModel.FullPath, ImageFileModel.BaseAddress); Updater.flashFirmware(this.ImageFileModel.FullPath, this.ImageFileModel.BaseAddress); // TODO: handle exceptions! (see below ...) Reset(); if (DeviceModel.IsSerial) { Status = "Complete! Waiting for application to start."; } else { Status = "Complete! Press Reset button to start application."; } Value = 100; if (DeviceModel.IsSerial) { IsConnectedTimer.Interval = new TimeSpan(0, 0, 10); IsConnectedTimer.Start(); } } catch (Exception e) { if (DeviceModel.IsSerial) { IsConnectedTimer.Start(); } throw e; } }, token); #endif } // Update()