| | |
| | | public string plcname { get; set; } = ""; |
| | | |
| | | |
| | | |
| | | [Category("PLC配置")] |
| | | [DisplayName("是否启用")] |
| | | [Description("是否启用")] |
| | |
| | | [Description("报警名称")] |
| | | public string alarmname { get; set; } = ""; |
| | | |
| | | [Category("配置")] |
| | | [DisplayName("报警种类")] |
| | | [Description("报警种类")] |
| | | public string alarmtype { get; set; } = ""; |
| | | |
| | | |
| | | [Browsable(false)] |
| | | [JsonIgnore] |
| | | public int value { get; set; } = -1; |
| | |
| | | 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> |
| | |
| | | //g.DrawString("厂商", font, brush, (startX + 20) * Scale, (startY + 5) * Scale);// |
| | | //g.DrawString("嘉彰科技", font2, brush, (startX + 140) * Scale, (startY + 4) * Scale); |
| | | |
| | | BarcodeWriter writer = new BarcodeWriter(); |
| | | writer.Format = BarcodeFormat.QR_CODE; |
| | | QrCodeEncodingOptions options = new QrCodeEncodingOptions() |
| | | { |
| | | DisableECI = true,//设置内容编码 |
| | | CharacterSet = "UTF-8", //设置二维码的宽度和高度 |
| | | Width = 123, |
| | | Height = 123, |
| | | Margin = 1//设置二维码的边距,单位不是固定像素 |
| | | }; |
| | | |
| | | ////第二行数据 |
| | | //g.DrawRectangle(p, startX * Scale, (startY + 20) * Scale, 70 * Scale, 20 * Scale); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | //private void printDocument_Print(object sender, PrintPageEventArgs e) |
| | | //{ |
| | | // Font fntTxt = new Font("黑体", 15, System.Drawing.FontStyle.Bold);//正文文字 |
| | | // System.Drawing.Brush brush = new SolidBrush(System.Drawing.Color.Black);//画刷 |
| | | // try |
| | | // { |
| | | // string numvalue = message; |
| | | |
| | | // float Scale = (float)0.95; |
| | | // int startX = 10; |
| | | // int startY = 25; |
| | | |
| | | // //int length = 320 * Scale; |
| | | // //int height = 160 * Scale; |
| | | // var g = e.Graphics; |
| | | |
| | | // Font font = new Font("Arial", 8 * Scale);//设置字体颜色 |
| | | // Font font2 = new Font("Arial", 11 * Scale);//设置字体颜色 |
| | | // Font font3 = new Font("Arial", 36 * Scale);//设置字体颜色 |
| | | // Font font4 = new Font("Arial", 12 * Scale);//设置字体颜色 |
| | | |
| | | |
| | | // Pen p = new Pen(Color.Black, Scale);//定义了一个黑色,宽度为1的画笔 |
| | | // g.Clear(Color.White); |
| | | // g.DrawRectangle(p, startX * Scale, startY * Scale, 70 * Scale, 20 * Scale);//在画板上画矩形,起始坐标为(10,10),宽为80,高为20 |
| | | // g.DrawRectangle(p, startX * Scale, startY * Scale, 280 * Scale, 20 * Scale);//在画板上画矩形,起始坐标为(90,10),宽为80,高为20 |
| | | // g.DrawString("厂商", font, brush, (startX + 20) * Scale, (startY + 5) * Scale);// |
| | | // g.DrawString("嘉彰科技", font2, brush, (startX + 140) * Scale, (startY + 4) * Scale); |
| | | |
| | | |
| | | // //第二行数据 |
| | | // g.DrawRectangle(p, startX * Scale, (startY + 20) * Scale, 70 * Scale, 20 * Scale); |
| | | // g.DrawRectangle(p, startX * Scale, (startY + 20) * Scale, 280 * Scale, 20 * Scale); |
| | | // g.DrawString("品名", font, brush, (startX + 20) * Scale, (startY + 25) * Scale); |
| | | // g.DrawString(@"COVER LG208H-RC100 #2", font4, brush, (startX + 71) * Scale, (startY + 22) * Scale); |
| | | |
| | | // //第三行数据 |
| | | // g.DrawRectangle(p, startX * Scale, (startY + 40) * Scale, 70 * Scale, 20 * Scale); |
| | | // g.DrawRectangle(p, startX * Scale, (startY + 40) * Scale, 280 * Scale, 20 * Scale); |
| | | // g.DrawString("料号", font, brush, (startX + 20) * Scale, (startY + 45) * Scale); |
| | | // g.DrawString(@"436LG208I000", font2, brush, (startX + 130) * Scale, (startY + 43) * Scale); |
| | | |
| | | // //第四行数据 |
| | | // g.DrawRectangle(p, startX * Scale, (startY + 60) * Scale, 70 * Scale, 20 * Scale); |
| | | // g.DrawRectangle(p, startX * Scale, (startY + 60) * Scale, 210 * Scale, 20 * Scale); |
| | | // g.DrawString("数量", font, brush, (startX + 20) * Scale, (startY + 65) * Scale); |
| | | // g.DrawString(@"50PCS", font2, brush, (startX + 120) * Scale, (startY + 62) * Scale); |
| | | |
| | | // //第五行数据 |
| | | // g.DrawRectangle(p, startX * Scale, (startY + 80) * Scale, 70 * Scale, 20 * Scale); |
| | | // g.DrawRectangle(p, startX * Scale, (startY + 80) * Scale, 210 * Scale, 20 * Scale); |
| | | // g.DrawString("生产日期", font, brush, (startX + 10) * Scale, (startY + 85) * Scale); |
| | | // g.DrawString($"{DateTime.Now.ToString("yyyy.MM.dd")}", font2, brush, (startX + 105) * Scale, (startY + 82) * Scale); |
| | | |
| | | // //第六行数据 |
| | | // g.DrawRectangle(p, startX * Scale, (startY + 100) * Scale, 70 * Scale, 20 * Scale); |
| | | // g.DrawRectangle(p, startX * Scale, (startY + 100) * Scale, 140 * Scale, 20 * Scale); |
| | | // g.DrawRectangle(p, startX * Scale, (startY + 100) * Scale, 210 * Scale, 20 * Scale); |
| | | // g.DrawString("MARK1", font, brush, (startX + 15) * Scale, (startY + 104) * Scale); |
| | | // g.DrawString("MARK2", font, brush, (startX + 155) * Scale, (startY + 104) * Scale); |
| | | |
| | | |
| | | // //侧面 |
| | | // g.DrawRectangle(p, (startX + 210) * Scale, (startY + 60) * Scale, 70 * Scale, 60 * Scale); |
| | | // g.DrawString(@"#2", font3, brush, (startX + 210) * Scale, (startY + 62) * Scale); |
| | | // } |
| | | // catch (Exception ee) |
| | | // { |
| | | // MessageBox.Show(ee.Message); |
| | | // } |
| | | //} |
| | | |
| | | private void printDocument_Print222(object sender, PrintPageEventArgs e) |
| | | { |
| | | Font fntTxt = new Font("黑体", 15, System.Drawing.FontStyle.Bold);//正文文字 |