public void CheckConnections(ref bool counterattached, ref bool refradioattached)
 {
     if (parameters.crystaltrimming)
     {
         try
         {
             Trimmer_NI4882.testtrimmerisattached(parameters.counter_id);
         }
         catch (Exception exc)
         {
             if (exc.Message.Contains("GPIB") || exc.Message.Contains("handle is out of range")) exc = new Exception_Yellow("Error involving the frequency counter or GPIB connection (" + exc.Message + " 1).  Confirm that the GPIB cable is plugged into both the computer and the frequency counter, or turn off crystal trimming in the settings file.");
             UpdateOutputText(exc.Message);
             counterattached = false;
         }
     }
     if (parameters.testing)
     {
         try
         {
             referenceRadio = new FTDIdevice(parameters, this);
             referenceRadio.OpenPort(parameters.reference_radio_pid, 3000);
             parameters.refradioplugged = true;
             UpdateProgressBar_Detail(0);
         }
         catch (Exception exc)
         {
             UpdateOutputText(exc.Message);
             refradioattached = false;
         }
     }
 }
        public void ExceptionHandler(Exception ex, string category)
        {
            try
            {
                thisUSB.SetEEPROMaftererror();    //temp useful for debugging if there are write issues, avoids using FT_prog if program stops before SetEEPROM. But causes trouble if there is no board attached.
                thisUSB.Close();
            }
            catch(Exception ee){}

            Finish();
            SelectScannerInputBox("");
            RunButtonEnabled(1);
            if (ex.Message.Contains("GPIB") || ex.Message.Contains("handle is out of range"))
            {
                ex = new Exception_Yellow("Error involving the frequency counter or GPIB connection (" + ex.Message + " 2).  Confirm that the GPIB cable is plugged into both the computer and the frequency counter, or turn off crystal trimming in the settings file.");
                category = "yellow";
            }
            UpdateOutputText(ex.Message);
            UpdateColorDisplay(category);
            UpdatePictureDisplay("fail");
            if (category == "yellow")
                AppendToOutputText("\n\nPlease unplug and re-plug USB and try test again.");
            else if (category == "red")
                AppendToOutputText("\n" +  "\n" +  "USB fails; please remove and discard.");
            else if (category == "generic")
            {
                if (ex.Message.Contains("NationalInstruments")) UpdateOutputText("Trimming error. Most likely cause is that this computer does not have the National Instruments GPIB software necessary to communicate with the frequency counter.  Disable trimming in the Settings.txt file to avoid this error.");
                AppendToOutputText("\n\nPlease unplug and re-plug USB and try test again.");
            }
            ErrorLogger(ex.Message);
        }