// Use this for initialization
    void Start()
    {
        minCos = -Mathf.Cos (minAngle * Mathf.Deg2Rad);
                maxCos = -Mathf.Cos (maxAngle * Mathf.Deg2Rad);
                orientationState = new Hysteresis ();

                orientationState.increasing = minCos < maxCos;
                orientationState.persistence = minCos;
                orientationState.activation = maxCos;
    }
Example #2
0
    // Use this for initialization
    void Start()
    {
        minCos           = -Mathf.Cos(minAngle * Mathf.Deg2Rad);
        maxCos           = -Mathf.Cos(maxAngle * Mathf.Deg2Rad);
        orientationState = new Hysteresis();

        orientationState.increasing  = minCos < maxCos;
        orientationState.persistence = minCos;
        orientationState.activation  = maxCos;
    }
Example #3
0
		void Start ()
		{
				gripState = new Hysteresis ();
				if (gripOff <= gripOn) {
						gripState.increasing = true;
						gripState.persistence = gripOff;
						gripState.activation = gripOn;
				} else {
						gripState.increasing = false;
						gripState.persistence = gripOn;
						gripState.activation = gripOff;
				}
		}
Example #4
0
 void Start()
 {
     gripState = new Hysteresis();
     if (gripOff <= gripOn)
     {
         gripState.increasing  = true;
         gripState.persistence = gripOff;
         gripState.activation  = gripOn;
     }
     else
     {
         gripState.increasing  = false;
         gripState.persistence = gripOn;
         gripState.activation  = gripOff;
     }
 }
        /// <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, "系统提示");
            }
        }