Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
        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);
            }
        }