Ejemplo n.º 1
0
        /// <summary>
        /// 获取数字量报警
        /// </summary>
        protected void GetDigitalAlarm(bool _value, string _alarmcode)
        {
            if (AlarmSettingList.Count(c => c.alarmCode == _alarmcode) > 0)
            {
                var tmp = AlarmSettingList.Where(c => c.alarmCode == _alarmcode).FirstOrDefault();
                tmp.AlarmLogValue.devID      = DevNum;
                tmp.AlarmLogValue.devName    = tmp.devName;
                tmp.AlarmLogValue.alarmCode  = _alarmcode;
                tmp.AlarmLogValue.alarmName  = tmp.alarmName;
                tmp.AlarmLogValue.alarmValue = Convert.ToDecimal(_value);
                tmp.AlarmLogValue.alarmState = _value ? 1 : -1;//_value=false时为异常状态
                tmp.AlarmLogValue.insertTime = DateTime.Now;

                if (!tmp.IsAlarm)
                {
                    if (!_value)
                    {
                        if (!tmp.TimerState)
                        {
                            tmp.TimerState    = true;
                            tmp.Timercallback = alarmlog_bll.Add;
                            tmp.ParamTimer.Change(tmp.delayed * 1000, Timeout.Infinite);
                        }
                    }
                    else
                    {
                        tmp.ParamTimer.Change(Timeout.Infinite, Timeout.Infinite);
                        tmp.TimerState = false;
                    }
                }
                else
                {
                    if (_value)
                    {
                        if (!tmp.TimerState)
                        {
                            tmp.TimerState    = true;
                            tmp.Timercallback = alarmlog_bll.ReSet;
                            tmp.ParamTimer.Change(tmp.delayed * 1000, Timeout.Infinite);
                        }
                    }
                    else
                    {
                        tmp.ParamTimer.Change(Timeout.Infinite, Timeout.Infinite);
                        tmp.TimerState = false;
                    }
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 获取模拟量报警
 /// </summary>
 protected void GetAnalogAlarm(decimal _value, string _alarmcode)
 {
     if (AlarmSettingList.Count(c => c.alarmCode == _alarmcode) > 0)
     {
         var tmp = AlarmSettingList.Where(c => c.alarmCode == _alarmcode).FirstOrDefault();
         tmp.AlarmLogValue.devID      = DevNum;
         tmp.AlarmLogValue.devName    = tmp.devName;
         tmp.AlarmLogValue.alarmCode  = _alarmcode;
         tmp.AlarmLogValue.alarmName  = tmp.alarmName;
         tmp.AlarmLogValue.alarmValue = _value;
         tmp.AlarmLogValue.insertTime = DateTime.Now;
         if (_value >= tmp.maxValue || _value <= tmp.minValue)
         {
             if (_value <= tmp.minValue)
             {
                 tmp.AlarmLogValue.alarmState = -2;//超低报警
             }
             else
             {
                 tmp.AlarmLogValue.alarmState = 2;//超高报警
             }
             if (!tmp.IsAlarm)
             {
                 if (!tmp.TimerState)
                 {
                     tmp.TimerState    = true;
                     tmp.Timercallback = alarmlog_bll.Add;
                     tmp.ParamTimer.Change(tmp.delayed * 1000, Timeout.Infinite);
                 }
             }
             else
             {
                 if (tmp.TimerState)
                 {
                     tmp.ParamTimer.Change(Timeout.Infinite, Timeout.Infinite);
                     tmp.TimerState = false;
                 }
             }
         }
         else
         {
             tmp.AlarmLogValue.alarmState = 1;//恢复正常
             if (tmp.IsAlarm)
             {
                 if (!tmp.TimerState)
                 {
                     tmp.TimerState    = true;
                     tmp.Timercallback = alarmlog_bll.ReSet;   //liuli :检查当前状态如果正常就新增一条数据记录代码正常
                     tmp.ParamTimer.Change(tmp.delayed * 1000, Timeout.Infinite);
                 }
             }
             else
             {
                 if (tmp.TimerState)
                 {
                     tmp.ParamTimer.Change(Timeout.Infinite, Timeout.Infinite);
                     tmp.TimerState = false;
                 }
             }
         }
     }
 }