| | |
| | | /// <summary> |
| | | /// 代码管理 |
| | | /// </summary> |
| | | private ObservableCollection<AlarmSetting> alarmSettings = new ObservableCollection<AlarmSetting>(); |
| | | private ObservableCollection<AlarmSetting> blockAlarmSettings = new ObservableCollection<AlarmSetting>(); |
| | | |
| | | public ObservableCollection<AlarmSetting> BlockAlarmSettings |
| | | { |
| | | get => blockAlarmSettings; |
| | | set |
| | | { |
| | | blockAlarmSettings = value; |
| | | RefreshBlockCache(); |
| | | } |
| | | } |
| | | private Dictionary<string, Dictionary<string, string>> BlockMap = new Dictionary<string, Dictionary<string, string>>(); |
| | | private Dictionary<string, string> BlockReadCache = new Dictionary<string, string>(); |
| | | |
| | | private void RefreshBlockCache() |
| | | { |
| | | BlockMap.Clear(); |
| | | BlockReadCache.Clear(); |
| | | if (BlockAlarmSettings == null || BlockAlarmSettings.Count <= 0) |
| | | { |
| | | return; |
| | | } |
| | | foreach (var setting in BlockAlarmSettings) |
| | | { |
| | | string key = $"{setting.DBAddress}.{setting.StartAddress}"; |
| | | if (!BlockMap.ContainsKey(key)) |
| | | { |
| | | BlockMap[key] = new Dictionary<string, string>(); |
| | | } |
| | | var codes = BlockMap[key]; |
| | | codes[setting.AlarmCode] = setting.Description; |
| | | } |
| | | } |
| | | |
| | | // <summary> |
| | | /// 标志位报警管理 |
| | | /// </summary> |
| | |
| | | /// </summary> |
| | | private List<AlarmText> currentAlarmCachePlcToMain = new List<AlarmText>(); |
| | | |
| | | private AlarmText alarm; |
| | | //private AlarmText alarm; |
| | | private SystemSetting systemSetting; |
| | | |
| | | private ObservableCollection<AlarmText> datasource = new ObservableCollection<AlarmText>(); |
| | |
| | | |
| | | MonitorTimer = new Timer |
| | | { |
| | | Interval = 100, |
| | | Interval = 1000, |
| | | }; |
| | | MonitorTimer.Elapsed += MonitorTimer_Elapsed; |
| | | if (!lTSCADAApi.Connect2(opcIP, opcPort, localPort, out string errMsg)) |
| | |
| | | |
| | | PcTimer = new Timer |
| | | { |
| | | Interval = 100, |
| | | Interval = 1000, |
| | | AutoReset = false |
| | | }; |
| | | PcTimer.Elapsed += PcTimer_Elapsed; |
| | |
| | | |
| | | private void OpenSettingWindow() |
| | | { |
| | | AlarmSettingList listModal = new AlarmSettingList(blockPath, markPath,alarmSettings,markAlarmSetting, log) |
| | | AlarmSettingList listModal = new AlarmSettingList(blockPath, markPath, BlockAlarmSettings, markAlarmSetting, log) |
| | | { |
| | | Owner = Window.GetWindow(this) |
| | | }; |
| | | listModal.ShowDialog(); |
| | | alarmSettings = listModal.Datasource; |
| | | BlockAlarmSettings = listModal.Datasource; |
| | | markAlarmSetting = listModal.MarkDatasource; |
| | | } |
| | | |
| | |
| | | { |
| | | try |
| | | { |
| | | alarmSettings = XmlHelper.DeserializeFromXml<ObservableCollection<AlarmSetting>>(blockPath); |
| | | BlockAlarmSettings = XmlHelper.DeserializeFromXml<ObservableCollection<AlarmSetting>>(blockPath); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | log.Error("LoadAlarmSetting Error.", ex); |
| | | alarmSettings = new ObservableCollection<AlarmSetting>(); |
| | | BlockAlarmSettings = new ObservableCollection<AlarmSetting>(); |
| | | } |
| | | |
| | | try |
| | |
| | | case "AlarmCode": |
| | | AlarmText aalarm = AlarmTexts.FirstOrDefault(alarm => alarm.AlarmCode == MsgStr); |
| | | if (aalarm == null) break; |
| | | var data = new AlarmText { |
| | | var data = new AlarmText |
| | | { |
| | | Source = "PC", |
| | | AlarmCode = aalarm.AlarmCode, |
| | | AlarmInfo = aalarm.MAlarmText_CN, |
| | |
| | | // } |
| | | //} |
| | | |
| | | /// <summary> |
| | | /// PLC报警读取 |
| | | /// </summary> |
| | | /// <param name="sender"></param> |
| | | /// <param name="e"></param> |
| | | private void MonitorTimer_Elapsed(object sender, ElapsedEventArgs e) |
| | | { |
| | | try |
| | |
| | | |
| | | isHaveAlarm = false; |
| | | List<AlarmText> cache = new List<AlarmText>(); |
| | | foreach (var item in alarmSettings) |
| | | //foreach (var item in BlockAlarmSettings) |
| | | //{ |
| | | // var name = $"{item.DBAddress}.{item.StartAddress}"; |
| | | // if (lTSCADAApi.DoFctReadSingle(name, out string alarmCode, out errMsg) && alarmCode != "0") |
| | | // { |
| | | // isHaveAlarm = true; |
| | | // if (!textMap.TryGetValue(alarmCode, out alarm)) { |
| | | // continue; |
| | | // } |
| | | // var newAlarm = new AlarmText |
| | | // { |
| | | // Source = "PLC", |
| | | // AlarmCode = alarm.AlarmCode, |
| | | // ModuleName_CN = alarm.ModuleName_CN, |
| | | // MAlarmText_CN = alarm.MAlarmText_CN, |
| | | // Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), |
| | | // AlarmInfo = $"{alarm.ModuleName_CN} {alarm.MAlarmText_CN}" |
| | | // }; |
| | | // if (this.currentAlarmCachePlc |
| | | // .Find(alarm => alarm.AlarmCode == newAlarm.AlarmCode) == null) |
| | | // { |
| | | // this.currentAlarmCachePlc.Add(newAlarm); |
| | | // } |
| | | // } |
| | | //} |
| | | |
| | | foreach (var key in BlockMap.Keys) |
| | | { |
| | | var name = $"{item.DBAddress}.{item.StartAddress}"; |
| | | if (lTSCADAApi.DoFctReadSingle(name, out string alarmCode, out errMsg) && alarmCode != "0") |
| | | if (lTSCADAApi.DoFctReadSingle(key, out string alarmCode, out errMsg) && BlockMap[key].ContainsKey(alarmCode)) |
| | | { |
| | | //if(BlockReadCache.ContainsKey(key) && alarmCode) |
| | | isHaveAlarm = true; |
| | | if (!textMap.TryGetValue(alarmCode, out alarm)) { |
| | | continue; |
| | | } |
| | | var text = BlockMap[key][alarmCode]; |
| | | var newAlarm = new AlarmText |
| | | { |
| | | PLC_DB_BLOCK = key, |
| | | Source = "PLC", |
| | | AlarmCode = alarm.AlarmCode, |
| | | ModuleName_CN = alarm.ModuleName_CN, |
| | | MAlarmText_CN = alarm.MAlarmText_CN, |
| | | AlarmCode = alarmCode, |
| | | ModuleName_CN = text, |
| | | MAlarmText_CN = text, |
| | | Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), |
| | | AlarmInfo = $"{alarm.ModuleName_CN} {alarm.MAlarmText_CN}" |
| | | AlarmInfo = $"{alarmCode} {text}" |
| | | }; |
| | | if (this.currentAlarmCachePlc |
| | | .Find(alarm => alarm.AlarmCode == newAlarm.AlarmCode) == null) |
| | | .Find(alarm => alarm.AlarmCode == newAlarm.AlarmCode && alarm.PLC_DB_BLOCK == newAlarm.PLC_DB_BLOCK) == null) |
| | | { |
| | | this.currentAlarmCachePlc.Add(newAlarm); |
| | | } |
| | |
| | | } |
| | | finally |
| | | { |
| | | if(!isClosing) this.MonitorTimer.Enabled = true; |
| | | if (!isClosing) this.MonitorTimer.Enabled = true; |
| | | } |
| | | } |
| | | |
| | |
| | | private void RefreshDBSetting() |
| | | { |
| | | List<byte> bytes = new List<byte>(); |
| | | foreach (var item in alarmSettings) |
| | | foreach (var item in BlockAlarmSettings) |
| | | { |
| | | //byte[] itemalarmCodeBytes = this.plc.Simens_S7_ReadBytes_DB("DB", item.DBAddress, item.StartAddress, item.Length); |
| | | //bytes.AddRange(itemalarmCodeBytes.ToList()); |
| | |
| | | } |
| | | } |
| | | this.currentAlarmCachePc.Clear(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 发送日志消息 |
| | | /// </summary> |
| | | /// <param name="Msg">日志消息</param> |
| | | private void SendLogMsg(string Msg) |
| | | { |
| | | string LogMsg = "{\"Type\":\"Alarm\",\"Source\":\"" + alarm.Source + "\",\"Msg\":\"" + Msg + "\",\"Time\":\"" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\"}"; |
| | | this.loggeralarm.Send("Log", LogMsg); |
| | | } |
| | | } |
| | | } |