static void Main(string[] args) { if (args.Length == 0) { Console.WriteLine("Error processing request."); Console.WriteLine(""); Console.WriteLine("Syntax:"); Console.WriteLine("DFUDeploy [file] [options]"); Console.WriteLine(""); Console.WriteLine("Options:"); Console.WriteLine("\t/c"); Console.WriteLine("\tClears all memory. By default only the bootloader memory is erased."); Console.WriteLine("\tWith this option your NETMF runtime and deployment will also be erased."); Console.WriteLine(""); Console.WriteLine("\t/x"); Console.WriteLine("\tExits DFU mode after updating the bootloader."); Console.WriteLine(""); Console.WriteLine("\t/?"); Console.WriteLine("\tLists devices memory map."); Console.WriteLine(""); Console.WriteLine("WARNING: This tool will deploy to the first USB device found in DFU mode."); Console.WriteLine(""); return; } try { if (!firmwareUpdate.IsDFUDeviceFound()) { throw new Exception("No devices in DFU mode were found."); } if (args.Contains("/c") || args.Contains("/C")) { firmwareUpdate.OnFirmwareUpdateProgress += new FirmwareUpdateProgressEventHandler(firmwareUpdate_OnFirmwareUpdateProgress); UInt16 VID; UInt16 PID; UInt16 Version; try { firmwareUpdate.ParseDFU_File(args[0], out VID, out PID, out Version); } catch (Exception ex) { throw new Exception("Error parsing DFU file. " + ex.Message, ex); } Console.WriteLine("Found VID: " + VID.ToString("X4") + " PID: " + PID.ToString("X4") + " Version: " + Version.ToString("X4")); } try { bool eraseEveything = false; bool exitDFUMode = false; //The cC switch erases everything from the chip if (args.Contains("/c") || args.Contains("/C")) { eraseEveything = true; } //The xX switch exits the device from DFU mode if (args.Contains("/x") || args.Contains("/X")) { exitDFUMode = true; } firmwareUpdate.UpdateFirmware(args[0], eraseEveything, exitDFUMode); } catch (Exception ex) { throw new Exception("Error deploying DFU file. " + ex.Message, ex); } Console.WriteLine("Done."); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } }
private void button1_Click(object sender, EventArgs e) { if (!firmware_update_registered) { firmwareUpdate.OnFirmwareUpdateProgress += new FirmwareUpdateProgressEventHandler(firmwareUpdate_OnFirmwareUpdateProgress); firmware_update_registered = true; } FirmwareUpdateProgressEventArgs fupea; progressBar1.Maximum = 100; progressBar1.Step = 1; progressBar1.Value = 0; statusText = ""; statusTextbox.Clear(); progressBar1.Visible = true; Application.DoEvents(); fupea = new FirmwareUpdateProgressEventArgs(0, "Detecting DFU Interface...", false); firmwareUpdate_OnFirmwareUpdateProgress(this, fupea); if (port.IsOpen) { close_port(); } bool is_dfu_available = false; Cursor.Current = Cursors.WaitCursor; Application.DoEvents(); try { is_dfu_available = firmwareUpdate.IsDFUDeviceFound(); } catch (Exception ex) { fupea = new FirmwareUpdateProgressEventArgs(0, ex.Message, true); firmwareUpdate_OnFirmwareUpdateProgress(this, fupea); } if (!is_dfu_available) { Cursor.Current = Cursors.Default; progressBar1.Visible = false; Application.DoEvents(); dialog_in_progress = true; MessageBox.Show("To update navX-Model Firmware, ensure the device is in Firmware Update Mode.\n\n" + "1. Disconnect the device from the PC USB port.\n" + "2. Ensure the device has completely powered down (the RED 3.3V LED must be off).\n" + "3. While holding down the 'CAL' button, re-connect the device to the PC USB port.\n\n" + "4. After the device has powered up, release the 'CAL' button.\n" + "When in DFU mode, only the RED power LED will be ON.", "navX-Model Firmware Update", MessageBoxButtons.OK, MessageBoxIcon.Warning); dialog_in_progress = false; return; } String dfu_file_name = Path.GetTempPath() + "navx.dfu"; bool converted = hex2dfu.ConvertHexToDFU(full_path_to_hex_file, dfu_file_name, theVid, thePid, theBcd); if (!converted) { Cursor.Current = Cursors.Default; progressBar1.Visible = false; Application.DoEvents(); dialog_in_progress = true; MessageBox.Show("Error converting " + navXHexFilePath.Text + " to DFU format.", "navX-Model Firmware Update", MessageBoxButtons.OK, MessageBoxIcon.Error); dialog_in_progress = false; return; } UInt16 VID; UInt16 PID; UInt16 Version; try { firmwareUpdate.ParseDFU_File(dfu_file_name, out VID, out PID, out Version); } catch (Exception ex) { Cursor.Current = Cursors.Default; progressBar1.Visible = false; Application.DoEvents(); fupea = new FirmwareUpdateProgressEventArgs(0, "Error parsing DFU file. " + ex.Message, false); firmwareUpdate_OnFirmwareUpdateProgress(this, fupea); dialog_in_progress = true; MessageBox.Show("Error parsing DFU file. " + ex.Message, "navX-Model Firmware Update", MessageBoxButtons.OK, MessageBoxIcon.Error); dialog_in_progress = false; return; } fupea = new FirmwareUpdateProgressEventArgs(0, ("Found VID: " + VID.ToString("X4") + " PID: " + PID.ToString("X4") + " Version: " + Version.ToString("X4")), false); firmwareUpdate_OnFirmwareUpdateProgress(this, fupea); try { bool eraseEveything = false; bool exitDFUMode = true; firmwareUpdate.UpdateFirmware(dfu_file_name, eraseEveything, exitDFUMode); } catch (Exception ex) { Cursor.Current = Cursors.Default; progressBar1.Visible = false; Application.DoEvents(); fupea = new FirmwareUpdateProgressEventArgs(0, "Error deploying DFU file. " + ex.Message, true); firmwareUpdate_OnFirmwareUpdateProgress(this, fupea); dialog_in_progress = true; MessageBox.Show("Error deploying DFU file. " + ex.Message, "navX-Model Firmware Update", MessageBoxButtons.OK, MessageBoxIcon.Error); dialog_in_progress = false; return; } progressBar1.Visible = false; Cursor.Current = Cursors.Default; }
private void mainCameraSetupDialog() { try { Log.Write(String.Format("SetupDialog, description = {0}\n", description)); SetupDialogForm F = new SetupDialogForm(); F.Version.Text = String.Format("Version: {0}", SharedResources.versionNumber); F.EnableLoggingCheckBox.Checked = enableLogging; F.EnableUntestedCheckBox.Checked = enableUntested; F.dumpDataEnabled.Checked = bDumpData; F.useDumpedData.Checked = bUseDumpedData; // some cameras cannot bin. // If this camera can't bin, disble the binGroup so binning cannot be modified. if (maxXBin > 1) { F.binGroup.Enabled = true; } else { F.binGroup.Enabled = false; } F.colorBinning.Checked = colorBinning; if (asymetricBinning) { F.asymetricBinning.Checked = true; F.binLabel.Text = "Max Y Bin"; F.xBinLabel.Visible = true; F.maxXBin.Visible = true; } else { F.asymetricBinning.Checked = false; F.binLabel.Text = "Max Bin"; F.xBinLabel.Visible = false; F.maxXBin.Visible = false; } F.maxXBin.Value = maxXBin; F.maxYBin.Value = maxYBin; F.fixedBinning.Checked = fixedBinning; F.fixedBin.Enabled = F.fixedBinning.Checked; F.fixedBin.Value = fixedBin; // interlaced box F.equalizeFrames.Checked = interlacedEqualizeFrames; F.squareLodestarPixels.Checked = squareLodestarPixels; F.doubleExposeShort.Checked = interlacedDoubleExposeShortExposures; F.doubleExposureThreshold.Enabled = F.doubleExposeShort.Checked; F.doubleExposureThreshold.Value = interlacedDoubleExposureThreshold; F.gaussianBlur.Checked = interlacedGaussianBlur; F.gaussianBlurRadius.Enabled = F.gaussianBlur.Checked; F.gaussianBlurRadius.Value = (decimal)interlacedGaussianBlurRadius; F.waitForCooldown.Checked = waitForCooldown; F.hardwareExposureThreshold.Value = (decimal)hardwareExposureThreshold; // advanced USB box F.selectionAllowAny.Checked = false; F.selectionExactModel.Checked = false; F.selectionExcludeModel.Checked = false; F.VID.Text = VID.ToString(); F.PID.Text = PID.ToString(); F.vidLabel.Visible = true; F.pidLabel.Visible = true; F.VID.Visible = true; F.PID.Visible = true; switch (selectionMethod) { case CAMERA_SELECTION_METHOD.CAMERA_SELECTION_ANY: F.selectionAllowAny.Checked = true; F.vidLabel.Visible = false; F.pidLabel.Visible = false; F.VID.Visible = false; F.PID.Visible = false; break; case CAMERA_SELECTION_METHOD.CAMERA_SELECTION_EXACT_MODEL: F.selectionExactModel.Checked = true; break; case CAMERA_SELECTION_METHOD.CAMERA_SELECTION_EXCLUDE_MODEL: F.selectionExcludeModel.Checked = true; break; default: throw new System.Exception(String.Format("Unknown Camera Selection Method {0} in SetupDialog", selectionMethod)); } F.advancedUSBParmsEnabled.Checked = false; F.usbGroup.Enabled = false; if (F.ShowDialog() == DialogResult.OK) { Log.Write("ShowDialog returned OK - saving parameters\n"); enableLogging = F.EnableLoggingCheckBox.Checked; enableUntested = F.EnableUntestedCheckBox.Checked; bDumpData = F.dumpDataEnabled.Checked; bUseDumpedData = F.useDumpedData.Checked; // interlaced box interlacedEqualizeFrames = F.equalizeFrames.Checked; squareLodestarPixels = F.squareLodestarPixels.Checked; interlacedDoubleExposeShortExposures = F.doubleExposeShort.Checked; if (interlacedDoubleExposeShortExposures) { interlacedDoubleExposureThreshold = (UInt16)F.doubleExposureThreshold.Value; } interlacedGaussianBlur = F.gaussianBlur.Checked; if (interlacedGaussianBlur) { interlacedGaussianBlurRadius = (double)F.gaussianBlurRadius.Value; } waitForCooldown = F.waitForCooldown.Checked; hardwareExposureThreshold = (double)F.hardwareExposureThreshold.Value; // binning box colorBinning = F.colorBinning.Checked; fixedBinning = F.fixedBinning.Checked; if (fixedBinning) { fixedBin = (byte)F.fixedBin.Value; } asymetricBinning = F.asymetricBinning.Checked; maxYBin = (byte)F.maxYBin.Value; if (asymetricBinning) { maxXBin = maxYBin; } else { maxXBin = (byte)F.maxXBin.Value; } // advanced usp box if (F.selectionAllowAny.Checked) { selectionMethod = Configuration.CAMERA_SELECTION_METHOD.CAMERA_SELECTION_ANY; } else { bool error = false; try { VID = Convert.ToUInt16(F.VID.Text); } catch (System.FormatException ex) { error = true; Log.Write(String.Format("Caught an exception converting VID [{0}] to UInt16: {1}", F.VID.Text, ex.ToString())); MessageBox.Show("An invalid VID was entered. Value was not changed"); } try { PID = Convert.ToUInt16(F.PID.Text); } catch (System.FormatException ex) { error = true; Log.Write(String.Format("Caught an exception converting PID [{0}] to UInt16: {1}", F.PID.Text, ex.ToString())); MessageBox.Show("An invalid PID was entered. Value was not changed"); } if (!error) { if (F.selectionExactModel.Checked) { selectionMethod = Configuration.CAMERA_SELECTION_METHOD.CAMERA_SELECTION_EXACT_MODEL; } else { selectionMethod = Configuration.CAMERA_SELECTION_METHOD.CAMERA_SELECTION_EXCLUDE_MODEL; } } } } } catch (ASCOM.DriverException ex) { throw ex; } catch (System.Exception ex) { Log.Write(String.Format("Unable to complete SetupDialog request - ex = {0}\n", ex.ToString())); throw ex; } }