diff --git a/BPASmartClient.MorkT.Lebai.JC/Control_MORKJC2.cs b/BPASmartClient.MorkT.Lebai.JC/Control_MORKJC2.cs index 2a87df17..45f2817e 100644 --- a/BPASmartClient.MorkT.Lebai.JC/Control_MORKJC2.cs +++ b/BPASmartClient.MorkT.Lebai.JC/Control_MORKJC2.cs @@ -53,6 +53,8 @@ namespace BPASmartClient.MorkTLebaiJC IsHealth = true; serverInit(); DataParse(); + ActionManage.GetInstance.Register(new Action((o) => { SimOrder(o); }), "SimOrder");//模拟订单委托注册 + } private void serverInit() @@ -241,15 +243,6 @@ namespace BPASmartClient.MorkTLebaiJC DoBoiledTea(); DoBoiledWater(); } - public void Main() - { - //开始心跳刷新,根据咖啡机及冰淇淋机来判断 - ThreadManage.GetInstance().StartLong(new Action(() => - { - IsHealth = true; - Thread.Sleep(100); - }), "MORK-IC心跳刷新"); - } /// /// 订单状态改变 @@ -850,7 +843,22 @@ namespace BPASmartClient.MorkTLebaiJC public void SimOrder(T simOrder) { - + if (simOrder != null) + { + + if (simOrder is List locs) + { + List orders = new List(); + string subId = Guid.NewGuid().ToString(); + foreach (var item in locs) + { + if (true) + { + orders.Add(new OrderLocInfo() { Loc = item, SuborderId = subId }); + } + } + } + } } public override void Stop() diff --git a/BPASmartClient.MorkT.Lebai.JC/ViewModel/DebugViewModel.cs b/BPASmartClient.MorkT.Lebai.JC/ViewModel/DebugViewModel.cs index 6b6c242c..9b4dd088 100644 --- a/BPASmartClient.MorkT.Lebai.JC/ViewModel/DebugViewModel.cs +++ b/BPASmartClient.MorkT.Lebai.JC/ViewModel/DebugViewModel.cs @@ -151,21 +151,47 @@ namespace BPASmartClient.MorkTLebaiJC.ViewModel; public bool MCU_DO_Value { get { return _mcu_DO_Valuer; } set { _mcu_DO_Valuer = value; OnPropertyChanged(); } } private bool _mcu_DO_Valuer = true; - - private void Button_McuOutput() + + public bool MCU_DI0 { get { return _mcu_DI0; }set { _mcu_DI0 = value;OnPropertyChanged(); } } + private bool _mcu_DI0 = true; + public bool MCU_DI1 { get { return _mcu_DI1; } set { _mcu_DI1 = value; OnPropertyChanged(); } } + private bool _mcu_DI1 = true; + public bool MCU_DI2 { get { return _mcu_DI2; } set { _mcu_DI2 = value; OnPropertyChanged(); } } + private bool _mcu_DI2 = true; + public bool MCU_DI3 { get { return _mcu_DI3; } set { _mcu_DI3 = value; OnPropertyChanged(); } } + private bool _mcu_DI3 = true; + public bool MCU_DI4 { get { return _mcu_DI4; } set { _mcu_DI4 = value; OnPropertyChanged(); } } + private bool _mcu_DI4 = true; + public bool MCU_DI5 { get { return _mcu_DI5; } set { _mcu_DI5 = value; OnPropertyChanged(); } } + private bool _mcu_DI5 = true; + public bool MCU_DI6 { get { return _mcu_DI6; } set { _mcu_DI6 = value; OnPropertyChanged(); } } + private bool _mcu_DI6 = true; + public bool MCU_DI7 { get { return _mcu_DI7; } set { _mcu_DI7 = value; OnPropertyChanged(); } } + private bool _mcu_DI7 = true; + /// + /// 单片机舵机输出 + /// + private void Button_McuOutput() { string sChoosePWM =Convert.ToString(MCU_PWM_CH+1); new WriteMcu() { TagName = "ServoControl", Address = sChoosePWM, Value = PWMInputNumber }.Publish(); } + /// + /// 单片机DO输出 + /// private void Button_McuDOutput() { string sChooseDO = Convert.ToString(MCU_DO_CH + 1); new WriteMcu() { TagName = "OutputControl", Address = sChooseDO, Value = MCU_DO_Value }.Publish(); } + /// + /// 乐白的DO输出 + /// private void Button_LebaiDOutput() { - string sChooseDO = Convert.ToString(Lebai_DO_CH + 1); - + int sChooseDO = Convert.ToInt16(Lebai_DO_CH); + bool lebai_DO_Value = Convert.ToInt16(Lebai_DO_Value) == 0; + new LebaiRobot_SetOutPutEvent { DeviceId = DeviceId, Pin = sChooseDO, Value = lebai_DO_Value }.Publish(); } #endregion @@ -205,7 +231,7 @@ namespace BPASmartClient.MorkTLebaiJC.ViewModel; ; }); - + ThreadManage.GetInstance().StartLong(new Action(() => { @@ -230,6 +256,7 @@ namespace BPASmartClient.MorkTLebaiJC.ViewModel; } Thread.Sleep(500); }), "MorkT-状态刷新"); + } } diff --git a/BPASmartClient.Morkt.JAKA.JC/BPASmartClient.MorkTJAKAJC.csproj b/BPASmartClient.Morkt.JAKA.JC/BPASmartClient.MorkTJAKAJC.csproj index 83fb3b7c..e0f098b1 100644 --- a/BPASmartClient.Morkt.JAKA.JC/BPASmartClient.MorkTJAKAJC.csproj +++ b/BPASmartClient.Morkt.JAKA.JC/BPASmartClient.MorkTJAKAJC.csproj @@ -1,4 +1,4 @@ - + net6.0-windows diff --git a/BPASmartClient.Morkt.JAKA.JC/Control_MORKJC.cs b/BPASmartClient.Morkt.JAKA.JC/Control_MORKJC.cs index 15ce6969..6d7c31f8 100644 --- a/BPASmartClient.Morkt.JAKA.JC/Control_MORKJC.cs +++ b/BPASmartClient.Morkt.JAKA.JC/Control_MORKJC.cs @@ -22,19 +22,14 @@ namespace BPASmartClient.MorktJAKAJC { public class Control_MORKJC : BaseDevice { - GVL_MORKJC mORKD = new GVL_MORKJC(); + GVL_MORKJC morkTJakaJC = new GVL_MORKJC(); //物料存放位置 private Dictionary batchings = new Dictionary(); //容器位置 private string holderLoc; //主料位置 private string mainMaterialLoc; - //子订单ID - private string subOrderId; - - private bool enableFunny = false; - private DateTime lastRecvdOrder = DateTime.Now; - private bool working = false; + public override global::BPA.Message.Enum.DeviceClientType DeviceType { get { return BPA.Message.Enum.DeviceClientType.MORKT; } } /// /// 果汁机做法,true:热饮,false:冷饮 /// @@ -44,119 +39,209 @@ namespace BPASmartClient.MorktJAKAJC { EventBus.EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { Status = oRDER_STATUS, SubOrderId = subid, deviceClientType = DeviceType }); } - - //private SerialPortClient commProxy; - public void ConnectOk() + public override void DoMain() { - + if (Json.Data.IsVerify) + { + IsHealth = true; + } + IsHealth = true; + serverInit(); + DataParse(); } - ConcurrentQueue morkOrderPushes = new ConcurrentQueue(); - public void Init() + + private void serverInit() { - ActionManage.GetInstance.Register(new Action((s) => + EventBus.EventBus.GetInstance().Subscribe(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack) { - if (s is DrCoffeeDrinksCode cf) + if (@event == null) return; + if (@event is MaterialDeliveryEvent material) { - mainMaterialLoc = ((int)cf).ToString(); - DoCoffee(); + orderMaterialDelivery = material.orderMaterialDelivery; } - }), "SimCoffee"); + }); + } - //构建所有商品物料信息 - batchings = PolymerBatching.BuildAll(); - EventBus.EventBus.GetInstance().Subscribe(DeviceId, DRCoffee_CoffeEndCookEventHandle); - Main(); - ReadData(); - ThreadManage.GetInstance().StartLong(new Action(() => - { - while (morkOrderPushes.Count > 0) - { - while (enableFunny) { Thread.Sleep(10); } - DeviceProcessLogShow("当前非自嗨模式,允许开工"); - working = true; - if (morkOrderPushes.TryDequeue(out MorkOrderPush order)) + private void DataParse() + { + EventBus.EventBus.GetInstance().Subscribe(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle) + { + if (@event == null) return; + if (@event is DoOrderEvent order) + { + if (order.MorkOrder.GoodBatchings == null) return; + OrderCount++; + DeviceProcessLogShow($"接收到{OrderCount}次订单"); + batchings = PolymerBatching.BuildAll(); + + //商品类型 + GOODS_TYPE currentGoodsType = GOODS_TYPE.NEITHER; + + foreach (var item in order.MorkOrder.GoodBatchings) { - DeviceProcessLogShow($"开始制作订单[{order.SortNum}]"); - //商品类型 - GOODS_TYPE currentGoodsType = GOODS_TYPE.NEITHER; - //子订单ID - subOrderId = order.SuborderId; - //遍历物料 - foreach (var item in order.GoodBatchings) + var res = orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId); + if (res != null) { - var res = Json.Data.orderMaterialDelivery.BatchingInfo.FirstOrDefault(p => p.BatchingId == item.BatchingId); - if (res != null) + //验证商品是做的某种饮料 + if (ValidateGoodsByBatching(res.BatchingLoc) != GOODS_TYPE.NEITHER) + { + //获取当前物料所属商品类型 + currentGoodsType = ValidateGoodsByBatching(res.BatchingLoc); + } + // + switch (batchings[res.BatchingLoc].BatchingClass) + { + case BATCHING_CLASS.HOLDER: + holderLoc = res.BatchingLoc; + break; + case BATCHING_CLASS.MAIN_MATERIAL: + mainMaterialLoc = res.BatchingLoc; + break; + } + //根据商品类型执行具体制作流程 + switch (currentGoodsType) { - //获取主料和容器位置 - switch (batchings[res.BatchingLoc].BatchingClass) - { - case BATCHING_CLASS.HOLDER: - holderLoc = res.BatchingLoc; - break; - case BATCHING_CLASS.MAIN_MATERIAL: - // mainMaterialLoc ="1"; - mainMaterialLoc = res.BatchingLoc; - //验证商品是咖啡还是冰淇淋 - if (ValidateGoodsByBatching(res.BatchingLoc) != GOODS_TYPE.NEITHER) + case GOODS_TYPE.COFFEE: + if (morkTJakaJC.morkOrderPushesCoffee.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null) + { + morkTJakaJC.morkOrderPushesCoffee.Enqueue(new OrderLocInfo() + { + SuborderId = order.MorkOrder.SuborderId, + BatchingId = res.BatchingId, + Loc = ushort.Parse(mainMaterialLoc), + GoodName = order.MorkOrder.GoodsName, + }); + } + break; + case GOODS_TYPE.JUICE: + GuMake = order.MorkOrder.MakeID == "2";//判断果汁的冷热 + if (morkTJakaJC.morkOrderPushesJuicer.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null) + { + morkTJakaJC.morkOrderPushesJuicer.Enqueue(new OrderLocInfo() + { + SuborderId = order.MorkOrder.SuborderId, + BatchingId = res.BatchingId, + Loc = ushort.Parse(mainMaterialLoc), + GoodName = order.MorkOrder.GoodsName, + }); + } + break; + case GOODS_TYPE.TEA: + if (morkTJakaJC.morkOrderPushesTea.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null) + { + morkTJakaJC.morkOrderPushesTea.Enqueue(new OrderLocInfo() + { + SuborderId = order.MorkOrder.SuborderId, + BatchingId = res.BatchingId, + Loc = ushort.Parse(mainMaterialLoc), + GoodName = order.MorkOrder.GoodsName, + }); + } + break; + case GOODS_TYPE.WATER: + if (morkTJakaJC.morkOrderPushesWater.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null) + { + morkTJakaJC.morkOrderPushesWater.Enqueue(new OrderLocInfo() { - //获取当前物料所属商品类型 - currentGoodsType = ValidateGoodsByBatching(res.BatchingLoc); - } - break; - } + SuborderId = order.MorkOrder.SuborderId, + BatchingId = res.BatchingId, + Loc = ushort.Parse(mainMaterialLoc), + GoodName = order.MorkOrder.GoodsName, + }); + } + break; + case GOODS_TYPE.NEITHER: + DeviceProcessLogShow("未知的商品类型"); + break; } } - //根据商品类型执行具体制作流程 - switch (currentGoodsType) - { - case GOODS_TYPE.COFFEE: - DoCoffee(); - break; - case GOODS_TYPE.JUICE: - GuMake = order.MakeID == "2"; - DoJuicer(); - break; - case GOODS_TYPE.TEA: - DoTea(); - break; - case GOODS_TYPE.WATER: - DoWater(); - break; - case GOODS_TYPE.NEITHER: - DeviceProcessLogShow("未知的商品类型"); - break; - } } - working = false; - lastRecvdOrder = DateTime.Now; } - Thread.Sleep(1000); - }), "订单制作"); + }); } - - public void Main() + private bool bFirstTrig_TeaWater = false; + private bool bFirstTrig_Coffee = false; + DateTime delayTimeOut_Coffee; + private bool bFirstTrig_Juice = false; + DateTime delayTimeOut_Juice; + /// + /// 判断接咖啡的位置是否有杯子 + /// + bool pickUpCoffeeHaveCup = false; + /// + /// 判断接果汁的位置是否有杯子 + /// + bool pickUpJuiceHaveCup = false; + /// + /// 判断接开水的位置是否有杯子 + /// + bool pickUpHotWaterHaveCup = false; + public override void MainTask() { - //开始心跳刷新,根据咖啡机及冰淇淋机来判断 - ThreadManage.GetInstance().StartLong(new Action(() => + EventBus.EventBus.GetInstance().Subscribe(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack) { - //IsHealth = - // Write.IsConnected && - // MorkCStatus.GetInstance().CanDo && - // JuicerHelper.GetInstance.IsOpen && - // MCUSerialHelper.GetInstance.IsOpen; - //GeneralConfig.Healthy = true; - Thread.Sleep(100); - }), "MORK-IC心跳刷新"); - } - - public void DataParse(T order) - { - if (order is MorkOrderPush morkOrderPush) + if (morkTJakaJC.IsHaveCoffeeCup) + morkTJakaJC.MakeCoffeeEnd = true; + }); + if (pickUpCoffeeHaveCup) { - morkOrderPushes.Enqueue(morkOrderPush); + if (!bFirstTrig_Coffee) + { + bFirstTrig_Coffee = true; + delayTimeOut_Coffee = DateTime.Now; + } + if (DateTime.Now.Subtract(delayTimeOut_Coffee).TotalSeconds > 180) + { + bFirstTrig_Coffee = false; + if (morkTJakaJC.IsHaveCoffeeCup) + morkTJakaJC.MakeCoffeeEnd = true; + } } + if (morkTJakaJC.IsHaveJuiceCup) + { + var Juicestate = GetStatus("GetDeviceStatus"); + if (Juicestate != null) + { + if (Juicestate.Length > 0) + { + var Juicestate1 = Convert.ToString(Juicestate[0], 2); + var Juicestate2 = Juicestate[1]; + if (Juicestate1.IndexOf("0") == 1 && Juicestate2 == 0) + { + morkTJakaJC.MakeJuiceEnd = true; + } + } + } + //若无状态返回 则加延迟 + if (!bFirstTrig_Juice) + { + bFirstTrig_Juice = true; + delayTimeOut_Juice = DateTime.Now; + } + if (DateTime.Now.Subtract(delayTimeOut_Juice).TotalSeconds > 30) + { + bFirstTrig_Juice = false; + morkTJakaJC.MakeJuiceEnd = true; + } + } + if (morkTJakaJC.IsHaveTeaWaterCup) + { + if (!bFirstTrig_TeaWater) + { + bFirstTrig_TeaWater = true; + delayTimeOut = DateTime.Now; + } + if (DateTime.Now.Subtract(delayTimeOut).TotalSeconds >= 50) + { + bFirstTrig_TeaWater = false; + morkTJakaJC.MakeTeaEnd = true; + } + } + DoCoffee(); + DoJuice(); + DoBoiledTea(); + DoBoiledWater(); } - /// /// 验证当前是做咖啡还是做冰淇淋 /// @@ -190,7 +275,26 @@ namespace BPASmartClient.MorktJAKAJC } } int[] devStatusBy = new int[2] { 0, 0 }; - + private bool IsMakeCoffee() + { + bool bMake = (IsHealth && morkTJakaJC.morkOrderPushesCoffee.Count > 0 && !morkTJakaJC.IsHaveCoffeeCup) ? true : false; + return bMake; + } + private bool IsMakeJuice() + { + bool bMake = (IsHealth && morkTJakaJC.morkOrderPushesJuicer.Count > 0 && !morkTJakaJC.IsHaveJuiceCup) ? true : false; + return bMake; + } + private bool IsMakeTeaWater() + { + bool bMake = (IsHealth && morkTJakaJC.morkOrderPushesTea.Count > 0 && !morkTJakaJC.IsHaveTeaWaterCup) ? true : false; + return bMake; + } + private bool IsMakeWater() + { + bool bMake = (IsHealth && morkTJakaJC.morkOrderPushesWater.Count > 0 && !morkTJakaJC.IsHaveTeaWaterCup) ? true : false; + return bMake; + } /// /// 传感器的输入信号 0:无意义 1:有信号 2:无信号 3:信号不正确 /// @@ -204,26 +308,88 @@ namespace BPASmartClient.MorktJAKAJC /// private void DoCoffee() { - #region 接咖啡流程 - are.Reset(); - OrderChange(subOrderId, BPA.Message.Enum.ORDER_STATUS.COOKING); - int resultTakeCup = takeCup(); - if (resultTakeCup == 1) - { - DeviceProcessLogShow("咖啡杯取杯完成"); - new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接咖啡 }.Publish(); - Wait(int.Parse(JakaModel.SENCE_接咖啡)); - new DRCoffee_MakeCoffeeEvent() { DeviceId = DeviceId, DrinkCode = (DrCoffeeDrinksCode)int.Parse(mainMaterialLoc) }.Publish(); //接咖啡控制 //DrCoffeeDrinksCode.热水 - are.WaitOne(1000 * 180); - new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放咖啡杯 }.Publish(); - Wait(int.Parse(JakaModel.SENCE_放咖啡杯)); - int resultputCup = putCup(); - if (resultputCup == 1) - { - //订单状态改变:完成 - new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish(); - Wait(int.Parse(JakaModel.SENCE_初始位)); - OrderChange(subOrderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE); + if (IsMakeCoffee()) + { + if (morkTJakaJC.morkOrderPushesCoffee.TryDequeue(out OrderLocInfo orderLoc)) + { + PickUpCoffee();//接咖啡 + morkTJakaJC.IsHaveCoffeeCup = true; + } + } + else if (morkTJakaJC.MakeCoffeeEnd) + { + PutCoffeeCup(); + pickUpCoffeeHaveCup = false; + morkTJakaJC.IsHaveCoffeeCup = false; + } + } + private void DoJuice() + { + if (IsMakeJuice()) + { + if (morkTJakaJC.morkOrderPushesJuicer.TryDequeue(out OrderLocInfo orderLoc)) + { + PickUpJuicer(); + morkTJakaJC.IsHaveJuiceCup = true; + } + } + else if (morkTJakaJC.MakeJuiceEnd) + { + Thread.Sleep(5000);//延迟五秒,防止接饮料口滴饮料 + putJuice(); + pickUpJuiceHaveCup = false; + morkTJakaJC.IsHaveJuiceCup = false; + morkTJakaJC.MakeJuiceEnd = false; + } + } + private void DoBoiledTea() + { + if (IsMakeTeaWater()) + { + if (morkTJakaJC.morkOrderPushesTea.TryDequeue(out OrderLocInfo orderLoc)) + { + PickUpTea(); + morkTJakaJC.IsHaveTeaWaterCup = true; + } + } + else if (morkTJakaJC.MakeTeaEnd) + { + PutWaterCup(); + pickUpHotWaterHaveCup = false; + morkTJakaJC.IsHaveTeaWaterCup = false; + morkTJakaJC.MakeTeaEnd = false; + } + } + private void DoBoiledWater() + { + if (IsMakeWater()) + { + if (morkTJakaJC.morkOrderPushesWater.TryDequeue(out OrderLocInfo orderLoc)) + { + PickUpWater(); + } + } + else if (morkTJakaJC.MakeTeaEnd) + { + PutWaterCup(); + pickUpHotWaterHaveCup = false; + morkTJakaJC.IsHaveTeaWaterCup = false; + morkTJakaJC.MakeTeaEnd = false; + } + } + private void PickUpCoffee() + { + if (!pickUpCoffeeHaveCup) + { + OrderChange(morkTJakaJC.morkOrderPushesCoffee.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING); + int resultTakeCup = takeCup(); + if (resultTakeCup == 1) + { + DeviceProcessLogShow("咖啡杯取杯完成"); + new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接咖啡 }.Publish(); + Wait(int.Parse(JakaModel.SENCE_接咖啡)); + new DRCoffee_MakeCoffeeEvent() { DeviceId = DeviceId, DrinkCode = (DrCoffeeDrinksCode)int.Parse(mainMaterialLoc) }.Publish(); //接咖啡控制 //DrCoffeeDrinksCode.热水 + are.WaitOne(1000 * 180); } else { @@ -231,309 +397,253 @@ namespace BPASmartClient.MorktJAKAJC Wait(int.Parse(JakaModel.SENCE_初始位)); } } - else if (resultTakeCup == 2 || resultTakeCup == 3) + } + private void PutCoffeeCup() + { + new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放咖啡杯 }.Publish(); + Wait(int.Parse(JakaModel.SENCE_放咖啡杯)); + int resultputCup = putCup(); + if (resultputCup == 1) + { + //订单状态改变:完成 + new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish(); + Wait(int.Parse(JakaModel.SENCE_初始位)); + OrderChange(morkTJakaJC.morkOrderPushesCoffee.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE); + } + else { new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish(); Wait(int.Parse(JakaModel.SENCE_初始位)); } - #endregion } /// - /// 做茶 + /// 接开水 /// - private void DoTea() + private void PickUpWater() { - #region 接茶流程 - OrderChange(subOrderId, BPA.Message.Enum.ORDER_STATUS.COOKING); - int resultTakeCup = takeCup(); - if (resultTakeCup == 1) + #region 接水流程 + if (!pickUpHotWaterHaveCup) { - DeviceProcessLogShow("取茶杯完成"); - new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接茶 }.Publish(); - Wait(int.Parse(JakaModel.SENCE_接茶)); - - new WriteMcu() { TagName = "ServoControl", Address = "1", Value = 105 }.Publish(); - Thread.Sleep(1000); - new WriteMcu() { TagName = "ServoControl", Address = "1", Value = 130 }.Publish(); - Thread.Sleep(1000); - new WriteMcu() { TagName = "ServoControl", Address = "1", Value = 105 }.Publish(); - - Thread.Sleep(3000); - new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接茶_接水 }.Publish(); - Wait(int.Parse(JakaModel.SENCE_接茶_接水)); - - - new WriteMcu() { TagName = "OutputControl", Value = false, Address = "4" }.Publish(); - new WriteMcu() { TagName = "OutputControl", Value = false, Address = "3" }.Publish(); + OrderChange(morkTJakaJC.morkOrderPushesWater.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING); + int resultTakeCup = takeCup(); + if (resultTakeCup == 1) + { + new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接水 }.Publish(); + Wait(int.Parse(JakaModel.SENCE_接水)); - Thread.Sleep(100); - new WriteMcu() { TagName = "OutputControl", Value = true, Address = "3" }.Publish(); - Thread.Sleep(3000); - new WriteMcu() { TagName = "OutputControl", Value = false, Address = "3" }.Publish(); - Thread.Sleep(100); + new WriteMcu() { TagName = "OutputControl", Value = false, Address = "4" }.Publish(); - new WriteMcu() { TagName = "OutputControl", Value = false, Address = "4" }.Publish(); - Thread.Sleep(100); - new WriteMcu() { TagName = "OutputControl", Value = true, Address = "4" }.Publish(); - Thread.Sleep(500); - new WriteMcu() { TagName = "OutputControl", Value = false, Address = "4" }.Publish(); - Thread.Sleep(50000); + new WriteMcu() { TagName = "OutputControl", Value = false, Address = "3" }.Publish(); + Thread.Sleep(100); + new WriteMcu() { TagName = "OutputControl", Value = true, Address = "3" }.Publish(); + Thread.Sleep(3000); + new WriteMcu() { TagName = "OutputControl", Value = false, Address = "3" }.Publish(); + Thread.Sleep(100); - new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放茶水杯 }.Publish(); - Wait(int.Parse(JakaModel.SENCE_放茶水杯)); - int resultputCup = putCup(); - if (resultputCup == 1) - { - new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish(); - Wait(int.Parse(JakaModel.SENCE_初始位)); - OrderChange(subOrderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE); + new WriteMcu() { TagName = "OutputControl", Value = false, Address = "4" }.Publish(); + Thread.Sleep(100); + new WriteMcu() { TagName = "OutputControl", Value = true, Address = "4" }.Publish(); + Thread.Sleep(500); + new WriteMcu() { TagName = "OutputControl", Value = false, Address = "4" }.Publish(); } - else + else if (resultTakeCup == 2 || resultTakeCup == 3) { new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish(); Wait(int.Parse(JakaModel.SENCE_初始位)); } } - else if (resultTakeCup == 2 || resultTakeCup == 3) + #endregion + } + /// + /// 放水杯 + /// + private void PutWaterCup() + { + new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放茶水杯 }.Publish(); + Wait(int.Parse(JakaModel.SENCE_放茶水杯)); + int resultputCup = putCup(); + if (resultputCup == 1) + { + //订单状态改变:完成 + new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish(); + Wait(int.Parse(JakaModel.SENCE_初始位)); + OrderChange(morkTJakaJC.morkOrderPushesCoffee.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE); + } + else { new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish(); Wait(int.Parse(JakaModel.SENCE_初始位)); } - #endregion } - /// - /// 接开水 + /// 做茶 /// - private void DoWater() + private void PickUpTea() { - #region 接水流程 - OrderChange(subOrderId, BPA.Message.Enum.ORDER_STATUS.COOKING); - int resultTakeCup = takeCup(); - if (resultTakeCup == 1) + #region 接茶流程 + if (!pickUpHotWaterHaveCup) { - new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接水 }.Publish(); - Wait(int.Parse(JakaModel.SENCE_接水)); + OrderChange(morkTJakaJC.morkOrderPushesTea.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING); + int resultTakeCup = takeCup(); + if (resultTakeCup == 1) + { + DeviceProcessLogShow("取茶杯完成"); + new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接茶 }.Publish(); + Wait(int.Parse(JakaModel.SENCE_接茶)); - new WriteMcu() { TagName = "OutputControl", Value = false, Address = "4" }.Publish(); + new WriteMcu() { TagName = "ServoControl", Address = "1", Value = 105 }.Publish(); + Thread.Sleep(1000); + new WriteMcu() { TagName = "ServoControl", Address = "1", Value = 130 }.Publish(); + Thread.Sleep(1000); + new WriteMcu() { TagName = "ServoControl", Address = "1", Value = 105 }.Publish(); + Thread.Sleep(3000); + new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接茶_接水 }.Publish(); + Wait(int.Parse(JakaModel.SENCE_接茶_接水)); - new WriteMcu() { TagName = "OutputControl", Value = false, Address = "3" }.Publish(); - Thread.Sleep(100); - new WriteMcu() { TagName = "OutputControl", Value = true, Address = "3" }.Publish(); - Thread.Sleep(3000); - new WriteMcu() { TagName = "OutputControl", Value = false, Address = "3" }.Publish(); - Thread.Sleep(100); - new WriteMcu() { TagName = "OutputControl", Value = false, Address = "4" }.Publish(); - Thread.Sleep(100); - new WriteMcu() { TagName = "OutputControl", Value = true, Address = "4" }.Publish(); - Thread.Sleep(500); - new WriteMcu() { TagName = "OutputControl", Value = false, Address = "4" }.Publish(); + new WriteMcu() { TagName = "OutputControl", Value = false, Address = "4" }.Publish(); + new WriteMcu() { TagName = "OutputControl", Value = false, Address = "3" }.Publish(); - Thread.Sleep(50000); - //添加控制接水机构程序 + Thread.Sleep(100); + new WriteMcu() { TagName = "OutputControl", Value = true, Address = "3" }.Publish(); + Thread.Sleep(3000); + new WriteMcu() { TagName = "OutputControl", Value = false, Address = "3" }.Publish(); + Thread.Sleep(100); - new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放茶水杯 }.Publish(); - Wait(int.Parse(JakaModel.SENCE_放茶水杯)); - int resultputCup = putCup(); - if (resultputCup == 1) - { - new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish(); - Wait(int.Parse(JakaModel.SENCE_初始位)); - OrderChange(subOrderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE); + new WriteMcu() { TagName = "OutputControl", Value = false, Address = "4" }.Publish(); + Thread.Sleep(100); + new WriteMcu() { TagName = "OutputControl", Value = true, Address = "4" }.Publish(); + Thread.Sleep(500); + new WriteMcu() { TagName = "OutputControl", Value = false, Address = "4" }.Publish(); } - else + else if (resultTakeCup == 2 || resultTakeCup == 3) { new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish(); Wait(int.Parse(JakaModel.SENCE_初始位)); } } - else if (resultTakeCup == 2 || resultTakeCup == 3) - { - new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish(); - Wait(int.Parse(JakaModel.SENCE_初始位)); - } #endregion } /// /// 果汁机控制信号 /// private byte JuicerNum; - /// - /// 做果汁 - /// - private void DoJuicer() + private int JuiceCH; + private void PickUpJuicer() { #region 接果汁流程 - are.Reset(); - OrderChange(subOrderId, BPA.Message.Enum.ORDER_STATUS.COOKING); - int resultTakeCup = takeCup(); - if (resultTakeCup == 1) + if (!pickUpJuiceHaveCup) { - int JuicerNum1 = int.Parse(mainMaterialLoc); - switch (JuicerNum1) + OrderChange(morkTJakaJC.morkOrderPushesWater.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING); + int resultTakeCup = takeCup(); + JuiceCH = int.Parse(mainMaterialLoc); + if (resultTakeCup == 1) { - case 52: - if (GuMake) - { - JuicerNum = 0x00; - } - else - { - JuicerNum = 0x01; - } - new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接果汁1 }.Publish(); - Wait(int.Parse(JakaModel.SENCE_接果汁1)); - break; - case 53: - if (GuMake) - { - JuicerNum = 0x02; - } - else - { - JuicerNum = 0x03; - } - new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接果汁2 }.Publish(); - Wait(int.Parse(JakaModel.SENCE_接果汁2)); - break; - case 54: - if (GuMake) - { - JuicerNum = 0x04; - } - else - { - JuicerNum = 0x05; - } - new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接果汁3 }.Publish(); - Wait(int.Parse(JakaModel.SENCE_接果汁3)); - break; - case 55: - if (GuMake) - { - JuicerNum = 0x06; - } - else - { - JuicerNum = 0x07; - } - new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接果汁4 }.Publish(); - Wait(int.Parse(JakaModel.SENCE_接果汁4)); - break; - default: - JuicerNum = 0x00; - new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接果汁1 }.Publish(); - Wait(int.Parse(JakaModel.SENCE_接果汁1)); - break; - } - var devStatus = GetStatus("GetDeviceStatus"); - var devStatus1 = Convert.ToString(devStatus[0], 2); - var devStatus2 = devStatus[1]; - - if (devStatus1.IndexOf("0") == 1 && devStatus2 == 0) - { - if (sensor_Sign(1) == 1) - { - new WriteJuicer() { Value = JuicerNum }.Publish(); - } - Thread.Sleep(100); - devStatusBy = GetStatus("GetDeviceStatus"); - while (!(devStatusBy[1] == 0)) - { - Thread.Sleep(100); - devStatusBy = GetStatus("GetDeviceStatus"); - while (devStatusBy.Length != 2) - { - Thread.Sleep(100); - devStatusBy = GetStatus("GetDeviceStatus"); - } - } - devStatusBy = GetStatus("GetDeviceStatus"); - Thread.Sleep(5000); - switch (JuicerNum1) + switch (JuiceCH) { case 52: - new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放果汁杯1 }.Publish(); - Wait(int.Parse(JakaModel.SENCE_放果汁杯1)); + if (GuMake) + { + JuicerNum = 0x00; + } + else + { + JuicerNum = 0x01; + } + new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接果汁1 }.Publish(); + Wait(int.Parse(JakaModel.SENCE_接果汁1)); break; case 53: - new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放果汁杯2 }.Publish(); - Wait(int.Parse(JakaModel.SENCE_放果汁杯2)); + if (GuMake) + { + JuicerNum = 0x02; + } + else + { + JuicerNum = 0x03; + } + new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接果汁2 }.Publish(); + Wait(int.Parse(JakaModel.SENCE_接果汁2)); break; case 54: - new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放果汁杯3 }.Publish(); - Wait(int.Parse(JakaModel.SENCE_放果汁杯3)); + if (GuMake) + { + JuicerNum = 0x04; + } + else + { + JuicerNum = 0x05; + } + new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接果汁3 }.Publish(); + Wait(int.Parse(JakaModel.SENCE_接果汁3)); break; case 55: - new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放果汁杯4 }.Publish(); - Wait(int.Parse(JakaModel.SENCE_放果汁杯4)); + if (GuMake) + { + JuicerNum = 0x06; + } + else + { + JuicerNum = 0x07; + } + new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接果汁4 }.Publish(); + Wait(int.Parse(JakaModel.SENCE_接果汁4)); break; default: - new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放果汁杯1 }.Publish(); - Wait(int.Parse(JakaModel.SENCE_放果汁杯1)); + JuicerNum = 0x00; + new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接果汁1 }.Publish(); + Wait(int.Parse(JakaModel.SENCE_接果汁1)); break; } - int resultputCup = putCup(); - if (resultputCup == 1) - { - new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish(); - Wait(int.Parse(JakaModel.SENCE_初始位)); - OrderChange(subOrderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE); - } - else - { - new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish(); - Wait(int.Parse(JakaModel.SENCE_初始位)); - } + new WriteJuicer() { Value = JuicerNum }.Publish(); + pickUpJuiceHaveCup = true; } else { - switch (JuicerNum1) - { - case 52: - new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放果汁杯1 }.Publish(); - Wait(int.Parse(JakaModel.SENCE_放果汁杯1)); - break; - case 53: - new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放果汁杯2 }.Publish(); - Wait(int.Parse(JakaModel.SENCE_放果汁杯2)); - break; - case 54: - new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放果汁杯3 }.Publish(); - Wait(int.Parse(JakaModel.SENCE_放果汁杯3)); - break; - case 55: - new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放果汁杯4 }.Publish(); - Wait(int.Parse(JakaModel.SENCE_放果汁杯4)); - break; - default: - new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放果汁杯1 }.Publish(); - Wait(int.Parse(JakaModel.SENCE_放果汁杯1)); - break; - } - int resultputCup = putCup(); - if (resultputCup == 1) - { - new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish(); - Wait(int.Parse(JakaModel.SENCE_初始位)); - OrderChange(subOrderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE); - } - else - { - new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish(); - Wait(int.Parse(JakaModel.SENCE_初始位)); - } + return; } } - else if (resultTakeCup == 2 || resultTakeCup == 3) + #endregion + } + private void putJuice() + { + switch (JuiceCH) + { + case 52: + new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放果汁杯1 }.Publish(); + Wait(int.Parse(JakaModel.SENCE_放果汁杯1)); + break; + case 53: + new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放果汁杯2 }.Publish(); + Wait(int.Parse(JakaModel.SENCE_放果汁杯2)); + break; + case 54: + new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放果汁杯3 }.Publish(); + Wait(int.Parse(JakaModel.SENCE_放果汁杯3)); + break; + case 55: + new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放果汁杯4 }.Publish(); + Wait(int.Parse(JakaModel.SENCE_放果汁杯4)); + break; + default: + new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放果汁杯1 }.Publish(); + Wait(int.Parse(JakaModel.SENCE_放果汁杯1)); + break; + } + int resultputCup = putCup(); + if (resultputCup == 1) + { + new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish(); + Wait(int.Parse(JakaModel.SENCE_初始位)); + OrderChange(morkTJakaJC.morkOrderPushesWater.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE); + } + else { new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish(); Wait(int.Parse(JakaModel.SENCE_初始位)); } - #endregion } private int getCup_cnt; /// @@ -656,9 +766,6 @@ namespace BPASmartClient.MorktJAKAJC } } private int cnt_Check; - - public override DeviceClientType DeviceType => throw new NotImplementedException(); - /// /// 检测放杯位,是否有杯子 /// @@ -730,7 +837,6 @@ namespace BPASmartClient.MorktJAKAJC { break; } - } if (cnt_Check >= 0) { @@ -750,14 +856,11 @@ namespace BPASmartClient.MorktJAKAJC public void SimOrder(T simOrder) { - - } - - public override void DoMain() - { - + } + + public override void Stop() { @@ -765,13 +868,9 @@ namespace BPASmartClient.MorktJAKAJC public override void ReadData() { - + } - public override void MainTask() - { - - } public override void ResetProgram() { diff --git a/BPASmartClient.Morkt.JAKA.JC/GVL_MORKJC.cs b/BPASmartClient.Morkt.JAKA.JC/GVL_MORKJC.cs index c12d4f3c..918782db 100644 --- a/BPASmartClient.Morkt.JAKA.JC/GVL_MORKJC.cs +++ b/BPASmartClient.Morkt.JAKA.JC/GVL_MORKJC.cs @@ -1,8 +1,69 @@ using BPASmartClient.Device; +using System.Collections.Concurrent; namespace BPASmartClient.MorktJAKAJC { public class GVL_MORKJC : IStatus { + /// + /// + /// 咖啡订单队列 + /// + public ConcurrentQueue morkOrderPushesCoffee = new ConcurrentQueue(); + /// + /// 是否有咖啡杯 + /// + public bool IsHaveCoffeeCup = false; + + /// + /// 咖啡是否制作完成 + /// + public bool MakeCoffeeEnd = false; + + /// + /// 果汁订单队列 + /// + public ConcurrentQueue morkOrderPushesJuicer = new ConcurrentQueue(); + /// + /// 果汁是否在制作中 + /// + public bool IsHaveJuiceCup = false; + /// + /// 咖啡是否制作完成 + /// + public bool MakeJuiceEnd = false; + + /// + /// 做茶订单队列 + /// + public ConcurrentQueue morkOrderPushesTea = new ConcurrentQueue(); + /// + /// 茶或水是否在制作中 + /// + public bool IsHaveTeaWaterCup = false; + /// + /// 咖啡是否制作完成 + /// + public bool MakeTeaEnd = false; + + /// + /// 做开水订单队列 + /// + public ConcurrentQueue morkOrderPushesWater = new ConcurrentQueue(); + + /// + /// 等待取餐订单 + /// + public OrderLocInfo waitMorkOrder = new OrderLocInfo(); + + /// + /// 当前正在制作咖啡 + /// + public OrderLocInfo MakeCoffeeOrder = new OrderLocInfo(); + + /// + /// 订单ID + /// + public string SuborderId = null; } } diff --git a/BPASmartClient.Morkt.JAKA.JC/OrderLocInfo.cs b/BPASmartClient.Morkt.JAKA.JC/OrderLocInfo.cs new file mode 100644 index 00000000..983d718b --- /dev/null +++ b/BPASmartClient.Morkt.JAKA.JC/OrderLocInfo.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.MorktJAKAJC +{ + public class OrderLocInfo + { + public string SuborderId { get; set; } + public ushort Loc { get; set; } + public ushort RecipeNumber { get; set; } + public int BatchingId { get; set; } + public string GoodName { get; set; } + } +} diff --git a/BPASmartClient.Morkt.JAKA.JC/View/DebugView.xaml b/BPASmartClient.Morkt.JAKA.JC/View/DebugView.xaml index 5cbc00e6..b6fbddaa 100644 --- a/BPASmartClient.Morkt.JAKA.JC/View/DebugView.xaml +++ b/BPASmartClient.Morkt.JAKA.JC/View/DebugView.xaml @@ -18,7 +18,7 @@ - + @@ -26,7 +26,7 @@ - + - + @@ -119,6 +119,10 @@ FontSize="20" Header=" 果汁机 "> + + + + @@ -127,7 +131,7 @@ - + @@ -157,7 +161,7 @@ - + 果汁