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); }
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); }
public void askinput(string id) { if (test.IsViewMode) { MessageBox.Show("历史数据不可以修改"); return; } input_dlg.Message = TranslateString(id); Decimal dat; if (!id.StartsWith("c_")) { if (DialogResult.OK == input_dlg.ShowDialog()) { process.form_result = input_dlg.result; setvalue(id, process.form_result); test[id] = process.form_result; if (test.CopyToOtherPages(id, process.form_result)) { FillInPage(""); } } } else { try { if (id.LastIndexOfAny("1234567890".ToCharArray()) != (id.Length - 1)) { throw new Exception("计算结果不能直接输入"); } if (process.bRunning) { throw new Exception("请在程序停止后再手工输入数据"); } if (DialogResult.OK == input_dlg.ShowDialog()) { process.form_result = input_dlg.result; if (!Decimal.TryParse(process.form_result, out dat)) { throw new Exception("数据格式错误"); } setvalue(id, process.form_result); test[id] = dat; test.AutoCaculation(false); FillInPage(""); } } catch (Exception err) { MessageBox.Show(err.Message, "错误"); } } if (process.bRunning) { uilock.Set(); } }