From aa072a1532d7a43262a4cff8dd71e27d5eb88f43 Mon Sep 17 00:00:00 2001 From: yahaha Date: Fri, 11 Nov 2022 17:57:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E8=8F=9C=E5=93=81=E5=BA=93?= =?UTF-8?q?=E4=B8=8E=E5=B0=8F=E7=82=92=E7=9A=84=E6=B5=81=E7=A8=8B=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BPASmartClient.MorkF/Control_MorkF.cs | 413 ++++++++++++++-------- BPASmartClient.MorkF/GVL_MorkF.cs | 15 +- BPASmartClient.MorkF/MaterialOperation.cs | 27 ++ 3 files changed, 304 insertions(+), 151 deletions(-) create mode 100644 BPASmartClient.MorkF/MaterialOperation.cs diff --git a/BPASmartClient.MorkF/Control_MorkF.cs b/BPASmartClient.MorkF/Control_MorkF.cs index ab657d51..c28b9688 100644 --- a/BPASmartClient.MorkF/Control_MorkF.cs +++ b/BPASmartClient.MorkF/Control_MorkF.cs @@ -12,6 +12,7 @@ using BPASmartClient.Model.小炒机; using BPASmartClient.MorkF.Model; using System.Text; using System.Collections.Concurrent; +using System.Windows.Documents; namespace BPASmartClient.MorkF { @@ -80,6 +81,11 @@ namespace BPASmartClient.MorkF /// private OrderLocInfo nowStirFryGood = null; + /// + /// 待取菜队列 + /// + private ConcurrentQueue materialOperationQuenes = new ConcurrentQueue(); + List resultorder = new List();//调试变量 /// @@ -102,6 +108,8 @@ namespace BPASmartClient.MorkF CommandRegist();//调试 ServerInit(); DeviceProcessLogShow("MORKF 设备初始化完成"); + ///初始化菜品库 + FoodLibInit(); } /// @@ -681,9 +689,21 @@ namespace BPASmartClient.MorkF /// /// 菜品库初始化 /// - public void FoodLibInit() + public bool FoodLibInit() { MaterailLibrary_Write("M0.2", true); + + for (int i = 0; i < sleepCount && !ml_morkf.InitialComplete; i++) + { + Thread.Sleep(sleepTime); + if (i >= sleepCount - 1) + { + MessageLog.GetInstance.Show("菜品库初始化超时"); + return false; + } + } + + return true; } /// /// 电磁阀启停 @@ -691,6 +711,11 @@ namespace BPASmartClient.MorkF /// 电磁阀启停:true:启动。false:停止。 public void Electromagnetism(object o) { + if (!ml_morkf.InitialComplete) + { + return; + } + if (o == null) return; if (o is List bs && bs.Count == 1) { @@ -699,6 +724,11 @@ namespace BPASmartClient.MorkF } public bool GetDistance_1() { + if (!ml_morkf.InitialComplete) + { + return false; + } + MessageLog.GetInstance.Show("爪子去到1号位"); MaterailLibrary_Write("M1.0", true); for (int i = 0; i < sleepCount && !ml_morkf.PawArrivePortOne; i++) @@ -718,6 +748,11 @@ namespace BPASmartClient.MorkF } public bool GetDistance_2() { + if (!ml_morkf.InitialComplete) + { + return false; + } + MessageLog.GetInstance.Show("爪子去到2号位"); MaterailLibrary_Write("M1.1", true); for (int i = 0; i < sleepCount && !ml_morkf.PawArrivePortTwo; i++) @@ -737,6 +772,11 @@ namespace BPASmartClient.MorkF } public bool GetDistance_3() { + if (!ml_morkf.InitialComplete) + { + return false; + } + MessageLog.GetInstance.Show("爪子去到3号位"); MaterailLibrary_Write("M1.2", true); for (int i = 0; i < sleepCount && !ml_morkf.PawArrivePortThree; i++) @@ -770,6 +810,11 @@ namespace BPASmartClient.MorkF /// public bool SetArmPosition(int x, int y) { + if(!ml_morkf.InitialComplete) + { + return false; + } + //取反 x -= 2 * x; y -= 2 * y; @@ -936,6 +981,10 @@ namespace BPASmartClient.MorkF ////关闭电磁阀 //Electromagnetism(new List { false }); //Thread.Sleep(300); + if(morkFs.ContainsKey(fryNum)) + { + morkFs[fryNum].GetMaterialComplete = true; + } } /// @@ -1169,13 +1218,39 @@ namespace BPASmartClient.MorkF { return; } + int i = 0; + //判断是否完成取菜 + for (i = 0; i < sleepCount*2 && !morkFs[num].GetMaterialComplete; i++) + { + if(i == 3) + { + //停止搅拌 + StopStir(num); + //火力设置为2档 + SetFire(new List { 2 }, num); + } + Thread.Sleep(sleepTime); + if (i >= sleepCount * 2 - 1) + { + MessageLog.GetInstance.Show($"炒锅{num}倒菜超时:未能等到取菜完成"); + return; + } + } + + if (i > 3) + { + //开启搅拌 + StartStir(num); + //火力设置回原本火力 + SetFire(new List { morkFs[num].Fire }, num); + } FirePot_Write("LB3", true, num); MessageLog.GetInstance.Show("倒菜启动"); - Thread.Sleep(400); + Thread.Sleep(200); - for (int i = 0; i < sleepCount && !morkFs[num].FryPot1_MaterialIntoPot; i++) + for (i = 0; i < sleepCount && !morkFs[num].FryPot1_MaterialIntoPot; i++) { Thread.Sleep(sleepTime); if (i >= sleepCount - 1) @@ -1571,7 +1646,7 @@ namespace BPASmartClient.MorkF //遍历炒锅,找到合适、空闲的炒锅 for(int i = 0;i + //设置当前炒制菜品 + nowStirFryGood = res; + //炒锅工作状态置为正在工作中 + morkFs[i].FryWorking = true; + //空闲炒锅入队列 + morkFs[i].StirFryGoodsQuenes.Enqueue(res); + //炒锅取菜状态置为未取到 + morkFs[i].GetMaterialComplete = false; + MessageLog.GetInstance.Show($"炒锅{i}开始炒制菜品{res.GoodName}"); + + //开启线程进行炒制 + ThreadManage.GetInstance().Start(new Action(() => + { + try { - try + int getMaterailNum = 0; + foreach (var potActions in res.StirPotActions) { - int getMaterailNum = 0; - foreach (var potActions in res.StirPotActions) + if (ThreadManage.GetInstance().IsCanncel(String.Format(striConst, i.ToString(), nowStirFryGood.GoodName))) { - if (ThreadManage.GetInstance().IsCanncel(String.Format(striConst, i.ToString(), nowStirFryGood.GoodName))) - { - return; - } - - switch (potActions.Actions) - { - case nameof(StirFryPotActionEnum.加热开启): - StartFire(i); - MessageLog.GetInstance.Show(potActions.Actions); - break; - case nameof(StirFryPotActionEnum.设置加热挡位1): - SetFire(new List { 1 }, i); - MessageLog.GetInstance.Show(potActions.Actions); - break; - case nameof(StirFryPotActionEnum.设置加热挡位2): - SetFire(new List { 2 }, i); - MessageLog.GetInstance.Show(potActions.Actions); - break; - case nameof(StirFryPotActionEnum.设置加热挡位3): - SetFire(new List { 3 }, i); - MessageLog.GetInstance.Show(potActions.Actions); - break; - case nameof(StirFryPotActionEnum.设置加热挡位4): - SetFire(new List { 4 }, i); - MessageLog.GetInstance.Show(potActions.Actions); - break; - case nameof(StirFryPotActionEnum.设置加热挡位5): - SetFire(new List { 5 }, i); - MessageLog.GetInstance.Show(potActions.Actions); - break; - case nameof(StirFryPotActionEnum.设置加热挡位6): - SetFire(new List { 6 }, i); - MessageLog.GetInstance.Show(potActions.Actions); - break; - case nameof(StirFryPotActionEnum.设置加热挡位7): - SetFire(new List { 7 }, i); - MessageLog.GetInstance.Show(potActions.Actions); - break; - case nameof(StirFryPotActionEnum.设置加热挡位8): - SetFire(new List { 8 }, i); - MessageLog.GetInstance.Show(potActions.Actions); - break; - case nameof(StirFryPotActionEnum.设置加热挡位9): - SetFire(new List { 9 }, i); - MessageLog.GetInstance.Show(potActions.Actions); - break; - case nameof(StirFryPotActionEnum.设置加热挡位10): - SetFire(new List { 10 }, i); - MessageLog.GetInstance.Show(potActions.Actions); - break; - case nameof(StirFryPotActionEnum.停止加热): - StopFire(i); - MessageLog.GetInstance.Show(potActions.Actions); - break; - case nameof(StirFryPotActionEnum.加调料): - OutSeasonings(potActions.SeasoningLists, i); - MessageLog.GetInstance.Show(potActions.Actions); - break; - case nameof(StirFryPotActionEnum.取原料): - GetMaterailTest(getMaterailNum); - getMaterailNum++; - MessageLog.GetInstance.Show(potActions.Actions); - break; - case nameof(StirFryPotActionEnum.开启搅拌): - StartStir(i); - MessageLog.GetInstance.Show(potActions.Actions); - break; - case nameof(StirFryPotActionEnum.设置搅拌挡位1): - SetStir(new List { 1 }, i); - MessageLog.GetInstance.Show(potActions.Actions); - break; - case nameof(StirFryPotActionEnum.设置搅拌挡位2): - SetStir(new List { 2 }, i); - MessageLog.GetInstance.Show(potActions.Actions); - break; - case nameof(StirFryPotActionEnum.设置搅拌挡位3): - SetStir(new List { 3 }, i); - MessageLog.GetInstance.Show(potActions.Actions); - break; - case nameof(StirFryPotActionEnum.关闭搅拌): - StopStir(i); - MessageLog.GetInstance.Show(potActions.Actions); - break; - case nameof(StirFryPotActionEnum.出餐启动): - MessageLog.GetInstance.Show(potActions.Actions); - break; - case nameof(StirFryPotActionEnum.道菜启动): - OutFood(i); - break; - case nameof(StirFryPotActionEnum.炒制菜品): - Thread.Sleep(potActions.During * 1000); - break; - case nameof(StirFryPotActionEnum.搅拌臂原点位): - StirArmGoOrigin(i); - MessageLog.GetInstance.Show(potActions.Actions); - break; - case nameof(StirFryPotActionEnum.搅拌臂炒制位): - StirArmGoWork(i); - MessageLog.GetInstance.Show(potActions.Actions); - break; - case nameof(StirFryPotActionEnum.洗锅): - MessageLog.GetInstance.Show(potActions.Actions); - break; - default: - break; - - } + return; } + switch (potActions.Actions) + { + case nameof(StirFryPotActionEnum.加热开启): + StartFire(i); + MessageLog.GetInstance.Show(potActions.Actions); + break; + case nameof(StirFryPotActionEnum.设置加热挡位1): + morkFs[i].Fire = 1; + SetFire(new List { 1 }, i); + MessageLog.GetInstance.Show(potActions.Actions); + break; + case nameof(StirFryPotActionEnum.设置加热挡位2): + morkFs[i].Fire = 2; + SetFire(new List { 2 }, i); + MessageLog.GetInstance.Show(potActions.Actions); + break; + case nameof(StirFryPotActionEnum.设置加热挡位3): + morkFs[i].Fire = 3; + SetFire(new List { 3 }, i); + MessageLog.GetInstance.Show(potActions.Actions); + break; + case nameof(StirFryPotActionEnum.设置加热挡位4): + morkFs[i].Fire = 4; + SetFire(new List { 4 }, i); + MessageLog.GetInstance.Show(potActions.Actions); + break; + case nameof(StirFryPotActionEnum.设置加热挡位5): + morkFs[i].Fire = 5; + SetFire(new List { 5 }, i); + MessageLog.GetInstance.Show(potActions.Actions); + break; + case nameof(StirFryPotActionEnum.设置加热挡位6): + morkFs[i].Fire = 6; + SetFire(new List { 6 }, i); + MessageLog.GetInstance.Show(potActions.Actions); + break; + case nameof(StirFryPotActionEnum.设置加热挡位7): + morkFs[i].Fire = 7; + SetFire(new List { 7 }, i); + MessageLog.GetInstance.Show(potActions.Actions); + break; + case nameof(StirFryPotActionEnum.设置加热挡位8): + morkFs[i].Fire = 8; + SetFire(new List { 8 }, i); + MessageLog.GetInstance.Show(potActions.Actions); + break; + case nameof(StirFryPotActionEnum.设置加热挡位9): + morkFs[i].Fire = 9; + SetFire(new List { 9 }, i); + MessageLog.GetInstance.Show(potActions.Actions); + break; + case nameof(StirFryPotActionEnum.设置加热挡位10): + morkFs[i].Fire = 10; + SetFire(new List { 10 }, i); + MessageLog.GetInstance.Show(potActions.Actions); + break; + case nameof(StirFryPotActionEnum.停止加热): + StopFire(i); + MessageLog.GetInstance.Show(potActions.Actions); + break; + case nameof(StirFryPotActionEnum.加调料): + OutSeasonings(potActions.SeasoningLists, i); + MessageLog.GetInstance.Show(potActions.Actions); + break; + case nameof(StirFryPotActionEnum.取原料): + //炒锅取菜状态置为未取到 + morkFs[i].GetMaterialComplete = false; + materialOperationQuenes.Enqueue(new MaterialOperation() { fryNum = i, x = 0, y = 0 }); + getMaterailNum++; + MessageLog.GetInstance.Show(potActions.Actions); + break; + case nameof(StirFryPotActionEnum.开启搅拌): + StartStir(i); + MessageLog.GetInstance.Show(potActions.Actions); + break; + case nameof(StirFryPotActionEnum.设置搅拌挡位1): + SetStir(new List { 1 }, i); + MessageLog.GetInstance.Show(potActions.Actions); + break; + case nameof(StirFryPotActionEnum.设置搅拌挡位2): + SetStir(new List { 2 }, i); + MessageLog.GetInstance.Show(potActions.Actions); + break; + case nameof(StirFryPotActionEnum.设置搅拌挡位3): + SetStir(new List { 3 }, i); + MessageLog.GetInstance.Show(potActions.Actions); + break; + case nameof(StirFryPotActionEnum.关闭搅拌): + StopStir(i); + MessageLog.GetInstance.Show(potActions.Actions); + break; + case nameof(StirFryPotActionEnum.出餐启动): + MessageLog.GetInstance.Show(potActions.Actions); + break; + case nameof(StirFryPotActionEnum.道菜启动): + OutFood(i); + break; + case nameof(StirFryPotActionEnum.炒制菜品): + Thread.Sleep(potActions.During * 1000); + break; + case nameof(StirFryPotActionEnum.搅拌臂原点位): + StirArmGoOrigin(i); + MessageLog.GetInstance.Show(potActions.Actions); + break; + case nameof(StirFryPotActionEnum.搅拌臂炒制位): + StirArmGoWork(i); + MessageLog.GetInstance.Show(potActions.Actions); + break; + case nameof(StirFryPotActionEnum.洗锅): + MessageLog.GetInstance.Show(potActions.Actions); + break; + default: + break; - Plc1Reset(i);//复位 - Thread.Sleep(3000); - //回原点位 - StirArmGoOrigin(i); + } + } - //while (!morkFs[i].ArmOnOrigin) - //{ - // Thread.Sleep(100); - //} - //出餐 - //OutMeal(i); - MessageLog.GetInstance.Show($"菜品{res.GoodName}完成"); + Plc1Reset(i);//复位 + Thread.Sleep(3000); + //回原点位 + StirArmGoOrigin(i); - } - catch (Exception ex) - { - ThreadManage.GetInstance().StopTask($"炒锅{i}{res.GoodName}炒制线程"); - MessageLog.GetInstance.Show($"炒锅{i}炒制菜品{res.GoodName}出错,错误信息:" + ex.Message); - } - finally - { - nowStirFryGood = null; - //炒完后出队列 - morkFs[i].StirFryGoodsQuenes.TryDequeue(out var orderQueue); - morkFs[i].FryWorking = false; - } - }), String.Format(striConst, i.ToString(), nowStirFryGood.GoodName)/*$"炒锅{i}炒制{res.GoodName}线程"*/); + //while (!morkFs[i].ArmOnOrigin) + //{ + // Thread.Sleep(100); + //} + //出餐 + //OutMeal(i); + MessageLog.GetInstance.Show($"菜品{res.GoodName}完成"); + + + } + catch (Exception ex) + { + ThreadManage.GetInstance().StopTask($"炒锅{i}{res.GoodName}炒制线程"); + MessageLog.GetInstance.Show($"炒锅{i}炒制菜品{res.GoodName}出错,错误信息:" + ex.Message); + } + finally + { + nowStirFryGood = null; + //炒完后出队列 + morkFs[i].StirFryGoodsQuenes.TryDequeue(out var orderQueue); + morkFs[i].FryWorking = false; + } + }), String.Format(striConst, i.ToString(), nowStirFryGood.GoodName)/*$"炒锅{i}炒制{res.GoodName}线程"*/); } } break; @@ -1742,6 +1831,30 @@ namespace BPASmartClient.MorkF } } + /// + /// 菜品库主流程 + /// + private void MainProcessMaterial() + { + if(materialOperationQuenes.Count > 0) + { + //判断是否初始化与是否在工作中 + if (ml_morkf.InitialComplete && !ml_morkf.MaterailIsWorking) + { + //待菜品库操作列出队列 + if (materialOperationQuenes.TryDequeue(out var res)) + { + ml_morkf.MaterailIsWorking = true; + MessageLog.GetInstance.Show("开始操作菜品库"); + //ThreadManage.GetInstance().Start(new Action(()=>{ + // GetMaterail(res.x, res.y, res.fryNum); + //}),"菜品库操作"); + GetMaterailTest(res.fryNum); + } + } + } + } + /// /// 信号处理 /// diff --git a/BPASmartClient.MorkF/GVL_MorkF.cs b/BPASmartClient.MorkF/GVL_MorkF.cs index 47999617..0f08aa54 100644 --- a/BPASmartClient.MorkF/GVL_MorkF.cs +++ b/BPASmartClient.MorkF/GVL_MorkF.cs @@ -18,7 +18,15 @@ namespace BPASmartClient.MorkF public bool IsAuto = true; - #region 炒锅1 + #region 炒锅 + /// + /// 炒锅上一次搅拌档位 + /// + public int Stir { set; get; } + /// + /// 炒锅上一次火力 + /// + public int Fire { get; set; } /// /// 炒锅是否在工作状态中 /// @@ -73,6 +81,11 @@ namespace BPASmartClient.MorkF /// public bool PotOnOrigin { get; set; } + /// + /// 获取菜品是否完成 + /// + public bool GetMaterialComplete { get; set; } + #endregion #region 调料通道 diff --git a/BPASmartClient.MorkF/MaterialOperation.cs b/BPASmartClient.MorkF/MaterialOperation.cs new file mode 100644 index 00000000..83b1a6d9 --- /dev/null +++ b/BPASmartClient.MorkF/MaterialOperation.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.MorkF +{ + /// + /// 菜品库操作类 + /// + internal class MaterialOperation + { + /// + /// x轴坐标 + /// + public int x; + /// + /// y轴坐标 + /// + public int y; + /// + /// 炒锅编号 + /// + public int fryNum; + } +}