private void MainWindow_Closed(object sender, EventArgs e) { ComDevice.Write("tozero,"); CompositionTarget.Rendering -= CompositionTarget_Rendering; TxtHelper.Write(txtpath, LastVal.ToString()); ComDevice.Close(); ComDevice.Dispose(); Thread.Sleep(2000); //time.Stop(); }
private void Time_Tick(object sender, EventArgs e) { try { //if (slider1.Value < 220) // slider1.Value += 1; if (isCanSend1) { if (cycleState != CycleState.pause) { if (index % 2 == 0) { #region left if (cycleState == CycleState.left) { if (_val < Valmax) { _val += 1; } else if ((bool)chk1.IsChecked) { cycleState = CycleState.right; } } #endregion #region right if (cycleState == CycleState.right) { if (_val > 21) { _val -= 1; } else if ((bool)chk1.IsChecked) { cycleState = CycleState.left; } } #endregion slider1.Value = _val; } } #region send val position CurrentVal = _val; if (LastVal != CurrentVal) { double _sub = CurrentVal - LastVal; if (cycleState == CycleState.pause || cycleState == CycleState.slider) { if (Math.Abs(_sub) > 1) { if (_sub > 0) { speed = 1; } if (_sub < 0) { speed = -1; } LastVal += speed; Console.WriteLine("***************************************************************current value:" + LastVal); //Thread.Sleep(20); ComDevice.Write(LastVal.ToString() + ","); if (LastVal == CurrentVal) { LastVal = _val; } } } if (cycleState == CycleState.left || cycleState == CycleState.right) { //Thread.Sleep(20); ComDevice.Write(_val.ToString() + ","); txt.Text = _val.ToString(); LastVal = _val; Console.WriteLine("----------------------------------------------------------------------------------------"); } } #endregion index++; if (index > 10000) { index = 1; } } #region 注释 // txt_Copy.Text = rees; // if (index % 3 == 0) // { // if (isCanSend1&& IsAutomatic) // { // //ComDevice.Write(CurrentVal.ToString()); // if (_val >= 1000) // { // if (_CirCleNum >= 100000000) // _CirCleNum = 0; // _CirCleNum++; // isBack = false; // _val = 999; // ErrorLog.WriteLog("It's turn back now!++:"+ _CirCleNum); // } // if (_val <= 0) // { // _CirCleNum++; // if (_CirCleNum >= 100000000) // _CirCleNum = 0; // _val = 1; // isBack = true; // ErrorLog.WriteLog("It's turn back now!--:"+ _CirCleNum); // } // if (isBack) // _val++; // else // _val--; // txt_Copy1.Text = "当前值:" + _val.ToString() + " 第:" + _CirCleNum + "圈"; // Console.WriteLine("-------------------------------:" + _val); // } // } // if (isCanSend) // { // isCanSend = false; // ComDevice.Write(_val.ToString() + ","); // _val1 = _val; // } // if (_val1 == _val) // isCanSend = false; // else // isCanSend = true; // index++; // if (index > 10000) // index = 1; #endregion } catch (Exception ex) { ErrorLog.WriteLog(ex); Process.GetCurrentProcess().Kill(); } }