/// <summary> /// Main method where all the action happens. /// Called by the Upload button. /// </summary> private void ButtonUpload_Click(object sender, EventArgs e) { // Clear the output box Debug.WriteLine("Clearing the output textboxes..."); this.textActivity.Clear(); this.textVerbose.Clear(); this.progressBar1.Value = 0; // Check if the file exists if (!File.Exists(this.textFileName.Text)) { this.AppendLog(string.Format("File {0} does not exist", this.textFileName.Text)); MessageBox.Show("Firmware file does not exist.", "Write Firmware", MessageBoxButtons.OK, MessageBoxIcon.Error); this.EnableControls(true); return; } // Check that the file size is OK // Max size is 120,832B (118KB) with bootloader, 129,024B (126KB) without int maxFileSize = 129024; if (this.writeBootloader_Yes.Checked) { maxFileSize = 120832; } long length = new System.IO.FileInfo(this.textFileName.Text).Length; if (length > maxFileSize) { this.AppendLog(string.Format("Firmware file is too large.\r\nFile is {1:n0} KB, maximum size is {2:n0} KB.", this.textFileName.Text, length / 1024, maxFileSize / 1024)); MessageBox.Show("Firmware file is too large.", "Write Firmware", MessageBoxButtons.OK, MessageBoxIcon.Error); this.EnableControls(true); return; } // Get the selected COM port string comPort = this.comPortSelector.SelectedValue.ToString(); // Check if the port can be opened if (!ComPort.CheckPort(comPort)) { this.AppendLog(string.Format("Couldn't open port {0}", comPort)); MessageBox.Show(string.Format("Couldn't open port {0}", comPort), "Write Firmware", MessageBoxButtons.OK, MessageBoxIcon.Error); this.EnableControls(true); return; } // Disable the buttons until this flash attempt is complete Debug.WriteLine("Disabling the controls..."); this.EnableControls(false); // Determine if we should use Maple or serial interface MapleDevice mapleResult = MapleDevice.FindMaple(); if (mapleResult.DeviceFound == true) { this.AppendLog(string.Format("Maple device found in {0} mode\r\n", mapleResult.Mode)); } // Do the selected flash using the appropriate method if (mapleResult.DeviceFound == true) { // MapleFlashWrite(textFileName.Text, comPort); MapleDevice.WriteFlash(this, this.textFileName.Text, comPort); } else { SerialDevice.WriteFlash(this, this.textFileName.Text, comPort); } }