From 651e2f54a5e42ee7050567298df5ec411c372396 Mon Sep 17 00:00:00 2001 From: pengliangyang <1406009520@qq.com> Date: Fri, 10 Jun 2022 18:32:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9E=9C=E6=B1=81=E6=9C=BA=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BPASmartClient.Lebai/LebaiRobot.cs | 13 + BPASmartClient.LebaiRobot/LebaiHelper.cs | 53 + BPASmartClient.Model/果汁机/JuicerModel.cs | 68 +- .../BPASmartClient.MorkTLebaiJC.csproj | 12 +- .../Control_MORKJC2.cs | 938 +++++++++--------- .../GVL_MorkTLebeiJC.cs | 75 ++ BPASmartClient.MorkT.Lebai.JC/OrderLocInfo.cs | 17 + .../View/DebugView.xaml | 399 ++++++++ .../View/DebugView.xaml.cs | 37 + .../ViewModel/DebugViewModel.cs | 235 +++++ .../ViewModel/MonitorViewModel.cs | 94 ++ .../View/DebugView.xaml | 24 +- .../View/DebugView.xaml.cs | 2 + .../ViewModel/DebugViewModel.cs | 177 ++-- 14 files changed, 1566 insertions(+), 578 deletions(-) create mode 100644 BPASmartClient.MorkT.Lebai.JC/GVL_MorkTLebeiJC.cs create mode 100644 BPASmartClient.MorkT.Lebai.JC/OrderLocInfo.cs create mode 100644 BPASmartClient.MorkT.Lebai.JC/View/DebugView.xaml create mode 100644 BPASmartClient.MorkT.Lebai.JC/View/DebugView.xaml.cs create mode 100644 BPASmartClient.MorkT.Lebai.JC/ViewModel/DebugViewModel.cs create mode 100644 BPASmartClient.MorkT.Lebai.JC/ViewModel/MonitorViewModel.cs diff --git a/BPASmartClient.Lebai/LebaiRobot.cs b/BPASmartClient.Lebai/LebaiRobot.cs index 62071417..9310d55f 100644 --- a/BPASmartClient.Lebai/LebaiRobot.cs +++ b/BPASmartClient.Lebai/LebaiRobot.cs @@ -52,6 +52,7 @@ namespace BPASmartClient.Lebai status["RobotValue1"] = LebaiHelper.GetInstance().GetValueAsync(1).Value; status["GetInput"] = LebaiHelper.GetInstance().GetInput(); status["GetInput2"] = LebaiHelper.GetInstance().GetInput(2); + if (LebaiHelper.GetInstance().robotData != null) status["RobotMode"] = LebaiHelper.GetInstance().robotData.RobotMode.Mode; LebaiHelper.GetInstance().GetRobotModeStatus(); Thread.Sleep(10); @@ -117,6 +118,12 @@ namespace BPASmartClient.Lebai case "机器人急停": LebaiHelper.GetInstance().EStopRobot(); break; + case "暂停": + LebaiHelper.GetInstance().pauseMode(); + break; + case "恢复": + LebaiHelper.GetInstance().resumeMode(); + break; default: break; } @@ -149,6 +156,12 @@ namespace BPASmartClient.Lebai public override void WriteData(string address, object value) { + + } + public void SetDO(bool value, int Ch=0) + { + LebaiHelper.GetInstance().SetOutput(value,Ch); } + } } diff --git a/BPASmartClient.LebaiRobot/LebaiHelper.cs b/BPASmartClient.LebaiRobot/LebaiHelper.cs index 91f68806..5cfa1212 100644 --- a/BPASmartClient.LebaiRobot/LebaiHelper.cs +++ b/BPASmartClient.LebaiRobot/LebaiHelper.cs @@ -189,6 +189,42 @@ namespace BPASmartClient.LebaiRobot MessageLog.GetInstance.ShowEx(ex.ToString()); } } + /// + /// 暂停 + /// + public async void pauseMode() + { + try + { + if (robotData != null) + { + await client.Pause(); + MessageLog.GetInstance.Show("机器人切换为暂停模式."); + } + } + catch (Exception ex) + { + MessageLog.GetInstance.ShowEx(ex.ToString()); + } + } + /// + /// 恢复 + /// + public async void resumeMode() + { + try + { + if (robotData != null) + { + await client.Resume(); + MessageLog.GetInstance.Show("机器人切换为暂停后恢复模式."); + } + } + catch (Exception ex) + { + MessageLog.GetInstance.ShowEx(ex.ToString()); + } + } /// /// 机器人急停 @@ -266,7 +302,24 @@ namespace BPASmartClient.LebaiRobot } return false; } + /// + /// 设置DO输出 + /// + /// + /// + public void SetOutput(bool bDO, int pin = 0) + { + try + { + if (client == null) { return; } + var res = client.SetDIO(new DIO() { Pin = pin, Value = bDO ? 1 : 0 }); + } + catch (Exception ex) + { + MessageLog.GetInstance.ShowEx(ex.ToString()); + } + } public bool GetTcpInput(int pin = 1) { try diff --git a/BPASmartClient.Model/果汁机/JuicerModel.cs b/BPASmartClient.Model/果汁机/JuicerModel.cs index 8855d87f..99e49d52 100644 --- a/BPASmartClient.Model/果汁机/JuicerModel.cs +++ b/BPASmartClient.Model/果汁机/JuicerModel.cs @@ -10,26 +10,56 @@ namespace BPASmartClient.Model public class JuicerModel { #region 果汁机设备MORKT2 Lebai机器人 - public const int JUICE2_初始位 = 10021; - public const int JUICE2_检测位回原点 = 10023; - public const int JUICE2_取纸杯 = 10006; - public const int JUICE2_二次取杯 = 10008; - public const int JUICE2_纸杯检测 = 10007; + //public const int JUICE2_初始位 = 10021; + //public const int JUICE2_检测位回原点 = 10023; + //public const int JUICE2_取纸杯 = 10006; + //public const int JUICE2_二次取杯 = 10008; + //public const int JUICE2_纸杯检测 = 10007; + //public const int JUICE2_再检测 = 10024; + //public const int JUICE2_接咖啡 = 10009; + //public const int JUICE2_放咖啡杯 = 10010; + + //public const int JUICE2_接茶叶 = 10017; + //public const int JUICE2_接茶水 = 10018; + //public const int JUICE2_接水 = 10020; + //public const int JUICE2_放水杯 = 10019; + + //public const int JUICE2_接果汁公共位 = 10011; + //public const int JUICE2_接1号果汁 = 10012; + //public const int JUICE2_接2号果汁 = 10013; + //public const int JUICE2_接3号果汁 = 10014; + //public const int JUICE2_接4号果汁 = 10015; + //public const int JUICE2_放果汁杯 = 10016; + + public const int JUICE2_初始位 = 10001; + public const int JUICE2_检测位回原点 = 10001; + public const int JUICE2_取空杯过渡位 = 10004; + public const int JUICE2_取纸杯 = 10002; + public const int JUICE2_取纸杯检测 = 10003; public const int JUICE2_再检测 = 10024; - public const int JUICE2_接咖啡 = 10009; - public const int JUICE2_放咖啡杯 = 10010; - - public const int JUICE2_接茶叶 = 10017; - public const int JUICE2_接茶水 = 10018; - public const int JUICE2_接水 = 10020; - public const int JUICE2_放水杯 = 10019; - - public const int JUICE2_接果汁公共位 = 10011; - public const int JUICE2_接1号果汁 = 10012; - public const int JUICE2_接2号果汁 = 10013; - public const int JUICE2_接3号果汁 = 10014; - public const int JUICE2_接4号果汁 = 10015; - public const int JUICE2_放果汁杯 = 10016; + public const int JUICE2_二次取杯 = 10008; + + //public const int JUICE2_取杯完成后接饮料过渡位 = 10004; + + public const int JUICE2_接咖啡 = 10004; + //public const int JUICE2_接咖啡放杯过渡位 = 10004; + public const int JUICE2_接果汁1 = 10004; + public const int JUICE2_接果汁2 = 10004; + public const int JUICE2_接果汁3 = 10004; + public const int JUICE2_接果汁4 = 10004; + + public const int JUICE2_接茶叶 = 10004; + public const int JUICE2_接茶水 = 10004; + public const int JUICE2_接开水 = 10004; + //public const int JUICE2_接开水_茶水放杯过渡位 = 10004; + + public const int JUICE2_放咖啡杯 = 10004;//放咖啡杯包括取接好咖啡的流程 + public const int JUICE2_放果汁杯1 = 10004; + public const int JUICE2_放果汁杯2 = 10004; + public const int JUICE2_放果汁杯3 = 10004; + public const int JUICE2_放果汁杯4 = 10004; + public const int JUICE2_放水杯 = 10004; + #endregion #region 果汁机设备 MORKT1 JAKA机器人 diff --git a/BPASmartClient.MorkT.Lebai.JC/BPASmartClient.MorkTLebaiJC.csproj b/BPASmartClient.MorkT.Lebai.JC/BPASmartClient.MorkTLebaiJC.csproj index 4d93c04a..d1d4a335 100644 --- a/BPASmartClient.MorkT.Lebai.JC/BPASmartClient.MorkTLebaiJC.csproj +++ b/BPASmartClient.MorkT.Lebai.JC/BPASmartClient.MorkTLebaiJC.csproj @@ -1,4 +1,4 @@ - + net6.0-windows @@ -7,10 +7,20 @@ + + + + + + $(DefaultXamlRuntime) + Designer + + + diff --git a/BPASmartClient.MorkT.Lebai.JC/Control_MORKJC2.cs b/BPASmartClient.MorkT.Lebai.JC/Control_MORKJC2.cs index 885f5031..34b58cbc 100644 --- a/BPASmartClient.MorkT.Lebai.JC/Control_MORKJC2.cs +++ b/BPASmartClient.MorkT.Lebai.JC/Control_MORKJC2.cs @@ -32,126 +32,160 @@ namespace BPASmartClient.MorkTLebaiJC */ public class Control_MORKJC2 : BaseDevice { - //物料存放位置 private Dictionary batchings = new Dictionary(); //容器位置 private string holderLoc; //主料位置 private string mainMaterialLoc; - //子订单ID - private string subOrderId; + public override global::BPA.Message.Enum.DeviceClientType DeviceType { get { return BPA.Message.Enum.DeviceClientType.MORKT; } } - private bool enableFunny = false; - private DateTime lastRecvdOrder = DateTime.Now; - private bool working = false; + GVL_MorkTLebaiJC morkTLebaiJC =new GVL_MorkTLebaiJC(); /// /// 果汁机做法,true:热饮,false:冷饮 /// private bool GuMake = false; - - //private SerialPortClient commProxy; - public void ConnectOk() + public override void DoMain() { + if (Json.Data.IsVerify) + { + IsHealth = true; + } + IsHealth = true; + serverInit(); + DataParse(); + } + private void serverInit() + { + EventBus.EventBus.GetInstance().Subscribe(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack) + { + if (@event == null) return; + if (@event is MaterialDeliveryEvent material) + { + orderMaterialDelivery = material.orderMaterialDelivery; + } + }); } - ConcurrentQueue morkOrderPushes = new ConcurrentQueue(); - public void Init() + private void DataParse() { - //构建所有商品物料信息 - batchings = PolymerBatching.BuildAll(); - EventBus.EventBus.GetInstance().Subscribe(DeviceId, DRCoffee_CoffeEndCookEventHandle); - Main(); - ReadData(); - ThreadManage.GetInstance().StartLong(new Action(() => + + EventBus.EventBus.GetInstance().Subscribe(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle) { - while (IsHealth && (morkOrderPushes.Count > 0)) + if (@event == null) return; + if (@event is DoOrderEvent order) { - working = true; - if (morkOrderPushes.TryDequeue(out MorkOrderPush 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) { - //获取主料和容器位置 - switch (batchings[res.BatchingLoc].BatchingClass) - { - case BATCHING_CLASS.HOLDER: - holderLoc = res.BatchingLoc; - break; - case BATCHING_CLASS.MAIN_MATERIAL: - mainMaterialLoc = res.BatchingLoc; - //验证商品是咖啡还是冰淇淋 - 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) + { + case GOODS_TYPE.COFFEE: + if (morkTLebaiJC.morkOrderPushesCoffee.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null) + { + morkTLebaiJC.morkOrderPushesCoffee.Enqueue(new OrderLocInfo() + { + SuborderId = order.MorkOrder.SuborderId, + BatchingId = res.BatchingId, + Loc = ushort.Parse( mainMaterialLoc), + GoodName = order.MorkOrder.GoodsName, + }); + } + //morkTLebaiJC.SuborderId = order.MorkOrder.SuborderId; + break; + case GOODS_TYPE.JUICE: + GuMake = order.MorkOrder.MakeID == "2";//判断果汁的冷热 + if (morkTLebaiJC.morkOrderPushesJuicer.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null) + { + morkTLebaiJC.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 (morkTLebaiJC.morkOrderPushesTea.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null) + { + morkTLebaiJC.morkOrderPushesTea.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.WATER: + if (morkTLebaiJC.morkOrderPushesWater.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null) + { + morkTLebaiJC.morkOrderPushesWater.Enqueue(new OrderLocInfo() + { + 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() { //开始心跳刷新,根据咖啡机及冰淇淋机来判断 ThreadManage.GetInstance().StartLong(new Action(() => { - IsHealth = GetStatus("JuicerIsConnected"); + IsHealth = true; Thread.Sleep(100); }), "MORK-IC心跳刷新"); } + /// + /// 订单状态改变 + /// + /// + /// private void OrderChange(string subid, ORDER_STATUS oRDER_STATUS) { EventBus.EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { Status = oRDER_STATUS, SubOrderId = subid, deviceClientType = DeviceType }); } - - public void DataParse(T order) - { - if (order is MorkOrderPush morkOrderPush) - { - morkOrderPushes.Enqueue(morkOrderPush); - } - } - /// - /// 验证当前是做咖啡还是做冰淇淋 + /// 验证商品是做的某种饮料 /// /// 物料位置 private GOODS_TYPE ValidateGoodsByBatching(string batchingLoc) @@ -160,9 +194,6 @@ namespace BPASmartClient.MorkTLebaiJC return batchings[batchingLoc].GoodsType; return GOODS_TYPE.NEITHER; } - - private AutoResetEvent are = new AutoResetEvent(false); - private void Wait(int value = 101) { while (!((bool)peripheralStatus["RobotOK"] && (int)peripheralStatus["RobotValue"] == value)) @@ -188,10 +219,21 @@ namespace BPASmartClient.MorkTLebaiJC } return default; } - int[] devStatusBy = new int[2] { 0, 0 }; bool outCupCheck = false;//放纸杯位置有无判断 /// + /// 判断接咖啡的位置是否有杯子 + /// + bool pickUpCoffeeHaveCup = false; + /// + /// 判断接果汁的位置是否有杯子 + /// + bool pickUpJuiceHaveCup = false; + /// + /// 判断接开水的位置是否有杯子 + /// + bool pickUpHotWaterHaveCup = false; + /// /// 传感器的输入信号 0:无意义 1:有信号 2:无信号 3:信号不正确 /// int bSensorInput; @@ -199,65 +241,141 @@ namespace BPASmartClient.MorkTLebaiJC /// 延迟的超时时间 /// DateTime delayTimeOut; + + private bool IsMakeCoffee() + { + bool bMake = (IsHealth && morkTLebaiJC.morkOrderPushesCoffee.Count > 0 && !morkTLebaiJC.IsHaveCoffeeCup) ? true : false; + return bMake; + } + + private bool IsMakeJuice() + { + bool bMake = (IsHealth && morkTLebaiJC.morkOrderPushesJuicer.Count > 0 && !morkTLebaiJC.IsHaveJuiceCup) ? true : false; + return bMake; + } + private bool IsMakeTeaWater() + { + bool bMake = (IsHealth && morkTLebaiJC.morkOrderPushesTea.Count > 0 && morkTLebaiJC.morkOrderPushesWater.Count > 0 && !morkTLebaiJC.IsHaveTeaWaterCup) ? true : false; + return bMake; + } /// - /// 做咖啡 + /// 做咖啡流程 /// - private void DoCoffee() + private void DoCoffee() { - #region 接咖啡流程 - are.Reset(); - while (GetStatus("RobotValue1"))//判断放杯位置是否有物品 + if (IsMakeCoffee()) { - if (!outCupCheck) - DeviceProcessLogShow("成品处有纸杯存在,请取走!!"); - outCupCheck = true; + if (morkTLebaiJC.morkOrderPushesCoffee.TryDequeue(out OrderLocInfo orderLoc)) + { + morkTLebaiJC.IsHaveCoffeeCup = true; + PickUpCoffee();//接咖啡 + } } - outCupCheck = false; - OrderChange(subOrderId, BPA.Message.Enum.ORDER_STATUS.COOKING); - int resultTakeCup = takeCup(); - if (resultTakeCup == 1) + else if(morkTLebaiJC.MakeCoffeeEnd) { - DeviceProcessLogShow("咖啡杯取杯完成"); - new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); - Sence(JuicerModel.JUICE2_接咖啡); - Wait(); - - new DRCoffee_MakeCoffeeEvent() { DrinkCode = (DrCoffeeDrinksCode)int.Parse(mainMaterialLoc) }.Publish(); //接咖啡控制 //DrCoffeeDrinksCode.热水 - //Task.Delay(10000).Wait();//模拟接咖啡 - //coffeEndCook.Publish();//模拟咖啡制作完成 - are.WaitOne(1000 * 360); - while (GetStatus("RobotValue1"))//判断放杯位置是否有物品 + PutCoffeeCup(); + pickUpCoffeeHaveCup = false; + morkTLebaiJC.IsHaveCoffeeCup = false; + } + } + private void DoJuice() + { + if (IsMakeJuice()) + { + if (morkTLebaiJC.morkOrderPushesJuicer.TryDequeue(out OrderLocInfo orderLoc)) { - if (!outCupCheck) - DeviceProcessLogShow("成品处有纸杯存在,请取走!!"); - outCupCheck = true; + morkTLebaiJC.IsHaveCoffeeCup = true; + PickUpJuicer(); } - outCupCheck = false; - while (GetStatus("RobotValue1"))//判断放杯位置是否有物品 + + } else if (morkTLebaiJC.MakeJuiceEnd) + { + putJuice(); + pickUpJuiceHaveCup = false; + morkTLebaiJC.IsHaveCoffeeCup = false; + morkTLebaiJC.MakeJuiceEnd = false; + } + } + private void DoBoiledTea() + { + if (IsMakeTeaWater()) + { + if (morkTLebaiJC.morkOrderPushesTea.TryDequeue(out OrderLocInfo orderLoc)) { - if (!outCupCheck) - DeviceProcessLogShow("成品处有纸杯存在,请取走!!"); - outCupCheck = true; + morkTLebaiJC.IsHaveTeaWaterCup = true; + PickUpTea(); } - outCupCheck = false; - new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); - Sence(JuicerModel.JUICE2_放咖啡杯); - Wait(); - OrderChange(subOrderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE); - DeviceProcessLogShow("咖啡制作完成"); } - else + else if(morkTLebaiJC.MakeTeaEnd) { - return; + PutWaterCup(); + pickUpHotWaterHaveCup = false; + morkTLebaiJC.IsHaveTeaWaterCup = false ; + morkTLebaiJC.MakeTeaEnd = false; + } + } + private void DoBoiledWater() + { + if (IsMakeTeaWater()) + { + if (morkTLebaiJC.morkOrderPushesWater.TryDequeue(out OrderLocInfo orderLoc)) + { + morkTLebaiJC.IsHaveTeaWaterCup = true; + PickUpWater(); + } + } + else if (morkTLebaiJC.MakeTeaEnd) + { + PutWaterCup(); + pickUpHotWaterHaveCup = false; + morkTLebaiJC.IsHaveTeaWaterCup = false; + morkTLebaiJC.MakeTeaEnd = false; } - #endregion } + + #region 做咖啡流程 /// - /// 做茶 + /// 接咖啡 /// - private void DoTea() + private void PickUpCoffee() + { + //while (GetStatus("RobotValue1"))//判断放杯位置是否有物品 + //{ + // if (!outCupCheck) + // DeviceProcessLogShow("成品处有纸杯存在,请取走!!"); + // outCupCheck = true; + //} + if (!pickUpCoffeeHaveCup) + { + outCupCheck = false; + + if (morkTLebaiJC.morkOrderPushesCoffee.Count > 0) + { + OrderChange(morkTLebaiJC.morkOrderPushesCoffee.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING); + } + int resultTakeCup = takeCup(); + if (resultTakeCup == 1) + { + DeviceProcessLogShow("咖啡杯取杯完成"); + new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); + Sence(JuicerModel.JUICE2_接咖啡); + Wait(); + pickUpCoffeeHaveCup = true; + //new DRCoffee_MakeCoffeeEvent() { DrinkCode = (DrCoffeeDrinksCode)int.Parse(mainMaterialLoc) }.Publish(); //接咖啡控制 //DrCoffeeDrinksCode.热水 //coffeEndCook.Publish();//模拟咖啡制作完成 + //are.WaitOne(1000 * 360); + } + else + { + DeviceProcessLogShow("取杯失败 回到初始位,请及时处理!!"); + Sence(JuicerModel.JUICE2_初始位); + } + } + } + /// + /// 咖啡杯接好,放咖啡杯 + /// + private void PutCoffeeCup() { - #region 接茶流程 while (GetStatus("RobotValue1"))//判断放杯位置是否有物品 { if (!outCupCheck) @@ -265,70 +383,103 @@ namespace BPASmartClient.MorkTLebaiJC outCupCheck = true; } outCupCheck = false; - OrderChange(subOrderId, BPA.Message.Enum.ORDER_STATUS.COOKING); - int resultTakeCup = takeCup(); - if (resultTakeCup == 1) + new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); + Sence(JuicerModel.JUICE2_放咖啡杯); + Wait(); + if (morkTLebaiJC.morkOrderPushesCoffee.Count > 0) { - DeviceProcessLogShow("取茶杯完成"); - new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); - Sence(JuicerModel.JUICE2_接茶叶); - Wait(); - - new WriteMcu() { TagName = "ServoControl", Address = "1", Value = 90 }.Publish(); - Thread.Sleep(1000); - new WriteMcu() { TagName = "ServoControl", Address = "1", Value = 150 }.Publish(); - Thread.Sleep(1000); - new WriteMcu() { TagName = "ServoControl", Address = "1", Value = 90 }.Publish(); - - Thread.Sleep(3000); - new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); - Sence(JuicerModel.JUICE2_接茶水); - Wait(); - - new WriteMcu() { TagName = "OutputControl", Address = "1", Value = false }.Publish(); - - new WriteMcu() { TagName = "OutputControl", Address = "0", Value = false }.Publish(); - Thread.Sleep(100); - new WriteMcu() { TagName = "OutputControl", Address = "0", Value = true }.Publish(); - Thread.Sleep(3000); - new WriteMcu() { TagName = "OutputControl", Address = "0", Value = false }.Publish(); - Thread.Sleep(100); - - new WriteMcu() { TagName = "OutputControl", Address = "1", Value = false }.Publish(); - Thread.Sleep(100); - new WriteMcu() { TagName = "OutputControl", Address = "1", Value = true }.Publish(); - Thread.Sleep(500); - new WriteMcu() { TagName = "OutputControl", Address = "1", Value = false }.Publish(); - Thread.Sleep(46000); - while (GetStatus("RobotValue1"))//判断放杯位置是否有物品 + OrderChange(morkTLebaiJC.morkOrderPushesCoffee.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE); + } + DeviceProcessLogShow("咖啡制作完成"); + } + #endregion + #region 做开水流程 + /// + /// 接开水 + /// + private void PickUpWater() + { + #region 接水流程 + if (!pickUpHotWaterHaveCup) + { + if (morkTLebaiJC.morkOrderPushesCoffee.Count > 0) { - if (!outCupCheck) - DeviceProcessLogShow("成品处有纸杯存在,请取走!!"); - outCupCheck = true; + OrderChange(morkTLebaiJC.morkOrderPushesWater.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING); } - outCupCheck = false; - new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); - Sence(JuicerModel.JUICE2_放水杯); - Wait(); - - - OrderChange(subOrderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE); - DeviceProcessLogShow("茶水制作完成"); + int resultTakeCup = takeCup(); + if (resultTakeCup == 1) + { + new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); + Sence(JuicerModel.JUICE2_接开水); + Wait(); + new WriteMcu() { TagName = "OutputControl", Address = "1", Value = false }.Publish(); + new WriteMcu() { TagName = "OutputControl", Address = "0", Value = false }.Publish(); + Thread.Sleep(100); + new WriteMcu() { TagName = "OutputControl", Address = "0", Value = true }.Publish(); + Thread.Sleep(3000); + new WriteMcu() { TagName = "OutputControl", Address = "0", Value = false }.Publish(); + Thread.Sleep(100); + new WriteMcu() { TagName = "OutputControl", Address = "1", Value = false }.Publish(); + Thread.Sleep(100); + new WriteMcu() { TagName = "OutputControl", Address = "1", Value = true }.Publish(); + Thread.Sleep(500); + new WriteMcu() { TagName = "OutputControl", Address = "1", Value = false }.Publish(); + Thread.Sleep(46000); + } + else + { + return; + } } - else + #endregion + } + #endregion + #region 做茶流程 + /// + /// 做茶 + /// + private void PickUpTea() + { + #region 接茶流程 + if (!pickUpHotWaterHaveCup) { - return; + if (morkTLebaiJC.morkOrderPushesCoffee.Count > 0) + { + OrderChange(morkTLebaiJC.morkOrderPushesTea.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING); + } + int resultTakeCup = takeCup(); + if (resultTakeCup == 1) + { + DeviceProcessLogShow("取茶杯完成"); + new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); + Sence(JuicerModel.JUICE2_接茶叶); + Wait(); + + new WriteMcu() { TagName = "ServoControl", Address = "1", Value = 90 }.Publish(); + Thread.Sleep(1000); + new WriteMcu() { TagName = "ServoControl", Address = "1", Value = 150 }.Publish(); + Thread.Sleep(1000); + new WriteMcu() { TagName = "ServoControl", Address = "1", Value = 90 }.Publish(); + + Thread.Sleep(3000); + new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); + Sence(JuicerModel.JUICE2_接茶水); + Wait(); + pickUpHotWaterHaveCup = true; + } + else + { + return; + } } #endregion } - /// - /// 接开水 + /// 放水杯流程 /// - private void DoWater() + private void PutWaterCup() { - #region 接水流程 while (GetStatus("RobotValue1"))//判断放杯位置是否有物品 { if (!outCupCheck) @@ -336,222 +487,149 @@ namespace BPASmartClient.MorkTLebaiJC outCupCheck = true; } outCupCheck = false; - OrderChange(subOrderId, BPA.Message.Enum.ORDER_STATUS.COOKING); - int resultTakeCup = takeCup(); - if (resultTakeCup == 1) - { - new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); - Sence(JuicerModel.JUICE2_接水); - Wait(); - new WriteMcu() { TagName = "OutputControl", Address = "1", Value = false }.Publish(); - new WriteMcu() { TagName = "OutputControl", Address = "0", Value = false }.Publish(); - Thread.Sleep(100); - new WriteMcu() { TagName = "OutputControl", Address = "0", Value = true }.Publish(); - Thread.Sleep(3000); - new WriteMcu() { TagName = "OutputControl", Address = "0", Value = false }.Publish(); - Thread.Sleep(100); - - new WriteMcu() { TagName = "OutputControl", Address = "1", Value = false }.Publish(); - Thread.Sleep(100); - new WriteMcu() { TagName = "OutputControl", Address = "1", Value = true }.Publish(); - Thread.Sleep(500); - new WriteMcu() { TagName = "OutputControl", Address = "1", Value = false }.Publish(); - Thread.Sleep(46000); - while (GetStatus("RobotValue1"))//判断放杯位置是否有物品 - { - if (!outCupCheck) - DeviceProcessLogShow("成品处有纸杯存在,请取走!!"); - outCupCheck = true; - } - outCupCheck = false; - //添加控制接水机构程序 - new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); - Sence(JuicerModel.JUICE2_放水杯); - Wait(); - OrderChange(subOrderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE); - DeviceProcessLogShow("纯净水制作完成"); - - } - else + new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); + Sence(JuicerModel.JUICE2_放水杯); + Wait(); + if (morkTLebaiJC.morkOrderPushesCoffee.Count > 0) { - return; + OrderChange(morkTLebaiJC.morkOrderPushesWater.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE); } - #endregion + DeviceProcessLogShow("茶水制作完成"); } + + #endregion + #region 做果汁流程 /// /// 果汁机控制信号 /// private byte JuicerNum; + private int JuiceCH; /// - /// 做果汁 + /// 接果汁 /// - private void DoJuicer() + private void PickUpJuicer() { #region 接果汁流程 - are.Reset(); + if (!pickUpJuiceHaveCup) + { + if (morkTLebaiJC.morkOrderPushesCoffee.Count > 0) + { + OrderChange(morkTLebaiJC.morkOrderPushesJuicer.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING); + } + int resultTakeCup = takeCup(); + JuiceCH = int.Parse(mainMaterialLoc); + if (resultTakeCup == 1) + { + switch (JuiceCH) + { + case 52: + if (GuMake) + JuicerNum = 0x00; + else + JuicerNum = 0x01; + new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); + Sence(JuicerModel.JUICE2_接果汁1); + Wait(); + break; + case 53: + if (GuMake) + JuicerNum = 0x02; + else + JuicerNum = 0x03; + new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); + Sence(JuicerModel.JUICE2_接果汁2); + Wait(); + break; + case 54: + if (GuMake) + JuicerNum = 0x04; + else + JuicerNum = 0x05; + new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); + Sence(JuicerModel.JUICE2_接果汁3); + Wait(); + break; + case 55: + if (GuMake) + JuicerNum = 0x06; + else + JuicerNum = 0x07; + new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); + Sence(JuicerModel.JUICE2_接果汁4); + Wait(); + break; + default: + JuicerNum = 0x00; + new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); + Sence(JuicerModel.JUICE2_接果汁1); + Wait(); + break; + } + pickUpJuiceHaveCup = true; + } + else + { + return; + } + } + #endregion + } + /// + /// 取接好果汁杯 + /// + private void putJuice() + { while (GetStatus("RobotValue1"))//判断放杯位置是否有物品 { if (!outCupCheck) DeviceProcessLogShow("成品处有纸杯存在,请取走!!"); outCupCheck = true; } - OrderChange(subOrderId, BPA.Message.Enum.ORDER_STATUS.COOKING); - int resultTakeCup = takeCup(); - if (resultTakeCup == 1) + outCupCheck = false; + switch (JuiceCH) { - int JuicerNum1 = int.Parse(mainMaterialLoc); - switch (JuicerNum1) - { - case 52: - if (GuMake) - { - JuicerNum = 0x00; - } - else - { - JuicerNum = 0x01; - } - new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); - Sence(JuicerModel.JUICE2_接果汁公共位); - Wait(); - - new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); - Sence(JuicerModel.JUICE2_接1号果汁); - Wait(); - - break; - case 53: - if (GuMake) - { - JuicerNum = 0x02; - } - else - { - JuicerNum = 0x03; - } - new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); - Sence(JuicerModel.JUICE2_接果汁公共位); - Wait(); - - new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); - Sence(JuicerModel.JUICE2_接2号果汁); - Wait(); - - break; - case 54: - if (GuMake) - { - JuicerNum = 0x04; - } - else - { - JuicerNum = 0x05; - } - new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); - Sence(JuicerModel.JUICE2_接果汁公共位); - Wait(); - - new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); - Sence(JuicerModel.JUICE2_接3号果汁); - Wait(); - - break; - case 55: - if (GuMake) - { - JuicerNum = 0x06; - } - else - { - JuicerNum = 0x07; - } - new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); - Sence(JuicerModel.JUICE2_接果汁公共位); - Wait(); - - new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); - Sence(JuicerModel.JUICE2_接4号果汁); ; - Wait(); - - break; - default: - JuicerNum = 0x00; - new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); - Sence(JuicerModel.JUICE2_接果汁公共位); - Wait(); - - new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); - Sence(JuicerModel.JUICE_接1号果汁); - Wait(); - - break; - } - var devStatus = GetStatus("GetDeviceStatus"); - var devStatus1 = Convert.ToString(devStatus[0], 2); - var devStatus2 = devStatus[1]; - - if (devStatus1.IndexOf("0") == 1 && devStatus2 == 0) - { - 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); - while (GetStatus("RobotValue1"))//判断放杯位置是否有物品 - { - if (!outCupCheck) - DeviceProcessLogShow("成品处有纸杯存在,请取走!!"); - outCupCheck = true; - } - outCupCheck = false; + case 52: new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); - Sence(JuicerModel.JUICE2_放果汁杯); + Sence(JuicerModel.JUICE2_放果汁杯1); Wait(); - - OrderChange(subOrderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE); - DeviceProcessLogShow("果汁制作完成"); - - } - ////模拟果汁 - //Thread.Sleep(15000); - //while (GetStatus("RobotValue1"))//判断放杯位置是否有物品 - //{ - // if (!outCupCheck) - // DeviceProcessLogShow("成品处有纸杯存在,请取走!!"); - // outCupCheck = true; - //} - //outCupCheck = false; - //new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); - //Sence(JuicerModel.JUICE2_放果汁杯); - //Wait(); - - //OrderChange(subOrderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE); - //DeviceProcessLogShow("果汁制作完成"); + break; + case 53: + new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); + Sence(JuicerModel.JUICE2_放果汁杯2); + Wait(); + break; + case 54: + new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); + Sence(JuicerModel.JUICE2_放果汁杯3); + Wait(); + break; + case 55: + new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); + Sence(JuicerModel.JUICE2_放果汁杯4); + Wait(); + break; + default: + new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); + Sence(JuicerModel.JUICE2_放果汁杯1); + Wait(); + break; } - else + if (morkTLebaiJC.morkOrderPushesCoffee.Count > 0) { - return; + OrderChange(morkTLebaiJC.morkOrderPushesJuicer.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE); } - #endregion + DeviceProcessLogShow("果汁制作完成"); } + #endregion + /// /// 取杯的次数 /// private int nCnt; - private int checkCnt;//检测次数 - - public override DeviceClientType DeviceType => throw new NotImplementedException(); - + /// + /// 传感器的检测次数 + /// + private int checkCnt; /// /// 取杯流程 /// @@ -568,7 +646,7 @@ namespace BPASmartClient.MorkTLebaiJC Sence(JuicerModel.JUICE2_取纸杯); Wait(); new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); - Sence(JuicerModel.JUICE2_纸杯检测); + Sence(JuicerModel.JUICE2_取纸杯检测); Wait(); nCnt++; Thread.Sleep(2000); @@ -606,7 +684,7 @@ namespace BPASmartClient.MorkTLebaiJC Wait(); new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish(); - Sence(JuicerModel.JUICE2_纸杯检测); + Sence(JuicerModel.JUICE2_取纸杯检测); Wait(); checkCnt = 0; while (checkCnt < 3) @@ -632,7 +710,7 @@ namespace BPASmartClient.MorkTLebaiJC { DeviceProcessLogShow(ex.ToString()); } - return 1; + return 2; } /// /// 放杯 @@ -664,7 +742,6 @@ namespace BPASmartClient.MorkTLebaiJC return 0; } } - /// /// 检测放杯位,是否有杯子 /// @@ -688,73 +765,12 @@ namespace BPASmartClient.MorkTLebaiJC } } - private void CoffeEndCookHandle(IEvent @event, EventCallBackHandle callBack) - { - are.Set(); - } - - - //public void ReadData() - //{ - // //ThreadManage.GetInstance.StartLong(new Action(() => - // //{ - // // lebai = JuicerModel.GetInstance.GetValueAsync(); - // // JuicerModel.GetInstance.GetRobotModeStatus(); - // // //JuicerModel.GetInstance.GetInput(); - - - // // Thread.Sleep(100); - // //}), "乐百机器人数据读取", true); - //} public void SimOrder(T simOrder) { - //if (morkOrderPushes.Count > 0) - //{ - // morkOrderPushes.Clear(); - //} - //morkOrderPushes.Enqueue(simOrder as MorkOrderPush); - } - - - - /// - /// IOT 广播消息命令 - /// - //public void IotBroadcast(T broadcast) - //{ - // if (broadcast != null && broadcast is IOTCommandModel iOTCommand) - // { - // switch (iOTCommand.CommandName) - // { - // case 0://控制类 - // if (iOTCommand.CommandValue != null) - // { - // if (iOTCommand.CommandValue.ContainsKey("SimOrder")) - // { - // //SimOrder(new SimOrderData { NoodleLoc = 1, BowlLoc = 10 }); - // } - // } - // break; - // case 1://设置属性 - - // break; - // case 2://通知消息 - - // break; - // default: - // break; - // } - // } - //} - private void DRCoffee_CoffeEndCookEventHandle(IEvent @event, EventCallBackHandle callBack) - { - are.Set(); - } - public override void DoMain() - { + } - + public override void Stop() { } @@ -764,32 +780,50 @@ namespace BPASmartClient.MorkTLebaiJC } + private bool bFirstTrig = false; public override void MainTask() { + EventBus.EventBus.GetInstance().Subscribe(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack) + { + if (morkTLebaiJC.IsHaveCoffeeCup) + morkTLebaiJC.MakeCoffeeEnd = true; + }); + 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) + { + morkTLebaiJC.MakeJuiceEnd= true; + } + } + } + if (morkTLebaiJC.IsHaveTeaWaterCup) + { + if (!bFirstTrig) + { + bFirstTrig = true; + delayTimeOut = DateTime.Now; + } + if (DateTime.Now.Subtract(delayTimeOut).TotalSeconds >= 50) + { + bFirstTrig = false; + morkTLebaiJC.MakeTeaEnd = true; + } + } + DoCoffee(); + DoJuice(); + DoBoiledTea(); + DoBoiledTea(); } - public override void ResetProgram() { } public override void SimOrder() { } - - public class SimOrderData - { - public string id { get; set; } - - public int OrderStatus { get; set; } - - public string Loc { get; set; } - - public MorkOrderPush morkOrder { get; set; } - - public SimOrderData() - { - id = Guid.NewGuid().ToString(); - OrderStatus = 0; - } - } } } diff --git a/BPASmartClient.MorkT.Lebai.JC/GVL_MorkTLebeiJC.cs b/BPASmartClient.MorkT.Lebai.JC/GVL_MorkTLebeiJC.cs new file mode 100644 index 00000000..72510db6 --- /dev/null +++ b/BPASmartClient.MorkT.Lebai.JC/GVL_MorkTLebeiJC.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BPASmartClient.Device; +using System.Collections.Concurrent; + +namespace BPASmartClient.MorkTLebaiJC +{ + public class GVL_MorkTLebaiJC : 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.Lebai.JC/OrderLocInfo.cs b/BPASmartClient.MorkT.Lebai.JC/OrderLocInfo.cs new file mode 100644 index 00000000..9b6facb3 --- /dev/null +++ b/BPASmartClient.MorkT.Lebai.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.MorkTLebaiJC +{ + 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.Lebai.JC/View/DebugView.xaml b/BPASmartClient.MorkT.Lebai.JC/View/DebugView.xaml new file mode 100644 index 00000000..da2a1bc4 --- /dev/null +++ b/BPASmartClient.MorkT.Lebai.JC/View/DebugView.xaml @@ -0,0 +1,399 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 制热 + 制冷 + 缺水 + 童锁 + 使用 + + + + + + + + 果汁 + + 饮品1 + 饮品2 + 饮品3 + 饮品4 + + + 冷饮 + 热饮 + + + + + + + + + + + + + + + + + + + DI输入 + + + + + + + + + + + + + + + DI0 + + + DI1 + + + DI2 + + + DI3 + + + DI4 + + + DI5 + + + DI6 + + + DI7 + + + + + + + + + + + + + + + + + + DO输出 + + + + DO0 + DO1 + DO2 + DO3 + DO4 + DO5 + DO6 + DO7 + + + + + + + True + false + + + + + + diff --git a/BPASmartClient.MorkT.Lebai.JC/View/DebugView.xaml.cs b/BPASmartClient.MorkT.Lebai.JC/View/DebugView.xaml.cs new file mode 100644 index 00000000..aa18d11e --- /dev/null +++ b/BPASmartClient.MorkT.Lebai.JC/View/DebugView.xaml.cs @@ -0,0 +1,37 @@ +using BPASmartClient.Helper; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace BPASmartClient.MorkTJAKAJC.View +{ + /// + /// DebugView.xaml 的交互逻辑 + /// + public partial class DebugView : UserControl + { + public DebugView() + { + InitializeComponent(); + } + + private void Dubug_Unloaded(object sender, RoutedEventArgs e) + { + ThreadManage.GetInstance().StopTask("MorkT-状态刷新"); + ThreadManage.GetInstance().StopTask("MorkT-传感器监视"); + + } + } + +} diff --git a/BPASmartClient.MorkT.Lebai.JC/ViewModel/DebugViewModel.cs b/BPASmartClient.MorkT.Lebai.JC/ViewModel/DebugViewModel.cs new file mode 100644 index 00000000..6b6c242c --- /dev/null +++ b/BPASmartClient.MorkT.Lebai.JC/ViewModel/DebugViewModel.cs @@ -0,0 +1,235 @@ +using BPASmartClient.Business; +using BPASmartClient.Device; +using BPASmartClient.DRCoffee; +using BPASmartClient.EventBus; +using BPASmartClient.GSIceCream; +using BPASmartClient.Helper; +using BPASmartClient.LebaiRobot; +using BPASmartClient.Message; +using BPASmartClient.Model; +using BPASmartClient.Model.乐白机器人; +using BPASmartClient.Model.冰淇淋.Enum; +using BPASmartClient.Model.单片机; +using BPASmartClient.Model.单片机.Enum; +using BPASmartClient.Model.咖啡机.Enum; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Threading; +namespace BPASmartClient.MorkTLebaiJC.ViewModel; + public class DebugViewModel : ObservableObject + { + + #region 乐白机器人 + /// + /// 乐白机器人连接状态 + /// + public string RobotConnected { get { return _robotConnected; } set { _robotConnected = value; OnPropertyChanged(); } } + private string _robotConnected { get; set; } + /// + /// 乐白机器人的模式状态 + /// + public string RobotMode { get { return _robotMode; } set { _robotMode = value; OnPropertyChanged(); } } + private string _robotMode { get; set; } + /// + /// 机器人控制指令 + /// + public RelayCommand Button_RobotControlCommand { get; set; } + /// + /// 机器人控制 + /// + /// + private void Button_RobotControl(object o) + { + EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiControlEvent { DeviceId = DeviceId, LebaiControl = o.ToString() }); + } + + #endregion + + #region 果汁机 + /// + /// 果汁机的连接状态 + /// + public string JuicerConnected { get { return _JuicerConnected; } set { _JuicerConnected = value; OnPropertyChanged(); } } + private string _JuicerConnected { get; set; } + + /// + /// 果汁机的状态 + /// + public string JuicerState { get { return _JuicerState; } set { _JuicerState = value; OnPropertyChanged(); } } + private string _JuicerState { get; set; } + + #endregion + + #region 咖啡机 + /// + /// 咖啡机连接状态 + /// + public string CoffeeConnected { get { return _coffeeConnected; } set { _coffeeConnected = value; OnPropertyChanged(); } } + private string _coffeeConnected { get; set; } + /// + /// 咖啡机状态 + /// + public string CoffeeStatus { get { return _coffeeStatus; } set { _coffeeStatus = value; OnPropertyChanged(); } } + private string _coffeeStatus { get; set; } + /// + /// 应用状态 + /// + public string AppStatus { get { return _appStatus; } set { _appStatus = value; OnPropertyChanged(); } } + private string _appStatus { get; set; } + /// + /// 告警 + /// + public string Warning { get { return _warning; } set { _warning = value; OnPropertyChanged(); } } + public string _warning { get; set; } + /// + /// 故障信息 + /// + public string CaffeeFault { get { return _caffeeFault; } set { _caffeeFault = value; OnPropertyChanged(); } } + public string _caffeeFault { get; set; } + + public List Coffees { get; set; } = new List(); + public string SelectedCoffee { get; set; } + + public List CoffeeCmds { get; set; } = new List(); + public string SelectedCoffeeCmd { get; set; } + /// + /// 制作咖啡 + /// + public RelayCommand Button_MakeCoffeeCommand { get; set; } + /// + /// 停止制作咖啡 + /// + public RelayCommand Button_StopMakeCoffeCommand { get; set; } + /// + /// 咖啡模式设置 + /// + public RelayCommand Button_CoffeeModeSetCommand { get; set; } + + private void Button_MakeCoffee() + { + EventBus.EventBus.GetInstance().Publish(new DRCoffee_MakeCoffeeEvent() { DeviceId = DeviceId, DrinkCode = (DrCoffeeDrinksCode)Enum.Parse(typeof(DrCoffeeDrinksCode), SelectedCoffee)}); + } + private void Button_StopMakeCoffe() + { + EventBus.EventBus.GetInstance().Publish(new DRCoffee_CancelMakeCoffeeEvent() { DeviceId = DeviceId }); + } + private void Button_CoffeeModeSet() + { + EventBus.EventBus.GetInstance().Publish(new DRCoffee_CoffeeCommCmdEvent() { DeviceId = DeviceId, CommCmd = (DrCoffeeCommCmd)Enum.Parse(typeof(DrCoffeeCommCmd), SelectedCoffeeCmd)}); + } + #endregion + + #region 单片机 + public string MCUConnected { get { return _mcuConnected; } set { _mcuConnected = value; OnPropertyChanged(); } } + private string _mcuConnected { get; set; } + + public RelayCommand Button_MCUOuputCommand { get; set; } + public RelayCommand Button_MCUDOuputCommand { get; set; } + public RelayCommand Button_LebaiDOuputCommand { get; set; } + + public int PWMInputNumber { get { return _pwmInputNumber; } set { _pwmInputNumber = value; OnPropertyChanged(); } } + private int _pwmInputNumber = 1; + + public int MCU_PWM_CH { get { return _choosePWM; } set { _choosePWM = value; OnPropertyChanged(); } } + private int _choosePWM = 1; + + public int MCU_DO_CH { get { return _mcuDO_CH; } set { _mcuDO_CH = value; OnPropertyChanged(); } } + private int _mcuDO_CH = 1; + + public int Lebai_DO_CH { get { return _lebaiDO_CH; } set { _lebaiDO_CH = value; OnPropertyChanged(); } } + private int _lebaiDO_CH = 1; + + public int Lebai_DO_Value { get { return _lebaiDO_Value; } set { _lebaiDO_Value = value; OnPropertyChanged(); } } + private int _lebaiDO_Value = 1; + + private int[] DICH { get { return _diCH; } set { _diCH = value; OnPropertyChanged(); } } + private int[] _diCH = new int[8]; + + 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() + { + string sChoosePWM =Convert.ToString(MCU_PWM_CH+1); + new WriteMcu() { TagName = "ServoControl", Address = sChoosePWM, Value = PWMInputNumber }.Publish(); + } + private void Button_McuDOutput() + { + string sChooseDO = Convert.ToString(MCU_DO_CH + 1); + new WriteMcu() { TagName = "OutputControl", Address = sChooseDO, Value = MCU_DO_Value }.Publish(); + } + private void Button_LebaiDOutput() + { + string sChooseDO = Convert.ToString(Lebai_DO_CH + 1); + + } + #endregion + + /// + /// 设备ID + /// + public int DeviceId { get; set; } + /// + /// 设备数据 + /// + public ObservableCollection variableMonitors { get; set; } + + public DebugViewModel() + { + Button_RobotControlCommand = new RelayCommand(Button_RobotControl); + Button_MakeCoffeeCommand = new RelayCommand(Button_MakeCoffee); + Button_StopMakeCoffeCommand = new RelayCommand(Button_StopMakeCoffe); + Button_CoffeeModeSetCommand = new RelayCommand(Button_CoffeeModeSet); + + Button_MCUOuputCommand = new RelayCommand(Button_McuOutput); + Button_MCUDOuputCommand = new RelayCommand(Button_McuDOutput); + Button_LebaiDOuputCommand = new RelayCommand(Button_LebaiDOutput); + foreach (DrCoffeeDrinksCode code in Enum.GetValues(typeof(DrCoffeeDrinksCode))) + { + Coffees.Add(code.ToString()); + } + SelectedCoffee = Coffees[0]; + foreach (DrCoffeeCommCmd code in Enum.GetValues(typeof(DrCoffeeCommCmd))) + { + CoffeeCmds.Add(code.ToString()); + } + SelectedCoffeeCmd = CoffeeCmds[0]; + + Plugin.GetInstance()?.GetPlugin()?.GetDevices().ForEach(device => + { + if (device.Name == "MorkT") DeviceId = device.DeviceId + ; + }); + + + + ThreadManage.GetInstance().StartLong(new Action(() => + { + + variableMonitors = Plugin.GetInstance()?.GetPlugin()?.GetDevices()?.FirstOrDefault(p => p.DeviceId == DeviceId)?.variableMonitors; + + if (variableMonitors != null && variableMonitors.Count > 0) + { + RobotConnected = variableMonitors.FirstOrDefault(p=>p.Notes == "机器人连接状态").CurrentValue == "True" ? "已连接" : "未连接"; + CoffeeConnected = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机连接状态").CurrentValue == "True" ? "已连接" : "未连接"; + JuicerConnected = variableMonitors.FirstOrDefault(p => p.Notes == "果汁机连接状态").CurrentValue == "True" ? "已连接" : "未连接"; + MCUConnected = variableMonitors.FirstOrDefault(p => p.Notes == "单片机连接状态").CurrentValue == "True" ? "已连接" : "未连接"; + + RobotMode = variableMonitors.FirstOrDefault(p => p.Notes == "机器人状态").CurrentValue; + + CoffeeStatus = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机状态").CurrentValue; + AppStatus = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机应用状态").CurrentValue; + Warning = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机告警").CurrentValue; + CaffeeFault = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机故障").CurrentValue; + + + } + Thread.Sleep(500); + }), "MorkT-状态刷新"); + } + } + diff --git a/BPASmartClient.MorkT.Lebai.JC/ViewModel/MonitorViewModel.cs b/BPASmartClient.MorkT.Lebai.JC/ViewModel/MonitorViewModel.cs new file mode 100644 index 00000000..2a61a967 --- /dev/null +++ b/BPASmartClient.MorkT.Lebai.JC/ViewModel/MonitorViewModel.cs @@ -0,0 +1,94 @@ +using BPASmartClient.Business; +using BPASmartClient.Helper; +using BPASmartClient.Model.乐白机器人; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Data; +using System.Windows.Media; + +namespace BPASmartClient.MorkTLebaiJC.ViewModel +{ + + public class MonitorViewModel: ObservableObject + { + #region 传感器 + /// + /// 机器人夹爪传感器 + /// + public bool RobotSenser { get { return _robotSenser; } set { _robotSenser = value; OnPropertyChanged(); } } + private bool _robotSenser; + /// + /// 冰淇淋出口传感器 + /// + public bool IceCreamSenser { get { return _iceCreamSenser; } set { _iceCreamSenser = value; OnPropertyChanged(); } } + private bool _iceCreamSenser; + /// + /// 取餐口检测传感器 + /// + public bool TakeMealSenser { get { return _takeMealSenser; } set { _takeMealSenser = value; OnPropertyChanged(); } } + private bool _takeMealSenser; + + #endregion + + + /// + /// 设备ID + /// + int DeviceId; + public MonitorViewModel() + { + Plugin.GetInstance()?.GetPlugin()?.GetDevices().ForEach(device => + { + if (device.Name == "MorkT") DeviceId = device.DeviceId; + + }); + ThreadManage.GetInstance().StartLong(new Action(() => + { + EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetTCPInputEvent() { DeviceId = DeviceId, Pin = 1 },(res)=> + { + if(res != null&& res.Length>0&& res[0] is bool b) + { + RobotSenser = b; + } + }); + + EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetInputEvent() { DeviceId = DeviceId, Pin = 0 }, (res) => + { + if (res != null && res.Length > 0 && res[0] is bool b) + { + TakeMealSenser = b; + } + }); + + EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetTCPInputEvent() { DeviceId = DeviceId, Pin = 3 }, (res) => + { + if (res != null && res.Length > 0 && res[0] is bool b) + { + IceCreamSenser = b; + } + }); + Thread.Sleep(500); + }), "MorkT-传感器监视"); + } + } + + public class BoolToColorConvert : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + return (bool) value? new SolidColorBrush(Color.FromRgb(144, 238, 144)) : new SolidColorBrush(Color.FromRgb(178, 34, 34)); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } + +} diff --git a/BPASmartClient.Morkt.JAKA.JC/View/DebugView.xaml b/BPASmartClient.Morkt.JAKA.JC/View/DebugView.xaml index a1e6ee6b..5cbc00e6 100644 --- a/BPASmartClient.Morkt.JAKA.JC/View/DebugView.xaml +++ b/BPASmartClient.Morkt.JAKA.JC/View/DebugView.xaml @@ -79,11 +79,11 @@ + - - 1 + + @@ -330,7 +332,7 @@ - DI0 + DI0 DI1 @@ -372,7 +374,7 @@ DO输出 - + DO0 DO1 DO2 @@ -384,10 +386,10 @@ - + - True + True false diff --git a/BPASmartClient.Morkt.JAKA.JC/View/DebugView.xaml.cs b/BPASmartClient.Morkt.JAKA.JC/View/DebugView.xaml.cs index 9a5f1480..aa18d11e 100644 --- a/BPASmartClient.Morkt.JAKA.JC/View/DebugView.xaml.cs +++ b/BPASmartClient.Morkt.JAKA.JC/View/DebugView.xaml.cs @@ -30,6 +30,8 @@ namespace BPASmartClient.MorkTJAKAJC.View { ThreadManage.GetInstance().StopTask("MorkT-状态刷新"); ThreadManage.GetInstance().StopTask("MorkT-传感器监视"); + } } + } diff --git a/BPASmartClient.Morkt.JAKA.JC/ViewModel/DebugViewModel.cs b/BPASmartClient.Morkt.JAKA.JC/ViewModel/DebugViewModel.cs index 9b0c3763..35951331 100644 --- a/BPASmartClient.Morkt.JAKA.JC/ViewModel/DebugViewModel.cs +++ b/BPASmartClient.Morkt.JAKA.JC/ViewModel/DebugViewModel.cs @@ -19,7 +19,6 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Threading; - namespace BPASmartClient.MorkTJAKAJC.ViewModel; public class DebugViewModel : ObservableObject { @@ -65,109 +64,104 @@ namespace BPASmartClient.MorkTJAKAJC.ViewModel; public string JuicerState { get { return _JuicerState; } set { _JuicerState = value; OnPropertyChanged(); } } private string _JuicerState { get; set; } - #endregion + #endregion #region 咖啡机 - /// - /// 咖啡机连接状态 - /// - public string CoffeeConnected { get { return _coffeeConnected; } set { _coffeeConnected = value; OnPropertyChanged(); } } - private string _coffeeConnected { get; set; } - /// - /// 咖啡机状态 - /// - public string CoffeeStatus { get { return _coffeeStatus; } set { _coffeeStatus = value; OnPropertyChanged(); } } - private string _coffeeStatus { get; set; } - /// - /// 应用状态 - /// - public string AppStatus { get { return _appStatus; } set { _appStatus = value; OnPropertyChanged(); } } - private string _appStatus { get; set; } - /// - /// 告警 - /// - public string Warning { get { return _warning; } set { _warning = value; OnPropertyChanged(); } } - public string _warning { get; set; } - /// - /// 故障信息 - /// - public string CaffeeFault { get { return _caffeeFault; } set { _caffeeFault = value; OnPropertyChanged(); } } - public string _caffeeFault { get; set; } - - public List Coffees { get; set; } = new List(); - public string SelectedCoffee { get; set; } - - public List CoffeeCmds { get; set; } = new List(); - public string SelectedCoffeeCmd { get; set; } - /// - /// 制作咖啡 - /// - public RelayCommand Button_MakeCoffeeCommand { get; set; } - /// - /// 停止制作咖啡 - /// - public RelayCommand Button_StopMakeCoffeCommand { get; set; } - /// - /// 咖啡模式设置 + /// + /// 咖啡机连接状态 /// - public RelayCommand Button_CoffeeModeSetCommand { get; set; } - - private void Button_MakeCoffee() - { - EventBus.EventBus.GetInstance().Publish(new DRCoffee_MakeCoffeeEvent() { DeviceId = DeviceId, DrinkCode = (DrCoffeeDrinksCode)Enum.Parse(typeof(DrCoffeeDrinksCode), SelectedCoffee)}); - } - private void Button_StopMakeCoffe() - { - EventBus.EventBus.GetInstance().Publish(new DRCoffee_CancelMakeCoffeeEvent() { DeviceId = DeviceId }); - } - private void Button_CoffeeModeSet() - { - EventBus.EventBus.GetInstance().Publish(new DRCoffee_CoffeeCommCmdEvent() { DeviceId = DeviceId, CommCmd = (DrCoffeeCommCmd)Enum.Parse(typeof(DrCoffeeCommCmd), SelectedCoffeeCmd)}); - } - #endregion - - #region 单片机 + public string CoffeeConnected { get { return _coffeeConnected; } set { _coffeeConnected = value; OnPropertyChanged(); } } + private string _coffeeConnected { get; set; } + /// + /// 咖啡机状态 + /// + public string CoffeeStatus { get { return _coffeeStatus; } set { _coffeeStatus = value; OnPropertyChanged(); } } + private string _coffeeStatus { get; set; } + /// + /// 应用状态 + /// + public string AppStatus { get { return _appStatus; } set { _appStatus = value; OnPropertyChanged(); } } + private string _appStatus { get; set; } /// - /// 咖啡杯或冰淇淋杯落杯 + /// 告警 /// - public RelayCommand Button_CupControlCommand { get; set; } + public string Warning { get { return _warning; } set { _warning = value; OnPropertyChanged(); } } + public string _warning { get; set; } /// - /// 单片机冰淇淋机器制冷 + /// 故障信息 /// - public RelayCommand Button_SCChipRefrigerationCommand { get; set; } + public string CaffeeFault { get { return _caffeeFault; } set { _caffeeFault = value; OnPropertyChanged(); } } + public string _caffeeFault { get; set; } + + public List Coffees { get; set; } = new List(); + public string SelectedCoffee { get; set; } + + public List CoffeeCmds { get; set; } = new List(); + public string SelectedCoffeeCmd { get; set; } /// - /// 单片机冰淇淋机器打料 + /// 制作咖啡 /// - public RelayCommand Button_SCChipDischargeCommand { get; set; } + public RelayCommand Button_MakeCoffeeCommand { get; set; } /// - /// 模拟测试 + /// 停止制作咖啡 /// - public RelayCommand Button_SCChipTestCommand { get; set; } + public RelayCommand Button_StopMakeCoffeCommand { get; set; } + /// + /// 咖啡模式设置 + /// + public RelayCommand Button_CoffeeModeSetCommand { get; set; } - private void Button_CupControl(object CupType) + private void Button_MakeCoffee() { - EventBus.EventBus.GetInstance().Publish(new SCChip_TakeCupEvent() { DeviceId = DeviceId, Cup = (IC_CUP)Enum.Parse(typeof(IC_CUP), CupType.ToString()) }); + EventBus.EventBus.GetInstance().Publish(new DRCoffee_MakeCoffeeEvent() { DeviceId = DeviceId, DrinkCode = (DrCoffeeDrinksCode)Enum.Parse(typeof(DrCoffeeDrinksCode), SelectedCoffee)}); } - - private void Button_SCChipRefrigeration() + private void Button_StopMakeCoffe() { - EventBus.EventBus.GetInstance().Publish(new SCChip_RotorSwitchEvent { DeviceId = DeviceId, TurnOn = true }); - Thread.Sleep(500); - EventBus.EventBus.GetInstance().Publish(new SCChip_RotorSwitchEvent { DeviceId = DeviceId, TurnOn = false }); - + EventBus.EventBus.GetInstance().Publish(new DRCoffee_CancelMakeCoffeeEvent() { DeviceId = DeviceId }); } - - private void Button_SCChipDischarge() + private void Button_CoffeeModeSet() { - EventBus.EventBus.GetInstance().Publish(new SCChip_MakeIceCreamEvent { DeviceId = DeviceId, SteeringEngine = IC_SE.SE_2 }); + EventBus.EventBus.GetInstance().Publish(new DRCoffee_CoffeeCommCmdEvent() { DeviceId = DeviceId, CommCmd = (DrCoffeeCommCmd)Enum.Parse(typeof(DrCoffeeCommCmd), SelectedCoffeeCmd)}); } - #endregion - /// - /// 设备ID - /// - public int DeviceId { get; set; } + #region 单片机 + public string MCUConnected { get { return _mcuConnected; } set { _mcuConnected = value; OnPropertyChanged(); } } + private string _mcuConnected { get; set; } + + public RelayCommand Button_MCUOuputCommand { get; set; } + public RelayCommand Button_MCUDOuputCommand { get; set; } + public int PWMInputNumber { get { return _pwmInputNumber; } set { _pwmInputNumber = value; OnPropertyChanged(); } } + private int _pwmInputNumber = 1; + + public int MCU_PWM_CH { get { return _choosePWM; } set { _choosePWM = value; OnPropertyChanged(); } } + private int _choosePWM = 1; + + public int MCU_DO_CH { get { return _mcuDO_CH; } set { _mcuDO_CH = value; OnPropertyChanged(); } } + private int _mcuDO_CH = 1; + + private int[] DICH { get { return _diCH; } set { _diCH = value; OnPropertyChanged(); } } + private int[] _diCH = new int[8]; + + 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() + { + string sChoosePWM =Convert.ToString(MCU_PWM_CH+1); + new WriteMcu() { TagName = "ServoControl", Address = sChoosePWM, Value = PWMInputNumber }.Publish(); + } + private void Button_McuDOutput() + { + string sChooseDO = Convert.ToString(MCU_DO_CH + 1); + new WriteMcu() { TagName = "OutputControl", Address = sChooseDO, Value = MCU_DO_Value }.Publish(); + } + #endregion + + /// + /// 设备ID + /// + public int DeviceId { get; set; } /// /// 设备数据 /// @@ -180,15 +174,8 @@ namespace BPASmartClient.MorkTJAKAJC.ViewModel; Button_StopMakeCoffeCommand = new RelayCommand(Button_StopMakeCoffe); Button_CoffeeModeSetCommand = new RelayCommand(Button_CoffeeModeSet); - Button_CupControlCommand = new RelayCommand(Button_CupControl); - Button_SCChipRefrigerationCommand = new RelayCommand(Button_SCChipRefrigeration); - Button_SCChipDischargeCommand = new RelayCommand(Button_SCChipDischarge); - Button_SCChipTestCommand = new RelayCommand(() => - { - Button_SCChipRefrigeration(); - Thread.Sleep(50); - Button_SCChipDischarge(); - }); + Button_MCUOuputCommand = new RelayCommand(Button_McuOutput); + Button_MCUDOuputCommand = new RelayCommand(Button_McuDOutput); foreach (DrCoffeeDrinksCode code in Enum.GetValues(typeof(DrCoffeeDrinksCode))) { @@ -216,9 +203,10 @@ namespace BPASmartClient.MorkTJAKAJC.ViewModel; if (variableMonitors != null && variableMonitors.Count > 0) { - RobotConnected = variableMonitors.FirstOrDefault(p=>p.Notes == "机器人连接状态").CurrentValue == "True" ? "已连接" : "未连接"; + RobotConnected = variableMonitors.FirstOrDefault(p=>p.Notes == "机器人连接状态").CurrentValue == "True" ? "已连接" : "未连接"; CoffeeConnected = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机连接状态").CurrentValue == "True" ? "已连接" : "未连接"; JuicerConnected = variableMonitors.FirstOrDefault(p => p.Notes == "果汁机连接状态").CurrentValue == "True" ? "已连接" : "未连接"; + MCUConnected = variableMonitors.FirstOrDefault(p => p.Notes == "单片机连接状态").CurrentValue == "True" ? "已连接" : "未连接"; RobotMode = variableMonitors.FirstOrDefault(p => p.Notes == "机器人状态").CurrentValue; @@ -229,7 +217,6 @@ namespace BPASmartClient.MorkTJAKAJC.ViewModel; } - Thread.Sleep(500); }), "MorkT-状态刷新"); }