From b4917ce53449dbe291376ea03f139357216a61d3 Mon Sep 17 00:00:00 2001 From: NXX <447201003@qq> Date: Tue, 8 Nov 2022 13:36:42 +0800 Subject: [PATCH] Morkf --- BPASmartClient.Business/Plugin/MQTTMgr.cs | 2 +- BPASmartClient.Modbus/ModbusTcp.cs | 20 +- .../BPASmartClient.MorkBF.csproj | 8 + BPASmartClient.MorkBF/Control_MorkBF.cs | 194 +++++++++++- BPASmartClient.MorkBF/GVL_MorkBF.cs | 292 +++++++++++++++++- BPASmartClient.MorkBF/VIew/DebugView.xaml | 28 +- BPASmartClient.MorkBF/VIew/Monitor.xaml | 242 +++++++++++++++ BPASmartClient.MorkBF/VIew/Monitor.xaml.cs | 28 ++ .../ViewModel/DebugViewModel.cs | 65 +++- .../ViewModel/MonitorViewModel.cs | 25 ++ 10 files changed, 875 insertions(+), 29 deletions(-) create mode 100644 BPASmartClient.MorkBF/VIew/Monitor.xaml create mode 100644 BPASmartClient.MorkBF/VIew/Monitor.xaml.cs create mode 100644 BPASmartClient.MorkBF/ViewModel/MonitorViewModel.cs diff --git a/BPASmartClient.Business/Plugin/MQTTMgr.cs b/BPASmartClient.Business/Plugin/MQTTMgr.cs index 7ea8120d..1fc625b1 100644 --- a/BPASmartClient.Business/Plugin/MQTTMgr.cs +++ b/BPASmartClient.Business/Plugin/MQTTMgr.cs @@ -64,7 +64,7 @@ namespace BPASmartClient.Business string deviceId = deviceConfig[0].deviceModels[0].DeviceId; clientId = Plugin.GetInstance().GetPlugin().ClientId; //MQTT 初始化 - mqttProxy.Connect(MqttServerAccount.UserName, MqttServerAccount.Password, MqttServerConfig.Host, MqttServerConfig.Port, "ClientId:" + clientId + "DeviceId:" + deviceId + Guid.NewGuid().ToString()); + mqttProxy.Connect(MqttServerAccount.UserName, MqttServerAccount.Password, MqttServerConfig.Host, MqttServerConfig.Port, "ClientId:" + clientId + "DeviceId:" + deviceId + Guid.NewGuid().ToString()); ThreadManage.GetInstance().Start(() => { diff --git a/BPASmartClient.Modbus/ModbusTcp.cs b/BPASmartClient.Modbus/ModbusTcp.cs index 745cd61b..b18f23db 100644 --- a/BPASmartClient.Modbus/ModbusTcp.cs +++ b/BPASmartClient.Modbus/ModbusTcp.cs @@ -118,7 +118,15 @@ namespace BPASmartClient.Modbus if (address.Length > 0) { address = address.Trim(); - if (address.ToUpper().Contains("M") && address.Length >= 4) + if (address.ToUpper().Contains("GM") && address.Length >= 3) + { + var res = address.Remove(0, 2); + if (res != null && res.Length > 0) + { + return int.Parse(res) + 4096; + } + } + else if (address.ToUpper().Contains("M") && address.Length >= 4) { var res = address.Substring(1).Split('.'); if (res != null && res.Length == 2) @@ -132,15 +140,7 @@ namespace BPASmartClient.Modbus } } } - else if (address.ToUpper().Contains("GM") && address.Length >= 3) - { - var res = address.Remove(0,2); - if (res != null && res.Length > 0) - { - return int.Parse(res) + 4096; - } - } - + else if (address.ToUpper().Contains("GI") && address.Length >= 3) { var res = address.Remove(0, 2); diff --git a/BPASmartClient.MorkBF/BPASmartClient.MorkBF.csproj b/BPASmartClient.MorkBF/BPASmartClient.MorkBF.csproj index 79ecd1f7..14337820 100644 --- a/BPASmartClient.MorkBF/BPASmartClient.MorkBF.csproj +++ b/BPASmartClient.MorkBF/BPASmartClient.MorkBF.csproj @@ -11,7 +11,15 @@ + + + + $(DefaultXamlRuntime) + Designer + + + diff --git a/BPASmartClient.MorkBF/Control_MorkBF.cs b/BPASmartClient.MorkBF/Control_MorkBF.cs index 48f158dc..0b775b40 100644 --- a/BPASmartClient.MorkBF/Control_MorkBF.cs +++ b/BPASmartClient.MorkBF/Control_MorkBF.cs @@ -3,6 +3,7 @@ using BPASmartClient.Device; using BPASmartClient.EventBus; using BPASmartClient.Helper; using BPASmartClient.Model; +using BPASmartClient.MorkBF.ViewModel; using System; using System.Collections.Generic; using System.Linq; @@ -21,8 +22,8 @@ namespace BPASmartClient.MorkBF public override void DoMain() { - + MonitorViewModel.DeviceId = DeviceId; CommandRegist();//调试 ServerInit(); DataParse();//数据解析 @@ -115,7 +116,7 @@ namespace BPASmartClient.MorkBF ActionManage.GetInstance.Register(RobotProgramStart, "RobotProgramStart");//程序启动 ActionManage.GetInstance.Register(Robot_Pot1AllowInMaterail, "Robot_Pot1AllowInMaterail");//1号炒锅允许机器人投料 ActionManage.GetInstance.Register(Robot_Pot1OutFoodInSlowDown, "Robot_Pot1OutFoodInSlowDown");//1号炒锅出餐倒料到减速位 - ActionManage.GetInstance.Register(Robot_Pot1OutFoodInSlowDown, "Robot_Pot1OutFoodInSlowDown");//1号炒锅出餐倒料完成 + ActionManage.GetInstance.Register(Robot_Pot1OutFood, "Robot_Pot1OutFoodInSlowDown");//1号炒锅出餐倒料完成 ActionManage.GetInstance.Register(Robot_Pot2AllowInMaterail, "Robot_Pot2AllowInMaterail");//2号炒锅允许机器人投料 ActionManage.GetInstance.Register(Robot_Pot2OutFoodInSlowDown, "Robot_Pot2OutFoodInSlowDown");//2号炒锅出餐倒料到减速位 ActionManage.GetInstance.Register(Robot_Pot2OutFood, "Robot_Pot2OutFood");//2号炒锅出餐倒料完成 @@ -163,7 +164,122 @@ namespace BPASmartClient.MorkBF public override void ReadData() { - + GetStatus("M20.0",new Action((o)=> + { + if (o == null) return; + if(o is bool[] values&&values.Length == 19) + { + morkBF.FirePot1_InitCompleted = values[0]; + morkBF.FirePot1_IsAuto = values[1]; + morkBF.FirePot1_Emergencystop = values[2]; + morkBF.FirePot1_MealTubExist = values[3]; + morkBF.FirePot1_VegetablesTub1Exist = values[4]; + morkBF.FirePot1_VegetablesTub2Exist = values[5]; + morkBF.FirePot1_Seasoning1Exist = values[6]; + morkBF.FirePot1_Seasoning2Exist = values[7]; + morkBF.FirePot1_Accessories1Exist = values[8]; + morkBF.FirePot1_Accessories2Exist = values[9]; + morkBF.FirePot1_OutFoodTubExist = values[10]; + morkBF.FirePot1_OnOrigin = values[11]; + morkBF.FirePot1_FirePosition1 = values[12]; + morkBF.FirePot1_FirePosition2 = values[13]; + morkBF.FirePot1_FirePosition3 = values[14]; + morkBF.FirePot1_FirePosition4 = values[15]; + morkBF.FirePot1_PotOnOutFoodPosition = values[16]; + morkBF.FirePot1_PotOnIntoFoodPosition = values[17]; + morkBF.FirePot1_PotOnCleanPosition = values[18]; + + } + }),0); + + GetStatus("VW120", new Action((o) => + { + if (o == null) return; + if (o is int[] values&&values.Length == 2) + { + morkBF.FirePot1_Temperature = values[0]; + morkBF.FirePot1_Pulse = values[1]; + + } + }), 0); + + GetStatus("M25.0", new Action((o) => + { + if (o == null) return; + if (o is bool[] values&& values.Length == 19) + { + morkBF.FirePot2_InitCompleted = values[0]; + morkBF.FirePot2_IsAuto = values[1]; + morkBF.FirePot2_Emergencystop = values[2]; + morkBF.FirePot2_MealTubExist = values[3]; + morkBF.FirePot2_VegetablesTub1Exist = values[4]; + morkBF.FirePot2_VegetablesTub2Exist = values[5]; + morkBF.FirePot2_Seasoning1Exist = values[6]; + morkBF.FirePot2_Seasoning2Exist = values[7]; + morkBF.FirePot2_Accessories1Exist = values[8]; + morkBF.FirePot2_Accessories2Exist = values[9]; + morkBF.FirePot2_OutFoodTubExist = values[10]; + morkBF.FirePot2_OnOrigin = values[11]; + morkBF.FirePot2_FirePosition1 = values[12]; + morkBF.FirePot2_FirePosition2 = values[13]; + morkBF.FirePot2_FirePosition3 = values[14]; + morkBF.FirePot2_FirePosition4 = values[15]; + morkBF.FirePot2_PotOnOutFoodPosition = values[16]; + morkBF.FirePot2_PotOnIntoFoodPosition = values[17]; + morkBF.FirePot2_PotOnCleanPosition = values[18]; + + } + }), 0); + + GetStatus("VW150", new Action((o) => + { + if (o == null) return; + if (o is int[] values&& values.Length == 2) + { + morkBF.FirePot2_Temperature = values[0]; + morkBF.FirePot2_Pulse = values[1]; + + } + }), 0); + GetStatus("GM500", new Action((o) => + { + if (o == null) return; + if (o is bool[] values && values.Length == 7) + { + morkBF.Robot_FirePot1OutMeal = values[0]; + morkBF.Robot_FirePot1OutVegetables1 = values[1]; + morkBF.Robot_FirePot1OutVegetables2 = values[2]; + morkBF.Robot_FirePot1OutSeasoning = values[3]; + morkBF.Robot_FirePot1OutAccessories = values[4]; + morkBF.Robot_ArriveFirePot1 = values[5]; + morkBF.Robot_FirePot1OutFoodComplete = values[6]; + + } + }), 1); + GetStatus("GM510", new Action((o) => + { + if (o == null) return; + if (o is bool[] values && values.Length == 7) + { + morkBF.Robot_FirePot2OutMeal = values[0]; + morkBF.Robot_FirePot2OutVegetables1 = values[1]; + morkBF.Robot_FirePot2OutVegetables2 = values[2]; + morkBF.Robot_FirePot2OutSeasoning = values[3]; + morkBF.Robot_FirePot2OutAccessories = values[4]; + morkBF.Robot_ArriveFirePot2 = values[5]; + morkBF.Robot_FirePot2OutFoodComplete = values[6]; + + } + }), 1); + GetStatus("GI5", new Action((o) => + { + if (o == null) return; + if (o is int[] values && values.Length == 1) + { + morkBF.Robot_ActionCallback = values[0]; + } + }), 1); + } public override void ResetProgram() @@ -182,11 +298,32 @@ namespace BPASmartClient.MorkBF } + /// + /// 获取炒锅PLC的所有状态 + /// + /// + /// + /// 炒锅编号 + private void GetStatus(string key, Action action, int num) + { + if (dicPort2peripheralStatus.ContainsKey(num)) + { + if (dicPort2peripheralStatus[num].ContainsKey(key)) + { + action((object)dicPort2peripheralStatus[num][key]);//获取PLC指定地址的状态值 + } + } + } + #region 控制 private void FirePot_Write(string address, object value, int i = 0) { WriteControlExact(address, value, i); } + private void Robot_Write(string address, object value, int i = 1) + { + WriteControlExact(address, value, i); + } #region 炒锅1 /// @@ -251,6 +388,7 @@ namespace BPASmartClient.MorkBF } } #endregion + #region 炒锅2 /// /// 炒锅2设定加热挡位 @@ -315,6 +453,7 @@ namespace BPASmartClient.MorkBF } #endregion + #region 炒锅通用 /// /// 炒锅复位 @@ -548,61 +687,88 @@ namespace BPASmartClient.MorkBF } } #endregion + #region 机器人 /// /// 机器人启动 /// private void RobotStart() { - + Robot_Write("GM600",true); } /// /// 机器人停止 /// private void RobotStop() { - + Robot_Write("GM601", true); } /// /// 机器人复位 /// private void RobotReset() { - + Robot_Write("GM602", true); } /// /// 机器人程序重启 /// private void RobotProgramStart() { - + Robot_Write("GM603", true); } /// /// 1号炒锅允许机器人投料(炒锅在投料位给出) /// private void Robot_Pot1AllowInMaterail() { - + Robot_Write("GM520", true); } + /// + /// 1号炒锅出餐倒料到减速位 + /// private void Robot_Pot1OutFoodInSlowDown() { - + Robot_Write("GM621", true); } + /// + /// 1号炒锅出餐倒料完成 + /// + private void Robot_Pot1OutFood() + { + Robot_Write("GM522", true); + } + /// + /// 2号炒锅允许机器人投料(炒锅在投料位给出) + /// private void Robot_Pot2AllowInMaterail() { - + Robot_Write("GM530", true); } + /// + /// 2号炒锅出餐倒料到减速位。开始倒菜 + /// private void Robot_Pot2OutFoodInSlowDown() { - + Robot_Write("GM531", true); } + /// + /// 2号炒锅出餐倒料完成 + /// private void Robot_Pot2OutFood() { - + Robot_Write("GM532", true); } - private void RobotActionStart() + /// + /// + /// + private void RobotActionStart(object o) { - + if (o == null) return; + if(o is int value) + { + Robot_Write("GI0",value); + } } #endregion diff --git a/BPASmartClient.MorkBF/GVL_MorkBF.cs b/BPASmartClient.MorkBF/GVL_MorkBF.cs index 0dedfe7a..b232e8f0 100644 --- a/BPASmartClient.MorkBF/GVL_MorkBF.cs +++ b/BPASmartClient.MorkBF/GVL_MorkBF.cs @@ -1,4 +1,5 @@ -using BPASmartClient.MorkBF.Model; +using BPASmartClient.Device; +using BPASmartClient.MorkBF.Model; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -27,6 +28,295 @@ namespace BPASmartClient.MorkBF /// public bool FirePan2_Busy = false; + #region 炒锅1读取数据 + /// + /// 炒锅1锅低温度 + /// + [VariableMonitor("炒锅1锅低温度", "VW120","160")] + public int FirePot1_Temperature; + /// + /// 炒锅1脉冲值 + /// + [VariableMonitor("炒锅1脉冲值", "VW122", "161")] + public int FirePot1_Pulse; + /// + /// 炒锅1初始化完成 + /// + [VariableMonitor("炒锅1初始化完成", "M20.0", "480")] + public bool FirePot1_InitCompleted = false; + + /// + /// 炒锅1手动自动模式 + /// + [VariableMonitor("炒锅1手动自动模式", "M20.1", "481")] + public bool FirePot1_IsAuto; + /// + /// 炒锅1急停 + /// + [VariableMonitor("炒锅1急停", "M20.2", "482")] + public bool FirePot1_Emergencystop; + /// + /// 1#炒锅荤菜盆有无检测 + /// + [VariableMonitor("1#炒锅1锅低温度", "M20.3", "483")] + public bool FirePot1_MealTubExist; + /// + /// 1#炒锅素菜盆1有无检测 + /// + [VariableMonitor("炒锅素菜盆1有无检测", "M20.4", "484")] + public bool FirePot1_VegetablesTub1Exist; + /// + /// 1#炒锅素菜盆2有无检测 + /// + [VariableMonitor("1#炒锅素菜盆2有无检测", "M20.5", "485")] + public bool FirePot1_VegetablesTub2Exist; + /// + /// 1#炒锅调料盆1有无检测 + /// + [VariableMonitor("1#炒锅调料盆1有无检测", "M20.6", "486")] + public bool FirePot1_Seasoning1Exist; + /// + /// 1#炒锅调料盆2有无检测 + /// + [VariableMonitor("1#炒锅调料盆2有无检测", "M20.7", "487")] + public bool FirePot1_Seasoning2Exist; + /// + /// 1#炒锅辅料盆1有无检测 + /// + [VariableMonitor("1#炒锅辅料盆1有无检测", "M21.0", "488")] + public bool FirePot1_Accessories1Exist; + /// + /// 1#炒锅辅料盆2有无检测 + /// + [VariableMonitor("1#炒锅辅料盆2有无检测", "M21.1", "489")] + public bool FirePot1_Accessories2Exist; + /// + /// 1#炒锅出餐空盆有无检测 + /// + [VariableMonitor("1#炒锅出餐空盆有无检测", "M21.2", "490")] + public bool FirePot1_OutFoodTubExist; + /// + /// 1#炒锅在原点反馈 + /// + [VariableMonitor("1#炒锅在原点反馈", "M21.3", "491")] + public bool FirePot1_OnOrigin; + /// + /// 1#炒制位置1反馈 + /// + [VariableMonitor("1#炒制位置1反馈", "M21.4", "492")] + public bool FirePot1_FirePosition1; + /// + /// 1#炒制位置2反馈 + /// + [VariableMonitor("1#炒制位置2反馈", "M21.5", "493")] + public bool FirePot1_FirePosition2; + /// + /// 1#炒制位置3反馈 + /// + [VariableMonitor("1#炒制位置3反馈", "M21.6", "494")] + public bool FirePot1_FirePosition3; + /// + /// 1#炒制位置4反馈 + /// + [VariableMonitor("1#炒制位置4反馈", "M21.7", "495")] + public bool FirePot1_FirePosition4; + /// + /// 1#炒锅在出餐倒料位置反馈 + /// + [VariableMonitor("1#炒锅在出餐倒料位置反馈", "M22.0", "496")] + public bool FirePot1_PotOnOutFoodPosition; + /// + /// 1#炒锅在投料位置反馈、 + /// + [VariableMonitor("1#炒锅在投料位置反馈", "M22.1", "497")] + public bool FirePot1_PotOnIntoFoodPosition; + /// + /// 1#炒锅在洗锅位置反馈 + /// + [VariableMonitor("1#炒锅在洗锅位置反馈", "M22.2", "498")] + public bool FirePot1_PotOnCleanPosition; + #endregion + + #region 炒锅2读取数据 + /// + /// 炒锅2锅低温度 + /// + [VariableMonitor("炒锅2锅低温度", "VW150", "175")] + public int FirePot2_Temperature; + /// + /// 炒锅2脉冲值 + /// + [VariableMonitor("炒锅2脉冲值", "VW152", "176")] + public int FirePot2_Pulse; + /// + /// 炒锅2初始化完成 + /// + [VariableMonitor("炒锅2初始化完成", "M25.0", "520")] + public bool FirePot2_InitCompleted = false; + + /// + /// 炒锅2手动自动模式 + /// + [VariableMonitor("炒锅2手动自动模式", "M25.1", "521")] + public bool FirePot2_IsAuto; + /// + /// 炒锅2急停 + /// + [VariableMonitor("炒锅2急停", "M25.2", "522")] + public bool FirePot2_Emergencystop; + /// + /// 2#炒锅荤菜盆有无检测 + /// + [VariableMonitor("2#炒锅荤菜盆有无检测", "M25.3", "523")] + public bool FirePot2_MealTubExist; + /// + /// 2#炒锅素菜盆1有无检测 + /// + [VariableMonitor("2#炒锅素菜盆1有无检测", "M25.4", "524")] + public bool FirePot2_VegetablesTub1Exist; + /// + /// 2#炒锅素菜盆2有无检测 + /// + [VariableMonitor("2#炒锅素菜盆2有无检测", "M25.5", "525")] + public bool FirePot2_VegetablesTub2Exist; + /// + /// 2#炒锅调料盆1有无检测 + /// + [VariableMonitor("2#炒锅调料盆1有无检测", "M25.6", "526")] + public bool FirePot2_Seasoning1Exist; + /// + /// 2#炒锅调料盆2有无检测 + /// + [VariableMonitor("2#炒锅调料盆2有无检测", "M25.7", "527")] + public bool FirePot2_Seasoning2Exist; + /// + /// 2#炒锅辅料盆1有无检测 + /// + [VariableMonitor("2#炒锅1锅低温度", "M26.0", "528")] + public bool FirePot2_Accessories1Exist; + /// + /// 2#炒锅辅料盆2有无检测 + /// + [VariableMonitor("2#炒锅辅料盆2有无检测", "M26.1", "529")] + public bool FirePot2_Accessories2Exist; + /// + /// 2#炒锅出餐空盆有无检测 + /// + [VariableMonitor("2#炒锅出餐空盆有无检测", "M26.2", "530")] + public bool FirePot2_OutFoodTubExist; + /// + /// 2#炒锅在原点反馈 + /// + [VariableMonitor("2#炒锅在原点反馈", "M26.3", "531")] + public bool FirePot2_OnOrigin; + /// + /// 2#炒制位置1反馈 + /// + [VariableMonitor("2#炒制位置1反馈", "M26.4", "532")] + public bool FirePot2_FirePosition1; + /// + /// 2#炒制位置2反馈 + /// + [VariableMonitor("2#炒制位置2反馈", "M26.5", "533")] + public bool FirePot2_FirePosition2; + /// + /// 2#炒制位置3反馈 + /// + [VariableMonitor("2#炒制位置3反馈", "M26.6", "534")] + public bool FirePot2_FirePosition3; + /// + /// 2#炒制位置4反馈 + /// + [VariableMonitor("2#炒制位置4反馈", "M26.7", "535")] + public bool FirePot2_FirePosition4; + /// + /// 2#炒锅在出餐倒料位置反馈 + /// + [VariableMonitor("2#炒锅在出餐倒料位置反馈", "M27.0", "536")] + public bool FirePot2_PotOnOutFoodPosition; + /// + /// 2#炒锅在投料位置反馈、 + /// + [VariableMonitor("2#炒锅在投料位置反馈", "M27.1", "537")] + public bool FirePot2_PotOnIntoFoodPosition; + /// + /// 2#炒锅在洗锅位置反馈 + /// + [VariableMonitor("2#炒锅在洗锅位置反馈", "M27.2", "538")] + public bool FirePot2_PotOnCleanPosition; + #endregion + + #region 机器人数据读取 + /// + /// 1号锅倒荤菜完成 + /// + public bool Robot_FirePot1OutMeal; + /// + /// 1号炒锅倒素菜1完成 + /// + public bool Robot_FirePot1OutVegetables1; + /// + /// 1号炒锅倒素菜2完成 + /// + public bool Robot_FirePot1OutVegetables2; + /// + /// 1号炒锅倒调料完成 + /// + public bool Robot_FirePot1OutSeasoning; + /// + /// 1号炒锅倒辅料完成 + /// + public bool Robot_FirePot1OutAccessories; + /// + /// 机器人到位,请求1#炒锅倒菜 + /// + public bool Robot_ArriveFirePot1; + /// + /// 1号炒锅出餐完成 + /// + public bool Robot_FirePot1OutFoodComplete; + + + + + + /// + /// 2号锅倒荤菜完成 + /// + public bool Robot_FirePot2OutMeal; + /// + /// 2号炒锅倒素菜1完成 + /// + public bool Robot_FirePot2OutVegetables1; + /// + /// 2号炒锅倒素菜2完成 + /// + public bool Robot_FirePot2OutVegetables2; + /// + /// 2号炒锅倒调料完成 + /// + public bool Robot_FirePot2OutSeasoning; + /// + /// 2号炒锅倒辅料完成 + /// + public bool Robot_FirePot2OutAccessories; + /// + /// 机器人到位,请求1#炒锅倒菜 + /// + public bool Robot_ArriveFirePot2; + /// + /// 2号炒锅出餐完成 + /// + public bool Robot_FirePot2OutFoodComplete; + /// + /// 机器人动作反馈 + /// + public int Robot_ActionCallback; + + #endregion + + + public DateTime FirePan1_Date; public DateTime FirePan2_Date; } diff --git a/BPASmartClient.MorkBF/VIew/DebugView.xaml b/BPASmartClient.MorkBF/VIew/DebugView.xaml index cf4a0723..09a396e5 100644 --- a/BPASmartClient.MorkBF/VIew/DebugView.xaml +++ b/BPASmartClient.MorkBF/VIew/DebugView.xaml @@ -57,7 +57,33 @@ - + +