//THIS IS THE MAIN CODE THAT RUNS WHEN THE BUTTON IS CLICKED public void MainProcess() { int BufferErrorIncrementer = 0; GoToForBufferingErrorRetry: try { Setup(); ReadCounterID(); CheckRequirements(); //check that necessary stuff is plugged in ReadBarcode(); //come back to this //read scanned barcode (MAC address) from text box parameters.SetSerialNumber(); UpdateOutputText("Opening USB port..."); thisUSB.OpenPort(parameters.USB_under_test_pid, 6000); //open up the usb port enableResetLine(); //enable control of the reset line on the dongle by applying new EEPROM settings to the FTDI chip (takes a few sec) thisUSB.ChipReset(); //load ssl using RAMLoader thisUSB.adjustBaudRate(Parameters.BaudRate_SSL); RAMLoader loadSSL = new RAMLoader(parameters, thisUSB, parameters.SSLfilepath, this); loadSSL.Run(true); thisUSB.adjustBaudRate(Parameters.BaudRate_SSL); //increase the baud rate 8x, saves six seconds on loading (goes from 14 to 8) SSLInterface ssl = new SSLInterface(parameters, thisUSB); FirmwareLoader fwloader = new FirmwareLoader(parameters, thisUSB, this); fwloader.EraseSector24(ssl); SetCrystalTrim(); //program the trim adjustment values for the crystal clock (depending on options set in Settings.txt) fwloader.LoadTrimsOnly(ssl); thisUSB.Close(); Finish(); //items to only do once totally successful: Logger(); UpdateProgressBar_Overall(progressBar_overall.Maximum); SaveSerialNumber(); UpdateColorDisplay("green"); UpdatePictureDisplay("pass");//add pic @20120402 by Nino Liu //add serial number @20120328 by nino if (parameters.testing && parameters.loading) UpdateOutputText("Test and load with MAC: " + parameters.MAC + '\n' + "Serial number: " + parameters.SN + '\n' + "Spent time: " + parameters.totaltesttime + " seconds."+ '\n' + "Optimal Frequency: " + parameters.frequency_measured); else if (parameters.loading) UpdateOutputText("Loading with MAC: " + parameters.MAC + '\n' + "Serial number: " + parameters.SN + '\n' + "Spent time: " + parameters.totaltesttime + " seconds." + '\n' + "Optimal Frequency: " + parameters.frequency_measured); else UpdateOutputText("Testing with MAC: " + parameters.MAC + '\n' + "Serial number: " + parameters.SN + '\n' + "Spent time: " + parameters.totaltesttime + " seconds." + '\n' + "Optimal Frequency: " + parameters.frequency_measured); } catch (Exception_Yellow e) { ExceptionHandler(e, "yellow"); } catch (Exception_Red e) { ExceptionHandler(e, "red"); } catch (Exception e) { if (e.Message.Contains("supplied buffer is not big enough")) { BufferErrorIncrementer++; if (BufferErrorIncrementer > 3) Output.Text = "Persistent buffering error -- unplug and replug dongle and try again. If error persists, dongle fails."; else { Output.Text = "Buffering error -- restarting after 2 seconds."; UpdateColorDisplay("orange"); System.Windows.Forms.Application.DoEvents(); System.Threading.Thread.Sleep(2000); goto GoToForBufferingErrorRetry; } } ExceptionHandler(e, "generic"); } }
public void LoadFirmware() { UpdateOutputText("Resetting chip..."); thisUSB.ChipReset(); UpdateOutputText("Loading secondary stage loader..."); FirmwareLoader loadFW = new FirmwareLoader(parameters, thisUSB, this);//, parameters.FWimagefilepath); loadFW.Run(); //loadFW.LoadHardwareSettings(); UpdateProgressBar_Overall(95); }