Пример #1
0
        public void StartSelfcheck(bool bStart)
        {
            GetTachometerPrepareRealTimeDataAckParams ackParams = new GetTachometerPrepareRealTimeDataAckParams();

            if (bStart)
            {
                if (!_dynoCmd.GetTachometerPrepareRealTimeDataCmd(true, false, ref ackParams, out string errMsg))
                {
                    MessageBox.Show("执行开始获取转速计实时数据命令失败", "执行命令出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    _timer.Enabled = true;
                }
            }
            else
            {
                if (!_dynoCmd.GetTachometerPrepareRealTimeDataCmd(false, true, ref ackParams, out string errMsg))
                {
                    MessageBox.Show("执行停止获取转速计实时数据命令失败", "执行命令出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    _timer.Enabled = false;
                    lblMsg.Text    = "已手动停止转速计自检";
                }
            }
        }
Пример #2
0
        private void OnTimer(object source, System.Timers.ElapsedEventArgs e)
        {
            GetTachometerPrepareRealTimeDataAckParams ackParams = new GetTachometerPrepareRealTimeDataAckParams();

            if (_dynoCmd.GetTachometerPrepareRealTimeDataCmd(true, false, ref ackParams, out string errMsg) && ackParams != null)
            {
                if (_timer != null && _timer.Enabled)
                {
                    try {
                        Invoke((EventHandler) delegate {
                            lblGasRPMLow.Text     = ackParams.QYRPMLow.ToString();
                            lblGasRPMHigh.Text    = ackParams.QYRPMHigt.ToString();
                            lblGasRPM.Text        = ackParams.RPM.ToString();
                            lblDieselRPMLow.Text  = ackParams.CYRPMLow.ToString();
                            lblDieselRPMHigh.Text = ackParams.CYRPMHigt.ToString();
                            lblDieselRPM.Text     = ackParams.CYRPM.ToString();
                            lblOBDRPM.Text        = ackParams.OBDRPM.ToString();
                            bool RPMOK            = (ackParams.RPM >= ackParams.QYRPMLow) && (ackParams.RPM <= ackParams.QYRPMHigt);
                            RPMOK      = RPMOK || ((ackParams.CYRPM >= ackParams.CYRPMLow) && (ackParams.CYRPM <= ackParams.CYRPMHigt));
                            bool OBDOK = Math.Abs(ackParams.OBDRPM - ackParams.RPM) <= RPM_Tolerance;
                            OBDOK      = OBDOK || Math.Abs(ackParams.OBDRPM - ackParams.CYRPM) <= RPM_Tolerance;
                            OBDOK      = OBDOK && ackParams.OBDRPM > 0;
                            if ((RPMOK || OBDOK) || _dicStops[this])
                            {
                                _timer.Enabled    = false;
                                _dicResults[this] = true;
                                ackParams         = new GetTachometerPrepareRealTimeDataAckParams();
                                _dynoCmd.GetTachometerPrepareRealTimeDataCmd(false, true, ref ackParams, out errMsg);
                                SelfcheckDoneEventArgs args = new SelfcheckDoneEventArgs {
                                    Result = _dicResults[this]
                                };
                                SelfcheckDone?.Invoke(this, args);
                            }
                        });
                    } catch (ObjectDisposedException) {
                        // 关闭窗口后仍有一定几率会进入主UI线程,此时访问界面元素会引发此异常,直接忽略即可
                    }
                }
            }
        }