/// <summary> /// 读ERS信号 /// </summary> /// <param name="er"></param> /// <returns></returns> private bool readAndWriteData(out string er) { er = string.Empty; bool alarm = false; string e = string.Empty; try { for (int i = _startAddr; i <= _endAddr; i++) { if (_dispose) { return(true); } if (_Mon[i].Base.status == ESTATUS.禁用) { _Mon[i].Base.conStatus = false; continue; } if (_iniOK) { if (!writeData(out er)) { OnDataArgs.OnEvented(new CDataArgs(er, false, true)); } } if (!readLoadData(i, out er)) { e += er; alarm = true; _Mon[i].Base.conStatus = false; } else { _Mon[i].Base.conStatus = true; } } if (alarm) { er = e; return(false); } return(true); } catch (Exception ex) { er = ex.ToString(); return(false); } }
/// <summary> /// 启动监控 /// </summary> private void OnStart() { try { while (true) { if (_dispose) { return; } Thread.Sleep(_delayMs); if (!_autoMode && _paused) { continue; } Stopwatch wather = new Stopwatch(); wather.Start(); string er = string.Empty; //if (_iniOK) //{ // if (!writeData(out er)) // OnDataArgs.OnEvented(new CDataArgs(er, false, true)); //} //if (!readData(out er)) // OnDataArgs.OnEvented(new CDataArgs(er, false, true)); if (!readAndWriteData(out er)) { OnDataArgs.OnEvented(new CDataArgs(er, false, true)); } _iniOK = true; wather.Stop(); if (!_autoMode) { _paused = true; _threadStatus = EThreadStatus.暂停; OnDataArgs.OnEvented(new CDataArgs(CLanguage.Lan("监控扫描时间") + ":" + wather.ElapsedMilliseconds.ToString() + "ms")); continue; } _threadStatus = EThreadStatus.运行; } } catch (Exception ex) { OnStatusArgs.OnEvented(new CConArgs(_threadMon.Name + CLanguage.Lan("监控线程异常错误") + ":" + ex.ToString(), true)); } finally { _dispose = false; _threadStatus = EThreadStatus.退出; OnStatusArgs.OnEvented(new CConArgs(_threadMon.Name + CLanguage.Lan("监控线程销毁退出"), true)); } }