Ejemplo n.º 1
0
 protected override void OnActive(SubCondition condition, Storage value, DateTime timeStamp)
 {
     if (condition.SubAlarmType != ActiveSubCondition)
     {
         if (condition.SubAlarmType != _tempType)
         {
             _timeStamp = timeStamp;
             _tempType  = condition.SubAlarmType;
         }
         if (_delay == 0 || (timeStamp - _timeStamp).TotalMilliseconds > _delay)
         {
             if (ActiveSubCondition == SubAlarmType.None)
             {
                 _active         = true;
                 _condLastActive = timeStamp;
             }
             _ack = false;
             ActiveSubCondition = condition.SubAlarmType;
             _current.Duration  = timeStamp - SubCondLastActive;
             _current           = new AlarmItem(timeStamp, condition.Message, _tag.GetValue(value), ActiveSubCondition, condition.Severity, _id, _source);
             if (AlarmActive != null)
             {
                 foreach (AlarmEventHandler deleg in AlarmActive.GetInvocationList())
                 {
                     deleg.BeginInvoke(this, _current, null, null);
                 }
             }
             RaiseChanged("Value");
         }
     }
     else
     {
         RaiseChanged("Value");
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Configures the low humidity alarm
        /// </summary>
        /// <param name="humOn">The percent humidity to trip the alarm</param>
        /// <param name="humOff">The percent humidity to turn off the alarm</param>
        /// <param name="mode">Alarm active state</param>
        /// <param name="outputConfig">Alarm output configuration</param>
        /// <returns>Total amount of data transferred</returns>
        public int setAlarmLow(int humOn, int humOff, AlarmActive mode = AlarmActive.High, AlarmOutputConfig outputConfig = AlarmOutputConfig.Open_Drain)
        {
            byte[] rawConfig = new byte[3];
            readEEPROM(EEPROM.Cust_Config, rawConfig);
            int config = rawConfig[1] << 8 | rawConfig[2];

            if (mode != AlarmActive.High)
            {
                config |= 0x200;
            }
            else
            {
                config &= 0xFDFF;
            }

            if (outputConfig == AlarmOutputConfig.Open_Drain)
            {
                config |= 0x400;
            }
            else
            {
                config &= 0xFBFF;
            }

            humOn  = (int)(humOn * 168.83);
            humOff = (int)(humOff * 168.83);
            int result = writeEEPROM(EEPROM.Alarm_Low_On, new byte[] { (byte)(humOn >> 8), (byte)(humOn &= 0xFF) });

            Thread.Sleep(20);
            result += writeEEPROM(EEPROM.Alarm_Low_Off, new byte[] { (byte)(humOff >> 8), (byte)(humOff &= 0xFF) });
            Thread.Sleep(20);
            result += writeEEPROM(EEPROM.Cust_Config, new byte[] { (byte)(config >> 8), (byte)(config &= 0xFF) });
            Thread.Sleep(20);
            return(result);
        }
Ejemplo n.º 3
0
 protected override void OnInActive(Storage value)
 {
     if (ActiveSubCondition != SubAlarmType.None)
     {
         _active            = false;
         ActiveSubCondition = SubAlarmType.None;
         _current.Duration  = DateTime.Now - LastActive;
         _current           = new AlarmItem(DateTime.Now, string.Concat("【", Comment, "】", ALARMSTOP), 0, SubAlarmType.None, Severity.Normal, _id, _source);
         if (AlarmActive != null)
         {
             foreach (AlarmEventHandler deleg in AlarmActive.GetInvocationList())
             {
                 deleg.BeginInvoke(this, _current, null, null);
             }
         }
     }
 }
Ejemplo n.º 4
0
 protected override void OnActive(SubCondition condition, Storage value, DateTime timeStamp)
 {
     if (ActiveSubCondition == SubAlarmType.None)
     {
         _active         = true;
         _condLastActive = timeStamp;
     }
     _ack = false;
     ActiveSubCondition = condition.SubAlarmType;
     _current           = new AlarmItem(timeStamp, condition.Message, value.Int16, ActiveSubCondition, condition.Severity, _id, _source);
     if (AlarmActive != null)
     {
         foreach (AlarmEventHandler deleg in AlarmActive.GetInvocationList())
         {
             deleg.BeginInvoke(this, _current, null, null);
         }
     }
     RaiseChanged("Value");
 }
Ejemplo n.º 5
0
 public void InvokeAlarmActive(AlarmActiveEventArgs args)
 {
     AlarmActive?.Invoke(this, args);
 }