Ejemplo n.º 1
0
        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();
            }
        }
Ejemplo n.º 2
0
        private void ExecuteInitialize()
        {
            StringBuilder info = new StringBuilder();

            info.Append("程序正在初始化。。" + DateTime.Now.ToShortTimeString() + "\r\n");
            try
            {
                //串口初始化
                if (!string.IsNullOrEmpty(SelectedCom))
                {
                    info.Append("串口初始化中。。。");
                    if (Port.IsOpen == true)
                    {
                        Port.Close();
                    }
                    Port.PortName     = SelectedCom.Trim();
                    Port.Parity       = 0;
                    Port.BaudRate     = 19200;
                    Port.StopBits     = StopBits.Two;
                    Port.DataBits     = 8;
                    Port.ReadTimeout  = 100;
                    Port.WriteTimeout = 100;

                    Port.Open();
                    string msg = TranBase.IsPortReady(Port, SerBuf) + DateTime.Now.ToShortTimeString();
                    if (msg == null)
                    {
                        info.Append("I2C通信失败!");
                        DisplayInfo = info.ToString();
                    }
                    else
                    {
                        IsPortReady = true;
                        info.Append("初始化成功 \r\n");
                        info.Append("msg");
                        DisplayInfo = info.ToString();
                    }
                }
                else
                {
                    info.Append("未选择串口号!\r\n");
                    info.Append("串口初始化失败!\r\n");
                    DisplayInfo = info.ToString();
                }
                //设备初始化
                foreach (var item in Devices)
                {
                    if (item.IsSelected == true)
                    {
                        if (item.Address != 0)
                        {
                            string address = item.Address.ToString();
                            int    index   = Array.IndexOf(Devices, item);
                            switch (index)
                            {
                            case 0:
                                if (Ag34401A != null)
                                {
                                    Ag34401A.Dispose();
                                }
                                info.Append("Aglient34401A初始化中。。。\r\n");
                                Ag34401A = new Aglient34401A(address);
                                info.Append(Ag34401A.GetIdn());
                                if (Ag34401A != null)
                                {
                                    info.Append(Ag34401A.DeviceName + "初始化OK \r\n");
                                }
                                else
                                {
                                    info.Append(Ag34401A.DeviceName + "初始化失败 \r\n");
                                }
                                DisplayInfo = info.ToString();

                                break;

                            case 1:
                                if (AgE3631A != null)
                                {
                                    AgE3631A.Dispose();
                                }
                                info.Append("AglientE3631A初始化中。。。\r\n");
                                AgE3631A = new AglientE3631A(address);
                                info.Append(AgE3631A.GetIdn());
                                if (AgE3631A != null)
                                {
                                    AgE3631A.Open();
                                    info.Append(AgE3631A.DeviceName + "初始化OK \r\n");
                                }
                                else
                                {
                                    info.Append(AgE3631A.DeviceName + "初始化失败 \r\n");
                                }
                                DisplayInfo = info.ToString();

                                break;

                            case 2:
                                if (Hp8153A != null)
                                {
                                    Hp8153A.Dispose();
                                }
                                info.Append("Hp8153A初始化中。。。\r\n");
                                Hp8153A = new HP8153A(address);
                                info.Append(Hp8153A.GetIdn());
                                if (Hp8153A != null)
                                {
                                    info.Append(Hp8153A.DeviceName + "初始化OK \r\n");
                                }

                                else
                                {
                                    info.Append(Hp8153A.DeviceName + "初始化失败 \r\n");
                                }
                                DisplayInfo = info.ToString();

                                break;

                            case 3:
                                if (Hp8156A != null)
                                {
                                    Hp8156A.Dispose();
                                }
                                info.Append("Hp8156A初始化中。。。\r\n");
                                Hp8156A = new HP8156A(address);
                                info.Append(Hp8156A.GetIdn());
                                if (Hp8156A != null)
                                {
                                    Hp8156A.Open();
                                    info.Append(Hp8156A.DeviceName + "初始化OK \r\n");
                                }
                                else
                                {
                                    info.Append(Hp8156A.DeviceName + "hp8156A初始化失败\r\n");
                                }
                                DisplayInfo = info.ToString();

                                break;

                            case 4:
                                if (Mp2100A != null)
                                {
                                    Mp2100A.Dispose();
                                }
                                info.Append("MP2100A初始化中。。。\r\n");
                                Mp2100A = new MP2100A(address);
                                info.Append(Mp2100A.GetIdn());
                                if (Mp2100A != null)
                                {
                                    info.Append(Mp2100A.DeviceName + "初始化OK \r\n");
                                }
                                else
                                {
                                    info.Append(Mp2100A.DeviceName + "初始化失败\r\n");
                                }
                                DisplayInfo = info.ToString();
                                break;

                            case 5:
                                if (P3202 != null)
                                {
                                    P3202.Dispose();
                                }
                                info.Append("P3202初始化中。。。\r\n");
                                P3202 = new PST3202(address);
                                info.Append(P3202.GetIdn());
                                if (P3202 != null)
                                {
                                    P3202.Open();
                                    info.Append(P3202.DeviceName + "初始化OK \r\n");
                                }

                                else
                                {
                                    info.Append(P3202.DeviceName + "初始化失败");
                                }
                                DisplayInfo = info.ToString();

                                break;

                            case 6:
                                if (Aq6317B != null)
                                {
                                    Aq6317B.Dispose();
                                }
                                info.Append("AQ6317B初始化中。。。\r\n");
                                Aq6317B = new AQ6317B(address);
                                info.Append(Aq6317B.GetIdn());
                                if (Aq6317B != null)
                                {
                                    info.Append(Aq6317B.DeviceName + "初始化OK \r\n");
                                }
                                else
                                {
                                    info.Append(Aq6317B.DeviceName + "初始化失败");
                                }
                                DisplayInfo = info.ToString();
                                break;

                            case 7:
                                if (Keith != null)
                                {
                                    Keith.Dispose();
                                }
                                info.Append("Keithley初始化中。。。\r\n");
                                Keith = new Keithley(address);
                                info.Append(Keith.GetIdn());
                                if (Keith != null)
                                {
                                    info.Append(Keith.DeviceName + "初始化成功\r\n");
                                }
                                else
                                {
                                    info.Append(Keith.DeviceName + "初始化失败\r\n");
                                }
                                DisplayInfo = info.ToString();
                                break;

                            default:
                                throw new Exception("该设备不存在");
                            }
                        }
                    }
                }
                IsReady = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "系统提示");
                IsReady = false;
            }
        }