using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Threading; using System.Collections.Concurrent; using System.Diagnostics; using System.Threading.Tasks; using BPASmartClient.Device; using BPA.Message.Enum; using BPA.Message; using BPA.Helper; using BPASmartClient.Model.咖啡机.Enum; using BPASmartClient.Model; using BPASmartClient.Model.乐白机器人; using BPASmartClient.Model.单片机; using BPASmartClient.Model.PLC; using BPASmartClient.DRCoffee; using BPASmartClient.LebaiRobot; using BPASmartClient.RobotGripper; using BPASmartClient.Model.电夹爪; using BPASmartClient.Model.奶茶味魔方; using static BPA.Helper.EventBus; namespace BPASmartClient.MorkT_BarCounter { /* * 冰淇淋咖啡机组合套装 * 物料位置: * 1:冰淇料 * 2:冰淇淋杯 * 5:咖啡 * 6:咖啡杯 * 9: 茶 * 10: 茶杯 */ public class Control_MorkT_BarCounter : BaseDevice { private Dictionary batchings = new Dictionary(); //容器位置 private string holderLoc; //主料位置 private string mainMaterialLoc; public override global::BPA.Message.Enum.DeviceClientType DeviceType { get { return BPA.Message.Enum.DeviceClientType.MORKT; } } GVL_MorkT morkT = new GVL_MorkT(); /// /// 果汁机做法,true:热饮,false:冷饮 /// private bool GuMake = false; /// /// 订单是否加冰 /// private bool IsAddIce = false; public override void DoMain() { if (Json.Data.IsVerify) { IsHealth = true; } Json.Read(); GVL_MorkT.MilkTeaCHValue = Json.Data.parData; IsHealth = true; serverInit(); DataParse(); ActionManage.GetInstance.Register(new Action((o) => { SimOrder(o); }), "SimOrder");//模拟订单委托注册 } private void serverInit() { EventBus.GetInstance.Subscribe(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack) { if (@event == null) return; if (@event is MaterialDeliveryEvent material) { orderMaterialDelivery = material.orderMaterialDelivery; } }); } private void DataParse() { 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) { var res = 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) { case GOODS_TYPE.COFFEE: if (morkT.morkOrderPushesCoffee.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null) { morkT.morkOrderPushesCoffee.Enqueue(new OrderLocInfo() { SuborderId = order.MorkOrder.SuborderId, BatchingId = res.BatchingId, Loc = ushort.Parse(mainMaterialLoc), GoodName = order.MorkOrder.GoodsName, }); morkT.morkOrderPushesAll.Enqueue(new OrderLocInfo() { SuborderId = order.MorkOrder.SuborderId, BatchingId = res.BatchingId, Loc = ushort.Parse(mainMaterialLoc), GoodName = order.MorkOrder.GoodsName, }); } break; //case GOODS_TYPE.JUICE: // 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, // makeID = order.MorkOrder.MakeID, // }); // } // break; case GOODS_TYPE.MilkTea: if (morkT.morkOrderPushesMilkTea.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null) { morkT.morkOrderPushesMilkTea.Enqueue(new OrderLocInfo() { SuborderId = order.MorkOrder.SuborderId, BatchingId = res.BatchingId, Loc = ushort.Parse(mainMaterialLoc), GoodName = order.MorkOrder.GoodsName, }); morkT.morkOrderPushesAll.Enqueue(new OrderLocInfo() { 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; } } } } }); } /// /// 将空杯放好到接饮料的地方的标志位 /// private bool bFirstTrig_MilkTea = false; private bool bFirstTrig_Coffee = false; /// /// 延迟的超时时间 /// DateTime delayTimeOut_Coffee; DateTime delayTimeOut_MilkTea; public override void MainTask() { EventBus.GetInstance.Subscribe(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack) { if (morkT.IsHaveCoffeeCup && morkT.MakeCoffeeEnd != true) morkT.MakeCoffeeEnd = true; bFirstTrig_Coffee = false; }); if (morkT.IsHaveCoffeeCup && morkT.MakeCoffeeEnd != true) { if (!bFirstTrig_Coffee) { bFirstTrig_Coffee = true; delayTimeOut_Coffee = DateTime.Now; } else if (DateTime.Now.Subtract(delayTimeOut_Coffee).TotalSeconds > 180 && bFirstTrig_Coffee == true) { DeviceProcessLogShow("接咖啡超时,接咖啡结束,等待取咖啡"); bFirstTrig_Coffee = false; if (morkT.IsHaveCoffeeCup) morkT.MakeCoffeeEnd = true; } } if (morkT.IsHaveTeaMilkTeaCup && morkT.MakeMilkTeaEnd != true) { if (!bFirstTrig_MilkTea) { bFirstTrig_MilkTea = true; delayTimeOut_MilkTea = DateTime.Now;//开启接水信号后,记录当前时间 } else if (DateTime.Now.Subtract(delayTimeOut_MilkTea).TotalSeconds >= 180 && bFirstTrig_MilkTea == true)//接水超过50s后,启动接水完成标志,开启接水程序 { DeviceProcessLogShow("接茶或水延迟时间结束"); morkT.MakeMilkTeaEnd = true; } if (GetStatus("Get_MilkTeaCubeStatus") == true) { while (GetStatus("Get_MilkTeaCubeDosingStatus") == true) { if (morkT.IsHaveTeaMilkTeaCup && morkT.MakeMilkTeaEnd != true) { morkT.MakeMilkTeaEnd = true; bFirstTrig_MilkTea = false; new MilkTea_MakeMilkTeaEvent() { DeviceId = DeviceId, TagName = "StartSignReset" }.Publish(); } } } } DoCoffee(); DoMilkTea(); } /// /// 订单状态改变 /// /// /// private void OrderChange(string subid, ORDER_STATUS oRDER_STATUS) { EventBus.GetInstance.Publish(new OrderStatusChangedEvent() { Status = oRDER_STATUS, SubOrderId = subid, deviceClientType = DeviceType }); } /// /// 验证商品是做的某种饮料 /// /// 物料位置 private GOODS_TYPE ValidateGoodsByBatching(string batchingLoc) { if (batchings.ContainsKey(batchingLoc)) return batchings[batchingLoc].GoodsType; return GOODS_TYPE.NEITHER; } /// /// 乐白的场景 /// /// private void Sence(int sen) { new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = sen }.Publish(); } /// /// 乐白的数字量输出 /// /// /// private void Output(bool value, int pin) { new LebaiRobot_SetOutPutEvent { DeviceId = DeviceId, Pin = pin, Value = value }.Publish(); } private T GetStatus(string key) { if (peripheralStatus.ContainsKey(key)) { if (peripheralStatus[key] != null) { return (T)(peripheralStatus[key]); } } return default; } int[] devStatusBy = new int[2] { 0, 0 }; /// /// 传感器的输入信号 0:无意义 1:有信号 2:无信号 3:信号不正确 /// int bSensorInput; /// /// 判断是否有咖啡订单 /// /// private bool IsMakeCoffee() { bool bMake = (IsHealth && morkT.morkOrderPushesCoffee.Count > 0 && !morkT.IsHaveCoffeeCup && morkT.morkOrderPushesAll.ElementAt(0).SuborderId == morkT.morkOrderPushesCoffee.ElementAt(0).SuborderId) ? true : false; return bMake; } /// /// 判断是否有果汁订单 /// /// private bool IsMakeJuice() { bool bMake = (IsHealth && morkT.morkOrderPushesJuicer.Count > 0 && !morkT.IsHaveJuiceCup && morkT.morkOrderPushesAll.ElementAt(0).SuborderId == morkT.morkOrderPushesCoffee.ElementAt(0).SuborderId) ? true : false; return bMake; } /// /// 判断是否有茶订单 /// /// private bool IsMakeMilkTea() { bool bMake = (IsHealth && morkT.morkOrderPushesMilkTea.Count > 0 && !morkT.IsHaveTeaMilkTeaCup && morkT.morkOrderPushesAll.ElementAt(0).SuborderId == morkT.morkOrderPushesMilkTea.ElementAt(0).SuborderId) ? true : false; return bMake; } /// /// 判断是否有开水订单 /// /// private bool IsMakeWater() { bool bMake = (IsHealth && morkT.morkOrderPushesWater.Count > 0 && !morkT.IsHaveTeaMilkTeaCup) ? true : false; return bMake; } /// /// 做咖啡流程 /// private void DoCoffee() { if (IsMakeCoffee()) { Discharge_Control(Kind.咖啡);//接咖啡 morkT.IsHaveCoffeeCup = true; } else if (morkT.MakeCoffeeEnd) { try { PutCup(Kind.咖啡); DeviceProcessLogShow("-------------咖啡制作完成------------"); morkT.MakeCoffeeEnd = false; morkT.IsHaveCoffeeCup = false; morkT.morkOrderPushesCoffee.TryDequeue(out OrderLocInfo orderLoc); morkT.morkOrderPushesAll.TryDequeue(out OrderLocInfo orderLoc1); } catch (Exception ex) { MessageLog.GetInstance.ShowEx(ex.ToString()); } } } private void DoMilkTea() { if (IsMakeMilkTea()) { Discharge_Control(Kind.奶茶);//接咖啡 morkT.IsHaveTeaMilkTeaCup = true; } else if (morkT.MakeMilkTeaEnd && morkT.morkOrderPushesMilkTea.Count > 0) { try { PutCup(Kind.奶茶); DeviceProcessLogShow("-------------奶茶制作完成------------"); morkT.IsHaveTeaMilkTeaCup = false; morkT.MakeMilkTeaEnd = false; morkT.morkOrderPushesMilkTea.TryDequeue(out OrderLocInfo orderLoc); morkT.morkOrderPushesAll.TryDequeue(out OrderLocInfo orderLoc1); } catch (Exception ex) { MessageLog.GetInstance.ShowEx(ex.ToString()); } } } #region 做咖啡流程 /// /// 出料控制 /// private void Discharge_Control(Kind kind) { if (!morkT.IsHaveCoffeeCup) { if (kind == Kind.咖啡) { OrderChange(morkT.morkOrderPushesCoffee.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING); } else { OrderChange(morkT.morkOrderPushesMilkTea.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING); } int resultTakeCup = takeCup(); if (resultTakeCup == 1) { if (kind == Kind.咖啡) { new WriteJaka() { DeviceId = DeviceId, TagName = "JaKaProgramName", Value = JakaModel.SENCE_取杯位_接咖啡位 }.Publish(); JakaWait(int.Parse(JakaModel.SENCE_取杯位_接咖啡位)); new DRCoffee_MakeCoffeeEvent() { DeviceId = DeviceId, DrinkCode = (DrCoffeeDrinksCode)(morkT.morkOrderPushesCoffee.ElementAt(0).Loc) }.Publish(); //控制咖啡出料 //new WriteGripper() { TagName = "PWMControl", CH_Number = "0", PWMOutput = "500" }.Publish();//夹爪的幅度控制 //new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接咖啡_初始位 }.Publish(); //Wait(int.Parse(JakaModel.SENCE_接咖啡_初始位)); //DeviceProcessLogShow("接咖啡杯动作完成"); } else { new WriteJaka() { DeviceId = DeviceId, TagName = "JaKaProgramName", Value = JakaModel.SENCE_取杯位_接奶茶位 }.Publish(); JakaWait(int.Parse(JakaModel.SENCE_取杯位_接奶茶位)); while (GetStatus("Get_MilkTeaCubeStatus") == false) { new MilkTea_MakeMilkTeaEvent() { DeviceId = DeviceId, TagName = "ParameterSet", MilkTeaKind = GVL_MorkT.MilkTeaCHValue }.Publish(); //写入奶茶参数 new MilkTea_MakeMilkTeaEvent() { DeviceId = DeviceId, TagName = "Start" }.Publish(); break; } //new WriteGripper() { TagName = "PWMControl", CH_Number = "0", PWMOutput = "500" }.Publish();//夹爪的幅度控制 //new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接奶茶_初始位 }.Publish(); //Wait(int.Parse(JakaModel.SENCE_接奶茶_初始位)); //DeviceProcessLogShow("接奶茶杯动作完成"); } } else { DeviceProcessLogShow("取杯失败 回到初始位,请及时处理!!"); new WriteJaka() { DeviceId = DeviceId, TagName = "JaKaProgramName", Value = JakaModel.SENCE_异常回初始位 }.Publish(); JakaWait(int.Parse(JakaModel.SENCE_异常回初始位)); } } } public bool outCupCheck; private void PutCup(Kind res) { //new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish(); //Wait(int.Parse(JakaModel.SENCE_初始位)); //new WriteGripper() { TagName = "PWMControl", CH_Number = "0", PWMOutput = "500" }.Publish();//夹爪的幅度控制 //new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish(); //Wait(int.Parse(JakaModel.SENCE_初始位_放杯位检测)); //while (GetStatus("Get_JakaRobotDI0"))//判断放杯位置是否有物品 //{ // if (!outCupCheck) // DeviceProcessLogShow("成品处有纸杯存在,请取走!!"); // outCupCheck = true; //} //outCupCheck = false; if (res == Kind.咖啡) { //new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放杯位检测_接咖啡 }.Publish(); //Wait(int.Parse(JakaModel.SENCE_放杯位检测_接咖啡)); //new WriteGripper() { TagName = "PWMControl", CH_Number = "0", PWMOutput = "1300" }.Publish();//夹爪的幅度控制 //new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放杯位检测_接咖啡 }.Publish(); //Wait(int.Parse(JakaModel.SENCE_接咖啡_放杯位)); //new WriteGripper() { TagName = "PWMControl", CH_Number = "0", PWMOutput = "500" }.Publish();//夹爪的幅度控制 new WriteJaka() { DeviceId = DeviceId, TagName = "JaKaProgramName", Value = JakaModel.SENCE_接咖啡位_放咖啡位 }.Publish(); JakaWait(int.Parse(JakaModel.SENCE_接咖啡位_放咖啡位)); //new WriteGripper() { DeviceId = DeviceId, TagName = "PWMControl", CH_Number = "0", PWMOutput = "0500" }.Publish();//夹爪的幅度控制 //new WriteJaka() { DeviceId = DeviceId, TagName = "JakaDOutput", Value = true, DO_Index = 1 }.Publish(); } else { //new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放杯位检测_接咖啡 }.Publish(); //Wait(int.Parse(JakaModel.SENCE_放杯位检测_接奶茶)); //new WriteGripper() { TagName = "PWMControl", CH_Number = "0", PWMOutput = "1300" }.Publish();//夹爪的幅度控制 //new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放杯位检测_接咖啡 }.Publish(); //Wait(int.Parse(JakaModel.SENCE_接奶茶_放杯位)); //new WriteGripper() { TagName = "PWMControl", CH_Number = "0", PWMOutput = "500" }.Publish();//夹爪的幅度控制 new WriteJaka() { DeviceId = DeviceId, TagName = "JaKaProgramName", Value = JakaModel.SENCE_等奶茶_接奶茶位 }.Publish(); JakaWait(int.Parse(JakaModel.SENCE_等奶茶_接奶茶位)); new WriteJaka() { DeviceId = DeviceId, TagName = "JaKaProgramName", Value = JakaModel.SENCE_接奶茶位_放奶茶位 }.Publish(); JakaWait(int.Parse(JakaModel.SENCE_接奶茶位_放奶茶位)); //new WriteGripper() { DeviceId = DeviceId, TagName = "PWMControl", CH_Number = "0", PWMOutput = "500" }.Publish();//夹爪的幅度控制 //new WriteJaka() { DeviceId = DeviceId, TagName = "JakaDOutput", Value = true, DO_Index = 1 }.Publish(); } new WriteJaka() { DeviceId = DeviceId, TagName = "JaKaProgramName", Value = JakaModel.SENCE_放杯位_初始位 }.Publish(); JakaWait(int.Parse(JakaModel.SENCE_放杯位_初始位)); if (GetStatus("Get_JakaRobotDI5")) { DeviceProcessLogShow("放杯完成,杯子感应器但仍有信号"); } if (res == Kind.咖啡) { OrderChange(morkT.morkOrderPushesCoffee.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE); DeviceProcessLogShow($"-------------{morkT.morkOrderPushesCoffee.ElementAt(0).GoodName}制作完成------------"); } else { OrderChange(morkT.morkOrderPushesMilkTea.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE); DeviceProcessLogShow($"-------------{morkT.morkOrderPushesMilkTea.ElementAt(0).GoodName}制作完成------------"); } } #endregion /// /// 取杯的次数 /// private int nCnt; /// /// 取杯流程 /// /// 0:无意义,1:取杯成功 2:取杯失败 private int takeCup() { try { // new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish(); // Wait(int.Parse(JakaModel.SENCE_初始位)); // new WriteGripper() { TagName = "PWMControl", CH_Number = "0", PWMOutput = "500" }.Publish();//夹爪的幅度控制 //p: new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_落杯 }.Publish(); // Wait(int.Parse(JakaModel.SENCE_落杯)); // new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_取杯位检测_取杯位 }.Publish(); // Wait(int.Parse(JakaModel.SENCE_初始位_取杯位检测)); // if (!GetStatus("Get_JakaRobotDI0")) // goto p; // new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_取杯位检测_取杯位 }.Publish(); // Wait(int.Parse(JakaModel.SENCE_取杯位检测_取杯位)); // new WriteGripper() { TagName = "PWMControl", CH_Number = "0", PWMOutput = "1300" }.Publish();//夹爪的幅度控制 // Thread.Sleep(2000); // while (!GetStatus("Get_JakaRobotDI0")) //读取传感器的值 // { // new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_异常回初始位 }.Publish(); // Wait(int.Parse(JakaModel.SENCE_异常回初始位)); // return 2; // } bool test1 = false; if (test1) { #region 第一种取杯方式 new WriteJaka() { DeviceId = DeviceId, TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish(); JakaWait(int.Parse(JakaModel.SENCE_初始位)); new WriteGripper() { DeviceId = DeviceId, TagName = "PWMControl", CH_Number = "0", PWMOutput = "1350" }.Publish();//夹爪的幅度控制 new WriteJaka() { DeviceId = DeviceId, TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位_取杯位 }.Publish(); JakaWait(int.Parse(JakaModel.SENCE_初始位_取杯位)); int cnt = 0; new WriteGripper() { DeviceId = DeviceId, TagName = "PWMControl", CH_Number = "0", PWMOutput = "1350" }.Publish();//夹爪的幅度控制 p: new WriteJaka() { DeviceId = DeviceId, TagName = "JaKaProgramName", Value = JakaModel.SENCE_落杯 }.Publish(); JakaWait(int.Parse(JakaModel.SENCE_落杯)); cnt = cnt + 1; if (!GetStatus("Get_JakaRobotDI6")) { if (cnt < 3) goto p; else { return 2; } } return 1; #endregion } else { #region 第二种取杯方式 new WriteJaka() { DeviceId = DeviceId, TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish(); JakaWait(int.Parse(JakaModel.SENCE_初始位)); //new WriteJaka() { DeviceId = DeviceId, TagName = "JakaDOutput", Value = false, DO_Index = 1 }.Publish(); //new WriteGripper() { DeviceId = DeviceId, TagName = "PWMControl", CH_Number = "0", PWMOutput = "1350" }.Publish();//夹爪的幅度控制 new WriteJaka() { DeviceId = DeviceId, TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位_取杯位 }.Publish(); JakaWait(int.Parse(JakaModel.SENCE_初始位_取杯位)); int cnt = 0; p: new WriteJaka() { DeviceId = DeviceId, TagName = "JaKaProgramName", Value = JakaModel.SENCE_落杯 }.Publish(); JakaWait(int.Parse(JakaModel.SENCE_落杯)); cnt = cnt + 1; if (!GetStatus("Get_JakaRobotDI5")) { if (cnt < 3) goto p; else { return 2; } } Thread.Sleep(2000); new WriteJaka() { DeviceId = DeviceId, TagName = "JaKaProgramName", Value = JakaModel.SENCE_取杯位_取杯放杯检测位 }.Publish(); JakaWait(int.Parse(JakaModel.SENCE_取杯位_取杯放杯检测位)); //new WriteJaka() { DeviceId = DeviceId, TagName = "JakaDOutput", Value = true, DO_Index = 1 }.Publish(); //Thread.Sleep(2000); //new WriteJaka() { DeviceId = DeviceId, TagName = "JakaDOutput", Value = false, DO_Index = 1 }.Publish(); //new WriteGripper() { DeviceId = DeviceId, TagName = "PWMControl", CH_Number = "0", PWMOutput = "1200" }.Publish();//夹爪的幅度控制 //Thread.Sleep(2000); //new WriteGripper() { DeviceId = DeviceId, TagName = "PWMControl", CH_Number = "0", PWMOutput = "1350" }.Publish();//夹爪的幅度控制 new WriteJaka() { DeviceId = DeviceId, TagName = "JaKaProgramName", Value = JakaModel.SENCE_取杯放杯检测位_取杯位 }.Publish(); JakaWait(int.Parse(JakaModel.SENCE_取杯放杯检测位_取杯位)); return 1; #endregion } } catch (Exception ex) { DeviceProcessLogShow(ex.ToString()); } return 2; } public void SimOrder(T simOrder) { } private void JakaWait(int value) { while (!((GetStatus("Get_JakaRobotAO1") == value) && GetStatus("Get_JakaRobotProgramStatus") == 0))//判断文件是否已经执行结束 且 文件末端变量值==文件名 { int a = GetStatus("Get_JakaRobotAO1"); int b = GetStatus("Get_JakaRobotProgramStatus"); Thread.Sleep(5); } } #region PLC 控制函数 private void WritePLCData(string address, object value) { EventBus.GetInstance.Publish(new WriteModel() { DeviceId = DeviceId, Address = address, Value = value }); } private void GetStatus(string key, Action action) { if (peripheralStatus.ContainsKey(key)) { if (peripheralStatus[key] != null) { action?.Invoke(peripheralStatus[key]); } } } public override void ReadData() { #region 乐白机器人状态 GetStatus("RobotIsConnected", new Action((o) => { if (o is bool b) { morkT.RobotIsConnected = b; } })); GetStatus("RobotMode", new Action((o) => { if (o is ELebaiRModel eLebaiRModel) { morkT.RobotMode = eLebaiRModel; } })); GetStatus("LeibaiGetTcpInput", new Action((o) => { if (o is bool b) { morkT.RobotGetTcpInput = b; } })); GetStatus("LeibaiGetInput1", new Action((o) => { if (o is bool b) { morkT.RobotGetInput0 = b; } })); GetStatus("LeibaiGetInput2", new Action((o) => { if (o is bool b) { morkT.RobotGetInput1 = b; } })); GetStatus("LeibaiGetInput3", new Action((o) => { if (o is bool b) { morkT.RobotGetInput2 = b; } })); GetStatus("LeibaiGetInput4", new Action((o) => { if (o is bool b) { morkT.RobotGetInput3 = b; } })); #endregion #region 制冰机状态 GetStatus("MakeIceConnected", new Action((o) => { if (o is bool bt) { morkT.IceMakerConnect = bt; } })); GetStatus("MakeIceDeviceStatus", new Action((o) => { if (o is byte bt) { morkT.IceMakerState = bt; } })); #endregion #region 咖啡机状态 GetStatus("CoffeeIsConnected", new Action((o) => { if (o is bool b) { morkT.CoffeeIsConnected = b; } })); GetStatus("CoffeeStatus", new Action((o) => { if (o is DrCoffeeStatus coffeeStatus) { morkT.DrCoffeeStatus = coffeeStatus; } })); GetStatus("CoffeeAppStatus", new Action((o) => { if (o is DrCoffeeAppStatus appStatus) { morkT.CoffeeAppStatus = appStatus; } })); GetStatus("CoffeeWarning", new Action((o) => { if (o is DrCoffeeWarning coffeeWarning) { morkT.CoffeeWarning = coffeeWarning; } })); GetStatus("CoffeeFault", new Action((o) => { if (o is DrCoffeeFault coffeeFault) { morkT.CaffeeFault = coffeeFault; } })); #endregion #region 单片机状态 EventBus.GetInstance.Publish(new ReadMcu() { DeviceId = DeviceId, ReadPar = 0, TagName = "SCChipGetInput0" }); EventBus.GetInstance.Publish(new ReadMcu() { DeviceId = DeviceId, ReadPar = 0, TagName = "SCChipGetInput1" }); EventBus.GetInstance.Publish(new ReadMcu() { DeviceId = DeviceId, ReadPar = 0, TagName = "SCChipGetInput2" }); EventBus.GetInstance.Publish(new ReadMcu() { DeviceId = DeviceId, ReadPar = 0, TagName = "SCChipGetInput3" }); EventBus.GetInstance.Publish(new ReadMcu() { DeviceId = DeviceId, ReadPar = 0, TagName = "SCChipGetInput4" }); EventBus.GetInstance.Publish(new ReadMcu() { DeviceId = DeviceId, ReadPar = 0, TagName = "SCChipGetInput5" }); EventBus.GetInstance.Publish(new ReadMcu() { DeviceId = DeviceId, ReadPar = 0, TagName = "SCChipGetInput6" }); EventBus.GetInstance.Publish(new ReadMcu() { DeviceId = DeviceId, ReadPar = 0, TagName = "SCChipGetInput7" }); GetStatus("SCChipIsConnect", new Action((o) => { if (o is bool b) { morkT.SCChipIsConnect = b; } })); GetStatus("SCChipGetInput0", new Action((o) => { if (o is bool b) { morkT.SCChipInput0 = b; } })); GetStatus("SCChipGetInput1", new Action((o) => { if (o is bool b) { morkT.SCChipInput1 = b; } })); GetStatus("SCChipGetInput2", new Action((o) => { if (o is bool b) { morkT.SCChipInput2 = b; } })); GetStatus("SCChipGetInput3", new Action((o) => { if (o is bool b) { morkT.SCChipInput3 = b; } })); GetStatus("SCChipGetInput4", new Action((o) => { if (o is bool b) { morkT.SCChipInput4 = b; } })); GetStatus("SCChipGetInput5", new Action((o) => { if (o is bool b) { morkT.SCChipInput5 = b; } })); GetStatus("SCChipGetInput6", new Action((o) => { if (o is bool b) { morkT.SCChipInput6 = b; } })); GetStatus("SCChipGetInput7", new Action((o) => { if (o is bool b) { morkT.SCChipInput7 = b; } })); #endregion #region 果汁机 GetStatus("GetJuicerConnected", new Action((o) => { if (o is bool b) { morkT.JuicerConnected = b; } })); GetStatus("GetJuicerDeviceStatus", new Action((o) => { if (o is int[] b) { morkT.JuicerState = b; } })); #endregion } #endregion public override void Stop() { } public override void ResetProgram() { } public override void SimOrder() { EventBus.GetInstance.Subscribe(0, delegate (IEvent @event, EventCallBackHandle callBackHandle) { string guid = Guid.NewGuid().ToString(); if (@event != null && @event is MorkTSimOrder msm) { DeviceProcessLogShow("----开始模拟订单----"); if (msm.OrderNum == 1) { morkT.morkOrderPushesCoffee.Enqueue(new OrderLocInfo() { Loc = (ushort)msm.DrinkCode, SuborderId = guid, GoodName = "模拟咖啡订单" }); } else if (msm.OrderNum == 2) { morkT.morkOrderPushesJuicer.Enqueue(new OrderLocInfo() { Loc = (ushort)(msm.JuiceList + 51), makeID = msm.JuiceMakeID, SuborderId = guid, GoodName = "模拟果汁订单" }); } else if (msm.OrderNum == 3) { morkT.morkOrderPushesMilkTea.Enqueue(new OrderLocInfo() { SuborderId = guid, GoodName = "模拟茶水订单" }); } else if (msm.OrderNum == 4) { morkT.morkOrderPushesWater.Enqueue(new OrderLocInfo() { SuborderId = guid, GoodName = "模拟开水订单" }); } } }); } } }