From fd37f833dbd94c4f0417a6fcf919c900769ff1b4 Mon Sep 17 00:00:00 2001 From: lhiven <2366881222@qq.com> Date: Mon, 22 Jan 2024 10:48:28 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=8F=91=E9=80=81=E7=BB=99=E4=B8=AD?= =?UTF-8?q?=E6=8E=A7=E6=B6=88=E6=81=AF=E5=A2=9E=E5=8A=A0=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E7=BC=96=E7=A0=81=E5=8F=82=E6=95=B0=202?= =?UTF-8?q?=E3=80=81=E5=A2=9E=E5=8A=A0=E6=8A=A5=E8=AD=A6=E5=BC=B9=E6=A1=86?= =?UTF-8?q?=E5=A4=84=E7=90=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Rs.SkyLine/Commom/AlarmMsg.cs | 53 +++++++ Rs.SkyLine/Commom/Scheduling.cs | 155 +++++++++++++++++++++ Rs.SkyLine/Entitys/AlarmEntity.cs | 8 ++ Rs.SkyLine/Flow/NormalFlow/TurnoverFlow.cs | 2 +- Rs.SkyLine/Flow/TestCenter.cs | 53 +++++-- Rs.SkyLine/Rs.SkyLine.csproj | 1 + Rs.SkyLine/SysConfig/StartPosConfig.cs | 2 +- Rs.SkyLine/TestFrm.Designer.cs | 13 ++ Rs.SkyLine/TestFrm.cs | 5 + 9 files changed, 278 insertions(+), 14 deletions(-) create mode 100644 Rs.SkyLine/Commom/AlarmMsg.cs diff --git a/Rs.SkyLine/Commom/AlarmMsg.cs b/Rs.SkyLine/Commom/AlarmMsg.cs new file mode 100644 index 0000000..045a140 --- /dev/null +++ b/Rs.SkyLine/Commom/AlarmMsg.cs @@ -0,0 +1,53 @@ +using Microsoft.SqlServer.Server; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json; +using Rs.MotionPlat.Flow; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static Rs.MotionPlat.Commom.SchedulingAlarms; +using static Rs.MotionPlat.Commom.SchedulingMessageBox; +using System.Threading; +using Rs.MotionPlat.Entitys; +using Rs.Framework; + +namespace Rs.MotionPlat.Commom +{ + public class AlarmMsg + { + static ETipButton Show(AlarmItem alarmInfo) + { + SchedulingAlarms alarms = new SchedulingAlarms(); + alarms.Alarms.Add(alarmInfo); + alarms.GroupID = 0; + alarms.TurnoverID = 0; + alarms.Instruction = EInstruction.SetAlarms; + string content = JsonConvert.SerializeObject(alarms, new StringEnumConverter()); + TestCenter.Instance.Send(content, Encoding.UTF8,true); + //信息发出去只有就等待 + while (true) + { + AlarmItem? alarm = TestCenter.Instance.GetAlarm(alarmInfo.NO); + if(alarm != null) + { + return alarm.Value.Button; + } + Thread.Sleep(500); + } + } + + public static ETipButton Show(int no, AlarmEntity alarmInfo,ETipButton button, Dictionary buttonText) + { + AlarmItem msg = new AlarmItem(); + msg.NO = no; + msg.ZH = alarmInfo.CN; + msg.EN = alarmInfo.EN; + msg.KO = alarmInfo.KO; + msg.Button = button; + msg.ButtonContexts = buttonText; + return Show(msg); + } + } +} diff --git a/Rs.SkyLine/Commom/Scheduling.cs b/Rs.SkyLine/Commom/Scheduling.cs index 4b9efd3..ca73120 100644 --- a/Rs.SkyLine/Commom/Scheduling.cs +++ b/Rs.SkyLine/Commom/Scheduling.cs @@ -6,6 +6,8 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; +using static Rs.MotionPlat.Commom.SchedulingAlarms; +using static Rs.MotionPlat.Commom.SchedulingMessageBox; namespace Rs.MotionPlat.Commom { @@ -830,6 +832,159 @@ namespace Rs.MotionPlat.Commom } + + public interface IAlarmItem : IEquatable + { + /// + /// 编号 + /// + int NO { get; } + /// + /// 报警节点的UID + /// + long NodeUID { get; } + /// + /// 报警节点内的所有错误索引 + /// + ISet Indexes { get; } + /// + /// 标签 + /// + string Tag { get; } + /// + /// 该报警是否会引发停机 + /// + bool Pause { get; } + /// + /// 报警等级 + /// + AlarmLevel Level { get; } + /// + /// 已在别的地方展示,只收录,不弹窗 + /// + bool ShowElsewhere { get; } + /// + /// 获取报警信息 + /// + /// 区域信息 + /// + string GetMessage(CultureInfo culture); + } + public enum AlarmLevel + { + None, Warn, Alarm, Jam + } + + /// + /// 排料报警 + /// + public class SchedulingAlarms : Scheduling + { + /// + /// 报警项,如果item1 == item2 将会认作同一报警 + /// + public IList Alarms { get; set; } = new List(); + + + + public struct AlarmItem : IAlarmItem + { + /// + /// 报警序号 + /// + public int NO { get; set; } + /// + /// 引发报警的节点UID + /// + public long NodeUID { get; set; } + /// + /// 引发报警节点的穴位索引(如:周转盘穴位 3) + /// + public int? Index + { + get => Indexes?.LastOrDefault(null); + set + { + if (value == null) return; + if (Indexes == null) + Indexes = new HashSet(); + HashSet list = Indexes; + if (!list.Contains(value.Value)) + { + list.Add(value.Value); + } + } + } + + public override bool Equals(object obj) => obj is IAlarmItem other && Equals(other); + + /// + /// 相等比较方法 + /// + /// + /// + public bool Equals(IAlarmItem other) + => other != null && NO == other.NO && NodeUID == other.NodeUID && Tag == other.Tag; + /// + /// 引发报警的节点的穴位索引列表 + /// + public HashSet Indexes { get; set; } + /// + /// 报警标签 + /// + public string Tag { get; set; } + /// + /// 该报警是否会造成停机 + /// + public bool Pause { get; set; } + /// + /// 报警等级 + /// + public AlarmLevel Level { get; set; } + /// + /// 触发报警()时为报警弹窗显示的按钮, + /// 取消报警时为通过该按钮取消的报警弹窗 + /// + public ETipButton Button { get; set; } + /// + /// 定制弹窗按钮文本内容 + /// + public Dictionary ButtonContexts { get; set; } + /// + /// 已在别的地方展示,只收录,不弹窗 + /// + public bool ShowElsewhere { get; set; } + /// + /// 报警消息英文版 + /// + public string EN { get; set; } + /// + /// 报警消息中文版 + /// + public string ZH { get; set; } + /// + /// 报警消息韩文版 + /// + public string KO { get; set; } + + ISet IAlarmItem.Indexes => Indexes; + + public string GetMessage(CultureInfo culture) + { + switch ((culture ?? CultureInfo.CurrentCulture)?.TwoLetterISOLanguageName.ToLower()) + { + case "en": return EN; + case "ko": return string.IsNullOrEmpty(KO) ? KO : ZH; + default: return ZH; + } + } + } + + public SchedulingAlarms() { } + + public SchedulingAlarms(params AlarmItem[] items) => Alarms = items; + } + /// /// 指令 /// diff --git a/Rs.SkyLine/Entitys/AlarmEntity.cs b/Rs.SkyLine/Entitys/AlarmEntity.cs index 4072da6..45c97d2 100644 --- a/Rs.SkyLine/Entitys/AlarmEntity.cs +++ b/Rs.SkyLine/Entitys/AlarmEntity.cs @@ -123,5 +123,13 @@ namespace Rs.MotionPlat.Entitys /// 韩文 /// public string KO { get; set; } + + public AlarmEntity Transform(params string[] args) + { + CN = string.Format(CN, args); + EN = string.Format(EN, args); + KO = string.Format(KO, args); + return this; + } } } diff --git a/Rs.SkyLine/Flow/NormalFlow/TurnoverFlow.cs b/Rs.SkyLine/Flow/NormalFlow/TurnoverFlow.cs index 5b384b2..34a89fc 100644 --- a/Rs.SkyLine/Flow/NormalFlow/TurnoverFlow.cs +++ b/Rs.SkyLine/Flow/NormalFlow/TurnoverFlow.cs @@ -592,7 +592,7 @@ namespace Rs.MotionPlat.Flow { LoadAndUnloadTask.Instance.TestloadTaskArrived = false; string reportStr = LoadAndUnloadTask.Instance.GetTestLoadString(); - TestCenter.Instance.Send(reportStr); + TestCenter.Instance.Send(reportStr,Encoding.ASCII); LoadAndUnloadTask.Instance.Clear(1); MachineManage.Instance.SetLoadUnloadStatus(ERunState.Waiting); MessageQueue.Instance.Insert("通知中控周转载盘产品已取走,可以继续排料"); diff --git a/Rs.SkyLine/Flow/TestCenter.cs b/Rs.SkyLine/Flow/TestCenter.cs index 53046cc..ea18eaf 100644 --- a/Rs.SkyLine/Flow/TestCenter.cs +++ b/Rs.SkyLine/Flow/TestCenter.cs @@ -13,6 +13,7 @@ using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; +using static Rs.MotionPlat.Commom.SchedulingAlarms; using static Rs.MotionPlat.Commom.SchedulingSilo; using static System.Windows.Forms.AxHost; using static System.Windows.Forms.VisualStyles.VisualStyleElement; @@ -24,6 +25,7 @@ namespace Rs.MotionPlat.Flow TcpClientHelper client = new TcpClientHelper("127.0.0.1",2048); SchedulingResult schedulResult = new SchedulingResult(); SchedulingMaterial sm; + Dictionary alarmInfos = new Dictionary(); public event Action ReciveTaskEvent; public event Action ReplayTaskEvent; private TestCenter() { @@ -244,6 +246,17 @@ namespace Rs.MotionPlat.Flow case EInstruction.SetAlarms: break; case EInstruction.CancelAlarms: + SchedulingAlarms alarms= JsonConvert.DeserializeObject(msg); + if(alarms!=null&&alarms.Alarms!=null&&alarms.Alarms.Count>0) + { + foreach (AlarmItem alarm in alarms.Alarms) + { + if(!alarmInfos.ContainsKey(alarm.NO)) + { + alarmInfos.Add(alarm.NO, alarm); + } + } + } break; case EInstruction.TakingError: break; @@ -262,6 +275,18 @@ namespace Rs.MotionPlat.Flow } + + public AlarmItem? GetAlarm(int no) + { + AlarmItem? ret = null; + if (alarmInfos.ContainsKey(no)) + { + ret = alarmInfos[no]; + alarmInfos.Remove(no); + } + return ret; + } + /// /// 重排 /// @@ -484,30 +509,34 @@ namespace Rs.MotionPlat.Flow public bool LoadResult() { string content = LoadAndUnloadTask.Instance.GetLoadString(); - return Send(content) > 0; + return Send(content, Encoding.ASCII) > 0; } public bool LoadTestLoadResult() { string content = LoadAndUnloadTask.Instance.GetTestLoadString(); - return Send(content) > 0; + return Send(content, Encoding.ASCII) > 0; } public bool LoadTestUnLoadResult() { string content = LoadAndUnloadTask.Instance.GetTestUnLoadString(); - return Send(content) > 0; + return Send(content, Encoding.ASCII) > 0; } - public int Send(string content,bool writeLog=true) + public int Send(string content,Encoding encode,bool writeLog=true) { - int len = client.Send(content); - if(len>0 && writeLog) + while (true) { - LogHelper.Debug(" <<< " + content); - return len; + int len = client.Send(content, encode); + if (len > 0 && writeLog) + { + LogHelper.Debug(" <<< " + content); + return len; + } + Thread.Sleep(1000); } - return 0; + } /// /// 上报信息给中控 @@ -519,12 +548,12 @@ namespace Rs.MotionPlat.Flow if(scheduing.Instruction== EInstruction.InquireStatus) { string content = JsonConvert.SerializeObject(scheduing, new StringEnumConverter()); - return Send(content,false); + return Send(content, Encoding.ASCII,false); } else { string content = JsonConvert.SerializeObject(scheduing, new StringEnumConverter()); - return Send(content); + return Send(content, Encoding.ASCII); } } @@ -533,7 +562,7 @@ namespace Rs.MotionPlat.Flow Scheduling s = new Scheduling(); s.Instruction = EInstruction.EndInput; string content = JsonConvert.SerializeObject(s, new StringEnumConverter()); - Send(content); + Send(content, Encoding.ASCII); } diff --git a/Rs.SkyLine/Rs.SkyLine.csproj b/Rs.SkyLine/Rs.SkyLine.csproj index 4382c3e..4b345aa 100644 --- a/Rs.SkyLine/Rs.SkyLine.csproj +++ b/Rs.SkyLine/Rs.SkyLine.csproj @@ -133,6 +133,7 @@ + diff --git a/Rs.SkyLine/SysConfig/StartPosConfig.cs b/Rs.SkyLine/SysConfig/StartPosConfig.cs index f8bee67..778bddd 100644 --- a/Rs.SkyLine/SysConfig/StartPosConfig.cs +++ b/Rs.SkyLine/SysConfig/StartPosConfig.cs @@ -69,7 +69,7 @@ namespace Rs.MotionPlat.SysConfig s.Message = "hello"; s.Button = SchedulingMessageBox.ETipButton.RetrySkip; string content = JsonConvert.SerializeObject(s, new StringEnumConverter()); - TestCenter.Instance.Send(content); + TestCenter.Instance.Send(content, Encoding.ASCII); } } } diff --git a/Rs.SkyLine/TestFrm.Designer.cs b/Rs.SkyLine/TestFrm.Designer.cs index 4997151..d4eb996 100644 --- a/Rs.SkyLine/TestFrm.Designer.cs +++ b/Rs.SkyLine/TestFrm.Designer.cs @@ -59,6 +59,7 @@ this.button23 = new System.Windows.Forms.Button(); this.button24 = new System.Windows.Forms.Button(); this.button25 = new System.Windows.Forms.Button(); + this.button26 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // btnTurnoverSlotException @@ -371,11 +372,22 @@ this.button25.UseVisualStyleBackColor = true; this.button25.Click += new System.EventHandler(this.button25_Click); // + // button26 + // + this.button26.Location = new System.Drawing.Point(271, 585); + this.button26.Name = "button26"; + this.button26.Size = new System.Drawing.Size(173, 42); + this.button26.TabIndex = 3; + this.button26.Text = "报警弹框测试"; + this.button26.UseVisualStyleBackColor = true; + this.button26.Click += new System.EventHandler(this.button26_Click); + // // TestFrm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1336, 854); + this.Controls.Add(this.button26); this.Controls.Add(this.button24); this.Controls.Add(this.button23); this.Controls.Add(this.button14); @@ -446,5 +458,6 @@ private System.Windows.Forms.Button button23; private System.Windows.Forms.Button button24; private System.Windows.Forms.Button button25; + private System.Windows.Forms.Button button26; } } \ No newline at end of file diff --git a/Rs.SkyLine/TestFrm.cs b/Rs.SkyLine/TestFrm.cs index 686b22c..0947718 100644 --- a/Rs.SkyLine/TestFrm.cs +++ b/Rs.SkyLine/TestFrm.cs @@ -251,5 +251,10 @@ namespace Rs.MotionPlat } LogHelper.Debug("已到上方"); } + + private void button26_Click(object sender, EventArgs e) + { + AlarmMsg.Show(1001, AlarmCollection.Get(1001).Transform("3", "4"), ETipButton.Yes,null); + } } }