static void GetSensitivity() { StringBuilder sb = new StringBuilder(); List <Point> listPoint = new List <Point>(); try { //测量数量 衰减初始值 步进 int testCount = 10; double initialValue = 26; double interval = 0.5; Point point = new Point(); for (int i = 0; i < testCount; i++) { //Hp8156.Open(); Hp8156.SetAtt(initialValue.ToString()); point.X = initialValue; initialValue += interval; //sb.Append(point.X.ToString()); Thread.Sleep(1000); string errorRate = Mp.GetErrorRate(); string str = errorRate.Substring(2); //Error rate double.TryParse(str.Trim(), out double result); //判定当结果不为0时 if (result > 0) { //取对数 point.Y = Math.Log10(result); listPoint.Add(point); } Console.WriteLine("X:{0},Y:{1}", point.X, point.Y); } Console.WriteLine(); //噪声过滤 while (IsCountChanged && listPoint.Count > 5) { listPoint = PointFilter(listPoint); } Console.WriteLine(); foreach (var item in listPoint) { Console.WriteLine("X:{0},Y:{1}", item.X, item.Y); } //计算灵敏度 SenPara = LinearRegression(listPoint); //灵敏度计算条件:Error rate@E-3 SenPara.Sensitive = (-3 - SenPara.RCA) / SenPara.RCB; } catch { } }
static void Main(string[] args) { string supplyCurrent; string outputPower; double voltage = 0; double ini = 28.0; double span = 0.2; double sd_Desserted = 0, sd_Asserted = 0, hysis = 0; string crossing; string extiRatio; string jitter; string maskMargin; string sensitivity; bool saturation; bool txDisable; try { AgE3631 = new AglientE3631A("9"); Keith = new Keithley("24"); Hp8156 = new HP8156A("22"); Mp = new MP2100A("16"); Hp8153 = new HP8153A("5"); Console.WriteLine(Keith.GetIdn()); Console.WriteLine(Hp8156.GetIdn()); Console.WriteLine(Mp.GetIdn()); Console.WriteLine(Hp8153.GetIdn()); Console.WriteLine(AgE3631.GetIdn()); AgE3631.Open(); Hp8156.Open(); supplyCurrent = AgE3631.GetCurrent(); outputPower = Hp8153.ReadPower("2"); Console.WriteLine("Supply Current:{0}", supplyCurrent); Console.WriteLine("Output Power:{0}", outputPower); Console.WriteLine(); Mp.AutoScale(); Keith.SetMeasureVoltageOnlyPara("10"); Keith.Open(); //SD_Desserted, SD_High for (int i = 0; i <= 40; i++) { Hp8156.SetAtt(ini.ToString()); Thread.Sleep(300); voltage = GetKeithData(); Thread.Sleep(200); if (voltage >= 2.0) { sd_Desserted = ini; break; } else { ini += span; } } Console.WriteLine("SDHigh:{0}", voltage); Console.WriteLine("SdDesserted:{0}", sd_Desserted); Console.WriteLine(); //SD_Asserted,SD_Low for (int i = 0; i < 40; i++) { Hp8156.SetAtt(ini.ToString()); Thread.Sleep(300); voltage = GetKeithData(); Thread.Sleep(300); if (voltage <= 0.5) { sd_Asserted = ini; break; } else { ini -= 0.1; } } Console.WriteLine("SdLow:{0}", voltage); Console.WriteLine("SdAsserted:{0}", sd_Asserted); hysis = sd_Desserted - sd_Asserted; Console.WriteLine("Hys:{0}", hysis); Console.WriteLine(); Hp8156.SetAtt("28"); Thread.Sleep(2000); #region Mp2100 crossing = Mp.GetCrossing(); extiRatio = Mp.GetER(); Console.WriteLine("Crossing:{0}", crossing); Console.WriteLine("Extinction Ratio:{0}", extiRatio); jitter = Mp.GetJitter(); maskMargin = Mp.GetMaskMargin(); Console.WriteLine("Jitter:{0}", jitter); Console.WriteLine("Mask Margin:{0}", maskMargin); Console.WriteLine(); //Sensitivity GetSensitivity(); sensitivity = SenPara.Sensitive.ToString(); Console.WriteLine("Sensitivity:{0}", sensitivity); #endregion //Saturation Hp8156.SetAtt("9"); Thread.Sleep(2000); Console.WriteLine(); for (int i = 0; i < 5; i++) { Console.WriteLine("Saturation:{0}", Mp.GetErrorRate()); Thread.Sleep(1000); } Hp8156.Close(); Hp8156.SetAtt("28"); AgE3631.SetOutput("25", "2.0", "0.5"); Thread.Sleep(1000); Console.WriteLine("TxDisable:{0}", Hp8153.ReadPower("2")); Console.WriteLine("测试完成"); Console.ReadKey(); Keith.Close(); AgE3631.Close(); Dispose(); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadKey(); } }
/// <summary> /// 终测命令 /// </summary> private void ExecuteTest() { bool isSaveData = false; StringBuilder strBuild = new StringBuilder(); IsTestEnable = false; try { //另一线程执行该方法 Thread thread = new Thread(() => { //SN if (!string.IsNullOrEmpty(SN)) { TestingPara.SN = SN; } //GPIB通信 if (IsReady) { double ini = IniAtt; double span = 0.2; double voltage; double saturation = 0; //Hp8156A.Open(); Mp2100A.AutoScale(); Aq6317B.SetSingle(); //Supply Current SupplyCurrent = AgE3631A.GetCurrent(); TestingPara.SupplyCurrent = SupplyCurrent.ToString("F3"); //OutputPower OutputPower = Hp8153A.ReadPower("2"); TestingPara.OutputPower = OutputPower.ToString("F3"); //SD_Desserted SD_High for (int i = 0; i <= 40; i++) { Hp8156A.SetAtt(ini.ToString()); Thread.Sleep(300); voltage = Ag34401A.GetVoltage(); Thread.Sleep(100); if (i == 0 && voltage >= 2.0) { MessageBox.Show("初始即为高电压,请检查设备连接!", "系统提示"); return; } if (voltage >= 2.0) { SdDesserted = ini; TestingPara.SD_Desserted = SdDesserted.ToString(); SDHigh = voltage; TestingPara.SD_High = SDHigh.ToString("F3"); //SdDesserted SdHigh strBuild.Append(string.Format("SdDesserted:{0}", SdDesserted)); strBuild.Append(string.Format("SdHigh:{0}", SDHigh)); DisplayInfo = strBuild.ToString(); break; } else { ini += span; if (i == 40) { strBuild.Append("获取SdDesserted失败!"); DisplayInfo = strBuild.ToString(); } } } ; //SD_Asserted,SD_Low for (int i = 0; i <= 30; i++) { Hp8156A.SetAtt(ini.ToString()); Thread.Sleep(200); voltage = Ag34401A.GetVoltage(); Thread.Sleep(100); if (voltage < 0.5) { SdAsserted = ini; TestingPara.SD_Asserted = SdAsserted.ToString(); SDLow = voltage; TestingPara.SD_Low = SDLow.ToString(); strBuild.Append(string.Format("SdAsserted:{0}", SdAsserted)); strBuild.Append(string.Format("SdLow:{0}", SDLow)); DisplayInfo = strBuild.ToString(); break; } else { ini -= span; if (i == 30) { strBuild.Append("获取SdAsserted失败"); DisplayInfo = strBuild.ToString(); } } } //Hysteresis Hysteresis = SdDesserted = SdAsserted; TestingPara.Hysteresis = Hysteresis.ToString(); #region MP2100 Hp8156A.SetAtt(IniAtt.ToString()); //Exit.Ratio ExtiRatio = Mp2100A.GetExRatio(); TestingPara.ExtioRatio = ExtiRatio.ToString("F3"); strBuild.Append(string.Format("Extinction Ratio:{0}", ExtiRatio)); DisplayInfo = strBuild.ToString(); //Crossing CrossingRate = Mp2100A.GetCrossing(); TestingPara.Crossing = CrossingRate.ToString("F3"); strBuild.Append(string.Format("CrossingRate:{0}", CrossingRate)); DisplayInfo = strBuild.ToString(); //MaskMargin MaskMargin = Mp2100A.GetMaskMargin(); TestingPara.MaskMargin = MaskMargin.ToString("F3"); strBuild.Append(string.Format("Mask Margin:{0}", MaskMargin)); DisplayInfo = strBuild.ToString(); //Jitter Jitter = Mp2100A.GetJitter(); TestingPara.Jitter = Jitter.ToString("F3"); strBuild.Append(string.Format("Jitter:{0}", Jitter)); DisplayInfo = strBuild.ToString(); Thread.Sleep(2000); //OSA string osaData = Aq6317B.GetData(); string[] data = osaData.Split(','); //CenterWavelength if (double.TryParse(data[1].Trim(), out double data1)) { CenterWavelength = data1; } else { CenterWavelength = 0; } TestingPara.CenterWavelength = CenterWavelength.ToString(); //SMSR if (double.TryParse(data[4].Trim(), out double data4)) { SMSR = data4; } else { SMSR = 0; } TestingPara.SMSR = SMSR.ToString(); //WavelengthDiff if (double.TryParse(data[0].Trim(), out double data0)) { DifferenceWavelength = data0; } else { DifferenceWavelength = 0; } TestingPara.WavelengthDiff = DifferenceWavelength.ToString(); strBuild.AppendLine(string.Format("中心波长:{0}", CenterWavelength)); strBuild.AppendLine(string.Format("Δλ:{0}", DifferenceWavelength)); strBuild.AppendLine(string.Format("SMSR:{0}", SMSR)); DisplayInfo = strBuild.ToString(); //Sensitivity Sensitivity = Math.Round(GetSensitivity(), 2); TestingPara.Sensitivity = Sensitivity.ToString(); strBuild.Append(string.Format("Sensitivity:{0}", Sensitivity)); DisplayInfo = strBuild.ToString(); #endregion Thread.Sleep(300); //Saturation //测试饱和度 设置 衰减 Hp8156A.SetAtt(AttInSaturation); Thread.Sleep(3000); for (int i = 0; i < 5; i++) { Thread.Sleep(300); double r = Mp2100A.GetErrorRate(); if (r >= 0) { saturation = Math.Log10(r); if (saturation > -9) { Saturation = false; break; } } else { MessageBox.Show("读取眼图仪误码率发生错误", "系统设置"); break; } Saturation = true; } TestingPara.Saturation = Saturation; strBuild.Append(string.Format("Saturation:{0}", Saturation)); DisplayInfo = strBuild.ToString(); //TxDisable Thread.Sleep(200); Hp8156A.Close(); P3202.SetVolage("1", "2.0"); Thread.Sleep(3000); double txDisablePower = Hp8153A.ReadPower("2"); strBuild.Append(string.Format("Power@TxDisable:{0}", txDisablePower)); DisplayInfo = strBuild.ToString(); if (txDisablePower < -20.0 || Math.Log10(txDisablePower) > 10) { TxDisable = true; TestingPara.TxDisable = true; } P3202.SetVolage("1", "0.8"); isSaveData = true; } else { MessageBox.Show("设备初始化未完成,将无法进行GPIB测试", "系统提示"); } //IIC通信参数 if (IsPortReady) { I2CTest(); isSaveData = true; } else { MessageBox.Show("串口初始化未完成", "系统提示"); } if (isSaveData) { //将数据存储到本地 MessageBoxResult result = MessageBox.Show("测试完成,是否储存数据?", "系统提示", MessageBoxButton.OKCancel, MessageBoxImage.Question); if (result == MessageBoxResult.OK) { bool isEmpty = false; if (!Directory.Exists(@"E:\Xu")) { Directory.CreateDirectory(@"E:\Xu"); } using (FileStream fs = new FileStream(SavePath, FileMode.OpenOrCreate, FileAccess.Read, FileShare.None)) { using (StreamReader sr = new StreamReader(fs)) { string output = null; if ((output = sr.ReadLine()) == null) { isEmpty = true; } else { isEmpty = false; } } } using (FileStream fs = new FileStream(SavePath, FileMode.Append, FileAccess.Write, FileShare.None)) { using (StreamWriter sw = new StreamWriter(fs)) { if (isEmpty == true) { sw.WriteLine("SN,SupplyCurrent,OutputPower,ExRatio,Crossing,Jitter,MaskMargin," + "CenterWavelength,SMSR,WavelengthDiff,TxDisable,Sensitivity,SD_Asserted,SD_Desserted," + "Hysteresis,SD_High,SD_Low,Saturation,RxPoint1,RxPoint2,RxPoint3,TxPower," + "Vcc,Temp,Bias,IsAwPass,Date"); } sw.WriteLine(TestingPara.ToString()); } } } } IsTestEnable = true; }); thread.IsBackground = true; thread.Start(); } catch (Exception ex) { MessageBox.Show(ex.Message, "系统提示"); } }