示例#1
0
        public void StartProcess(BackgroundWorker formworker)
        {
            /*
             * ABCParam ppp = new ABCParam();
             * ppp.LoadFromIni("PROBE_TEST2");
             * double uu = Wendu.RValueToTValue(40.083 / ppp.rtp, ppp, ConvertMethod.ITS90);
             * return;
             */
            worker = formworker;

            FormAction("show_status", "测试进行中..."); // FormAction("show_message", "请到原始记录页,测量并填入500度时的实际温度和阻值");

            Dictionary <string, string> checkedpts = new Dictionary <string, string>();

            for (int ipage = 0; ipage < 6; ipage++)
            {
                string         pgid  = "abcdef"[ipage].ToString();
                List <TEMPRDG> trdgs = new List <TEMPRDG>();
                ABCParam       param = new ABCParam();
                if (!testdoc.IsValueAvailable(new string[] { "m_" + pgid + "_bzqbh" }))
                {
                    continue;
                }
                if (!param.LoadFromIni("PROBE_" + testdoc.StrValue("m_" + pgid + "_bzqbh")))
                {
                    throw new Exception(String.Format("第{0}页无效的标准器编号", (ipage + 1).ToString()));
                }

                for (int ipoint = 1; ipoint <= TestDocument.MAX_PT_1PAGE; ipoint++) //check every ipoint
                {
                    string sdwd = "m_" + pgid + "_" + ipoint.ToString() + "jddwd";
                    if (!testdoc.IsValueAvailable(new string[] { sdwd }))
                    {
                        continue;
                    }
                    if (checkedpts.ContainsKey(testdoc.StrValue(sdwd))) //tested before
                    {
                        continue;
                    }
                    checkedpts.Add(testdoc.StrValue(sdwd), "m_" + pgid + "_bzqbh");
                    Decimal setpoint;
                    if (!Decimal.TryParse(testdoc.StrValue(sdwd), out setpoint))
                    {
                        continue;
                    }
                    string choice = FormAction("show_message", String.Format("请将所有探头放入恒温槽,并将温度设置到 {0} ℃。\n点击'跳过'直接重测下一点", setpoint.ToString()));
                    if (choice == "skip")
                    {
                        continue;
                    }
                    FormAction("clear_graph", "");

                    CheckCancel(2);
                    trdgs.Clear();
                    //wait temp stable
                    scanner.ScanTo(0, WIREMODE.MODE_4WIRE); //force 1st channel (standard) to be 4 wire
                    double tempnow;

                    double period    = Double.Parse(Util.ConstIni.StringValue("CONDITION", "PERIOD"));
                    double pplimit   = Double.Parse(Util.ConstIni.StringValue("CONDITION", "PPLIMIT"));
                    int    scandelay = Int32.Parse(Util.ConstIni.StringValue("CONDITION", "SCANDELAY"));
                    int    goodcnt   = Int32.Parse(Util.ConstIni.StringValue("CONDITION", "GOODCNT"));

                    bridge.ClearBuffer();
                    while (true)
                    {
                        tempnow = Convert.ToDouble(ReadF700(1) * GetStdMultiply(param)) / param.rtp;
                        tempnow = Wendu.RValueToTValue(tempnow, param, ConvertMethod.ITS90);
                        //convert to temperature
                        trdgs.Add(new TEMPRDG(Convert.ToDecimal(tempnow), 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)) &&
                            IsDiffSmall(trdgs[trdgs.Count - 1].reading, setpoint, 2) &&
                            ((Util.my_max(trdgs, 0) - Util.my_min(trdgs, 0)) < pplimit))
                        {
                            break;
                        }
                        CheckCancel(1);
                    }
                    FormAction("clear_graph", "");
                    //start to collect data
                    Decimal rnow;
                    for (int round = 1; round <= 4; round++)
                    {
                        int sindex = 0;
                        for (int sch = 0; sch < 24; sch++)
                        {
                            if (sch > 0)
                            {
                                if (!testdoc.IsValueAvailable(new string[] { "m_" + sch.ToString() + "_dj" }))
                                {
                                    continue;
                                }

                                string cdpt = "m_" + "abcdef"[(sch - 1) / 4].ToString();
                                if (testdoc.IsValueAvailable(new string[] { cdpt + "_1jddwd" }) && (testdoc.StrValue(cdpt + "_1jddwd") == testdoc.StrValue(sdwd)))
                                {
                                    sindex++;
                                }
                                else if (testdoc.IsValueAvailable(new string[] { cdpt + "_2jddwd" }) && (testdoc.StrValue(cdpt + "_2jddwd") == testdoc.StrValue(sdwd)))
                                {
                                    sindex++;
                                }
                                else if (testdoc.IsValueAvailable(new string[] { cdpt + "_3jddwd" }) && (testdoc.StrValue(cdpt + "_3jddwd") == testdoc.StrValue(sdwd)))
                                {
                                    sindex++;
                                }
                                else
                                {
                                    continue;
                                }
                            }
                            if (sindex == 0)
                            {
                                FormAction("show_status", String.Format("正在采集标准温度计数据..."));
                                scanner.ScanTo(sindex, WIREMODE.MODE_4WIRE);
                            }
                            else
                            {
                                FormAction("show_status", String.Format("正在采集被检温度计 {0} 数据...", sindex));
                                scanner.ScanTo(sindex, wire);
                            }
                            CheckCancel(scandelay);
                            bridge.ClearBuffer();
                            rnow = ReadF700(goodcnt);
                            if (sindex == 0)
                            {
                                this["c_" + pgid + "_" + ipoint.ToString() + "sjwd_" + round.ToString()] = Convert.ToDecimal(Wendu.RValueToTValue(Convert.ToDouble(rnow * GetStdMultiply(param)) / param.rtp, param, ConvertMethod.ITS90));
                                FormGraphAction(sindex, Convert.ToDouble(rnow * GetStdMultiply(param)), "ohm");
                            }
                            else
                            {
                                if (wire == WIREMODE.MODE_3WIRE)
                                {
                                    this["c_" + sch.ToString() + "_" + ipoint.ToString() + "bcw3_" + round.ToString()] = rnow * GetMultiply();
                                }
                                else
                                {
                                    this["c_" + sch.ToString() + "_" + ipoint.ToString() + "bc_" + round.ToString()] = rnow * GetMultiply();
                                }
                                FormGraphAction(sindex, Convert.ToDouble(rnow * GetMultiply()), "ohm");
                            }
                            CheckCancel(2);
                        }
                        if (wire == WIREMODE.MODE_3WIRE) //another roudn for 2 wire measure
                        {
                            int nsindex = 0;
                            for (int sch = 0; sch < 24; sch++)
                            {
                                if (sch > 0)
                                {
                                    if (!testdoc.IsValueAvailable(new string[] { "m_" + sch.ToString() + "_dj" }))
                                    {
                                        continue;
                                    }

                                    string cdpt = "m_" + "abcdef"[(sch - 1) / 4].ToString();
                                    if (testdoc.IsValueAvailable(new string[] { cdpt + "_1jddwd" }) && (testdoc.StrValue(cdpt + "_1jddwd") == testdoc.StrValue(sdwd)))
                                    {
                                        nsindex++;
                                    }
                                    else if (testdoc.IsValueAvailable(new string[] { cdpt + "_2jddwd" }) && (testdoc.StrValue(cdpt + "_2jddwd") == testdoc.StrValue(sdwd)))
                                    {
                                        nsindex++;
                                    }
                                    else if (testdoc.IsValueAvailable(new string[] { cdpt + "_3jddwd" }) && (testdoc.StrValue(cdpt + "_3jddwd") == testdoc.StrValue(sdwd)))
                                    {
                                        nsindex++;
                                    }
                                    else
                                    {
                                        continue;
                                    }
                                }
                                if (nsindex == 0)
                                {
                                    continue;
                                }
                                else
                                {
                                    FormAction("show_status", String.Format("正在采集被检温度计 {0} 数据...", sindex));
                                    scanner.ScanTo(nsindex, WIREMODE.MODE_2WIRE);
                                }
                                CheckCancel(scandelay);
                                bridge.ClearBuffer();
                                rnow = ReadF700(goodcnt);
                                this["c_" + sch.ToString() + "_" + ipoint.ToString() + "bcw2_" + round.ToString()] = rnow * GetMultiply();
                                FormGraphAction(sindex, Convert.ToDouble(rnow * GetMultiply()), "ohm");
                                CheckCancel(2);
                                testdoc.AutoCaculation(true);
                            }
                        }
                    }
                    testdoc.AutoCaculation(false);
                }
            }
            scanner.ScanTo(0, WIREMODE.MODE_4WIRE);
            Thread.Sleep(1000);
        }
