private void PopulateComPorts() { object selectedItem = null; selectedItem = comPortSelector.SelectedItem; string[] comPorts = SerialPort.GetPortNames(); comPortSelector.Items.Clear(); foreach (string port in comPorts) { comPortSelector.Items.Add(port); } Thread.Sleep(50); // Check if we should add the DFU device (purely cosmetic, not really required) MapleTools.FindMapleResult mapleCheck = MapleTools.FindMaple(); if (mapleCheck.Device.DfuMode) { comPortSelector.Items.Add("DFU Device"); comPortSelector.SelectedValue = "DFU Device"; } comPortSelector.SelectedItem = selectedItem; CheckControls(); }
private async void MapleFlashWrite(string fileName, string comPort) { string command; string commandArgs; int returnCode = -1; AppendLog("Starting Multimodule update\r\n"); string mapleMode = MapleTools.FindMaple().Device.Mode; if (mapleMode == "USB") { AppendLog("Switching Multimodule into DFU mode ..."); command = ".\\bin\\maple-reset.exe"; commandArgs = comPort; await Task.Run(() => { returnCode = RunCommand(command, commandArgs); }); if (returnCode != 0) { EnableControls(true); AppendLog(" failed!"); MessageBox.Show("Failed to get module to DFU mode.", "Firmware Update", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } AppendLog(" done\r\n"); // Check for a Maple DFU device AppendLog("Waiting for DFU device ..."); bool dfuCheck = false; int counter = 0; dfuCheck = MapleTools.FindMaple().Device.DfuMode; while (dfuCheck == false && counter < 20) { Thread.Sleep(50); dfuCheck = MapleTools.FindMaple().Device.DfuMode; counter++; } if (dfuCheck) { AppendLog(" got it\r\n"); } else { AppendLog(" failed!"); MessageBox.Show("Failed to find module in DFU mode.", "Firmware Update", MessageBoxButtons.OK, MessageBoxIcon.Error); EnableControls(true); return; } } // Flash firmware AppendLog("Writing firmware to Multimodule ..."); command = ".\\bin\\dfu-util.exe"; commandArgs = String.Format("-R -a 2 -d 1EAF:0003 -D \"{0}\"", fileName, comPort); await Task.Run(() => { returnCode = RunCommand(command, commandArgs); }); if (returnCode != 0) { EnableControls(true); AppendLog(" failed!"); MessageBox.Show("Failed to write the firmware.", "Firmware Update", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } AppendLog(" done\r\n"); AppendLog("\r\nMultimodule updated sucessfully"); MessageBox.Show("Multimodule updated sucessfully.", "Firmware Update", MessageBoxButtons.OK, MessageBoxIcon.Information); EnableControls(true); }
private void ButtonUpload_Click(object sender, EventArgs e) { // Clear the output box Debug.WriteLine("Clearing the output textboxes..."); textActivity.Clear(); textVerbose.Clear(); progressBar1.Value = 0; // Check if the file exists if (!File.Exists(textFileName.Text)) { AppendLog(String.Format("File {0} does not exist", textFileName.Text)); MessageBox.Show("Fimrware file does not exist.", "Write Firmware", MessageBoxButtons.OK, MessageBoxIcon.Error); EnableControls(true); return; } // Check that the file size is OK - max size is 120,832B (118KB) to allow for bootloader and EEPROM emulation int maxFileSize = 120832; long length = new System.IO.FileInfo(textFileName.Text).Length; if (length > maxFileSize) { AppendLog(String.Format("Firmware file is too large.\r\nFile is {1:n0} KB, maximum size is {2:n0} KB.", textFileName.Text, length / 1024, maxFileSize / 1024)); MessageBox.Show("Firmware file is too large.", "Write Firmware", MessageBoxButtons.OK, MessageBoxIcon.Error); EnableControls(true); return; } // Get the selected COM port string comPort = comPortSelector.SelectedItem.ToString(); // Check if the port can be opened if (!PortCheck(comPort)) { 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); EnableControls(true); return; } // Disable the buttons until this flash attempt is complete Debug.WriteLine("Disabling the controls..."); EnableControls(false); // Determine if we should use Maple or serial interface MapleTools.FindMapleResult mapleResult = MapleTools.FindMaple(); if (mapleResult.MapleFound == true) { AppendLog(String.Format("Maple device found in {0} mode\r\n", mapleResult.Device.Mode)); } // Do the selected flash using the appropriate method if (mapleResult.MapleFound == true) { MapleFlashWrite(textFileName.Text, comPort); } else { SerialFlashWrite(textFileName.Text, comPort); } }