private void ButtonSampleClear_Click(object sender, RoutedEventArgs e) { Read.Focus(); _HolesFullAD = null; _adClear = 10; ButtonSampleClear.Content = string.Empty + _adClear; ButtonSampleClear.IsEnabled = false; for (int i = 0; i < Global.deviceHole.HoleCount; ++i) { _list1[i].Content = string.Empty; _list2[i].Content = string.Empty; _list3[i].Content = string.Empty; _list4[i].Content = string.Empty; _list5[i].Content = string.Empty; _list6[i].Content = string.Empty; _list7[i].Content = string.Empty; _list8[i].Content = string.Empty; } _Max1 = 0; _Max2 = 0; _Max3 = 0; _Max4 = 0; _Min1 = 0; _Min2 = 0; _Min3 = 0; _Min4 = 0; label1.Content = string.Empty; label2.Content = string.Empty; label3.Content = string.Empty; label4.Content = string.Empty; for (int i = 0; i < _boolL.Count; i++) { _boolL[i] = false; _list0[i].Foreground = new SolidColorBrush(Colors.Black); } }
// 读取data,处理AD,根据item,把t值和a值 private void HandleAd(byte[] data) { _HolesCurAD = FgdCaculate.RawDataToAD(data); if (null == _HolesFullAD) { _HolesFullAD = _HolesCurAD; } FgdCaculate.TLimit tLimit = new FgdCaculate.TLimit(1.2, 0.99, 1.01); //FgdCaculate.TLimit tLimit = new FgdCaculate.TLimit(1.2, 0.95, 1.05); FgdCaculate.ALimit aLimit = new FgdCaculate.ALimit(5); FgdCaculate.HolesT t = FgdCaculate.CaculateT(_HolesCurAD, _HolesFullAD, tLimit); tgList = FgdCaculate.CaculateT(_HolesCurAD, _HolesFullAD, tLimit, string.Empty); adList = FgdCaculate.CaculateA(_HolesCurAD, _HolesFullAD, t, aLimit, string.Empty); }
// 根据给定的data,更新界面 private void Update(byte[] data) { try { HandleAd(data); //更新满值AD if (0 == _adClear) { _HolesFullAD = _HolesCurAD; --_adClear; ButtonSampleClear.Content = "清零"; ButtonSampleClear.IsEnabled = true; } else if (_adClear > 0) { --_adClear; ButtonSampleClear.Content = string.Empty + _adClear; } int num = 0; // 更新吸光度和透光率 dbValues if (Global.deviceHole.HoleCount * 4 <= adList.Count && Global.deviceHole.HmCount * 4 <= tgList.Count && Global.IsTest) { //单通道判定标准 double decisionCriteria = Global.DecisionCriteria1; for (int i = 0; i < Global.deviceHole.HoleCount; ++i) { num += 1; _list1[i].Content = FgdCaculate.A_To_String(adList[i * 4]); if (_boolL[i]) { _list0[i].Foreground = new SolidColorBrush(Colors.Goldenrod); } _list2[i].Content = FgdCaculate.A_To_String(adList[i * 4 + 1]); _list3[i].Content = FgdCaculate.A_To_String(adList[i * 4 + 2]); _list4[i].Content = FgdCaculate.A_To_String(adList[i * 4 + 3]); if (!_list5[i].Content.ToString().Equals("100.00%") && _list6[i].Content.ToString() != "100.00%" && _list7[i].Content.ToString() != "100.00%" && _list8[i].Content.ToString() != "100.00%") { _numbool = i; } if (tgList[i * 4] != 1) { _num1 = tgList[i * 4]; } if (tgList[i * 4 + 1] != 1) { _num2 = tgList[i * 4 + 1]; } if (tgList[i * 4 + 2] != 1) { _num3 = tgList[i * 4 + 2]; } if (tgList[i * 4 + 3] != 1) { _num4 = tgList[i * 4 + 3]; } if (num <= 4)//1-4灯 0.2994 { double wc1 = 0, wc2 = 0, wc3 = 0, wc4 = 0; wc1 = Global.Standard1 - tgList[i * 4]; if (tgList[i * 4] != 1 && (wc1 < 0 ? wc1 = wc1 * -1 : wc1) > decisionCriteria) { _list5[i].Content = FgdCaculate.T_To_String(tgList[i * 4]); _list5[i].Foreground = new SolidColorBrush(Colors.Red); } else { _list5[i].Content = FgdCaculate.T_To_String(tgList[i * 4]); _list5[i].Foreground = new SolidColorBrush(Colors.Black); } wc2 = Global.Standard2 - tgList[i * 4 + 1]; if (tgList[i * 4 + 1] != 1 && (wc2 < 0 ? wc2 = wc2 * -1 : wc2) > decisionCriteria) { _list6[i].Content = FgdCaculate.T_To_String(tgList[i * 4 + 1]); _list6[i].Foreground = new SolidColorBrush(Colors.Red); } else { _list6[i].Content = FgdCaculate.T_To_String(tgList[i * 4 + 1]); _list6[i].Foreground = new SolidColorBrush(Colors.Black); } wc3 = Global.Standard3 - tgList[i * 4 + 2]; if (tgList[i * 4 + 2] != 1 && (wc3 < 0 ? wc3 = wc3 * -1 : wc3) > decisionCriteria) { _list7[i].Content = FgdCaculate.T_To_String(tgList[i * 4 + 2]); _list7[i].Foreground = new SolidColorBrush(Colors.Red); } else { _list7[i].Content = FgdCaculate.T_To_String(tgList[i * 4 + 2]); _list7[i].Foreground = new SolidColorBrush(Colors.Black); } wc4 = Global.Standard4 - tgList[i * 4 + 3]; if (tgList[i * 4 + 3] != 1 && (wc4 < 0 ? wc4 = wc4 * -1 : wc4) > decisionCriteria) { _list8[i].Content = FgdCaculate.T_To_String(tgList[i * 4 + 3]); _list8[i].Foreground = new SolidColorBrush(Colors.Red); } else { _list8[i].Content = FgdCaculate.T_To_String(tgList[i * 4 + 3]); _list8[i].Foreground = new SolidColorBrush(Colors.Black); } } if (num >= 5 && num <= 8)//5-8灯 0.3008 { double wc1 = 0, wc2 = 0, wc3 = 0, wc4 = 0; wc1 = Global.Standard1 - tgList[i * 4]; if (tgList[i * 4] != 1 && (wc1 < 0 ? wc1 = wc1 * -1 : wc1) > decisionCriteria) { _list5[i].Content = FgdCaculate.T_To_String(tgList[i * 4]); _list5[i].Foreground = new SolidColorBrush(Colors.Red); } else { _list5[i].Content = FgdCaculate.T_To_String(tgList[i * 4]); _list5[i].Foreground = new SolidColorBrush(Colors.Black); } wc2 = Global.Standard2 - tgList[i * 4 + 1]; if (tgList[i * 4 + 1] != 1 && (wc2 < 0 ? wc2 = wc2 * -1 : wc2) > decisionCriteria) { _list6[i].Content = FgdCaculate.T_To_String(tgList[i * 4 + 1]); _list6[i].Foreground = new SolidColorBrush(Colors.Red); } else { _list6[i].Content = FgdCaculate.T_To_String(tgList[i * 4 + 1]); _list6[i].Foreground = new SolidColorBrush(Colors.Black); } wc3 = Global.Standard3 - tgList[i * 4 + 2]; if (tgList[i * 4 + 2] != 1 && (wc3 < 0 ? wc3 = wc3 * -1 : wc3) > decisionCriteria) { _list7[i].Content = FgdCaculate.T_To_String(tgList[i * 4 + 2]); _list7[i].Foreground = new SolidColorBrush(Colors.Red); } else { _list7[i].Content = FgdCaculate.T_To_String(tgList[i * 4 + 2]); _list7[i].Foreground = new SolidColorBrush(Colors.Black); } wc4 = Global.Standard4 - tgList[i * 4 + 3]; if (tgList[i * 4 + 3] != 1 && (wc4 < 0 ? wc4 = wc4 * -1 : wc4) > decisionCriteria) { _list8[i].Content = FgdCaculate.T_To_String(tgList[i * 4 + 3]); _list8[i].Foreground = new SolidColorBrush(Colors.Red); } else { _list8[i].Content = FgdCaculate.T_To_String(tgList[i * 4 + 3]); _list8[i].Foreground = new SolidColorBrush(Colors.Black); } } if (num >= 9 && num <= 12)//9-12灯 0.2609 { double wc1 = 0, wc2 = 0, wc3 = 0, wc4 = 0; wc1 = Global.Standard1 - tgList[i * 4]; if (tgList[i * 4] != 1 && (wc1 < 0 ? wc1 = wc1 * -1 : wc1) > decisionCriteria) { _list5[i].Content = FgdCaculate.T_To_String(tgList[i * 4]); _list5[i].Foreground = new SolidColorBrush(Colors.Red); } else { _list5[i].Content = FgdCaculate.T_To_String(tgList[i * 4]); _list5[i].Foreground = new SolidColorBrush(Colors.Black); } wc2 = Global.Standard2 - tgList[i * 4 + 1]; if (tgList[i * 4 + 1] != 1 && (wc2 < 0 ? wc2 = wc2 * -1 : wc2) > decisionCriteria) { _list6[i].Content = FgdCaculate.T_To_String(tgList[i * 4 + 1]); _list6[i].Foreground = new SolidColorBrush(Colors.Red); } else { _list6[i].Content = FgdCaculate.T_To_String(tgList[i * 4 + 1]); _list6[i].Foreground = new SolidColorBrush(Colors.Black); } wc3 = Global.Standard3 - tgList[i * 4 + 2]; if (tgList[i * 4 + 2] != 1 && (wc3 < 0 ? wc3 = wc3 * -1 : wc3) > decisionCriteria) { _list7[i].Content = FgdCaculate.T_To_String(tgList[i * 4 + 2]); _list7[i].Foreground = new SolidColorBrush(Colors.Red); } else { _list7[i].Content = FgdCaculate.T_To_String(tgList[i * 4 + 2]); _list7[i].Foreground = new SolidColorBrush(Colors.Black); } wc4 = Global.Standard4 - tgList[i * 4 + 3]; if (tgList[i * 4 + 3] != 1 && (wc4 < 0 ? wc4 = wc4 * -1 : wc4) > decisionCriteria) { _list8[i].Content = FgdCaculate.T_To_String(tgList[i * 4 + 3]); _list8[i].Foreground = new SolidColorBrush(Colors.Red); } else { _list8[i].Content = FgdCaculate.T_To_String(tgList[i * 4 + 3]); _list8[i].Foreground = new SolidColorBrush(Colors.Black); } } if (num >= 13 && num <= 16)//13-16灯 0.2534 { double wc1 = 0, wc2 = 0, wc3 = 0, wc4 = 0; wc1 = Global.Standard1 - tgList[i * 4]; if (tgList[i * 4] != 1 && (wc1 < 0 ? wc1 = wc1 * -1 : wc1) > decisionCriteria) { _list5[i].Content = FgdCaculate.T_To_String(tgList[i * 4]); _list5[i].Foreground = new SolidColorBrush(Colors.Red); } else { _list5[i].Content = FgdCaculate.T_To_String(tgList[i * 4]); _list5[i].Foreground = new SolidColorBrush(Colors.Black); } wc2 = Global.Standard2 - tgList[i * 4 + 1]; if (tgList[i * 4 + 1] != 1 && (wc2 < 0 ? wc2 = wc2 * -1 : wc2) > decisionCriteria) { _list6[i].Content = FgdCaculate.T_To_String(tgList[i * 4 + 1]); _list6[i].Foreground = new SolidColorBrush(Colors.Red); } else { _list6[i].Content = FgdCaculate.T_To_String(tgList[i * 4 + 1]); _list6[i].Foreground = new SolidColorBrush(Colors.Black); } wc3 = Global.Standard3 - tgList[i * 4 + 2]; if (tgList[i * 4 + 2] != 1 && (wc3 < 0 ? wc3 = wc3 * -1 : wc3) > decisionCriteria) { _list7[i].Content = FgdCaculate.T_To_String(tgList[i * 4 + 2]); _list7[i].Foreground = new SolidColorBrush(Colors.Red); } else { _list7[i].Content = FgdCaculate.T_To_String(tgList[i * 4 + 2]); _list7[i].Foreground = new SolidColorBrush(Colors.Black); } wc4 = Global.Standard4 - tgList[i * 4 + 3]; if (tgList[i * 4 + 3] != 1 && (wc4 < 0 ? wc4 = wc4 * -1 : wc4) > decisionCriteria) { _list8[i].Content = FgdCaculate.T_To_String(tgList[i * 4 + 3]); _list8[i].Foreground = new SolidColorBrush(Colors.Red); } else { _list8[i].Content = FgdCaculate.T_To_String(tgList[i * 4 + 3]); _list8[i].Foreground = new SolidColorBrush(Colors.Black); } } } } else if (Global.deviceHole.HoleCount * 4 <= adList.Count && Global.deviceHole.HmCount * 4 <= tgList.Count) { for (int i = 0; i < Global.deviceHole.HoleCount; ++i) { _list1[i].Content = FgdCaculate.A_To_String(adList[i * 4]); _list2[i].Content = FgdCaculate.A_To_String(adList[i * 4 + 1]); _list3[i].Content = FgdCaculate.A_To_String(adList[i * 4 + 2]); _list4[i].Content = FgdCaculate.A_To_String(adList[i * 4 + 3]); _list5[i].Content = FgdCaculate.T_To_String(tgList[i * 4]); _list6[i].Content = FgdCaculate.T_To_String(tgList[i * 4 + 1]); _list7[i].Content = FgdCaculate.T_To_String(tgList[i * 4 + 2]); _list8[i].Content = FgdCaculate.T_To_String(tgList[i * 4 + 3]); } } } catch (Exception ex) { MessageBox.Show("异常(Update):\n" + ex.Message); } }