Ejemplo n.º 1
0
        public TEMPRDG GetTemperature(int channel)
        {
            if (channel <= 0 || channel > 4)
            {
                return(invalid_rdg);
            }
            TEMPRDG ret = rdgs[channel - 1];

            rdgs[channel - 1] = invalid_rdg;
            return(ret);
        }
Ejemplo n.º 2
0
        public void StartProcess(BackgroundWorker formworker)
        {
            worker = formworker;

            FormAction("show_status", "测试进行中...");

            List <TEMPRDG> trdgs = new List <TEMPRDG>();

            for (int ipoint = 1; ipoint <= TestDocument.MAX_PT_1PAGE; ipoint++) //check every ipoint
            {
                string  pkey = "m_1_" + ipoint.ToString();                      //all pages should have same setpoint
                Decimal setpoint;
                if (!testdoc.IsValueAvailable(new string[] { pkey + "wdd" }))
                {
                    continue;
                }
                if (!Decimal.TryParse(testdoc.StrValue(pkey + "wdd"), out setpoint))
                {
                    continue;
                }

                SetTemperature(setpoint);
                FormAction("clear_graph", "");
                CheckCancel(2);
                trdgs.Clear();
                #region wait temp stable
                double tempnow;
                double period  = Double.Parse(Util.ConstIni.StringValue("CONDITION", "PERIOD"));
                double pplimit = Double.Parse(Util.ConstIni.StringValue("CONDITION", "PPLIMIT"));

                while (true)
                {
                    DateTime st = DateTime.Now;
                    while (!wd1529.HasReading(1))
                    {
                        FormAction("show_status", "读取标准温度计温度....");
                        CheckCancel(1);
                        if (DateTime.Now.Subtract(st).TotalSeconds > 10)
                        {
                            MessageBox.Show("读取标准温度计读数失败,请检查FLUKE 1529 连接和设置.(PRINT ON, 波特率9600).");
                            st = DateTime.Now;
                        }
                    }

                    TEMPRDG rdg = wd1529.GetTemperature(1);
                    tempnow = Convert.ToDouble(rdg.reading);
                    //convert to temperature
                    trdgs.Add(new TEMPRDG(rdg.reading, DateTime.Now));
                    FormGraphAction(0, tempnow, "c");
                    FormAction("show_status", String.Format("等待温度稳定....{0} ℃", tempnow.ToString("F03")));

                    while ((trdgs.Count > 0) && trdgs[0].time < DateTime.Now.AddMinutes(-period))
                    {
                        trdgs.RemoveAt(0);
                    }


                    if ((trdgs.Count > 10) &&
                        (trdgs[trdgs.Count - 1].time.Subtract(trdgs[0].time).TotalMinutes > (period - 0.1)) &&
                        ((Util.my_max(trdgs, 0) - Util.my_min(trdgs, 0)) < pplimit) &&
                        IsDiffSmall(trdgs[trdgs.Count - 1].reading, setpoint, 2))
                    {
                        break;
                    }

                    CheckCancel(1);
                }
                #endregion
                FormAction("clear_graph", "");
                #region start to collect const temp data
                Decimal rnow = 0;
                for (int round = 1; round <= 4; round++)
                {
                    while (!wd1529.HasReading(1))
                    {
                        CheckCancel(1);
                    }
                    Decimal stdnow = wd1529.GetTemperature(1).reading;
                    FormGraphAction(0, Convert.ToDouble(stdnow), "c");
                    for (int sch = 1; sch < TestDocument.MAX_BC; sch++)
                    {
                        if (!testdoc.IsValueAvailable(new string[] { "m_" + sch.ToString() + "_fdz" }))
                        {
                            continue;
                        }
                        this["c_" + sch.ToString() + "_" + ipoint.ToString() + "wd_" + round.ToString()] = stdnow;
                        int   retry  = 0;
                        Input askdlg = new Input();
                        askdlg.Message = String.Format("请输入控温仪{0} 示值数据...", sch);

                        while (true)
                        {
                            if (askdlg.ShowDialog() == DialogResult.OK)
                            {
                                if (Decimal.TryParse(askdlg.result, out rnow))
                                {
                                    break;
                                }
                            }

                            if (retry++ > 3)
                            {
                                throw new Exception("测试被中止.");
                            }
                        }
                        this["c_" + sch.ToString() + "_" + ipoint.ToString() + "bc_" + round.ToString()] = rnow;
                        FormGraphAction(sch, Convert.ToDouble(rnow), "ohm");
                    }
                }
                #endregion
                testdoc.AutoCaculation();
            }
            FormAction("clear_graph", "");
            //start qie huan data test
            for (int ipoint = 1; ipoint <= TestDocument.MAX_PT_1PAGE; ipoint++) //check every ipoint
            {
                string  pkey = "m_1_" + ipoint.ToString();                      //all pages should have same setpoint
                Decimal setpoint;
                if (!testdoc.IsValueAvailable(new string[] { pkey + "qhwd" }))
                {
                    continue;
                }
                if (!Decimal.TryParse(testdoc.StrValue(pkey + "qhwd"), out setpoint))
                {
                    continue;
                }

                SetTemperature(setpoint);
                #region wait temp stable
                double tempnow;
                double period  = Double.Parse(Util.ConstIni.StringValue("CONDITION", "PERIOD"));
                double pplimit = Double.Parse(Util.ConstIni.StringValue("CONDITION", "PPLIMIT"));
                while (true)
                {
                    while (!wd1529.HasReading(1))
                    {
                        CheckCancel(1);
                    }

                    TEMPRDG rdg = wd1529.GetTemperature(1);
                    tempnow = Convert.ToDouble(rdg.reading);
                    //convert to temperature
                    trdgs.Add(new TEMPRDG(rdg.reading, DateTime.Now));
                    FormGraphAction(0, tempnow, "c");
                    FormAction("show_status", String.Format("准备测量切换温度,等待温度稳定....{0} ℃", tempnow.ToString("F03")));

                    while ((trdgs.Count > 0) && trdgs[0].time < DateTime.Now.AddMinutes(-period))
                    {
                        trdgs.RemoveAt(0);
                    }
                    if ((trdgs.Count > 10) && (trdgs[trdgs.Count - 1].time.Subtract(trdgs[0].time).TotalMinutes > (period - 0.1)) &&
                        (Util.my_max(trdgs, 0) - Util.my_min(trdgs, 0)) < pplimit &&
                        IsDiffSmall(trdgs[trdgs.Count - 1].reading, setpoint, 2)) //sojo
                    {
                        break;
                    }
                    CheckCancel(1);
                }
                #endregion

                string lastio = GetCurrentIO();
                FormAction("clear_graph", "");
                #region collect up switch temperature

                decimal uprange = Decimal.Parse(Util.ConstIni.StringValue("CONDITION", "UPRANGE"));
                SetTemperature(setpoint + uprange);
                FormAction("show_status", String.Format("上切换值测量中...."));
                while (true)
                {
                    if (!wd1529.HasReading(1))
                    {
                        CheckCancel();
                        continue;
                    }
                    TEMPRDG rdg = wd1529.GetTemperature(1);
                    FormGraphAction(0, Convert.ToDouble(rdg.reading), "c");

                    string newio   = GetCurrentIO();
                    bool   alldone = true;
                    for (int ibc = 1; ibc <= TestDocument.MAX_BC; ibc++)
                    {
                        if (!testdoc.IsValueAvailable(new string[] { "m_" + ibc.ToString() + "_fdz" }))
                        {
                            continue;
                        }
                        if (newio[ibc - 1] == lastio[ibc - 1])
                        {
                            alldone = false;
                            continue;
                        }
                        string ckey;
                        ckey = "c_" + ibc.ToString() + "_" + ipoint.ToString() + "sqh_1";
                        if (!testdoc.IsValueAvailable(new string[] { ckey }))
                        {
                            this[ckey] = rdg.reading;
                            Thread.Sleep(200);
                            while (!wd1529.HasReading(1))
                            {
                                Thread.Sleep(200);
                            }
                            rdg  = wd1529.GetTemperature(1);
                            ckey = "c_" + ibc.ToString() + "_" + ipoint.ToString() + "sqh_2";
                            if (!testdoc.IsValueAvailable(new string[] { ckey }))
                            {
                                this[ckey] = rdg.reading;
                            }
                        }
                    }
                    if (alldone || IsDiffSmall(rdg.reading, setpoint + uprange + 2, 2))
                    {
                        break;
                    }
                }
                testdoc.AutoCaculation();
                #endregion

                #region collect down switch temperature
                lastio = GetCurrentIO();
                decimal dnrange = Decimal.Parse(Util.ConstIni.StringValue("CONDITION", "DNRANGE"));
                SetTemperature(setpoint + dnrange);
                FormAction("show_status", String.Format("下切换值测量中...."));
                while (true)
                {
                    if (!wd1529.HasReading(1))
                    {
                        CheckCancel();
                        continue;
                    }
                    TEMPRDG rdg = wd1529.GetTemperature(1);
                    FormGraphAction(0, Convert.ToDouble(rdg.reading), "c");

                    string newio   = GetCurrentIO();
                    bool   alldone = true;
                    for (int ibc = 1; ibc <= TestDocument.MAX_BC; ibc++)
                    {
                        if (!testdoc.IsValueAvailable(new string[] { "m_" + ibc.ToString() + "_fdz" }))
                        {
                            continue;
                        }
                        if (newio[ibc - 1] == lastio[ibc - 1])
                        {
                            alldone = false;
                            continue;
                        }
                        string ckey;
                        ckey = "c_" + ibc.ToString() + "_" + ipoint.ToString() + "xqh_1";
                        if (!testdoc.IsValueAvailable(new string[] { ckey }))
                        {
                            this[ckey] = rdg.reading;
                            Thread.Sleep(200);
                            while (!wd1529.HasReading(1))
                            {
                                Thread.Sleep(200);
                            }
                            rdg = wd1529.GetTemperature(1); ckey = "c_" + ibc.ToString() + "_" + ipoint.ToString() + "xqh_2";
                            if (!testdoc.IsValueAvailable(new string[] { ckey }))
                            {
                                this[ckey] = rdg.reading;
                            }
                        }
                    }
                    if (alldone || IsDiffSmall(rdg.reading, setpoint + dnrange - 2, 2))
                    {
                        break;
                    }
                }
                testdoc.AutoCaculation();
                #endregion
            }
            Thread.Sleep(1000);
        }