protected bool SerchCoefPoints1E12(Attennuator tempAtt, ErrorDetector tempED, double startAttValue, double targetBer, double addStep, double sumStep, out ArrayList AttenPoints, out ArrayList BerPints) { byte i = 0; double currentBer = 0; //AttenPoints[]= AttenPoints = new ArrayList(); BerPints = new ArrayList(); AttenPoints.Clear(); BerPints.Clear(); do { tempAtt.AttnValue(startAttValue.ToString()); Thread.Sleep(200); currentBer = tempED.GetErrorRate(); if (currentBer != 0) { AttenPoints.Add(startAttValue); BerPints.Add(currentBer); } if (currentBer > targetBer) { startAttValue += addStep; } else { startAttValue -= sumStep; } i++; } while (i < 8 && (currentBer > (targetBer * 100))); return(true); }
protected UInt32 EnumMethod(UInt32[] inPutArray, DUT dut, ErrorDetector ed, byte substep, out ArrayList berArray, out ArrayList apdDacArray, out double minBer) { berArray = new ArrayList(); apdDacArray = new ArrayList(); UInt32 minimumDAC; for (byte i = 0; i < inPutArray.Length; i++) { // add write APD dut.WriteAPDDac(inPutArray[i]); apdDacArray.Add(inPutArray[i]); ed.GetErrorRate(); berArray.Add(ed.GetErrorRate()); } minBer = -1; byte minIndex = 0; #region Select minimum value minBer = Algorithm.SelectMinValue(berArray, out minIndex); minimumDAC = inPutArray[minIndex]; #endregion #region Fine Tune Target Value dut.WriteAPDDac(Algorithm.Uint16DataConvertoBytes((UInt16)(inPutArray[minIndex] + substep))); double tempBer1 = ed.GetErrorRate(); dut.WriteAPDDac(Algorithm.Uint16DataConvertoBytes((UInt16)(inPutArray[minIndex] - substep))); double tempBer2 = ed.GetErrorRate(); double mintempBer = Math.Min(tempBer1, tempBer2); if (mintempBer == tempBer1) { if (minBer > tempBer1) { minimumDAC = Convert.ToUInt16(minimumDAC + substep); apdDacArray.Add(minimumDAC); dut.WriteAPDDac(minimumDAC); minBer = ed.GetErrorRate(); berArray.Add(minBer); } } else { if (minBer > tempBer2) { minimumDAC = Convert.ToUInt16(minimumDAC - substep); apdDacArray.Add(minimumDAC); dut.WriteAPDDac(minimumDAC); minBer = ed.GetErrorRate(); berArray.Add(minBer); } } #endregion return(minimumDAC); }
protected double SerchTargetPoint(Attennuator tempAtt, ErrorDetector tempED, double attValue, double targetBerLL, double targetBerUL, double addStep, double sumStep) { byte i = 0; double currentCense = 0; do { tempAtt.AttnValue(attValue.ToString()); Thread.Sleep(200); currentCense = tempED.GetErrorRate(); if (currentCense > targetBerUL) { attValue += addStep; } else { attValue -= sumStep; } i++; } while (i < 20 && (currentCense > targetBerUL || currentCense < targetBerLL)); return(attValue); }
protected override bool StartTest() { logger.FlushLogBuffer(); logoStr = ""; if (AnalysisInputParameters(inputParameters) == false) { return(false); } if (selectedEquipList["ATTEN"] != null && selectedEquipList["ERRORDETE"] != null && selectedEquipList["DUT"] != null && selectedEquipList["POWERSUPPLY"] != null) { Powersupply tempps = (Powersupply)selectedEquipList["POWERSUPPLY"]; // open apc string apcstring = null; dut.APCStatus(out apcstring); if (apcstring == "OFF" || apcstring == "FF") { logoStr += logger.AdapterLogString(0, "Step2...Start Open apc"); dut.APCON(); logoStr += logger.AdapterLogString(0, "Power off"); tempps.Switch(false); Thread.Sleep(200); logoStr += logger.AdapterLogString(0, "Power on"); tempps.Switch(true); Thread.Sleep(200); bool isOpen = dut.APCStatus(out apcstring); if (apcstring == "ON") { logoStr += logger.AdapterLogString(1, "APC ON"); } else { logoStr += logger.AdapterLogString(3, "APC NOT ON"); } } // open apc Attennuator tempAtten = (Attennuator)selectedEquipList["ATTEN"]; ErrorDetector tempED = (ErrorDetector)selectedEquipList["ERRORDETE"]; logoStr += logger.AdapterLogString(0, "Step3...SetAttenValue"); SetAttenValue(tempAtten, testBerStruct.CsenAlignRxPwr); Thread.Sleep(200); tempAtten.Switch(true); double attPoint = 0; logoStr += logger.AdapterLogString(0, "Step4...AutoAlaign"); bool isAutoAlaign = tempED.AutoAlaign(true); if (isAutoAlaign) { logoStr += logger.AdapterLogString(1, isAutoAlaign.ToString()); } else { logoStr += logger.AdapterLogString(4, isAutoAlaign.ToString()); logger.FlushLogBuffer(); return(isAutoAlaign); } if (isAutoAlaign) { if (testBerStruct.IsBerQuickTest == true) { tempAtten.AttnValue(testBerStruct.CsenStartingRxPwr.ToString()); Thread.Sleep(200); double sensitivity = tempED.GetErrorRate(); logoStr += logger.AdapterLogString(1, "SetAtten=" + testBerStruct.CsenStartingRxPwr.ToString()); if (sensitivity.ToString().ToUpper().Trim() == "NAN") { sensitivityPoint = -1000; AnalysisOutputParameters(outputParameters); logger.FlushLogBuffer(); return(false); } if (testBerStruct.CsenTargetBER == 1E-3) { if (sensitivity <= 1E-3) { sensitivityPoint = testBerStruct.CsenStartingRxPwr; } else { sensitivityPoint = -1000; logoStr += logger.AdapterLogString(4, "AttPoint=" + testBerStruct.CsenStartingRxPwr.ToString() + "CSENCE>1E-3 "); AnalysisOutputParameters(outputParameters); logger.FlushLogBuffer(); return(false); } } else if (testBerStruct.CsenTargetBER == 1E-12) { if (sensitivity <= 1E-12) { sensitivityPoint = testBerStruct.CsenStartingRxPwr; } else { sensitivityPoint = -1000; logoStr += logger.AdapterLogString(4, "AttPoint=" + testBerStruct.CsenStartingRxPwr.ToString() + "CSENCE>1E-12 "); AnalysisOutputParameters(outputParameters); logger.FlushLogBuffer(); return(false); } } sensitivityPoint = Math.Round(sensitivityPoint, 2); logoStr += logger.AdapterLogString(1, "sensitivityPoint= " + sensitivityPoint.ToString()); AnalysisOutputParameters(outputParameters); logger.FlushLogBuffer(); return(true); } else { logoStr += logger.AdapterLogString(0, "Step5...SerchTargetPoint"); attPoint = SerchTargetPoint(tempAtten, tempED, testBerStruct.CsenStartingRxPwr, testBerStruct.SearchTargetBerLL, testBerStruct.SearchTargetBerUL, testBerStruct.SearchTargetBerAddStep, testBerStruct.SearchTargetBerSubStep); logoStr += logger.AdapterLogString(1, "SetAtten=" + attPoint.ToString()); ArrayList attPoints; ArrayList berPoints; double intercept; double slope; logoStr += logger.AdapterLogString(0, "Step6...SerchCoefPoints"); if (testBerStruct.CsenTargetBER == 1E-3) { SerchCoefPointsTarget1E3(tempAtten, tempED, attPoint, testBerStruct.CsenTargetBER, testBerStruct.CoefCsenSubStep, testBerStruct.CoefCsenAddStep, out attPoints, out berPoints); byte tmepCount = (byte)Math.Min(attPoints.Count, berPoints.Count); double[] tempattPoints = new double[tmepCount]; double[] tempberPoints = new double[tmepCount]; for (byte i = 0; i < tmepCount; i++) { tempattPoints[i] = double.Parse(attPoints[i].ToString()); tempberPoints[i] = double.Parse(berPoints[i].ToString()); logoStr += logger.AdapterLogString(1, "attPoints[ " + i.ToString() + "]" + double.Parse(attPoints[i].ToString()) + " " + "berPoints[ " + i.ToString() + "]" + double.Parse(berPoints[i].ToString())); } algorithm.LinearRegression(algorithm.Getlog10(algorithm.GetNegative(algorithm.Getlog10(tempberPoints))), tempattPoints, out slope, out intercept); sensitivityPoint = slope + (intercept * System.Math.Log10(System.Math.Log10(testBerStruct.CsenTargetBER) * (-1))); } else if (testBerStruct.CsenTargetBER == 1E-12) { SerchCoefPoints1E12(tempAtten, tempED, attPoint, testBerStruct.CsenTargetBER, testBerStruct.CoefCsenSubStep, testBerStruct.CoefCsenAddStep, out attPoints, out berPoints); byte tmepCount = (byte)Math.Min(attPoints.Count, berPoints.Count); double[] tempattPoints = new double[tmepCount]; double[] tempberPoints = new double[tmepCount]; for (byte i = 0; i < tmepCount; i++) { tempattPoints[i] = double.Parse(attPoints[i].ToString()); tempberPoints[i] = double.Parse(berPoints[i].ToString()); logoStr += logger.AdapterLogString(1, "attPoints[ " + i.ToString() + "]" + double.Parse(attPoints[i].ToString()) + " " + "berPoints[ " + i.ToString() + "]" + double.Parse(berPoints[i].ToString())); } algorithm.LinearRegression(algorithm.Getlog10(algorithm.GetNegative(algorithm.Getlog10(tempberPoints))), tempattPoints, out slope, out intercept); sensitivityPoint = slope + (intercept * System.Math.Log10(System.Math.Log10(testBerStruct.CsenTargetBER) * (-1))); } if (sensitivityPoint.ToString().ToUpper().Trim() == "NAN") { sensitivityPoint = -1000; AnalysisOutputParameters(outputParameters); logger.FlushLogBuffer(); return(false); } sensitivityPoint = Math.Round(sensitivityPoint, 2); logoStr += logger.AdapterLogString(1, "sensitivityPoint= " + sensitivityPoint.ToString()); AnalysisOutputParameters(outputParameters); logger.FlushLogBuffer(); return(true); } } else { logger.FlushLogBuffer(); return(false); } } else { logoStr += logger.AdapterLogString(4, "Equipments is not enough!"); logger.FlushLogBuffer(); return(false); } }
protected bool SearchTargetPoint(out byte Index) { Index = 0; ArrayList serchAttPointsTemp = new ArrayList(); serchAttPointsTemp.Clear(); ArrayList serchAttPoints = serchAttPointsTemp; ArrayList serchBerPoints = serchAttPointsTemp; try { //double currentCense = 0; //byte count = 0; serchAttPoints = new ArrayList(); serchBerPoints = new ArrayList(); serchAttPoints.Clear(); serchBerPoints.Clear(); ArrayList StrLog = new ArrayList(); ushort[] rxADCs = new ushort[adjustAPDStruct.SetPoints.Length]; int count = 0; for (int i = 0; i < adjustAPDStruct.SetPoints.Length; i++) { dut.WriteAPDDac(adjustAPDStruct.SetPoints[i]); serchAttPoints.Add(adjustAPDStruct.SetPoints[i]); Thread.Sleep(200); double TempValue = pED.GetErrorRate(); if (Math.Abs(TempValue - 9.999E+17) < 1.0E-6) { count++;//记录误码不通的数量 } serchBerPoints.Add(TempValue); dut.ReadRxpADC(out rxADCs[i]); StrLog.Add("adjustAPDStruct.SetPoints[" + i + "] = " + adjustAPDStruct.SetPoints[i].ToString() + " " + " serchBerPoints[" + i + "] = " + TempValue + " RxADC[" + i + "] = " + rxADCs[i]); } for (int i = 0; i < StrLog.Count; i++) { Log.SaveLogToTxt(StrLog[i].ToString()); } if (count == adjustAPDStruct.SetPoints.Length)//如果全部不通 { return(false); } // byte Index; Algorithm.SelectMinValue(serchBerPoints, out Index); if (referenceRxADC_First == null) { referenceRxADC_First = new ushort[GlobalParameters.TotalChCount]; referenceTemp = GlobalParameters.CurrentTemp; } if (referenceTemp == GlobalParameters.CurrentTemp) { referenceRxADC_First[GlobalParameters.CurrentChannel - 1] = rxADCs[Index]; return(true); } ushort deltaRxADC = 65535; int index = Index; for (int i = 0; i < serchBerPoints.Count; i++) { if (Math.Abs(Convert.ToDouble(serchBerPoints[i]) - Convert.ToDouble(serchBerPoints[Index])) < 10 * Convert.ToDouble(serchBerPoints[Index])) { int delta = Math.Abs(rxADCs[i] - referenceRxADC_First[GlobalParameters.CurrentChannel - 1]); if (delta < deltaRxADC) { deltaRxADC = (ushort)delta; index = i; } } } Log.SaveLogToTxt("BestAPD = " + adjustAPDStruct.SetPoints[index] + " serchBerPoints = " + serchBerPoints[index] + " RxADC = " + rxADCs[index]); Index = (byte)index; return(true); } catch (InnoExCeption ex)//from driver { //Log.SaveLogToTxt(ex.ID + ": " + ex.Message + "\r\n" + ex.StackTrace); exceptionList.Add(ex); return(false); } catch (Exception error)//from itself { //one way: deal this exception itself InnoExCeption ex = new InnoExCeption(ExceptionDictionary.Code._0x02108, error.StackTrace); //Log.SaveLogToTxt(ex.ID + ": " + ex.Message + "\r\n" + ex.StackTrace); exceptionList.Add(ex); return(false); //the other way is: should throw exception, rather than the above three code. see below: //throw new InnoExCeption(ExceptionDictionary.Code._0x02108, error.StackTrace); } }