public void AddTestInfoRow(WorkInfoSpecItem specItem) { var row = testItem.NewRow(); row["TestItemID"] = specItem.SpecItemID; row["TestItemName"] = specItem.ItemName; foreach (var resultItem in BaseSettingsManager.Get <ResultSettings>().NeedSettingResult) { if (!specItem.ComputeSetting.ContainsKey(resultItem.ResultID)) { row[string.Format("TestItemCompute{0}", resultItem.ResultID)] = "N/A"; } else { var computeItem = specItem.ComputeSetting[resultItem.ResultID]; row[string.Format("TestItemCompute{0}", resultItem.ResultID)] = string.IsNullOrEmpty(computeItem.ComputeValue) ? "未设置" : OperatorManager.GetOperator(computeItem.ComputeSign).GetDisplayString(computeItem.ComputeValue); } } row["TestItemPortSetting"] = MeasurementController.GetPortName(specItem.PortSetting); if (string.IsNullOrEmpty("specItem.TestTemp") || !specItem.TestTemp.IsNumeric()) { row["TestItemTemp"] = ""; } else { row["TestItemTemp"] = $"{specItem.TestTemp}℃"; } row["TestItemValue"] = ""; row["TestItemMaxValue"] = ""; row["TestItemMinValue"] = ""; row["TestItemLastValue"] = "-999"; row["TestItemStatus"] = -10; testItem.Rows.Add(row); var resultInfo = new ResultInfo() { TestInfoDataRow = row }; testReslut[specItem.SpecItemID] = resultInfo; var dgvResult = default(DataGridView); if (!dgvResults.TryGetValue(specItem.TestTemp, out dgvResult)) { return; } if (!specItem.TestSetting.IsDouble()) { return; } var wl = specItem.TestSetting.CastTo(1550D); var names = specItem.ItemName.Split(":"); var name = names.Length > 1 ? names[1] : names[0]; names = name.Split("@"); name = names[0]; var setting = TestPortSetting.Get(specItem.PortSetting); if (setting.ChannelID < 1 && name == "UL") { name = "IL"; } if (!dgvResult.Columns.Contains(name)) { dgvResult.Columns.Add(name, name); dgvResult.Columns[name].SortMode = DataGridViewColumnSortMode.NotSortable; } foreach (DataGridViewRow dataRow in dgvResult.Rows) { if (dataRow.Cells["Wavelength"].Value.ToString() == wl.ToString("F3") && dataRow.Cells["Port"].Value.ToString() == specItem.PortSetting.ToString()) { resultInfo.ResultViewCell = dataRow.Cells[name]; } } }
private MeasurementTestResult Calculate(Guid specItemID, out WorkInfoSpecItem item) { item = MeasurementJob.SpecData.WorkInfoSpecItems.FirstOrDefault(q => q.SpecItemID == specItemID); if (item == null) { return(new MeasurementTestResult() { Result = -1, Message = "规格异常", Data = 0D }); } var testResult = MeasuringManager.Calculate( MeasurementJob.ReferenceData, TestData, item.SystemTypeID, item.TestGroupTestType, item.TestTemp, item.PortSetting, item.TestSetting ); if (testResult.Result < 1) { return(testResult); } if (testResult.Data == double.MinValue) { testResult.Result = -1; testResult.Message = "计算结果出错"; return(testResult); } testResult.Result = 0; foreach (var resultSetting in BaseSettingsManager.Get <ResultSettings>().NeedSettingResult.OrderBy(q => q.ResultID)) { ComputeSettingItem computeItem = default(ComputeSettingItem); if (!item.ComputeSetting.TryGetValue(resultSetting.ResultID, out computeItem)) { testResult.Result = -1; testResult.Message = "规格判断标准设置错误"; return(testResult); } if (string.IsNullOrEmpty(computeItem.ComputeValue)) { continue; } if (OperatorManager.GetOperator(computeItem.ComputeSign).GetComputeResult(computeItem.ComputeValue, testResult.Data)) { testResult.Result = resultSetting.ResultID; testResult.Message = $"{item.ItemName} 通过"; } else { testResult.Message = "结果不符合规格"; } } return(testResult); }
private void GetPointTestData(IMeasurementTask testTask, string temp, TestSystemGroup systemGroup, WorkInfoSpecItem item, bool testAgain) { if (!item.TestSetting.IsDouble()) { return; } var wl = item.TestSetting.CastTo(1550D); if (item.PortSetting == 0) { return; } var type = "Point"; if (!testAgain && testTask.ContainsTestData(type, temp, item.PortSetting, wl)) { return; } currentChannel = MeasurementController.GetSimultaneityPort(testTask.TestOrderID, item.PortSetting); currentWavelength = wl; testInfoCallback?.Invoke(currentWavelength, currentChannel, currentUnit); var pws = default(Dictionary <int, double>); if (!MeasurementController.RunPointTest( false, currentWavelength, () => { return(!IsStop); }, () => { var setting = TestPortSetting.Get(currentChannel); pws = MeasurementController.GetMeterAllChannelPower(setting.DeviceID, setting.SwitchID); })) { throw new Exception(MeasurementController.ErrorString); } if (pws == null || pws.Count < 1) { throw new Exception($"读取功率失败,{MeasurementController.ErrorString}"); } var items = MeasurementJob.SpecData.GetTestGroupWorkInfoSpecItems(systemGroup.TestGroupID); foreach (var testItem in items) { var pw = 0D; var c = TestPortSetting.Get(testItem.PortSetting).ChannelID; if (!pws.TryGetValue(c, out pw)) { continue; } if (pw == double.MinValue) { throw new Exception($"读取功率失败,{MeasurementController.ErrorString}"); } AddPointTestData(testTask, type, temp, testItem.PortSetting, currentWavelength, pw); } }
private void GetManualPointPDLPointPDLTestData(IMeasurementTask testTask, string temp, TestSystemGroup systemGroup, WorkInfoSpecItem item, bool testAgain) { if (!item.TestSetting.IsDouble()) { return; } var wl = item.TestSetting.CastTo(1550D); if (item.PortSetting == 0) { return; } var type = "PointPDL"; if (!testAgain && testTask.ContainsTestData(type, temp, item.PortSetting, wl)) { return; } currentChannel = MeasurementController.GetSimultaneityPort(testTask.TestOrderID, item.PortSetting); currentWavelength = wl; testInfoCallback?.Invoke(currentWavelength, currentChannel, currentUnit); var pws = new Dictionary <int, List <double> >(); if (!MeasurementController.ChangeWaveLength(currentWavelength)) { throw new Exception($"切换波长失败,{MeasurementController.ErrorString}"); } FormMessageBox.SetShow(null, "正在测试", "请摇动手摇偏振控制器,完成后点击[继续测试]进行测试", 0); var setting = TestPortSetting.Get(currentChannel); while (FormMessageBox.MessageBoxResult == 0) { if (IsStop) { FormMessageBox.SetClose(2); break; } var powers = MeasurementController.GetMeterAllChannelPower(setting.DeviceID, setting.SwitchID); if (powers.Count < 1) { continue; } var max = new StringBuilder(); var min = new StringBuilder(); foreach (var pw in powers) { if (!pws.ContainsKey(pw.Key)) { pws[pw.Key] = new List <double>(); } if (pw.Value != double.MinValue) { pws[pw.Key].Add(pw.Value); } var maxP = pws[pw.Key].Max(); var minP = pws[pw.Key].Min(); if (maxP == double.MinValue || minP == double.MinValue) { max.Append($"{pw.Key}: -\r\n"); min.Append("-\r\n"); } else { max.Append($"{pw.Key}: {maxP:F3}\r\n"); min.Append($"{minP:F3}\r\n"); } } readingCallback?.Invoke( "-", max.ToString(), min.ToString() ); } readingCallback?.Invoke("-", "-", "-"); if (FormMessageBox.MessageBoxResult != 1) { IsStop = true; return; } if (pws == null || pws.Count < 1) { throw new Exception($"读取功率失败,{MeasurementController.ErrorString}"); } var items = MeasurementJob.SpecData.GetTestGroupWorkInfoSpecItems(systemGroup.TestGroupID); foreach (var testItem in items) { var pw = default(List <double>); var c = TestPortSetting.Get(testItem.PortSetting).ChannelID; if (!pws.TryGetValue(c, out pw)) { continue; } if (pw.Count < 2) { throw new Exception($"读取功率失败,{MeasurementController.ErrorString}"); } AddPointPDLTestData(testTask, type, temp, testItem.PortSetting, currentWavelength, pw); } }
private void GetPointRLTestData(IMeasurementTask testTask, string temp, TestSystemGroup systemGroup, WorkInfoSpecItem item, bool testAgain) { if (!item.TestSetting.IsDouble()) { return; } var wl = item.TestSetting.CastTo(1550D); var type = "RL"; if (!testAgain && testTask.ContainsTestData(type, temp, item.PortSetting, wl)) { return; } currentChannel = 1; currentWavelength = wl; testInfoCallback?.Invoke(currentWavelength, currentChannel, currentUnit); var pw = new List <double>(); if (!MeasurementController.RunPointTest( false, currentWavelength, () => { return(!IsStop); }, () => { var readTime = Framework.MeasurementSystemSetting.SystemData.Setting.Profile.RetrunLosssTime; pw = GetMeterPowers(1, readTime); })) { throw new Exception(MeasurementController.ErrorString); } if (pw.Count < 1) { throw new Exception("读取功率失败"); } AddPointRLTestData(testTask, type, temp, item.PortSetting, currentWavelength, pw); return; }
private int ShowFailMessage(IMeasurementTask testTask, string temp, TestSystemGroup systemGroup, WorkInfoSpecItem item, string tipMsg, string showMsg) { tipCallback?.Invoke(testTask.TestOrderID, 2, tipMsg, 0); var msg = ShowMessage(2, $"{showMsg}\r\n按[重新测试]对项目重新测试,按[继续测试]进行下一测试。", "测试失败"); if (msg == 3) { TestSpecItem(testTask, temp, systemGroup, item, true); } return(msg); }
private void TestSpecItem(IMeasurementTask testTask, string temp, TestSystemGroup systemGroup, WorkInfoSpecItem item, bool testAgain = false) { if (IsStop) { return; } testCallback?.Invoke(testTask.StartTime, testTask.TestOrderID, -1, "", item.SpecItemID, "正在测试", "", 3); try { switch (systemGroup.TestGroupTestType) { case "None": //计算 break; case "Swept": //扫描 throw new Exception("系统禁用了扫描功能"); case "PDLSwept": //扫描 throw new Exception("系统禁用了扫描功能"); case "RL": //回损 GetPointRLTestData(testTask, temp, systemGroup, item, testAgain); break; case "Point": //点测 GetPointTestData(testTask, temp, systemGroup, item, testAgain); break; case "PointPDL": GetPointPDLTestData(testTask, temp, systemGroup, item, testAgain); break; case "ManualPointPDL": GetManualPointPDLPointPDLTestData(testTask, temp, systemGroup, item, testAgain); break; } } catch (Exception ex) { lastGroupResult = -1; testCallback?.Invoke(testTask.StartTime, testTask.TestOrderID, -1, "", item.SpecItemID, ex.Message, "", 2); IsStop = true; return; } if (IsStop) { testCallback?.Invoke(testTask.StartTime, testTask.TestOrderID, -1, "", item.SpecItemID, "停止测试", "", 2); return; } var value1 = ""; var value2 = ""; var result = testTask.MeasurementTest(item.SpecItemID); var failString = new List <string>(); lastGroupResult = Math.Min(lastGroupResult, result.Result); if (result.Result < 1) { failString.Add(item.ItemName); value1 = result.Result < 0 ? "-" : result.Data.ToString("F2"); } else { value1 = result.Data.ToString("F2"); } testCallback?.Invoke(testTask.StartTime, testTask.TestOrderID, item.PortSetting, item.SystemTypeID, item.SpecItemID, value1, value2, result.Result > 0 ? 1 : 2); if (failString.Count > 0 && Framework.MeasurementSystemSetting.SystemData.Setting.Profile.TestFailTreatmentType > 0) { if (Framework.MeasurementSystemSetting.SystemData.Setting.Profile.TestFailTreatmentType == 2) { IsStop = true; return; } ShowFailMessage(testTask, temp, systemGroup, item, result.Message, $"项目测试结果失败: \r\n{string.Join("\r\n", failString)}"); } }