From 1e7b1b174e30c457a0a7c6e70c591a4e981b803d Mon Sep 17 00:00:00 2001 From: NXX <447201003@qq> Date: Sat, 28 May 2022 09:42:02 +0800 Subject: [PATCH] Morkt --- BPASmartClient.GSIceCream/IceCreamMachine.cs | 5 + BPASmartClient.Lebai/LebaiRobot.cs | 6 +- BPASmartClient.Model/单片机/Enum/IC_CUP.cs | 4 +- BPASmartClient.MorkT/Control_MorkT.cs | 124 ++++++++++-------- 4 files changed, 76 insertions(+), 63 deletions(-) diff --git a/BPASmartClient.GSIceCream/IceCreamMachine.cs b/BPASmartClient.GSIceCream/IceCreamMachine.cs index d755bd59..93b661f3 100644 --- a/BPASmartClient.GSIceCream/IceCreamMachine.cs +++ b/BPASmartClient.GSIceCream/IceCreamMachine.cs @@ -277,12 +277,14 @@ namespace BPASmartClient.GSIceCream { MessageLog.GetInstance.Show(string.Format("当前存在故障[{0}%],不允许制作",(MORKI_FAULT)status["IceCreamFault"])); new GSIceCream_EndCookEvent() { DeviceId = DeviceId,Status = false }.Publish(); + callBack?.Invoke(false); return; } if ((byte)status["IceCreamCXB"] <= 86) { MessageLog.GetInstance.Show(string.Format("当前成型比[{0}%],低于86%,不允许制作",(byte)status["IceCreamCXB"])); new GSIceCream_EndCookEvent() { DeviceId = DeviceId,Status = false }.Publish(); + callBack?.Invoke(false ); return; } @@ -320,16 +322,19 @@ namespace BPASmartClient.GSIceCream free = false; new GSIceCream_EndCookEvent() { DeviceId = DeviceId,Status =true}.Publish(); MessageLog.GetInstance.Show(string.Format("出料操作->设置模式[{0}]",MORKI_MODE.打料)); + callBack?.Invoke(true); } else { MessageLog.GetInstance.Show(string.Format("出料操作->模式切换失败,当前模式[{0}],不允许出料",(MORKI_MODE)status["IceCreamCurrentMode"])); new GSIceCream_EndCookEvent() { DeviceId = DeviceId,Status = false }.Publish(); + callBack?.Invoke(false); } } catch (Exception ex) { MessageLog.GetInstance.ShowEx($"BPASmartClient.GSIceCream 中引发错误,IceCreamMachine 类,描述:[{ex.Message}]"); + callBack?.Invoke(false); } }); InitStatus(); diff --git a/BPASmartClient.Lebai/LebaiRobot.cs b/BPASmartClient.Lebai/LebaiRobot.cs index a8a48143..721cc893 100644 --- a/BPASmartClient.Lebai/LebaiRobot.cs +++ b/BPASmartClient.Lebai/LebaiRobot.cs @@ -76,12 +76,12 @@ namespace BPASmartClient.Lebai } }); //获取Tcp信号 - EventBus.EventBus.GetInstance().Subscribe(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack) + EventBus.EventBus.GetInstance().Subscribe(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack) { if (@event == null) return; - if (@event is LebaiRobot_GetInputEvent getTCPInput) + if (@event is LebaiRobot_GetTCPInputEvent getTCPInput) { - callBack.Invoke(LebaiHelper.GetInstance().GetTcpInput(getTCPInput.Pin)); + callBack?.Invoke(LebaiHelper.GetInstance().GetTcpInput(getTCPInput.Pin)); } }); //机器人输入信号 diff --git a/BPASmartClient.Model/单片机/Enum/IC_CUP.cs b/BPASmartClient.Model/单片机/Enum/IC_CUP.cs index 695bb5e2..d717146e 100644 --- a/BPASmartClient.Model/单片机/Enum/IC_CUP.cs +++ b/BPASmartClient.Model/单片机/Enum/IC_CUP.cs @@ -14,10 +14,10 @@ namespace BPASmartClient.Model.单片机.Enum /// /// 冰淇淋杯 /// - CUP_ICECREAM = 0x01, + CUP_ICECREAM = 0x02, /// /// 咖啡杯 /// - CUP_COFFEE = 0x02 + CUP_COFFEE = 0x01 } } diff --git a/BPASmartClient.MorkT/Control_MorkT.cs b/BPASmartClient.MorkT/Control_MorkT.cs index 34f86631..53d67dd1 100644 --- a/BPASmartClient.MorkT/Control_MorkT.cs +++ b/BPASmartClient.MorkT/Control_MorkT.cs @@ -32,6 +32,10 @@ namespace BPASmartClient.MorkT public override void DoMain() { + if(Json.Data.IsVerify) + { + IsHealth = true; + } IsHealth = true; ServerInit(); DataParse(); @@ -142,7 +146,7 @@ namespace BPASmartClient.MorkT } })); - GetStatus("IceCreamCBX", new Action((o) => + GetStatus("IceCreamCXB", new Action((o) => { if (o is byte bt) { @@ -178,7 +182,7 @@ namespace BPASmartClient.MorkT { if (o is bool b) { - morkT.IceCreamIsConnected = b; + morkT.CoffeeIsConnected = b; } })); @@ -261,7 +265,7 @@ namespace BPASmartClient.MorkT morkT.batchings = PolymerBatching.BuildAll(); //商品类型 GOODS_TYPE currentGoodsType = GOODS_TYPE.NEITHER; - string loc_Goods = string.Empty; + foreach (var item in order.MorkOrder.GoodBatchings) { var res = orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId); @@ -273,42 +277,45 @@ namespace BPASmartClient.MorkT //获取当前物料所属商品类型 currentGoodsType = ValidateGoodsByBatching(res.BatchingLoc); } - + string loc_Goods = string.Empty; //获取主料和容器位置 if (morkT.batchings[res.BatchingLoc].BatchingClass == BATCHING_CLASS.MAIN_MATERIAL) loc_Goods = res.BatchingLoc; - - switch (currentGoodsType) + if (!string.IsNullOrEmpty(loc_Goods)) { - case GOODS_TYPE.COFFEE: - if (morkT.morkOrderPushesCoffee.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null) - { - morkT.morkOrderPushesCoffee.Enqueue(new OrderLocInfo() + switch (currentGoodsType) + { + case GOODS_TYPE.COFFEE: + if (morkT.morkOrderPushesCoffee.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null) { - SuborderId = order.MorkOrder.SuborderId, - BatchingId = res.BatchingId, - Loc = loc_Goods, - GoodsName = order.MorkOrder.GoodsName, - SortNum = order.MorkOrder.SortNum - }) ; - } - break; - case GOODS_TYPE.ICECREAM: - if (morkT.morkOrderPushesIceCream.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null) - { - morkT.morkOrderPushesIceCream.Enqueue(new OrderLocInfo() + morkT.morkOrderPushesCoffee.Enqueue(new OrderLocInfo() + { + SuborderId = order.MorkOrder.SuborderId, + BatchingId = res.BatchingId, + Loc = loc_Goods, + GoodsName = order.MorkOrder.GoodsName, + SortNum = order.MorkOrder.SortNum + }); + } + break; + case GOODS_TYPE.ICECREAM: + if (morkT.morkOrderPushesIceCream.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null) { - SuborderId = order.MorkOrder.SuborderId, - BatchingId = res.BatchingId, - Loc = loc_Goods, - GoodsName = order.MorkOrder.GoodsName, - SortNum = order.MorkOrder.SortNum - }); - } - break; - case GOODS_TYPE.NEITHER: - DeviceProcessLogShow("未知的商品类型"); - break; + morkT.morkOrderPushesIceCream.Enqueue(new OrderLocInfo() + { + SuborderId = order.MorkOrder.SuborderId, + BatchingId = res.BatchingId, + Loc = loc_Goods, + GoodsName = order.MorkOrder.GoodsName, + SortNum = order.MorkOrder.SortNum + }); + } + break; + case GOODS_TYPE.NEITHER: + DeviceProcessLogShow("未知的商品类型"); + break; + } } + } } @@ -363,11 +370,11 @@ namespace BPASmartClient.MorkT if (morkT.morkOrderPushesCoffee.TryDequeue(out OrderLocInfo orderLoc)) { DeviceProcessLogShow($"开始制作 [咖啡] 订单[{orderLoc.SortNum}]"); - GetAndCheeckCoffe(orderLoc); + GetAndCheeckCoffe(orderLoc);//取咖啡杯 EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = 10051}); //接咖啡后回原点 Wait(); EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }); - new DRCoffee_MakeCoffeeEvent() { DrinkCode = (Model.咖啡机.Enum.DrCoffeeDrinksCode)int.Parse(orderLoc.Loc) }.Publish(); //接咖啡控制 + EventBus.EventBus.GetInstance().Publish(new DRCoffee_MakeCoffeeEvent() {DeviceId = DeviceId, DrinkCode = (Model.咖啡机.Enum.DrCoffeeDrinksCode)int.Parse(orderLoc.Loc) });//接咖啡控制 DeviceProcessLogShow($"发送咖啡机制作{orderLoc.Loc}!"); morkT.IsCoffeeMake = true; morkT.MakeCoffeeOrder = orderLoc; } @@ -420,7 +427,7 @@ namespace BPASmartClient.MorkT EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = 10031 }); //SENCE_取咖啡杯 Wait(); - new SCChip_TakeCupEvent() { Cup = IC_CUP.CUP_COFFEE }.Publish();//落碗控制 + EventBus.EventBus.GetInstance().Publish(new SCChip_TakeCupEvent { DeviceId= DeviceId ,Cup = IC_CUP.CUP_COFFEE});//落碗控制 Thread.Sleep(500); DeviceProcessLogShow("尝试取咖啡杯!"); EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }); @@ -452,7 +459,7 @@ namespace BPASmartClient.MorkT DeviceProcessLogShow("执行二次取咖啡杯"); EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = 10035 }); //SENCE_二次取咖啡杯 Wait(); - new SCChip_TakeCupEvent() { Cup = IC_CUP.CUP_COFFEE }.Publish();//落碗控制 + EventBus.EventBus.GetInstance().Equals(new SCChip_TakeCupEvent { DeviceId = DeviceId, Cup = IC_CUP.CUP_COFFEE });//落碗控制 EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }); count++; goto p; @@ -477,14 +484,14 @@ namespace BPASmartClient.MorkT { if (IceCreamCanMake()) { - if(peripheralStatus.ContainsKey("CurrentMode")) + if(peripheralStatus.ContainsKey("IceCreamCurrentMode")) { - if ((MORKI_MODE)peripheralStatus["CurrentMode"] != MORKI_MODE.制冷模式) new GSIceCream_ModeSetEvent() { Mode = MORKI_MODE.制冷模式 }.Publish(); + if ((MORKI_MODE)peripheralStatus["IceCreamCurrentMode"] != MORKI_MODE.制冷模式) new GSIceCream_ModeSetEvent() { Mode = MORKI_MODE.制冷模式 }.Publish(); } - if(peripheralStatus.ContainsKey(".CBX")) + if(peripheralStatus.ContainsKey("IceCreamCXB")) { - if ((short)peripheralStatus["CBX"] >= 86 && morkT.morkOrderPushesIceCream.Count > 0)//成型比大于86才可以制作 + if ((byte)peripheralStatus["IceCreamCXB"] >= 86 && morkT.morkOrderPushesIceCream.Count > 0)//成型比大于86才可以制作 { bool result = true; EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetInputEvent { DeviceId = DeviceId, Pin = 3 }, (res) => @@ -531,7 +538,7 @@ namespace BPASmartClient.MorkT EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }); EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = 10032 }); //SENCE_取冰淇淋杯 Wait(); - new SCChip_TakeCupEvent() { Cup = IC_CUP.CUP_ICECREAM }.Publish();//落碗控制 + EventBus.EventBus.GetInstance().Publish(new SCChip_TakeCupEvent { DeviceId = DeviceId, Cup = IC_CUP.CUP_ICECREAM });//落碗控制 Thread.Sleep(500); DeviceProcessLogShow("尝试取冰淇淋杯!"); @@ -569,7 +576,7 @@ namespace BPASmartClient.MorkT } DeviceProcessLogShow($"执行{count}次取冰淇淋杯!"); EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = 10036 }); //SENCE_二次取冰淇淋杯 - new SCChip_TakeCupEvent() { Cup = IC_CUP.CUP_ICECREAM }.Publish();//落碗控制 + EventBus.EventBus.GetInstance().Equals(new SCChip_TakeCupEvent { DeviceId = DeviceId, Cup = IC_CUP.CUP_ICECREAM });//落碗控制 Wait(); EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }); count++; @@ -585,17 +592,17 @@ namespace BPASmartClient.MorkT private void GetIceCream(OrderLocInfo order) { //制冷模式 - new GSIceCream_ModeSetEvent() { Mode = MORKI_MODE.制冷模式 }.Publish(); + EventBus.EventBus.GetInstance().Publish(new GSIceCream_ModeSetEvent {DeviceId = DeviceId, Mode = MORKI_MODE.制冷模式 }); EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }); OrderChange(order.SuborderId, ORDER_STATUS.COOKING); EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = 10039 }); //SENCE_接1号冰淇淋 Wait(); bool doItResult = true; //出料 - new GSIceCream_DischargeEvent().Publish(delegate (object[] args) + EventBus.EventBus.GetInstance().Publish(new GSIceCream_DischargeEvent { DeviceId = DeviceId },(o)=> { - doItResult = (bool)args[0]; - }); + doItResult = (bool)o[0]; + }); if (doItResult) { IceCreamCookCheck(); @@ -604,7 +611,7 @@ namespace BPASmartClient.MorkT { int count_1 = 0; - while ((short)peripheralStatus["CBX"] <= 86) + while ((byte)peripheralStatus["IceCreamCXB"] <= 86) { Thread.Sleep(5); count_1++; @@ -647,19 +654,20 @@ namespace BPASmartClient.MorkT /// public void IceCreamCookCheck() { - bool result = true; + bool result = false; int retry = 3; DateTime beginTime = DateTime.Now; - EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetInputEvent { DeviceId = DeviceId, Pin = 3 } ,(res)=> - { - if (res[0] is bool resultValue) - { - result = resultValue; - } - } ); + while (!result) { - if (retry <= 0 && DateTime.Now.Subtract(beginTime).TotalSeconds >= 10) + EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetInputEvent { DeviceId = DeviceId, Pin = 3 }, (res) => + { + if (res[0] is bool resultValue) + { + result = resultValue; + } + }); + if (retry <= 0 || DateTime.Now.Subtract(beginTime).TotalSeconds >= 10) { DeviceProcessLogShow("超时未出料,重试次数用尽"); break; @@ -667,7 +675,7 @@ namespace BPASmartClient.MorkT if (DateTime.Now.Subtract(beginTime).TotalSeconds > 5) { DeviceProcessLogShow("超时未出料,重新发送打料指令"); - new GSIceCream_ModeSetEvent() { Mode = MORKI_MODE.打料 }.Publish(); + EventBus.EventBus.GetInstance().Publish( new GSIceCream_ModeSetEvent() { DeviceId =DeviceId, Mode = MORKI_MODE.打料 }); beginTime = DateTime.Now; retry--; }