示例#2
0
 public double GetWr(double r)
 {
     return(Wendu.GetWr(r));
 }
示例#3
0
        internal void AutoCaculation(bool min)
        {
            #region 3 WIRE caculation
            //this["c_" + sch.ToString() + "_" + ipoint.ToString() + "bcw3_" + round.ToString()] = rnow*GetMultiply();
            for (int round = 1; round <= 4; round++)
            {
                for (int ipoint = 1; ipoint <= MAX_PT_1PAGE; ipoint++)
                {
                    Decimal sum   = 0;
                    Decimal count = 0;
                    for (int sch = 0; sch < 24; sch++)
                    {
                        string w3 = "c_" + sch.ToString() + "_" + ipoint.ToString() + "bcw3_" + round.ToString();
                        string w2 = "c_" + sch.ToString() + "_" + ipoint.ToString() + "bcw2_" + round.ToString();
                        if (IsValueAvailable(new string[] { w3, w2 }))
                        {
                            this["c_" + sch.ToString() + "_" + ipoint.ToString() + "bc_" + round.ToString()] = 2 * Value(w3) - Value(w2);
                        }
                    }
                }
            }
            #endregion

            if (min)
            {
                return;
            }
            #region average caculation
            //c_1_1sjwd, c_1_1bc1,c_1_2bc1,c_1_3bc1 ... c_1_3bc4
            string[] avg_key = new string[] { "a_{0}sjwd", "b_{0}sjwd", "c_{0}sjwd", "d_{0}sjwd", "1_{0}bc", "2_{0}bc", "3_{0}bc", "4_{0}bc", "5_{0}bc", "6_{0}bc", "7_{0}bc", "8_{0}bc", "9_{0}bc", "10_{0}bc", "11_{0}bc", "12_{0}bc" };
            for (int i = 0; i < avg_key.Length; i++)
            {
                for (int ipoint = 1; ipoint <= MAX_PT_1PAGE; ipoint++)
                {
                    Decimal sum   = 0;
                    Decimal count = 0;
                    for (int j = 1; j < 5; j++)
                    {
                        string key = "c_" + avg_key[i] + "_" + j.ToString();
                        key = key.Replace("{0}", ipoint.ToString());
                        if (IsValueAvailable(new string[] { key }))
                        {
                            sum   = sum + Value(key);
                            count = count + 1;
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (count > 0)
                    {
                        sum = sum / count;
                        string avgid = ("c_" + avg_key[i]).Replace("{0}", ipoint.ToString());
                        this[avgid] = sum;
                    }
                }
            }
            #endregion
            //caculate all temperature related column
            string[] temp_key = new string[] { "" };

            string pageid = "abcdef";
            for (int page = 0; page < pageid.Length; page++)
            {
                string   pg = pageid[page].ToString();
                string   mkey;
                string   r0_prefix   = "";
                string   r100_prefix = "";
                ABCParam param       = new ABCParam();

                for (int ipoint = 1; ipoint <= MAX_PT_1PAGE; ipoint++)
                {
                    string prefix = "c_" + pg + "_" + ipoint.ToString();


                    mkey = "m_" + pg + "_" + ipoint.ToString() + "jddwd";
                    if (!IsValueAvailable(new string[] { mkey, prefix + "sjwd" })) //no setpoint information
                    {
                        continue;
                    }

                    if (StrValue(mkey).ToString().Trim() == "0")
                    {
                        r0_prefix = "c_" + pg + "_" + ipoint.ToString();
                    }
                    if (StrValue(mkey).ToString().Trim() == "100")
                    {
                        r100_prefix = "c_" + pg + "_" + ipoint.ToString();
                    }

                    this[prefix + "xzwd"] = Decimal.Parse(StrValue(mkey)) - Value(prefix + "sjwd"); //修正值


                    if (!param.LoadFromIni("PROBE_" + StrValue("m_a_bzqbh")))
                    {
                        throw new Exception("无效的标准器编号");
                    }
                    double dydz = Wendu.TValueToRValue(ToDouble(Value(mkey)), param, ConvertMethod.DIN90) -
                                  Wendu.TValueToRValue(ToDouble(Value(prefix + "sjwd")), param, ConvertMethod.DIN90); //对应电阻值
                    this[prefix + "dydz"] = dydz;


                    //caculate all bei ce related column
                    for (int ibc = 4 * page + 1; ibc <= 4 * page + 4; ibc++)
                    {
                        prefix = "c_" + ibc.ToString() + "_" + ipoint.ToString();
                        if (!IsValueAvailable(new string[] { prefix + "bc" }))
                        {
                            continue;
                        }
                        this[prefix + "sjzbc"] = Value(prefix + "bc") + ToDecimal(dydz);
                    }
                }
                if (r0_prefix != "" && r100_prefix != "")
                {
                    for (int ibc = 4 * page + 1; ibc <= 4 * page + 4; ibc++)
                    {
                        if (!IsValueAvailable(new string[] { r100_prefix.Replace("c_" + pg + "_", "c_" + ibc.ToString() + "_") + "sjzbc",
                                                             r0_prefix.Replace("c_" + pg + "_", "c_" + ibc.ToString() + "_") + "sjzbc",
                                                             "m_" + ibc.ToString() + "_dj" }))
                        {
                            continue;
                        }
                        double r100  = ToDouble(Value(r100_prefix.Replace("c_" + pg + "_", "c_" + ibc.ToString() + "_") + "sjzbc"));
                        double r0    = ToDouble(Value(r0_prefix.Replace("c_" + pg + "_", "c_" + ibc.ToString() + "_") + "sjzbc"));
                        double alpha = (r100 - r0) / (100 * r0);
                        this["c_" + ibc.ToString() + "_alphabc"] = ToDecimal(alpha);
                        double deltat0 = (r0 - Wendu.TValueToRValue(ToDouble(0), param, ConvertMethod.DIN90)) / 0.39083;
                        bool   valid1  = false;
                        bool   valid2  = false;
                        bool   valid3  = false;
                        string dg      = StrValue("m_" + ibc.ToString() + "_dj").ToString().Trim().ToUpper();

                        if (dg == "AA")
                        {
                            valid1 = (Math.Abs(r0 - 100) <= 0.039);
                        }
                        if (dg == "A")
                        {
                            valid1 = (Math.Abs(r0 - 100) <= 0.059);
                        }
                        if (dg == "B")
                        {
                            valid1 = (Math.Abs(r0 - 100) <= 0.117);
                        }
                        if (dg == "C")
                        {
                            valid1 = (Math.Abs(r0 - 100) <= 0.234);
                        }

                        if (dg == "AA")
                        {
                            valid2 = (Math.Abs(r100 - 138.506) <= 0.102);
                        }
                        if (dg == "A")
                        {
                            valid2 = (Math.Abs(r100 - 138.506) <= 0.133);
                        }
                        if (dg == "B")
                        {
                            valid2 = (Math.Abs(r100 - 138.506) <= 0.303);
                        }
                        if (dg == "C")
                        {
                            valid2 = (Math.Abs(r100 - 138.506) <= 0.607);
                        }

                        if (dg == "AA")
                        {
                            valid3 = (Math.Abs(alpha - 0.003851 + deltat0 * 30 * 1e-6) <= 7.0);
                        }
                        if (dg == "A")
                        {
                            valid3 = (Math.Abs(alpha - 0.003851 + deltat0 * 23 * 1e-6) <= 7.0);
                        }
                        if (dg == "B")
                        {
                            valid3 = (Math.Abs(alpha - 0.003851 + deltat0 * 21 * 1e-6) <= 14.0);
                        }
                        if (dg == "C")
                        {
                            valid3 = (Math.Abs(alpha - 0.003851 + deltat0 * 21 * 1e-6) <= 32.0);
                        }

                        if (valid1 && valid2 && valid3)
                        {
                            this["c_" + ibc.ToString() + "_jl"] = "合格";
                        }
                        else
                        {
                            string fail = "";
                            if (!valid1)
                            {
                                fail = "0度超差";
                            }
                            if (!valid2)
                            {
                                fail = fail + ";100度超差";
                            }
                            if (!valid3)
                            {
                                fail = fail + ";α超差";
                            }

                            this["c_" + ibc.ToString() + "_jl"] = fail.Trim(new char[] { ';' });
                        }
                    }
                }
            }
        }