using BPA.Message; using BPA.Message.Enum; using BPASmartClient.Device; using BPASmartClient.EventBus; using BPASmartClient.Helper; using BPASmartClient.Message; using BPASmartClient.Model; using BPASmartClient.Model.PLC; using BPA.Models; using static BPASmartClient.EventBus.EventBus; using BPASmartClient.Model.小炒机; using BPASmartClient.MorkF.Model; using System.Text; using System.Collections.Concurrent; namespace BPASmartClient.MorkF { public class Control_MorkF : BaseDevice { /// /// while循环最大sleep次数 /// private const int sleepCount = 20; /// /// while循环每次sleep时间 /// private const int sleepTime = 500; /// /// 初始化炒锅数量 /// private int count = 2; //当前炒锅,默认为1号炒锅 private int fryIndex = 0; public override DeviceClientType DeviceType => DeviceClientType.MORKCS; public AutoResetEvent minorReset = new AutoResetEvent(false); public AutoResetEvent mainReset = new AutoResetEvent(false); Dictionary morkFs = new Dictionary();//全局对象声明 /// /// 小炒菜单集合 /// public static List LocalstirFryGoods = new List(); /// /// 待炒小炒队列 /// private ConcurrentQueue StirFryGoodsQuenes = new ConcurrentQueue(); private const String striConst = "炒锅{0}炒制{1}线程"; /// /// 当前炒制菜品 /// private OrderLocInfo nowStirFryGood = null; List resultorder = new List();//调试变量 /// /// 入口 /// public override void DoMain() { WriteControl("VD836", 0); WriteControl("VD840", 0); Thread.Sleep(400); WriteControl("M0.0", true); for (int i = 0;i< count;i++) { morkFs.Add(i, new GVL_MorkF()); DataParse(i);//数据解析 } CommandRegist();//调试 ServerInit(); DeviceProcessLogShow("MORKF 设备初始化完成"); ReadData(); } #region 调试代码 public void CommandRegist() { #region 设备控制 ActionManage.GetInstance.Register(PLCInite, "InitCommand"); ActionManage.GetInstance.Register(StartOrder, "StartOrder"); ActionManage.GetInstance.Register(StartLocalOrder, "StartLocalOrder"); ActionManage.GetInstance.Register(StopLocalOrder, "StopLocalOrder"); #endregion #region 菜品库 ActionManage.GetInstance.Register(FoodLibInit, "FoodLibInit"); ActionManage.GetInstance.Register(Electromagnetism, "Electromagnetism"); ActionManage.GetInstance.Register(GetDistance_1, "GetDistance_1"); ActionManage.GetInstance.Register(GetDistance_2, "GetDistance_2"); ActionManage.GetInstance.Register(GetDistance_3, "GetDistance_3"); ActionManage.GetInstance.Register(PawTurnFront, "PawTurnFront"); ActionManage.GetInstance.Register(PawTurnBack, "PawTurnBack"); ActionManage.GetInstance.Register(SetArmPosition, "SetArmPosition"); #endregion //ActionManage.GetInstance.Register(PLCInite, "InitCommand"); #region 配料控制 ActionManage.GetInstance.Register(new Action((o) => { ThreadManage.GetInstance().Start(new Action(() => { OutSeasoning(o, fryIndex); }), "OutMaterials"); }), "OutMaterials"); //ActionManage.GetInstance.Register(OutSeasoning, "OutMaterials"); #endregion #region 炒锅1 ActionManage.GetInstance.Register(new Action(() => { ThreadManage.GetInstance().Start(new Action(() => { Plc1Reset(fryIndex); }), "Plc1Reset"); }) , "Plc1Reset"); ActionManage.GetInstance.Register(new Action(() => { ThreadManage.GetInstance().Start(new Action(() => { AddOil(); }), "AddOil"); }), "AddOil"); ActionManage.GetInstance.Register(new Action(() => { ThreadManage.GetInstance().Start(new Action(() => { StartFire(fryIndex); }), "StartFire"); }), "StartFire"); ActionManage.GetInstance.Register(new Action(() => { ThreadManage.GetInstance().Start(new Action(() => { StopFire(fryIndex); }), "StopFire"); }), "StopFire"); ActionManage.GetInstance.Register(new Action(() => { ThreadManage.GetInstance().Start(new Action(() => { StartStir(fryIndex); }), "StartStir"); }), "StartStir"); ActionManage.GetInstance.Register(new Action(() => { ThreadManage.GetInstance().Start(new Action(() => { StopStir(fryIndex); }), "StopStir"); }), "StopStir"); ActionManage.GetInstance.Register(new Action(() => { ThreadManage.GetInstance().Start(new Action(() => { OutFood(fryIndex); }), "OutFood"); }), "OutFood"); ActionManage.GetInstance.Register(new Action(() => { ThreadManage.GetInstance().Start(new Action(() => { StirArmGoOrigin(fryIndex); }), "StirArmGoOrigin"); }), "StirArmGoOrigin"); ActionManage.GetInstance.Register(new Action(() => { ThreadManage.GetInstance().Start(new Action(() => { StirArmGoWork(fryIndex); }), "StirArmGoWork"); }), "StirArmGoWork"); ActionManage.GetInstance.Register(new Action(() => { ThreadManage.GetInstance().Start(new Action(() => { HBOTGoWork(fryIndex); }), "HBOTGoWork"); }), "HBOTGoWork"); ActionManage.GetInstance.Register(new Action(() => { ThreadManage.GetInstance().Start(new Action(() => { OutMeal(fryIndex); }), "OutMeal"); }), "OutMeal"); ActionManage.GetInstance.Register(new Action((o) => { ThreadManage.GetInstance().Start(new Action(() => { SetFire(o,fryIndex); }), "SetFire"); }), "SetFire"); ActionManage.GetInstance.Register(new Action((o) => { ThreadManage.GetInstance().Start(new Action(() => { SetFry(o); }), "SetFry"); }), "SetFry"); ActionManage.GetInstance.Register(new Action((o) => { ThreadManage.GetInstance().Start(new Action(() => { SetStir(o,fryIndex); }), "SetStir"); }), "SetStir"); #endregion } #region 菜品库 /// /// 菜品库数据写入 /// /// /// private void MaterailLibrary_Write(string address,object value) { WriteControlExact(address, value, 1); } /// /// 菜品库初始化 /// public void FoodLibInit() { MaterailLibrary_Write("", true); } /// /// 电磁阀启停 /// /// public void Electromagnetism(object o) { if (o == null) return; if (o is List bs && bs.Count == 1) { MaterailLibrary_Write("", bs[0]); } } public void GetDistance_1() { MaterailLibrary_Write("", true); } public void GetDistance_2() { MaterailLibrary_Write("", true); } public void GetDistance_3() { MaterailLibrary_Write("", true); } public void PawTurnFront() { MaterailLibrary_Write("", true); } public void PawTurnBack() { MaterailLibrary_Write("", true); } /// /// 设定机械臂的位置 /// /// /// public void SetArmPosition(int X, int y) { MaterailLibrary_Write("", true); } #endregion /// /// 出调料 /// /// public void OutSeasoning(object o,int num) { if (o == null) return; if (o is List ints && ints.Count == 2&&morkFs.ContainsKey(num)) { FirePot1_Write(morkFs[num].PassWayValue[ints[0]], (ushort)ints[1],num);//写入通道值 Thread.Sleep(400); FirePot1_Write(morkFs[num].StartPassWay[ints[0]], true, num);//开启通道 Thread.Sleep(400); FirePot1_Write(morkFs[num].StartPassWay[ints[0]], false, num);//开启通道 } } /// /// 出多个调料 /// public void OutSeasonings(List seasoningLists,int num) { //防止越界 if(!morkFs.ContainsKey(num)) { return; } foreach (SeasoningList seasoning in seasoningLists) { FirePot1_Write(morkFs[num].PassWayValue[seasoning.Loc], (ushort)seasoning.Qty, num); Thread.Sleep(300); } foreach (SeasoningList seasoning in seasoningLists) { FirePot1_Write(morkFs[num].StartPassWay[seasoning.Loc], true, num); Thread.Sleep(300); } foreach (SeasoningList seasoning in seasoningLists) { FirePot1_Write(morkFs[num].StartPassWay[seasoning.Loc], false, num); Thread.Sleep(300); } foreach (SeasoningList seasoning in seasoningLists) { FirePot1_Write(morkFs[num].StartPassWay[seasoning.Loc], false, num); Thread.Sleep(300); } } #region 炒锅1 private void FirePot1_Write(string address,object value,int num) { WriteControlExact(address, value, num); } /// /// 复位 /// public void Plc1Reset(int num) { ThreadManage.GetInstance().Start(new Action(() => { StopFire(num); Thread.Sleep(200); StopStir(num); Thread.Sleep(200); FirePot1_Write("LB5", false, num); Thread.Sleep(200); FirePot1_Write("LB3", false, num); Thread.Sleep(200); FirePot1_Write("LB6", false, num); Thread.Sleep(200); FirePot1_Write("LB7", false, num); Thread.Sleep(200); FirePot1_Write("LB4", false, num); Thread.Sleep(200); FirePot1_Write("LB53", false, num); if(morkFs.ContainsKey(num)) { foreach (var item in morkFs[num].StartPassWay.Values) { Thread.Sleep(200); FirePot1_Write(item, false, num); } } }),"炒锅1初始化"); } //加油 public void AddOil() { } //加热启动 public void StartFire(int num) { FirePot1_Write("LB1", true, num); Thread.Sleep(200); } //加热停止 public void StopFire(int num) { FirePot1_Write("LB1", false, num); Thread.Sleep(200); } //搅拌启动 public void StartStir(int num) { FirePot1_Write("LB2", true, num); Thread.Sleep(200); } //搅拌启停止 public void StopStir(int num) { FirePot1_Write("LB2", false, num); Thread.Sleep(200); } //倒菜 public void OutFood(int num) { if(!morkFs.ContainsKey(num)) { return; } FirePot1_Write("LB3", true, num); MessageLog.GetInstance.Show("倒菜启动"); Thread.Sleep(400); for (int i = 0; i < sleepCount && !morkFs[num].FryPot1_MaterialIntoPot; i++) { Thread.Sleep(sleepTime); if (i >= sleepCount - 1) { MessageLog.GetInstance.Show($"炒锅{num}倒菜超时"); } } FirePot1_Write("LB3", false, num); Thread.Sleep(200); MessageLog.GetInstance.Show("倒菜完成"); } //搅拌臂去原点位 public void StirArmGoOrigin(int num) { if (!morkFs.ContainsKey(num)) { return; } FirePot1_Write("LB5", true, num); MessageLog.GetInstance.Show("搅拌臂去原点位"); for (int i = 0; i < sleepCount && !morkFs[num].ArmOnOrigin; i++) { Thread.Sleep(sleepTime); if (i >= sleepCount - 1) { MessageLog.GetInstance.Show($"炒锅{num}搅拌臂去原点位超时"); } } //while (!morkFs[num].ArmOnOrigin) //{ // Thread.Sleep(200); //} FirePot1_Write("LB5", false, num); Thread.Sleep(200); MessageLog.GetInstance.Show("搅拌臂到达原点位"); } //搅拌臂去炒制位 public void StirArmGoWork(int num) { if (!morkFs.ContainsKey(num)) { return; } if (!morkFs[num].ArmOnWorking/* && morkFs[num].PotOnOrigin*/) { FirePot1_Write("LB6", true, num); MessageLog.GetInstance.Show("搅拌臂去工作位"); for (int i = 0; i < sleepCount && !morkFs[num].ArmOnWorking; i++) { Thread.Sleep(sleepTime); if (i >= sleepCount - 1) { MessageLog.GetInstance.Show($"炒锅{num}搅拌臂去炒制位超时"); } } //while (!morkFs[num].ArmOnWorking) //{ // Thread.Sleep(200); //} FirePot1_Write("LB6", false, num); Thread.Sleep(200); MessageLog.GetInstance.Show("搅拌臂到达工作位"); } } //HBOT放盒子到位 public void HBOTGoWork(int num) { FirePot1_Write("LB7", true, num); Thread.Sleep(400); FirePot1_Write("LB7", false, num); } //出餐启动 public void OutMeal(int num) { if (!morkFs[num].ArmOnOrigin /*&& morkFs[num].PotOnOrigin*/) { MessageLog.GetInstance.Show("搅拌臂不在原点位,无法完成出餐"); return; } FirePot1_Write("LB4", true, num); Thread.Sleep(200); FirePot1_Write("LB4", false, num); } //加热挡位设定 public void SetFire(object o, int num) { if (o == null) return; if (o is List ints && ints.Count == 1) { FirePot1_Write("LW14", (ushort)ints[0],num); Thread.Sleep(200); } } public void SetFry(object o) { if (o == null) return; if (o is List ints && ints.Count == 1) { fryIndex = ints[0] - 1; } } /// /// 搅拌挡位设定 /// /// public void SetStir(object o, int num) { if (o == null) return; if (o is List ints && ints.Count == 1) { FirePot1_Write("LW15", (ushort)ints[0],num); Thread.Sleep(200); } } #endregion /// /// 本地菜单下单 /// private void StartOrder(object o) { if(o==null) return; if(o is int goodId) { var res = LocalstirFryGoods?.FirstOrDefault(p => p.GoodsKey == goodId);//匹配订单对应制作流程 if (res != null) { /* morkF.listStirBom.Add(res.StirFryBomInfo);*///添加订单制作流程 if (StirFryGoodsQuenes.Count > 0) return; StirFryGoodsQuenes.Enqueue(new OrderLocInfo() { SuborderId = Guid.NewGuid().ToString(), StirPotActions = res.StirPotActions, GoodName = "本地菜品" }); MessageLog.GetInstance.Show($"添加本地订单{res.GoodsKey}"); } } } private void StartLocalOrder() { if (StirFryGoodsQuenes.Count > 0) return;//只能一个一个做 if (Json.Data.LocalstirFryGoods.StirPotActions.Count>0) { StirFryGoodsQuenes.Enqueue(new OrderLocInfo() { SuborderId = Guid.NewGuid().ToString(), StirPotActions = Json.Data.LocalstirFryGoods.StirPotActions, GoodName = "本地菜品" }); MessageLog.GetInstance.Show($"添加本地模拟的订单{Json.Data.LocalstirFryGoods.GoodsKey}"); } } private void StopLocalOrder() { //判断当前是否有炒制菜品 if (nowStirFryGood == null) return; ThreadManage.GetInstance().StopTask(String.Format(striConst, fryIndex.ToString(), nowStirFryGood.GoodName), new Action(() => { Plc1Reset(fryIndex); })); } #endregion public override void ResetProgram() { morkFs.Clear(); morkFs = new Dictionary(); for (int i = 0; i < count; i++) { morkFs.Add(i, new GVL_MorkF()); } } /// /// PLC数据读取 /// public override void ReadData() { for (int i = 0; i < morkFs.Count; i++) { GetStatus("LB50", new Action((objects) => { if (!morkFs.ContainsKey(i)) { return; } if(objects is bool[] bools) { morkFs[i].FryPot1_InitialComplete = bools[0]; morkFs[i].FryPot1_HOBTPut = bools[1]; morkFs[i].FryPot1_HOBTGet = bools[2]; morkFs[i].FryPot1_MaterialIntoPot = bools[3]; morkFs[i].OutFoodCompelete = bools[4]; morkFs[i].CanOutFood = bools[5]; morkFs[i].GetFoodCompelete = bools[6]; morkFs[i].CanOutPotWashingWater = bools[7]; morkFs[i].ArmOnOrigin = bools[8]; morkFs[i].ArmOnWorking = bools[9]; morkFs[i].PotOnOrigin = bools[10]; } }), i); } for (int j = 0; j < morkFs.Count; j++) { GetStatus("LB74", new Action((objects) => { if (!morkFs.ContainsKey(j)) { return; } if (objects is bool[] bools) { for (int i = 0; i < 14; i++) { morkFs[j].PassWay1_Compelete[i] = bools[i]; } } }), j); } for (int i = 0; i < morkFs.Count; i++) { if (!morkFs.ContainsKey(i)) { return; } GetStatus("LB90", new Action((objects) => { if (objects is bool[] bools) { morkFs[i].AutoMode = bools[0]; } }), i); } for (int j = 0; j < morkFs.Count; j++) { GetStatus("VD808", new Action((objects) => { if (!morkFs.ContainsKey(j)) { return; } if (objects is object[] bools) { for (int i = 0; i < 1; i++) { var a = bools[i]; } } }), j); GetStatus("VD814", new Action((objects) => { if (!morkFs.ContainsKey(j)) { return; } if (objects is object[] bools) { for (int i = 0; i < 1; i++) { var a = bools[i]; } } }), j); GetStatus("VD816", new Action((objects) => { if (!morkFs.ContainsKey(j)) { return; } if (objects is object[] bools) { for (int i = 0; i < 1; i++) { var a = bools[i]; } } }), j); } } 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; } }); //配方数据信息 EventBus.EventBus.GetInstance().Subscribe(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack) { if (@event == null) return; if (@event is RecipeBomEvent recipe) { recipeBoms = recipe.recipeBoms; } }); //小炒流程信息 EventBus.EventBus.GetInstance().Subscribe(DeviceId, delegate (IEvent @event, EventCallBackHandle callback) { if (@event == null) return; if (@event is StirFryGoodsEvent stirFry) { if (stirFry.stirFrymessage.stirFryGoods.Count > 0) { foreach (var item in stirFry.stirFrymessage.stirFryGoods) { LocalstirFryGoods.Add(new StirFryGoods { GoodsKey = item.GoodsKey, StirPotActions = OrderSort(item.StirPotActions), }); } } MessageLog.GetInstance.Show("接收到小炒流程信息"); //流程解析 foreach (var item in LocalstirFryGoods) { MessageLog.GetInstance.Show($"添加菜谱{item.GoodsKey}"); // morkF.listStirBom.Add(item.StirFryBomInfo);//添加订单制作流程 string MenuStep = "菜单步骤:"; foreach (var items in item.StirPotActions) { switch (items.Actions) { case nameof(StirFryPotActionEnum.加热开启): MenuStep += items.Actions + ","; break; case nameof(StirFryPotActionEnum.设置加热挡位1): MenuStep += items.Actions + ","; break; case nameof(StirFryPotActionEnum.设置加热挡位2): MenuStep += items.Actions + ","; break; case nameof(StirFryPotActionEnum.设置加热挡位3): MenuStep += items.Actions + ","; break; case nameof(StirFryPotActionEnum.设置加热挡位4): MenuStep += items.Actions + ","; break; case nameof(StirFryPotActionEnum.设置加热挡位5): MenuStep += items.Actions + ","; break; case nameof(StirFryPotActionEnum.设置加热挡位6): MenuStep += items.Actions + ","; break; case nameof(StirFryPotActionEnum.设置加热挡位7): MenuStep += items.Actions + ","; break; case nameof(StirFryPotActionEnum.设置加热挡位8): MenuStep += items.Actions + ","; break; case nameof(StirFryPotActionEnum.设置加热挡位9): MenuStep += items.Actions + ","; break; case nameof(StirFryPotActionEnum.设置加热挡位10): MenuStep += items.Actions + ","; break; case nameof(StirFryPotActionEnum.停止加热): MenuStep += items.Actions + ","; break; case nameof(StirFryPotActionEnum.加调料): MenuStep += items.Actions + ","; break; case nameof(StirFryPotActionEnum.取原料): MenuStep += items.Actions + ","; break; case nameof(StirFryPotActionEnum.开启搅拌): MenuStep += items.Actions + ","; break; case nameof(StirFryPotActionEnum.设置搅拌挡位1): MenuStep += items.Actions + ","; break; case nameof(StirFryPotActionEnum.设置搅拌挡位2): MenuStep += items.Actions + ","; break; case nameof(StirFryPotActionEnum.设置搅拌挡位3): MenuStep += items.Actions + ","; break; case nameof(StirFryPotActionEnum.关闭搅拌): MenuStep += items.Actions + ","; break; case nameof(StirFryPotActionEnum.出餐启动): MenuStep += items.Actions + ","; break; case nameof(StirFryPotActionEnum.道菜启动): MenuStep += items.Actions + ","; break; case nameof(StirFryPotActionEnum.炒制菜品): MenuStep += items.Actions + ","; break; case nameof(StirFryPotActionEnum.搅拌臂原点位): MenuStep += items.Actions + ","; break; case nameof(StirFryPotActionEnum.搅拌臂炒制位): MenuStep += items.Actions + ","; break; case nameof(StirFryPotActionEnum.洗锅): MenuStep += items.Actions + ","; break; default: break; } } MessageLog.GetInstance.Show(MenuStep); } } }); } private List OrderSort(List potActions) { if (potActions.Count > 1) { potActions.Sort( delegate (PotActions st1, PotActions st2) { //降序排列 //return st2.FryTime.CompareTo(st1.FryTime); //升序版(颠倒 st1 和 st2 即可) return st1.FryTime.CompareTo(st2.FryTime); }); } return potActions; } /// /// 订单状态发布 /// /// /// private void OrderChange(string subid, ORDER_STATUS oRDER_STATUS) { EventBus.EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { Status = oRDER_STATUS, SubOrderId = subid }); } /// /// 数据解析 /// private void DataParse(int num) { if (!morkFs.ContainsKey(num)) { return; } 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}次订单"); Enum.GetNames(typeof(StirFryPotActionEnum)); var res = LocalstirFryGoods?.FirstOrDefault(p => p.GoodsKey == order.MorkOrder.RecipeId);//匹配订单对应制作流程 if (res != null) { /* morkF.listStirBom.Add(res.StirFryBomInfo);*///添加订单制作流程 //添加到带炒小炒队列 if (StirFryGoodsQuenes.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null) { lock (lock_MainProcessExcute) { StirFryGoodsQuenes.Enqueue(new OrderLocInfo() { SuborderId = order.MorkOrder.SuborderId, StirPotActions = res.StirPotActions, GoodName = order.MorkOrder.GoodsName }); } } } } }); } /// /// 主任务 /// public override void MainTask() { MainProcessExcute(); //MinorProcessExcute(); //SingleProcess(); } private object lock_MainProcessExcute = new object(); /// /// 炒锅主流程 /// private void MainProcessExcute() { //判断是否有订单信息 if(StirFryGoodsQuenes.Count > 0) { //遍历炒锅,找到合适、空闲的炒锅 for(int i = 0;i { try { foreach (var potActions in res.StirPotActions) { if (ThreadManage.GetInstance().IsCanncel(String.Format(striConst, i.ToString(), nowStirFryGood.GoodName))) { break; } switch (potActions.Actions) { case nameof(StirFryPotActionEnum.加热开启): StartFire(i); MessageLog.GetInstance.Show(potActions.Actions); break; case nameof(StirFryPotActionEnum.设置加热挡位1): SetFire(new List { 1 }, i); MessageLog.GetInstance.Show(potActions.Actions); break; case nameof(StirFryPotActionEnum.设置加热挡位2): SetFire(new List { 2 }, i); MessageLog.GetInstance.Show(potActions.Actions); break; case nameof(StirFryPotActionEnum.设置加热挡位3): SetFire(new List { 3 }, i); MessageLog.GetInstance.Show(potActions.Actions); break; case nameof(StirFryPotActionEnum.设置加热挡位4): SetFire(new List { 4 }, i); MessageLog.GetInstance.Show(potActions.Actions); break; case nameof(StirFryPotActionEnum.设置加热挡位5): SetFire(new List { 5 }, i); MessageLog.GetInstance.Show(potActions.Actions); break; case nameof(StirFryPotActionEnum.设置加热挡位6): SetFire(new List { 6 }, i); MessageLog.GetInstance.Show(potActions.Actions); break; case nameof(StirFryPotActionEnum.设置加热挡位7): SetFire(new List { 7 }, i); MessageLog.GetInstance.Show(potActions.Actions); break; case nameof(StirFryPotActionEnum.设置加热挡位8): SetFire(new List { 8 }, i); MessageLog.GetInstance.Show(potActions.Actions); break; case nameof(StirFryPotActionEnum.设置加热挡位9): SetFire(new List { 9 }, i); MessageLog.GetInstance.Show(potActions.Actions); break; case nameof(StirFryPotActionEnum.设置加热挡位10): SetFire(new List { 10 }, i); MessageLog.GetInstance.Show(potActions.Actions); break; case nameof(StirFryPotActionEnum.停止加热): StopFire(i); MessageLog.GetInstance.Show(potActions.Actions); break; case nameof(StirFryPotActionEnum.加调料): OutSeasonings(potActions.SeasoningLists, i); MessageLog.GetInstance.Show(potActions.Actions); break; case nameof(StirFryPotActionEnum.取原料): MessageLog.GetInstance.Show(potActions.Actions); break; case nameof(StirFryPotActionEnum.开启搅拌): StartStir(i); MessageLog.GetInstance.Show(potActions.Actions); break; case nameof(StirFryPotActionEnum.设置搅拌挡位1): SetStir(new List { 1 }, i); MessageLog.GetInstance.Show(potActions.Actions); break; case nameof(StirFryPotActionEnum.设置搅拌挡位2): SetStir(new List { 2 }, i); MessageLog.GetInstance.Show(potActions.Actions); break; case nameof(StirFryPotActionEnum.设置搅拌挡位3): SetStir(new List { 3 }, i); MessageLog.GetInstance.Show(potActions.Actions); break; case nameof(StirFryPotActionEnum.关闭搅拌): StopStir(i); MessageLog.GetInstance.Show(potActions.Actions); break; case nameof(StirFryPotActionEnum.出餐启动): MessageLog.GetInstance.Show(potActions.Actions); break; case nameof(StirFryPotActionEnum.道菜启动): OutFood(i); break; case nameof(StirFryPotActionEnum.炒制菜品): Thread.Sleep(potActions.During * 1000); break; case nameof(StirFryPotActionEnum.搅拌臂原点位): StirArmGoOrigin(i); MessageLog.GetInstance.Show(potActions.Actions); break; case nameof(StirFryPotActionEnum.搅拌臂炒制位): StirArmGoWork(i); MessageLog.GetInstance.Show(potActions.Actions); break; case nameof(StirFryPotActionEnum.洗锅): MessageLog.GetInstance.Show(potActions.Actions); break; default: break; } } Plc1Reset(i);//复位 Thread.Sleep(3000); //回原点位 StirArmGoOrigin(i); for (int i = 0; i < sleepCount && !morkFs[i].ArmOnOrigin; i++) { Thread.Sleep(sleepTime); if (i >= sleepCount - 1) { MessageLog.GetInstance.Show($"炒锅{i}炒制过程完成后,搅拌臂去原点位超时"); } } //while (!morkFs[i].ArmOnOrigin) //{ // Thread.Sleep(100); //} //出餐 //OutMeal(i); MessageLog.GetInstance.Show($"菜品{res.GoodName}完成"); } catch (Exception ex) { ThreadManage.GetInstance().StopTask($"炒锅{i}{res.GoodName}炒制线程"); MessageLog.GetInstance.Show($"炒锅{i}炒制菜品{res.GoodName}出错,错误信息:" + ex.Message); } finally { nowStirFryGood = null; //炒完后出队列 morkFs[i].StirFryGoodsQuenes.TryDequeue(out var orderQueue); morkFs[i].FryWorking = false; } }), String.Format(striConst, i.ToString(), nowStirFryGood.GoodName)/*$"炒锅{i}炒制{res.GoodName}线程"*/); } } break; } } } } //辅流程执行 //private void MinorProcessExcute() //{ // if (!morkF.MinorProcessExcuteLock) // { // morkF.MinorProcessExcuteLock = true; // Task.Run(() => // { // if (morkF.MinorProcessFlag && morkF.TakeMaterialQueue.Count > 0 && morkF.listStirBom.Count > 0 ) // { // morkF.MinorProessStatus = true; // morkF.MainProcessStatus = false; // StirFryBom bom = morkF.listStirBom.ElementAt(0); // morkF.listStirBom.RemoveAt(0); // foreach (var res in bom.StirFryActions) // { // DeviceProcessLogShow($"执行流程{res.Time}"); // //机器人线程 // Task taskRobot = Task.Run(new Action(() => // { // foreach (var temp in res.RobotActions) // { // switch (temp) // { // } // } // })); // //炒锅线程操作 // Task taskPot = Task.Run(new Action(() => // { // foreach (var temp in res.PotActions) // { // switch (temp) // { // case StirFryPotAction.NONE: // break; // } // } // })); // Task.WhenAll(taskRobot, taskPot).Wait();//等待所有线程结束 // Task.Delay(res.During * 1000).Wait();//当前流程延迟 // if (morkF.MainProcessWait) // { // if (morkF.MainHasTakeMaterial) // { // } // else // { // //关闭灶加热 // //阻塞辅流程 // minorReset.WaitOne(); // //morkF.MinorProessStatus = true; // //morkF.MainProcessStatus = false; // } // } // } // morkF.MinorOutMealComplete = true; // } // else // { // morkF.MinorProcessExcuteLock = false;//解除辅流程自锁 // } // }); // } //} /// /// 信号处理 /// private void SingleProcess() { //if (!morkF.AutoMode) //{ // if (morkF.IsAuto) // { // Plc1Reset(); // morkF.IsAuto = false; // } //} //else morkF.IsAuto = true; } /// /// 获取炒锅PLC的所有状态 /// /// /// /// 炒锅编号 private void GetStatus(string key, Action action,int num) { if(dicPort2peripheralStatus.ContainsKey(num)) { if (dicPort2peripheralStatus[num].ContainsKey(key)) { action((object)dicPort2peripheralStatus[num][key]);//获取PLC指定地址的状态值 } } } ///// ///// 写数据 ///// ///// ///// //private void WriteData(string address, object value) //{ // EventBus.EventBus.GetInstance().Publish(new WriteModel() { DeviceId = DeviceId, Address = address, Value = value }); //} /// /// 炒锅初始化 /// public void PLCInite() { for(int i = 0;i=sleepCount-1) { MessageLog.GetInstance.Show($"炒锅{j}初始化超时"); } } //while (!morkFs[i].FryPot1_InitialComplete) //{ // Thread.Sleep(500); //} FirePot1_Write("LB0", false, i); } } /// public override void Stop() { } public override void SimOrder() { ActionManage.GetInstance.Register(morkSim, "模拟小炒锅1订单"); } private void morkSim(object o) { //if (o == null) return; //if(o is List ins) //{ // ThreadManage.GetInstance().Start(new Action(() => // { // if (morkF.FryPot1_InitialComplete && morkF.AutoMode)//初始化完成&&自动模式&& 锅在原点位置 // { // if (!morkF.ArmOnWorking)//搅拌臂是否在工作位 // { // StirArmGoWork(); // while (!morkF.ArmOnWorking) // { // Thread.Sleep(500); // } // OutSeasoning(new List { 1, 100 });//加油500g // while (!morkF.PassWay1_1Compelete) // { // Thread.Sleep(1000); // } // WriteControlExact(morkF.StartPassWay[ 1], false);//开启通道关闭 // Thread.Sleep(500); // SetFire(new List { ins[1] });//加热三档 // StartFire();//开始加热 // Thread.Sleep(500); // SetStir(new List { ins[2] });//搅拌二挡 // Thread.Sleep(500); // StartStir();//开始搅拌 // Thread.Sleep(ins[0]*1000);//加热10s // OutSeasoning(new List { 11, 30 });//加调料1 50g // Thread.Sleep(400); // OutSeasoning(new List { 12, 30 });//加调料2 30g // while (!morkF.PassWay1_11Compelete&& !morkF.PassWay1_12Compelete) // { // Thread.Sleep(1000); // } // WriteControlExact(morkF.StartPassWay[11], false);//开启通道关闭 // Thread.Sleep(500); // WriteControlExact(morkF.StartPassWay[12], false);//开启通道信号关闭 // Thread.Sleep(500); // OutFood();//倒菜品1 // while (!morkF.FryPot1_MaterialIntoPot)//菜品1倒菜完成 // { // Thread.Sleep(500); // } // WriteControlExact("LB53", false); // Thread.Sleep(500); // SetFire(new List { ins[4] });//菜品1加热档 // Thread.Sleep(500); // SetStir(new List() { ins[5] });//菜品1搅拌挡 // Thread.Sleep(ins[3]*1000);//菜品1炒制时间 // OutSeasoning(new List {3, 8 });//加调料3 20g // while (!morkF.PassWay1_3Compelete) // { // Thread.Sleep(1000); // } // WriteControlExact(morkF.StartPassWay[3], false);//开启通道信号关闭 // Thread.Sleep(500); // OutFood();//倒菜菜品2 // while (!morkF.FryPot1_MaterialIntoPot)//菜品2倒菜完成 // { // Thread.Sleep(500); // } // WriteControlExact("LB53", false); // Thread.Sleep(500); // SetFire(new List { ins[7] });//菜品2加热档 // Thread.Sleep(500); // SetStir(new List() { ins[8] });//菜品2搅拌挡 // Thread.Sleep(ins[6] * 1000);//菜品2炒制时间 // StopStir();//停止搅拌 // Thread.Sleep(500); // StopFire();//停止加热 // Thread.Sleep(2000); // StirArmGoOrigin();//搅拌臂回原点位 // } // } // }), "模拟炒锅1订单"); //} } } }