From aafaeabb0e5532594bf04b0780fefb10bf3ba136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com> Date: Fri, 8 Apr 2022 11:34:48 +0800 Subject: [PATCH] =?UTF-8?q?IOT=E4=B8=8A=E6=8A=A5=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HardwareStatusAttribute.cs | 28 ++++++ HBLConsole.Business/IotReport.cs | 40 ++++++--- HBLConsole.Factory/SimpleFactory.cs | 7 +- HBLConsole.Interface/IHardwareStatus.cs | 15 ++++ HBLConsole.MORKS/Alarm.cs | 22 +++++ HBLConsole.MORKS/Control_MORKS.cs | 6 +- HBLConsole.MORKS/HardwareStatus.cs | 19 ++++ HBLConsole/ViewModel/AlarmViewModel.cs | 38 ++++++++ HBLConsole/ViewModel/MainViewModel.cs | 86 ++++++++++++------- .../ViewModel/VariableMonitorViewModel.cs | 26 +++--- 10 files changed, 230 insertions(+), 57 deletions(-) create mode 100644 HBLConsole.Attribute/HardwareStatusAttribute.cs create mode 100644 HBLConsole.Interface/IHardwareStatus.cs create mode 100644 HBLConsole.MORKS/Alarm.cs create mode 100644 HBLConsole.MORKS/HardwareStatus.cs diff --git a/HBLConsole.Attribute/HardwareStatusAttribute.cs b/HBLConsole.Attribute/HardwareStatusAttribute.cs new file mode 100644 index 0000000..b3eacc6 --- /dev/null +++ b/HBLConsole.Attribute/HardwareStatusAttribute.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HBLConsole.Attributes +{ + public class HardwareStatusAttribute : Attribute + { + public HardwareStatusAttribute(string describe, string address) + { + Describe = describe; + this.Address = address; + } + + /// + /// 描述 + /// + public string Describe { get; set; } + + + /// + /// 地址 + /// + public string Address { get; set; } + } +} diff --git a/HBLConsole.Business/IotReport.cs b/HBLConsole.Business/IotReport.cs index 889ce84..71adcff 100644 --- a/HBLConsole.Business/IotReport.cs +++ b/HBLConsole.Business/IotReport.cs @@ -35,6 +35,13 @@ namespace HBLConsole.Business /// 属性状态 /// public string NodeStatus = "{\"data\":[{\"Id\":0,\"VarName\":\"InitComplete\",\"PLCAddress\":\"M100.0\",\"Notes\":\"初始化完成\",\"ModbusTcpAddress\":\"1120\",\"CurrentValue\":\"False\"},{\"Id\":1,\"VarName\":\"TurntableInPlace\",\"PLCAddress\":\"M100.1\",\"Notes\":\"转台到位\",\"ModbusTcpAddress\":\"1121\",\"CurrentValue\":\"False\"},{\"Id\":2,\"VarName\":\"RBTakeNoodleComplete\",\"PLCAddress\":\"M100.2\",\"Notes\":\"机器人取面完成\",\"ModbusTcpAddress\":\"1122\",\"CurrentValue\":\"False\"},{\"Id\":3,\"VarName\":\"AxisIdle_1\",\"PLCAddress\":\"M100.3\",\"Notes\":\"轴空闲_1\",\"ModbusTcpAddress\":\"1123\",\"CurrentValue\":\"False\"},{\"Id\":4,\"VarName\":\"AxisIdle_2\",\"PLCAddress\":\"M100.4\",\"Notes\":\"轴空闲_2\",\"ModbusTcpAddress\":\"1124\",\"CurrentValue\":\"False\"},{\"Id\":5,\"VarName\":\"AxisAllowInvertedNoodle_1\",\"PLCAddress\":\"M100.5\",\"Notes\":\"轴允许倒面_1\",\"ModbusTcpAddress\":\"1125\",\"CurrentValue\":\"False\"},{\"Id\":6,\"VarName\":\"AxisAllowInvertedNoodle_2\",\"PLCAddress\":\"M100.6\",\"Notes\":\"轴允许倒面_2\",\"ModbusTcpAddress\":\"1126\",\"CurrentValue\":\"False\"},{\"Id\":7,\"VarName\":\"AxisAllowInvertedSoup_1\",\"PLCAddress\":\"M101.0\",\"Notes\":\"轴允许倒浇头_1\",\"ModbusTcpAddress\":\"1127\",\"CurrentValue\":\"False\"},{\"Id\":8,\"VarName\":\"AxisAllowInvertedSoup_2\",\"PLCAddress\":\"M101.0\",\"Notes\":\"轴允许倒浇头_2\",\"ModbusTcpAddress\":\"1128\",\"CurrentValue\":\"False\"},{\"Id\":9,\"VarName\":\"SoupHeatComplete_1\",\"PLCAddress\":\"M101.1\",\"Notes\":\"浇头加热完成_1\",\"ModbusTcpAddress\":\"1129\",\"CurrentValue\":\"False\"},{\"Id\":10,\"VarName\":\"SoupHeatComplete_2\",\"PLCAddress\":\"M101.2\",\"Notes\":\"浇头加热完成_2\",\"ModbusTcpAddress\":\"1130\",\"CurrentValue\":\"False\"},{\"Id\":11,\"VarName\":\"CookNoodleBasketIdle_1\",\"PLCAddress\":\"M101.3\",\"Notes\":\"煮面篮空闲_1\",\"ModbusTcpAddress\":\"1131\",\"CurrentValue\":\"False\"},{\"Id\":12,\"VarName\":\"CookNoodleBasketIdle_2\",\"PLCAddress\":\"M101.4\",\"Notes\":\"煮面篮空闲_2\",\"ModbusTcpAddress\":\"1132\",\"CurrentValue\":\"False\"},{\"Id\":13,\"VarName\":\"CookNoodleBasketIdle_3\",\"PLCAddress\":\"M101.5\",\"Notes\":\"煮面篮空闲_3\",\"ModbusTcpAddress\":\"1133\",\"CurrentValue\":\"False\"},{\"Id\":14,\"VarName\":\"CookNoodleBasketIdle_4\",\"PLCAddress\":\"M101.6\",\"Notes\":\"煮面篮空闲_4\",\"ModbusTcpAddress\":\"1134\",\"CurrentValue\":\"False\"},{\"Id\":15,\"VarName\":\"CookNoodleBasketIdle_5\",\"PLCAddress\":\"M101.7\",\"Notes\":\"煮面篮空闲_5\",\"ModbusTcpAddress\":\"1135\",\"CurrentValue\":\"False\"},{\"Id\":16,\"VarName\":\"CookNoodleBasketIdle_6\",\"PLCAddress\":\"M101.8\",\"Notes\":\"煮面篮空闲_6\",\"ModbusTcpAddress\":\"1136\",\"CurrentValue\":\"False\"},{\"Id\":17,\"VarName\":\"CookNoodleComplete_1\",\"PLCAddress\":\"M102.1\",\"Notes\":\"煮面完成_1\",\"ModbusTcpAddress\":\"1137\",\"CurrentValue\":\"False\"},{\"Id\":18,\"VarName\":\"CookNoodleComplete_2\",\"PLCAddress\":\"M102.2\",\"Notes\":\"煮面完成_2\",\"ModbusTcpAddress\":\"1138\",\"CurrentValue\":\"False\"},{\"Id\":19,\"VarName\":\"CookNoodleComplete_3\",\"PLCAddress\":\"M102.3\",\"Notes\":\"煮面完成_3\",\"ModbusTcpAddress\":\"1139\",\"CurrentValue\":\"False\"},{\"Id\":20,\"VarName\":\"CookNoodleComplete_4\",\"PLCAddress\":\"M102.4\",\"Notes\":\"煮面完成_4\",\"ModbusTcpAddress\":\"1140\",\"CurrentValue\":\"False\"},{\"Id\":21,\"VarName\":\"CookNoodleComplete_5\",\"PLCAddress\":\"M102.5\",\"Notes\":\"煮面完成_5\",\"ModbusTcpAddress\":\"1141\",\"CurrentValue\":\"False\"},{\"Id\":22,\"VarName\":\"CookNoodleComplete_6\",\"PLCAddress\":\"M102.6\",\"Notes\":\"煮面完成_6\",\"ModbusTcpAddress\":\"1142\",\"CurrentValue\":\"False\"},{\"Id\":23,\"VarName\":\"TakeNoodleRobotIdle\",\"PLCAddress\":\"M102.7\",\"Notes\":\"取面机器人空闲状态\",\"ModbusTcpAddress\":\"1143\",\"CurrentValue\":\"False\"},{\"Id\":24,\"VarName\":\"TakeSoupRobotIdle\",\"PLCAddress\":\"M103.0\",\"Notes\":\"取浇头机器人空闲状态\",\"ModbusTcpAddress\":\"1144\",\"CurrentValue\":\"False\"},{\"Id\":25,\"VarName\":\"BreakMechanismIdle_1\",\"PLCAddress\":\"M103.1\",\"Notes\":\"破口机构空闲_1\",\"ModbusTcpAddress\":\"1145\",\"CurrentValue\":\"False\"},{\"Id\":26,\"VarName\":\"BreakMechanismIdle_2\",\"PLCAddress\":\"M103.2\",\"Notes\":\"破口机构空闲_2\",\"ModbusTcpAddress\":\"1146\",\"CurrentValue\":\"False\"},{\"Id\":27,\"VarName\":\"TakeSoupComplete\",\"PLCAddress\":\"M103.3\",\"Notes\":\"取浇头完成\",\"ModbusTcpAddress\":\"1147\",\"CurrentValue\":\"False\"},{\"Id\":28,\"VarName\":\"PutNoodleTakeMealComplete\",\"PLCAddress\":\"M103.4\",\"Notes\":\"放面至取餐口完成\",\"ModbusTcpAddress\":\"1148\",\"CurrentValue\":\"False\"},{\"Id\":29,\"VarName\":\"Initing\",\"PLCAddress\":\"M103.5\",\"Notes\":\"设备初始化中\",\"ModbusTcpAddress\":\"1149\",\"CurrentValue\":\"False\"},{\"Id\":30,\"VarName\":\"TurntableFeedbackloc\",\"PLCAddress\":\"VW1240\",\"Notes\":\"转台反馈位置\",\"ModbusTcpAddress\":\"720\",\"CurrentValue\":\"0\"},{\"Id\":31,\"VarName\":\"TurntableLowerLimit\",\"PLCAddress\":\"M120.0\",\"Notes\":\"转台下限位\",\"ModbusTcpAddress\":\"1280\",\"CurrentValue\":\"False\"},{\"Id\":32,\"VarName\":\"TurntableUpLimit\",\"PLCAddress\":\"M120.1\",\"Notes\":\"转台上限位\",\"ModbusTcpAddress\":\"1281\",\"CurrentValue\":\"False\"},{\"Id\":33,\"VarName\":\"SoupMaterialShortage_1\",\"PLCAddress\":\"M120.2\",\"Notes\":\"浇头缺料_1\",\"ModbusTcpAddress\":\"1282\",\"CurrentValue\":\"False\"},{\"Id\":34,\"VarName\":\"SoupMaterialShortage_2\",\"PLCAddress\":\"M120.3\",\"Notes\":\"浇头缺料_2\",\"ModbusTcpAddress\":\"1283\",\"CurrentValue\":\"False\"},{\"Id\":35,\"VarName\":\"SoupMaterialShortage_3\",\"PLCAddress\":\"M120.4\",\"Notes\":\"浇头缺料_3\",\"ModbusTcpAddress\":\"1284\",\"CurrentValue\":\"False\"},{\"Id\":36,\"VarName\":\"SoupMaterialShortage_4\",\"PLCAddress\":\"M120.5\",\"Notes\":\"浇头缺料_4\",\"ModbusTcpAddress\":\"1285\",\"CurrentValue\":\"False\"},{\"Id\":37,\"VarName\":\"SoupMaterialShortage_5\",\"PLCAddress\":\"M120.6\",\"Notes\":\"浇头缺料_5\",\"ModbusTcpAddress\":\"1286\",\"CurrentValue\":\"False\"},{\"Id\":38,\"VarName\":\"OutMealDetect_1\",\"PLCAddress\":\"M121.0\",\"Notes\":\"出餐口检测_1\",\"ModbusTcpAddress\":\"1287\",\"CurrentValue\":\"False\"},{\"Id\":39,\"VarName\":\"OutMealDetect_2\",\"PLCAddress\":\"M121.0\",\"Notes\":\"出餐口检测_2\",\"ModbusTcpAddress\":\"1288\",\"CurrentValue\":\"False\"},{\"Id\":40,\"VarName\":\"OutMealDetect_3\",\"PLCAddress\":\"M121.0\",\"Notes\":\"出餐口检测_3\",\"ModbusTcpAddress\":\"1289\",\"CurrentValue\":\"False\"},{\"Id\":41,\"VarName\":\"TemperatureReached\",\"PLCAddress\":\"M121.2\",\"Notes\":\"温度到达\",\"ModbusTcpAddress\":\"1290\",\"CurrentValue\":\"False\"},{\"Id\":42,\"VarName\":\"AllowPutSoup\",\"PLCAddress\":\"\",\"Notes\":\"允许倒浇头\",\"ModbusTcpAddress\":\"\",\"CurrentValue\":\"False\"},{\"Id\":43,\"VarName\":\"AllowTakeSoup\",\"PLCAddress\":\"\",\"Notes\":\"允许取浇头\",\"ModbusTcpAddress\":\"\",\"CurrentValue\":\"False\"},{\"Id\":44,\"VarName\":\"PutNoodleLoc\",\"PLCAddress\":\"\",\"Notes\":\"放面位置\",\"ModbusTcpAddress\":\"\",\"CurrentValue\":\"0\"},{\"Id\":45,\"VarName\":\"AxisIdleIndex\",\"PLCAddress\":\"\",\"Notes\":\"轴空闲位置\",\"ModbusTcpAddress\":\"\",\"CurrentValue\":\"-1\"},{\"Id\":46,\"VarName\":\"AxisIdleLockIndex\",\"PLCAddress\":\"\",\"Notes\":\"轴空闲互锁位置\",\"ModbusTcpAddress\":\"\",\"CurrentValue\":\"0\"},{\"Id\":47,\"VarName\":\"TurntableLoc\",\"PLCAddress\":\"\",\"Notes\":\"转台位置\",\"ModbusTcpAddress\":\"\",\"CurrentValue\":\"0\"},{\"Id\":48,\"VarName\":\"RobotTaskInterlock\",\"PLCAddress\":\"\",\"Notes\":\"机器人任务互锁信号\",\"ModbusTcpAddress\":\"\",\"CurrentValue\":\"False\"},{\"Id\":49,\"VarName\":\"TakeBowlInterlock\",\"PLCAddress\":\"\",\"Notes\":\"取碗互锁信号\",\"ModbusTcpAddress\":\"\",\"CurrentValue\":\"False\"},{\"Id\":50,\"VarName\":\"TakeNoodleInterlock\",\"PLCAddress\":\"\",\"Notes\":\"取面互锁信号\",\"ModbusTcpAddress\":\"\",\"CurrentValue\":\"False\"},{\"Id\":51,\"VarName\":\"OutNoodleing\",\"PLCAddress\":\"\",\"Notes\":\"出面中\",\"ModbusTcpAddress\":\"\",\"CurrentValue\":\"False\"},{\"Id\":52,\"VarName\":\"AllowTakeNoodle\",\"PLCAddress\":\"\",\"Notes\":\"允许取面\",\"ModbusTcpAddress\":\"\",\"CurrentValue\":\"False\"},{\"Id\":53,\"VarName\":\"TurntableInterlock\",\"PLCAddress\":\"\",\"Notes\":\"转台互锁信号\",\"ModbusTcpAddress\":\"\",\"CurrentValue\":\"False\"},{\"Id\":54,\"VarName\":\"CookNodeState_1\",\"PLCAddress\":null,\"Notes\":\"煮面炉互锁_1\",\"ModbusTcpAddress\":null,\"CurrentValue\":\"False\"},{\"Id\":55,\"VarName\":\"CookNodeState_2\",\"PLCAddress\":null,\"Notes\":\"煮面炉互锁_2\",\"ModbusTcpAddress\":null,\"CurrentValue\":\"False\"},{\"Id\":56,\"VarName\":\"CookNodeState_3\",\"PLCAddress\":null,\"Notes\":\"煮面炉互锁_3\",\"ModbusTcpAddress\":null,\"CurrentValue\":\"False\"},{\"Id\":57,\"VarName\":\"CookNodeState_4\",\"PLCAddress\":null,\"Notes\":\"煮面炉互锁_4\",\"ModbusTcpAddress\":null,\"CurrentValue\":\"False\"},{\"Id\":58,\"VarName\":\"CookNodeState_5\",\"PLCAddress\":null,\"Notes\":\"煮面炉互锁_5\",\"ModbusTcpAddress\":null,\"CurrentValue\":\"False\"},{\"Id\":59,\"VarName\":\"CookNodeState_6\",\"PLCAddress\":null,\"Notes\":\"煮面炉互锁_6\",\"ModbusTcpAddress\":null,\"CurrentValue\":\"False\"},{\"Id\":60,\"VarName\":\"AxisIdleLock_1\",\"PLCAddress\":null,\"Notes\":\"轴空闲互锁_1\",\"ModbusTcpAddress\":null,\"CurrentValue\":\"False\"},{\"Id\":61,\"VarName\":\"AxisIdleLock_2\",\"PLCAddress\":null,\"Notes\":\"轴空闲互锁_2\",\"ModbusTcpAddress\":null,\"CurrentValue\":\"False\"},{\"Id\":62,\"VarName\":\"AllowRun\",\"PLCAddress\":\"\",\"Notes\":\"允许运行\",\"ModbusTcpAddress\":\"\",\"CurrentValue\":\"False\"}]}"; + + /// + /// 硬件状态 + /// + public string HardwareStatus; + + public TargetIOT targetIOT { get; set; } = new TargetIOT(); #endregion #region IOT上报公共调用 @@ -45,13 +52,13 @@ namespace HBLConsole.Business /// public void SendAlarmMessage(AlarmTable alarmTable) { - if (IOTDevServer.client != null && IOTDevServer.client.IsConnected && device!=null) + if (IOTDevServer.client != null && IOTDevServer.client.IsConnected && device != null) { alarmTable.ClientId = InternetInfo.ClientId.ToString(); alarmTable.devicename = device.devicename; string json = Tools.JsonConvertTools>(new IotModel { @params = new AlarmIOT { GJXX = Tools.JsonConvertTools(alarmTable) } }); - IOTDevServer.GetInstance().IOT_Publish(IOTDevServer.PubTopic,json); - } + IOTDevServer.GetInstance().IOT_Publish(IOTDevServer.PubTopic, json); + } } /// @@ -66,7 +73,7 @@ namespace HBLConsole.Business logTable.devicename = device.devicename; logTable.ClientId = InternetInfo.ClientId.ToString(); string json = Tools.JsonConvertTools>(new IotModel { @params = new LogIOT { SZXX = Tools.JsonConvertTools(logTable) } }); - IOTDevServer.GetInstance().IOT_Publish(IOTDevServer.PubTopic,json); + IOTDevServer.GetInstance().IOT_Publish(IOTDevServer.PubTopic, json); } } @@ -85,6 +92,9 @@ namespace HBLConsole.Business NodeStatus = json; } + + + /// /// 上报属性状态 /// 调用示例:SendTargetMessage(); @@ -98,8 +108,8 @@ namespace HBLConsole.Business bool IsAllowRun = false; bool TemperatureReached = false; #endregion - string kzsx = Tools.JsonConvertTools(new DevSX{ data = new List { new DevSXBase { SXMC="", SXLX="" } }}); - + string kzsx = Tools.JsonConvertTools(new DevSX { data = new List { new DevSXBase { SXMC = "", SXLX = "" } } }); + string jbsx = Tools.JsonConvertTools(new DevSX { data = new List @@ -159,8 +169,8 @@ namespace HBLConsole.Business default: break; } - string jsonstr = Tools.JsonConvertTools>(new IotModel { @params = new TargetIOT { JBSX = jbsx,KZSX = kzsx,NodeStatus= NodeStatus } }); - IOTDevServer.GetInstance().IOT_Publish(IOTDevServer.PubTopic,jsonstr); + string jsonstr = Tools.JsonConvertTools>(new IotModel { @params = new TargetIOT { JBSX = jbsx, KZSX = kzsx, NodeStatus = NodeStatus } }); + IOTDevServer.GetInstance().IOT_Publish(IOTDevServer.PubTopic, jsonstr); } } #endregion @@ -171,7 +181,7 @@ namespace HBLConsole.Business /// public bool Initialize() { - if (!IOTDevServer.GetInstance().CreateLinks(InternetInfo.ClientId,out device)) + if (!IOTDevServer.GetInstance().CreateLinks(InternetInfo.ClientId, out device)) { MessageLog.GetInstance.Show($"设备{InternetInfo.ClientId}阿里云上没有该设备。"); return false; @@ -217,11 +227,16 @@ namespace HBLConsole.Business /// private T GetTypeValue(string str) { - return (T)SimpleFactory.GetInstance.GVL?.GetType().GetProperty(str)?.GetValue(SimpleFactory.GetInstance.GVL,null); + return (T)SimpleFactory.GetInstance.GVL?.GetType().GetProperty(str)?.GetValue(SimpleFactory.GetInstance.GVL, null); } #endregion } + public class IOTNode + { + public T data { get; set; } + } + /// /// 日志上报 /// @@ -260,5 +275,10 @@ namespace HBLConsole.Business /// 属性状态 /// public string NodeStatus { get; set; } + + /// + /// 硬件状态 + /// + public string HardwareStatus { get; set; } } } diff --git a/HBLConsole.Factory/SimpleFactory.cs b/HBLConsole.Factory/SimpleFactory.cs index 50f31e9..0916f5b 100644 --- a/HBLConsole.Factory/SimpleFactory.cs +++ b/HBLConsole.Factory/SimpleFactory.cs @@ -96,6 +96,7 @@ namespace HBLConsole.Factory public IControl control { get; set; } public IGvl GVL { get; set; } public IAlarm Alarm { get; set; } + public IHardwareStatus HardwareStatus { get; set; } public ControlAbstract controlAbstract { get; set; } /// @@ -116,6 +117,7 @@ namespace HBLConsole.Factory ActionManage.GetInstance.Register(new Action((o) => { control?.SimOrder(o); }), "SimOrder"); ActionManage.GetInstance.Register(new Action((o) => { control?.IotBroadcast(o); }), "IotBroadcast"); ConnectHelper.GetInstance.Init(); + ActionManage.GetInstance.Send("监控数据初始化"); //GetControlBase(); } @@ -142,12 +144,15 @@ namespace HBLConsole.Factory { GVL = (item.GetValue(control)) as IGvl; GvlName = item.Name; - } else if (inters.Name.Equals("IAlarm")) { Alarm = (item.GetValue(control)) as IAlarm; } + else if (inters.Name.Equals("IHardwareStatus")) + { + HardwareStatus = (item.GetValue(control)) as IHardwareStatus; + } } } } diff --git a/HBLConsole.Interface/IHardwareStatus.cs b/HBLConsole.Interface/IHardwareStatus.cs new file mode 100644 index 0000000..605e0c6 --- /dev/null +++ b/HBLConsole.Interface/IHardwareStatus.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HBLConsole.Interface +{ + /// + /// 硬件状态接口 + /// + public interface IHardwareStatus + { + } +} diff --git a/HBLConsole.MORKS/Alarm.cs b/HBLConsole.MORKS/Alarm.cs new file mode 100644 index 0000000..52d904f --- /dev/null +++ b/HBLConsole.MORKS/Alarm.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using HBLConsole.Interface; +using HBLConsole.Attributes; + +namespace HBLConsole.MORKS +{ + public class Alarm : IAlarm + { + [Alarm("报警测试1")] + public bool AlarmTest1 { get; set; } + + [Alarm("报警测试2")] + public bool AlarmTest2 { get; set; } + + [Alarm("报警测试3")] + public bool AlarmTest3 { get; set; } + } +} diff --git a/HBLConsole.MORKS/Control_MORKS.cs b/HBLConsole.MORKS/Control_MORKS.cs index 94b5805..2e649ad 100644 --- a/HBLConsole.MORKS/Control_MORKS.cs +++ b/HBLConsole.MORKS/Control_MORKS.cs @@ -1,5 +1,4 @@ -//#define test -using BPA.Message; +using BPA.Message; using HBLConsole.Communication; using HBLConsole.Factory; using HBLConsole.Interface; @@ -22,6 +21,9 @@ namespace HBLConsole.MORKS public class Control_MORKS : IControl { GVL_MORKS mORKS = new GVL_MORKS(); + Alarm alarm = new Alarm(); + HardwareStatus hardwareStatus = new HardwareStatus(); + public void Init() { ActionManage.GetInstance.Register(new Action(() => { WriteRecipeBoms(); }), "recipeBom"); diff --git a/HBLConsole.MORKS/HardwareStatus.cs b/HBLConsole.MORKS/HardwareStatus.cs new file mode 100644 index 0000000..d73d2df --- /dev/null +++ b/HBLConsole.MORKS/HardwareStatus.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using HBLConsole.Interface; +using HBLConsole.Attributes; + +namespace HBLConsole.MORKS +{ + public class HardwareStatus : IHardwareStatus + { + [HardwareStatus("输入状态", "I0.0")] + public bool Input1 { get; set; } + + [HardwareStatus("输出状态", "Q0.0")] + public bool OutPut1 { get; set; } + } +} diff --git a/HBLConsole/ViewModel/AlarmViewModel.cs b/HBLConsole/ViewModel/AlarmViewModel.cs index 1ef426b..57ceebb 100644 --- a/HBLConsole/ViewModel/AlarmViewModel.cs +++ b/HBLConsole/ViewModel/AlarmViewModel.cs @@ -9,6 +9,8 @@ using System.Windows; using HBLConsole.Model; using HBLConsole.Service; using HBLConsole.Business; +using HBLConsole.Factory; +using System.Threading; namespace HBLConsole.ViewModel { @@ -65,6 +67,42 @@ namespace HBLConsole.ViewModel } + + public static void AlarmMonitoring() + { + ThreadManage.GetInstance.StartLong(new Action(() => + { + if (SimpleFactory.GetInstance.Alarm != null) + { + foreach (var item in SimpleFactory.GetInstance.Alarm.GetType().GetProperties()) + { + var res = item.GetValue(SimpleFactory.GetInstance.Alarm); + if (res != null) + { + if (res is bool blen) + { + if (item.CustomAttributes.Count() > 0) + { + if (item.CustomAttributes.ElementAt(0)?.ConstructorArguments.Count() > 0) + { + var info = item.CustomAttributes.ElementAt(0)?.ConstructorArguments.ElementAt(0).Value; + if (info != null) + { + App.Current.Dispatcher.Invoke(new Action(() => + { + AlarmHelper.GetInstance.EdgeAlarm(blen, info.ToString()); + })); + } + } + } + } + } + } + } + Thread.Sleep(500); + }), "报警检测监控"); + } + private void GetHistoryAlarm() { var data = Sqlite.GetInstance.Base.ToList(); diff --git a/HBLConsole/ViewModel/MainViewModel.cs b/HBLConsole/ViewModel/MainViewModel.cs index 8f38625..c2c9524 100644 --- a/HBLConsole/ViewModel/MainViewModel.cs +++ b/HBLConsole/ViewModel/MainViewModel.cs @@ -15,6 +15,8 @@ using HBLConsole.Model; using HBLConsole.Business; using HBLConsole.Factory; using HBLConsole.Attributes; +using BPA.Message.IOT; +using System.Collections.ObjectModel; namespace HBLConsole.ViewModel { @@ -32,44 +34,66 @@ namespace HBLConsole.ViewModel OrderCount = orderStatusLists.Count; Thread.Sleep(1000); }), "界面状态监控"); - AlarmMonitoring(); + //AlarmMonitoring(); + Init(); } - private void AlarmMonitoring() + private void Init() { - ThreadManage.GetInstance.StartLong(new Action(() => + ActionManage.GetInstance.Register(new Action(() => { - if (SimpleFactory.GetInstance.Alarm != null) + AlarmViewModel.AlarmMonitoring(); + VariableMonitorViewModel.AddMonitorData(); + VariableMonitorViewModel.UpdateValue(); + ThreadManage.GetInstance.StartLong(new Action(() => { - foreach (var item in SimpleFactory.GetInstance.Alarm.GetType().GetProperties()) - { - var res = item.GetValue(SimpleFactory.GetInstance.Alarm); - if (res != null) - { - if (res is bool blen) - { - if (item.CustomAttributes.Count() > 0) - { - if (item.CustomAttributes.ElementAt(0)?.ConstructorArguments.Count() > 0) - { - var info = item.CustomAttributes.ElementAt(0)?.ConstructorArguments.ElementAt(0).Value; - if (info != null) - { - App.Current.Dispatcher.Invoke(new Action(() => - { - AlarmHelper.GetInstance.EdgeAlarm(blen, info.ToString()); - })); - } - } - } - } - } - } - } - Thread.Sleep(500); - }), "报警检测监控"); + //节点状态上报 + IotReport.GetInstance.SendNodeStatusMessage(Tools.JsonConvertTools(new IOTNode> { data = VariableMonitorViewModel.VariableMonitors })); + + + + Thread.Sleep(1000); + }), "IOT数据上报"); + }), "监控数据初始化"); + + } + //private void AlarmMonitoring() + //{ + // ThreadManage.GetInstance.StartLong(new Action(() => + // { + // if (SimpleFactory.GetInstance.Alarm != null) + // { + // foreach (var item in SimpleFactory.GetInstance.Alarm.GetType().GetProperties()) + // { + // var res = item.GetValue(SimpleFactory.GetInstance.Alarm); + // if (res != null) + // { + // if (res is bool blen) + // { + // if (item.CustomAttributes.Count() > 0) + // { + // if (item.CustomAttributes.ElementAt(0)?.ConstructorArguments.Count() > 0) + // { + // var info = item.CustomAttributes.ElementAt(0)?.ConstructorArguments.ElementAt(0).Value; + // if (info != null) + // { + // App.Current.Dispatcher.Invoke(new Action(() => + // { + // AlarmHelper.GetInstance.EdgeAlarm(blen, info.ToString()); + // })); + // } + // } + // } + // } + // } + // } + // } + // Thread.Sleep(500); + // }), "报警检测监控"); + //} + public RelayCommand NavChangedCommand { get; set; } private void DoNavChanged(object obj) diff --git a/HBLConsole/ViewModel/VariableMonitorViewModel.cs b/HBLConsole/ViewModel/VariableMonitorViewModel.cs index 69f6766..1db9deb 100644 --- a/HBLConsole/ViewModel/VariableMonitorViewModel.cs +++ b/HBLConsole/ViewModel/VariableMonitorViewModel.cs @@ -22,13 +22,13 @@ namespace HBLConsole.ViewModel WindowName = "变量监控"; } - static VariableMonitorViewModel() - { - AddMonitorData(); - UpdateValue(); - } + //static VariableMonitorViewModel() + //{ + // AddMonitorData(); + // UpdateValue(); + //} - private static void AddMonitorData() + public static void AddMonitorData() { if (SimpleFactory.GetInstance.GVL == null) return; foreach (var item in SimpleFactory.GetInstance.GVL.GetType().GetProperties()) @@ -129,7 +129,7 @@ namespace HBLConsole.ViewModel } } - private static void UpdateValue() + public static void UpdateValue() { if (SimpleFactory.GetInstance.GVL == null) return; ThreadManage.GetInstance.StartLong(new Action(() => @@ -171,8 +171,8 @@ namespace HBLConsole.ViewModel } } - - IotReport.GetInstance.SendNodeStatusMessage(Tools.JsonConvertTools(new IOTNode { data = VariableMonitors })); + + //IotReport.GetInstance.SendNodeStatusMessage(Tools.JsonConvertTools(new IOTNode { data = VariableMonitors })); Thread.Sleep(1000); }), "变量监控"); } @@ -181,8 +181,8 @@ namespace HBLConsole.ViewModel public static ObservableCollection VariableMonitors { get; set; } = new ObservableCollection(); } - public class IOTNode - { - public ObservableCollection data { get; set; } - } + //public class IOTNode + //{ + // public ObservableCollection data { get; set; } + //} }