//BridgeChange event handler...display the data from a bridge change event void br_Data(object sender, BridgeDataEventArgs e) { //キャリブレーション BridgeDataEventData convertValue = AddCalibretion(e); //初期値未設定 if ((LeftTenStatus.TenInt == 0) | (RightTenStatus.TenInt == 0)) { //初期値設定へ InitialTensionSetting(convertValue); } //初期値設定済 else { //接圧監視へ MonitorTension(convertValue); } if (convertValue.Index == bridgeCmbL.SelectedIndex) { leftValueTxt.Text = convertValue.Value.ToString(); OutputLog("L," + convertValue.Value.ToString() + ","); } if (convertValue.Index == bridgeCmbR.SelectedIndex) { rightValueTxt.Text = convertValue.Value.ToString(); OutputLog("R," + convertValue.Value.ToString() + "\n"); } }
// 初期値設定 private void InitialTensionSetting(BridgeDataEventData e) { var initEndCount = Int32.Parse(ConfigurationManager.AppSettings.Get("InitSampNum")); // 初期値取得 if ((dataL.Count < initEndCount) | (dataR.Count < initEndCount)) { if (e.Index == (int)bridgeCmbL.SelectedIndex) { dataL.Add(e.Value); } if (e.Index == (int)bridgeCmbR.SelectedIndex) { dataR.Add(e.Value); } } else { double sum = 0; // 初期値設定(平均値) if (LeftTenStatus.TenInt == 0) { foreach (double data in dataL) { sum += data; } LeftTenStatus.TenInt = (sum / dataL.Count); initialLeftValueTxt.Text = LeftTenStatus.TenInt.ToString(); LeftTenStatus.TenMax = LeftTenStatus.TenInt + PermiRange; LeftTenStatus.TenMin = LeftTenStatus.TenInt - PermiRange; OutputLog(",,,,L_Init," + LeftTenStatus.TenInt.ToString() + "\n"); dataL.Clear(); } else if (RightTenStatus.TenInt == 0) { foreach (double data in dataR) { sum += data; } RightTenStatus.TenInt = (sum / dataR.Count); initialRightValueTxt.Text = RightTenStatus.TenInt.ToString(); RightTenStatus.TenMax = RightTenStatus.TenInt + PermiRange; RightTenStatus.TenMin = RightTenStatus.TenInt - PermiRange; OutputLog("\n,,,,R_Init," + RightTenStatus.TenInt.ToString() + "\n"); dataR.Clear(); } } }
//初期値設定 private void InitialTensionSetting(BridgeDataEventData e) { //初期値取得 if ((initialdataL.Count < TENSION_SAMPLE_NUM) | (initialdataR.Count < TENSION_SAMPLE_NUM)) { if (e.Index == (int)bridgeCmbL.SelectedIndex) { initialdataL.Add(e.Value); } if (e.Index == (int)bridgeCmbR.SelectedIndex) { initialdataR.Add(e.Value); } } else { double sum = 0; //初期値設定(平均値) if (LeftTenStatus.TenInt == 0) { foreach (double data in initialdataL) { sum += data; } LeftTenStatus.TenInt = (sum / initialdataL.Count); initialLeftValueTxt.Text = LeftTenStatus.TenInt.ToString(); LeftTenStatus.TenMax = LeftTenStatus.TenInt + PermiRange; //LeftTenStatus.TenMin = LeftTenStatus.TenInt; LeftTenStatus.TenMin = LeftTenStatus.TenInt - PermiRange; OutputLog(",,,,L_Init," + LeftTenStatus.TenInt.ToString() + "\n"); } else if (RightTenStatus.TenInt == 0) { foreach (double data in initialdataR) { sum += data; } RightTenStatus.TenInt = (sum / initialdataR.Count); initialRightValueTxt.Text = RightTenStatus.TenInt.ToString(); RightTenStatus.TenMax = RightTenStatus.TenInt + PermiRange; //RightTenStatus.TenMin = RightTenStatus.TenInt; RightTenStatus.TenMin = RightTenStatus.TenInt - PermiRange; OutputLog("\n,,,,R_Init," + RightTenStatus.TenInt.ToString() + "\n"); } } }
// 変位イベント BridgeChange event handler...display the data from a bridge change event void Br_Data(object sender, BridgeDataEventArgs e) { // オートキャリブレーション中なら if (CalibStartBtn.Enabled == false) { AutoCalibration(e); return; } // キャリブレーション反映 BridgeDataEventData convertValue = AddCalibration(e); // 初期値未設定 if ((LeftTenStatus.TenInt == 0) | (RightTenStatus.TenInt == 0)) { // 初期値設定へ InitialTensionSetting(convertValue); } // 初期値設定済 else { // 値取得・表示更新 if (MonitorTension(convertValue)) { // トラバース制御 ControlTraversal(); } } // 表示更新とログ出力 if (convertValue.Index == bridgeCmbL.SelectedIndex) { leftValueTxt.Text = convertValue.Value.ToString(); OutputLog("L," + convertValue.Value.ToString() + ","); } if (convertValue.Index == bridgeCmbR.SelectedIndex) { rightValueTxt.Text = convertValue.Value.ToString(); OutputLog("R," + convertValue.Value.ToString() + "\n"); } }
//耳糸接圧監視 private void MonitorTension(BridgeDataEventData e) { //L if (e.Index == (int)bridgeCmbL.SelectedIndex) { LeftTenStatus.Ten = e.Value; } //R else if (e.Index == (int)bridgeCmbR.SelectedIndex) { RightTenStatus.Ten = e.Value; } else { //なし } //ステータス更新 //1) Tl > TlMax、Tr > TrMaxの場合 ・・・ 両耳高傾向 if ((LeftTenStatus.Ten > LeftTenStatus.TenMax) & (RightTenStatus.Ten > RightTenStatus.TenMax)) { //幅広 widthState.BackColor = TENSION_STATUS_WIDTH_WIDE; leftState.BackColor = TENSION_STATUS_MORE; rightState.BackColor = TENSION_STATUS_MORE; } //2) Tl > TlMax、Tr < TrMinの場合・・・ 左耳高、右耳低 else if ((LeftTenStatus.Ten > LeftTenStatus.TenMax) & (RightTenStatus.Ten < RightTenStatus.TenMin)) { //左寄り widthState.BackColor = TENSION_STATUS_NONE; leftState.BackColor = TENSION_STATUS_MORE; rightState.BackColor = TENSION_STATUS_LESS; } //3) Tl > TlMax、Tr = OK の場合・・・ 左耳高 else if ((LeftTenStatus.Ten > LeftTenStatus.TenMax) & (RightTenStatus.Ten > RightTenStatus.TenMin) & (RightTenStatus.Ten < RightTenStatus.TenMax)) { //幅広、左寄り widthState.BackColor = TENSION_STATUS_WIDTH_WIDE; leftState.BackColor = TENSION_STATUS_MORE; rightState.BackColor = TENSION_STATUS_NONE; } //4) Tl < TlMin、Tr > TrMaxの場合・・・ 左耳低、右耳高 else if ((LeftTenStatus.Ten < LeftTenStatus.TenMin) & (RightTenStatus.Ten > RightTenStatus.TenMax)) { //右寄り widthState.BackColor = TENSION_STATUS_NONE; leftState.BackColor = TENSION_STATUS_LESS; rightState.BackColor = TENSION_STATUS_MORE; } //5) Tl = OK、Tr > TrMaxの場合・・・ 右耳高 else if ((LeftTenStatus.Ten < LeftTenStatus.TenMax) & (LeftTenStatus.Ten > LeftTenStatus.TenMin) & (RightTenStatus.Ten > RightTenStatus.TenMax)) { //幅広、右寄り widthState.BackColor = TENSION_STATUS_WIDTH_WIDE; leftState.BackColor = TENSION_STATUS_NONE; rightState.BackColor = TENSION_STATUS_MORE; } //6) Tl < TlMin、Tr = OKの場合・・・ 左耳低 else if ((LeftTenStatus.Ten < LeftTenStatus.TenMin) & (RightTenStatus.Ten > RightTenStatus.TenMin) & (RightTenStatus.Ten < RightTenStatus.TenMax)) { //幅狭、右寄り widthState.BackColor = TENSION_STATUS_WIDTH_NARROW; leftState.BackColor = TENSION_STATUS_LESS; rightState.BackColor = TENSION_STATUS_NONE; } //7) Tl = OK、Tr < TrMinの場合・・・ 右耳低 else if ((LeftTenStatus.Ten < LeftTenStatus.TenMax) & (LeftTenStatus.Ten > LeftTenStatus.TenMin) & (RightTenStatus.Ten < RightTenStatus.TenMin)) { //幅狭、左寄り widthState.BackColor = TENSION_STATUS_WIDTH_NARROW; leftState.BackColor = TENSION_STATUS_NONE; rightState.BackColor = TENSION_STATUS_LESS; } //8) Tl < TlMin、Tr < TrMinの場合・・・ 両耳低傾向 else if ((LeftTenStatus.Ten < LeftTenStatus.TenMin) & (RightTenStatus.Ten < RightTenStatus.TenMin)) { //幅狭 widthState.BackColor = TENSION_STATUS_WIDTH_NARROW; leftState.BackColor = TENSION_STATUS_LESS; rightState.BackColor = TENSION_STATUS_LESS; } //9) Tl,Tr = OK の場合 else { //丁度良い widthState.BackColor = TENSION_STATUS_NONE; leftState.BackColor = TENSION_STATUS_NONE; rightState.BackColor = TENSION_STATUS_NONE; } }
// 耳糸接圧監視 private bool MonitorTension(BridgeDataEventData e) { var controlflg = false; var ctlEndCount = Int32.Parse(ConfigurationManager.AppSettings.Get("CtlSampNum")); // Left if (e.Index == (int)bridgeCmbL.SelectedIndex) { LeftTenStatus.Ten = e.Value; dataL.Add(e.Value); if (dataL.Count >= ctlEndCount) { double sum = 0; foreach (double data in dataL) { sum += data; } LeftTenStatus.TenAve = (sum / dataL.Count); LeftTenStatus.isGotAve = true; } } // Right else if (e.Index == (int)bridgeCmbR.SelectedIndex) { RightTenStatus.Ten = e.Value; dataR.Add(e.Value); if (dataR.Count >= ctlEndCount) { double sum = 0; foreach (double data in dataR) { sum += data; } RightTenStatus.TenAve = (sum / dataR.Count); RightTenStatus.isGotAve = true; } } else { // 来ないはず } // ステータス表示更新 // 1) Tl > TlMax、Tr > TrMaxの場合 ・・・ 両耳高傾向 if ((LeftTenStatus.Ten > LeftTenStatus.TenMax) & (RightTenStatus.Ten > RightTenStatus.TenMax)) { // 幅広 widthState.BackColor = TENSION_STATUS_WIDTH_WIDE; leftState.BackColor = TENSION_STATUS_MORE; rightState.BackColor = TENSION_STATUS_MORE; } // 2) Tl > TlMax、Tr < TrMinの場合・・・ 左耳高、右耳低 else if ((LeftTenStatus.Ten > LeftTenStatus.TenMax) & (RightTenStatus.Ten < RightTenStatus.TenMin)) { // 左寄り widthState.BackColor = TENSION_STATUS_NONE; leftState.BackColor = TENSION_STATUS_MORE; rightState.BackColor = TENSION_STATUS_LESS; } // 3) Tl > TlMax、Tr = OK の場合・・・ 左耳高 else if ((LeftTenStatus.Ten > LeftTenStatus.TenMax) & (RightTenStatus.Ten > RightTenStatus.TenMin) & (RightTenStatus.Ten < RightTenStatus.TenMax)) { // 幅広、左寄り widthState.BackColor = TENSION_STATUS_WIDTH_WIDE; leftState.BackColor = TENSION_STATUS_MORE; rightState.BackColor = TENSION_STATUS_NONE; } // 4) Tl < TlMin、Tr > TrMaxの場合・・・ 左耳低、右耳高 else if ((LeftTenStatus.Ten < LeftTenStatus.TenMin) & (RightTenStatus.Ten > RightTenStatus.TenMax)) { // 右寄り widthState.BackColor = TENSION_STATUS_NONE; leftState.BackColor = TENSION_STATUS_LESS; rightState.BackColor = TENSION_STATUS_MORE; } // 5) Tl = OK、Tr > TrMaxの場合・・・ 右耳高 else if ((LeftTenStatus.Ten < LeftTenStatus.TenMax) & (LeftTenStatus.Ten > LeftTenStatus.TenMin) & (RightTenStatus.Ten > RightTenStatus.TenMax)) { // 幅広、右寄り widthState.BackColor = TENSION_STATUS_WIDTH_WIDE; leftState.BackColor = TENSION_STATUS_NONE; rightState.BackColor = TENSION_STATUS_MORE; } // 6) Tl < TlMin、Tr = OKの場合・・・ 左耳低 else if ((LeftTenStatus.Ten < LeftTenStatus.TenMin) & (RightTenStatus.Ten > RightTenStatus.TenMin) & (RightTenStatus.Ten < RightTenStatus.TenMax)) { // 幅狭、右寄り widthState.BackColor = TENSION_STATUS_WIDTH_NARROW; leftState.BackColor = TENSION_STATUS_LESS; rightState.BackColor = TENSION_STATUS_NONE; } // 7) Tl = OK、Tr < TrMinの場合・・・ 右耳低 else if ((LeftTenStatus.Ten < LeftTenStatus.TenMax) & (LeftTenStatus.Ten > LeftTenStatus.TenMin) & (RightTenStatus.Ten < RightTenStatus.TenMin)) { // 幅狭、左寄り widthState.BackColor = TENSION_STATUS_WIDTH_NARROW; leftState.BackColor = TENSION_STATUS_NONE; rightState.BackColor = TENSION_STATUS_LESS; } // 8) Tl < TlMin、Tr < TrMinの場合・・・ 両耳低傾向 else if ((LeftTenStatus.Ten < LeftTenStatus.TenMin) & (RightTenStatus.Ten < RightTenStatus.TenMin)) { // 幅狭 widthState.BackColor = TENSION_STATUS_WIDTH_NARROW; leftState.BackColor = TENSION_STATUS_LESS; rightState.BackColor = TENSION_STATUS_LESS; } // 9) Tl,Tr = OK の場合 else { // 丁度良い widthState.BackColor = TENSION_STATUS_NONE; leftState.BackColor = TENSION_STATUS_NONE; rightState.BackColor = TENSION_STATUS_NONE; } // 両方更新されたらフラグ立てる controlflg = LeftTenStatus.isGotAve & RightTenStatus.isGotAve; return(controlflg); }