| | |
| | | using HMI.Core.Entity; |
| | | using HMI.Core.Setting; |
| | | using HMI.Core.Util; |
| | | using HMI.Simple.Util; |
| | | using log4net; |
| | | using S7Driver; |
| | | using System; |
| | | using System.Collections.Generic; |
| | |
| | | |
| | | public event EventHandler<LoadMsg> LoadMessageAppend; |
| | | |
| | | private static ILog log = LogManager.GetLogger("AlarmHelper"); |
| | | |
| | | internal AlarmHelper() |
| | | { |
| | | |
| | | } |
| | | |
| | | public ObservableCollection<AlarmSetting> BlockSettings { get; private set; } |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | //log.Error("Read OPCServer Data Error.", ex); |
| | | log.Error("Read PLC Alarm Data Error.", ex); |
| | | } |
| | | finally |
| | | { |
| | |
| | | |
| | | private void RefershAlarm() |
| | | { |
| | | alarmRefershToMain.Send("AlarmRefersh", string.Empty); |
| | | alarmRefershToMain.Send("AlarmRefersh", string.Empty, string.Empty, 0); |
| | | List<AlarmText> alarms = new List<AlarmText>(); |
| | | |
| | | foreach (AlarmText alarm in currentPLCAlarmCache) |
| | |
| | | try |
| | | { |
| | | mqTimer.Enabled = false; |
| | | alarmQueue.Receive(100, out string MessageID, out string MsgStr); |
| | | if (MessageID != string.Empty) |
| | | alarmQueue.Receive(100, out string MessageID, out MQAlarm alarm); |
| | | if (MessageID != string.Empty && alarm != null) |
| | | { |
| | | switch (MessageID) |
| | | { |
| | |
| | | //} |
| | | break; |
| | | default: |
| | | string[] arr = MsgStr.Split(','); |
| | | string source = "PC"; |
| | | string info = string.Empty; |
| | | if (arr.Length > 1) |
| | | { |
| | | source = arr[0]; |
| | | info = arr[1]; |
| | | } |
| | | else |
| | | { |
| | | info = MsgStr; |
| | | } |
| | | string source = string.IsNullOrEmpty(alarm.Source) ? "PC" : alarm.Source; |
| | | string info = alarm.Content; |
| | | |
| | | AlarmText newAlarm = new AlarmText |
| | | { |
| | | Source = source, |
| | | VirtualId = $"{source}:{info}", |
| | | AlarmInfo = info, |
| | | Level = 3, |
| | | Level = alarm.Level, |
| | | Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") |
| | | }; |
| | | if (currentMQAlarmCache |
| | | .Find(alarm => alarm.Source == newAlarm.Source && alarm.AlarmInfo == newAlarm.AlarmInfo) == null) |
| | | .Find(a => a.Source == newAlarm.Source && a.AlarmInfo == newAlarm.AlarmInfo) == null) |
| | | { |
| | | currentMQAlarmCache.Add(newAlarm); |
| | | RefershAlarm(); |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | //log.Error("PcTimer Execute Failed", ex); |
| | | log.Error("Read MSMQ Alarm Data Failed", ex); |
| | | } |
| | | finally |
| | | { |
| | |
| | | BlockReadCache.Clear(); |
| | | try |
| | | { |
| | | BlockSettings = XmlHelper.DeserializeFromXml<ObservableCollection<AlarmSetting>>(blockFilePath); |
| | | BlockSettings = HMI.Core.Util.XmlHelper.DeserializeFromXml<ObservableCollection<AlarmSetting>>(blockFilePath); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | { |
| | | try |
| | | { |
| | | MarkSettings = XmlHelper.DeserializeFromXml<ObservableCollection<AlarmSetting>>(markFilePath); |
| | | MarkSettings = HMI.Core.Util.XmlHelper.DeserializeFromXml<ObservableCollection<AlarmSetting>>(markFilePath); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | |
| | | public void UpdateBlockSettings(IEnumerable<AlarmSetting> settings) |
| | | { |
| | | XmlHelper.SerializeToXml(blockFilePath, settings); |
| | | HMI.Core.Util.XmlHelper.SerializeToXml(blockFilePath, settings); |
| | | RefreshBlockSettings(); |
| | | } |
| | | |
| | | public void UpdateMarkSettings(IEnumerable<AlarmSetting> settings) |
| | | { |
| | | XmlHelper.SerializeToXml(markFilePath, settings); |
| | | HMI.Core.Util.XmlHelper.SerializeToXml(markFilePath, settings); |
| | | RefreshMarkSettings(); |
| | | } |
| | | } |