| | |
| | | using MySql.Data.MySqlClient; |
| | | using Newtonsoft.Json; |
| | | using Newtonsoft.Json.Linq; |
| | | using NPOI.SS.Formula.Function; |
| | | using NPOI.SS.Formula.Functions; |
| | | using Org.BouncyCastle.Asn1.X509; |
| | | using Org.BouncyCastle.Ocsp; |
| | |
| | | |
| | | |
| | | Dictionary<string, List<int>> StateDIC = new Dictionary<string, List<int>>(); |
| | | List<string> AlarmTypeList = new List<string>(); |
| | | |
| | | int numplc = 0; |
| | | while (true) |
| | | { |
| | |
| | | } |
| | | |
| | | var alrams = item1.AlarmDetails; |
| | | |
| | | var plcdev = DeviceCollection.FirstOrDefault(u => u.Id == item1.plcname) as PLCBase; |
| | | |
| | | if (!StateDIC.ContainsKey(plcdev.Name)) |
| | | { |
| | | StateDIC[plcdev.Name] = new List<int>(); |
| | | } |
| | | |
| | | |
| | | |
| | | foreach (var item in alrams.GroupBy(u => u.address)) |
| | | { |
| | | int add = item.Key; |
| | | |
| | | var readres = plcdev.Read(add, 1, out _)[0]; |
| | | |
| | | var Allbin = Convert.ToString(readres, 2).PadLeft(16, '0').Select(c => c - '0').ToArray(); |
| | |
| | | foreach (var item2 in item) |
| | | { |
| | | item2.value = Allbin[item2.address2]; |
| | | |
| | | if (!AlarmTypeList.Contains(item2.alarmtype)) |
| | | { |
| | | |
| | | AlarmTypeList.Add(item2.alarmtype); |
| | | |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"报警类别{item2.alarmtype}加入队列,队列个数为{AlarmTypeList.Count}"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | string StateDICKey = ""; |
| | | |
| | | foreach (var item in AlarmTypeList) |
| | | { |
| | | |
| | | StateDICKey = plcdev.Name +"_"+ item; |
| | | |
| | | if (!StateDIC.ContainsKey(StateDICKey)) |
| | | { |
| | | |
| | | StateDIC[StateDICKey] = new List<int>(); |
| | | |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"报警类别{StateDICKey}加入字典:StateDIC"); |
| | | |
| | | } |
| | | |
| | | //if (!StateDIC.ContainsKey(plcdev.Name)) |
| | | //{ |
| | | |
| | | // StateDIC[plcdev.Name] = new List<int>(); |
| | | //} |
| | | } |
| | | |
| | | Dictionary<string, AlarmTypeData> AlarmType = new Dictionary<string, AlarmTypeData>(); |
| | | |
| | | List<int> list = new List<int>(); |
| | | |
| | | foreach (var item in alrams) |
| | | { |
| | | csvhead += $",{item.alarmname}"; |
| | | csvdata += $",{(item.value == 1 ? "1" : "")}"; |
| | | list.Add(item.value); |
| | | } |
| | | if (!AlarmType.ContainsKey(item.alarmtype)) |
| | | { |
| | | AlarmType.Add(item.alarmtype, new AlarmTypeData() |
| | | { |
| | | CSVhead = csvhead, |
| | | CSVdata = csvdata, |
| | | }); |
| | | |
| | | if (!StateDIC[plcdev.Name].SequenceEqual(list)) |
| | | } |
| | | |
| | | if (AlarmType.ContainsKey(item.alarmtype)) |
| | | { |
| | | AlarmType[item.alarmtype].CSVhead += $",{item.alarmname}"; |
| | | |
| | | AlarmType[item.alarmtype].CSVdata += $",{(item.value == 1 ? "1" : "")}"; |
| | | |
| | | AlarmType[item.alarmtype].AlarmTypeValue.Add(item.value); |
| | | |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"报警类别{item.alarmtype};数值{item.value}加入字典:AlarmType"); |
| | | } |
| | | |
| | | } |
| | | foreach(var item in AlarmType.Keys) |
| | | { |
| | | StateDIC[plcdev.Name].Clear(); |
| | | StateDIC[plcdev.Name].AddRange(list); |
| | | |
| | | CSVRecordAsync($"PLCstate_{plcdev.Name}.csv", csvdata, csvhead); |
| | | list = AlarmType[item].AlarmTypeValue; |
| | | |
| | | var showdata = alrams.Where(u => u.value == 1).Select(u => u.alarmname).ToList(); |
| | | string key = plcdev.Name+"_"+item; |
| | | |
| | | if (showdata == null) |
| | | if (!StateDIC[key].SequenceEqual(list)) |
| | | { |
| | | showdata = new List<string>(); |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{plcdev.Name}报警类型:{item}的信号发生变化"); |
| | | |
| | | StateDIC[key].Clear(); |
| | | |
| | | StateDIC[key].AddRange(list); |
| | | |
| | | CSVRecordAsync($"PLCstate_{key}.csv", AlarmType[item].CSVhead, AlarmType[item].CSVdata); |
| | | |
| | | var showdata = alrams.Where(u => u.value == 1).Select(u => u.alarmname).ToList(); |
| | | |
| | | if (showdata == null) |
| | | { |
| | | showdata = new List<string>(); |
| | | } |
| | | |
| | | if (showdata.Count > 0) |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"{plcdev.Name}报警 个数:{showdata.Count} {string.Join(',', showdata)}"); |
| | | } |
| | | else |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{plcdev.Name}报警 个数:0"); |
| | | } |
| | | } |
| | | |
| | | if (showdata.Count > 0) |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"{plcdev.Name}报警 个数:{showdata.Count} {string.Join(',', showdata)}"); |
| | | } |
| | | else |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{plcdev.Name}报警 个数:0"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch |
| | | { |
| | |
| | | { |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | try |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | public class AlarmTypeData |
| | | { |
| | | public List <int> AlarmTypeValue; |
| | | |
| | | public string CSVhead; |
| | | |
| | | public string CSVdata; |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 网络预热 |
| | | /// </summary> |