/// <summary> /// Format the internal SD memory card in the ADCP. /// Give a warning before formating. /// </summary> private void FormatInternalStorage() { System.Windows.Application.Current.Dispatcher.BeginInvoke(new System.Action(() => { // Check if the user is ok with formating System.Windows.MessageBoxResult result = Xceed.Wpf.Toolkit.MessageBox.Show("Are you sure you would like to format the ADCP's internal SD card?\nThe data can not be recovered if formated.\nEnsure you have downloaded all the data from the ADCP before proceeding.", "Format Warning", System.Windows.MessageBoxButton.YesNo, System.Windows.MessageBoxImage.Warning); if (result == System.Windows.MessageBoxResult.Yes) { // Send the command to format the SD card _adcpConnection.SendData(Commands.AdcpCommands.CMD_DSFORMAT); // Refresh the internal storage usage CheckMemoryCard(); } })); }
/// <summary> /// Download the data from the ADCP. This will download the file selected /// in the list. /// </summary> private void DownloadData() { // The D command will cancel any pending downloads // Send it twice to first ignore the last packet sent, then // stop the download process _adcpConn.SendData(string.Format("{0}", RTI.Commands.AdcpCommands.CMD_DS_CANCEL)); _adcpConn.SendData(string.Format("{0}", RTI.Commands.AdcpCommands.CMD_DS_CANCEL)); // Turn off updating the serial data _isDownloadingData = true; _eventAggregator.PublishOnUIThread(new AdcpStatus(eAdcpStatus.Downloading)); this.NotifyOfPropertyChange(() => this.CanDownloadData); this.NotifyOfPropertyChange(() => this.CanCancelDownload); this.NotifyOfPropertyChange(() => this.CanPopulateDownloadList); this.NotifyOfPropertyChange(() => this.CanFormatSdCard); // Reset any previous cancels // Reset the wait if has been set previously _eventWaitDownload.Reset(); _downloadComplete = false; _cancelDownload = false; // Get the number of files selected // to monitor the progress DownloadListSize = 0; DownloadListProgress = 0; _downloadFailList = new List <string>(); this.NotifyOfPropertyChange(() => this.DownloadFails); DownloadFileName = ""; foreach (DownloadFile file in DownloadFileList) { if (file.IsSelected) { DownloadListSize++; } } // Check if the bg worker is cancelled if (_cancelDownload) { //e.Cancel = true; return; } // Go through each file in the list for (int x = 0; x < DownloadFileList.Count; x++) { // Set the flag for the download process to determine // if a timeout or completed download occured _downloadComplete = false; // Check if the bg worker is cancelled if (_cancelDownload) { return; } // If the file is selected // Download the data if (DownloadFileList[x].IsSelected) { // Initialize the values DownloadFileSize = 0; DownloadFileProgress = 0; DownloadFileName = DownloadFileList[x].FileInfo.FileName; // Create the directory if the folder // does not exist if (!CreateDirectory(DownloadDirectory)) { // If there was a issue creating // the directory stop now //e.Cancel = true; return; } // Create the file path string path = DownloadDirectory + "\\" + DownloadFileList[x].FileInfo.FileName; // If the file already exist, check if the user // wants the file overwritten if (!OverwriteDownloadFiles) { // Skip the file if it exist if (File.Exists(path)) { // Move to the next file DownloadListProgress++; _downloadComplete = true; _eventWaitDownload.Set(); } else { // Download the data from the serial port DownloadData(DownloadFileList[x].FileInfo.FileName); } } else { // Download the data from the serial port DownloadData(DownloadFileList[x].FileInfo.FileName); } // Wait until the complete event is received // before starting the next download // If a timeout occurs it either means the download took too // long or the download is hung. _eventWaitDownload.WaitOne(1000 * 60 * DownloadTimeout); // If this flag was not set, // then a timeout occurred and // consider the download for this // file a failure. if (!_downloadComplete) { DownloadFail(DownloadFileList[x].FileInfo.FileName); } // Allow the RS-485 to reset before moving to the next file Thread.Sleep(AdcpSerialPort.WAIT_STATE); } } // Check if the bg worker is cancelled if (_cancelDownload) { return; } // Retry downloading failed files RetryDownloadFails(); // Complete the download process On_DownloadDataCompleted(); }