From c9a7ab810f3e257d87236a3262f96248d07398ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com> Date: Sun, 25 Jun 2023 17:00:07 +0800 Subject: [PATCH] 1 --- BPASmartClient.Tourism/Control_MorkCL.cs | 203 +++++++++++++++-------- 1 file changed, 137 insertions(+), 66 deletions(-) diff --git a/BPASmartClient.Tourism/Control_MorkCL.cs b/BPASmartClient.Tourism/Control_MorkCL.cs index 461085c0..b18e2d7f 100644 --- a/BPASmartClient.Tourism/Control_MorkCL.cs +++ b/BPASmartClient.Tourism/Control_MorkCL.cs @@ -32,7 +32,6 @@ namespace BPASmartClient.MorkCL MonitorViewModel.DeviceId = DeviceId; //注册本地配方接收 - ActionManage.GetInstance.Send(NotifyTopic.FormulaDistribution, ""); ActionManage.GetInstance.Register(new Action(o => { if (o != null && o is ControlData cd) morkCL.cds.Enqueue(cd); @@ -77,75 +76,147 @@ namespace BPASmartClient.MorkCL private void FryingPanControl(EDeviceType et, ControlData cd) { DeviceProcessLogShow($"开始执行-{cd.Name} 任务"); - for (int i = 0; i < cd.ControlFuncs.Count; i++) + if (TaskList.ContainsKey(et) && TaskList[et].Cts.IsCancellationRequested) return; + while (cd.ControlFuncs.Count > 0) { - if (TaskList.ContainsKey(et) && TaskList[et].Cts.IsCancellationRequested) return; - var device = (FryingPanServer)devices[et]; - var robot = (RobotServer)devices[EDeviceType.机器人]; - var keyValues = cd.ControlFuncs.ElementAt(i); - int index = (ushort)et - 1; - DeviceProcessLogShow($"{cd.Name}-任务执行-{keyValues.Key.ToString()}-步骤"); - switch (keyValues.Key) + if (cd.ControlFuncs.TryDequeue(out FuncModel fm)) { - case EFunc.搅拌启动: - device.MixingFrequencySet(keyValues.Value[0].ParValue); - device.StirStartOrStop = true; - break; - case EFunc.搅拌停止: - device.StirStartOrStop = false; - break; - case EFunc.加热启动: - device.HeatingGearSet(keyValues.Value[0].ParValue); - device.HeatStartOrStop = true; - break; - case EFunc.加热停止: - device.HeatStartOrStop = false; - break; - case EFunc.添加调料: - var Seasoning = SqliteHelper.GetInstance.GetSeasoning().FirstOrDefault(p => p.Id == keyValues.Value[0].Id); - if (Seasoning != null) - { - device.CuttingControl(Seasoning.Loc.ToString(), keyValues.Value[1].ParValue); - } - break; - case EFunc.添加主料: - case EFunc.添加辅料: - MaterialBase mb = new MaterialBase(); - if (keyValues.Key == EFunc.添加辅料) - mb = SqliteHelper.GetInstance.GetAccessories().FirstOrDefault(p => p.Id == keyValues.Value[0].Id); - else mb = SqliteHelper.GetInstance.GetIngredients().FirstOrDefault(p => p.Id == keyValues.Value[0].Id); - robot.RobotTaskControl(mb.Loc.ToString(), et); - device.FeedingLocFB.Wait(Cts: TaskList[et].Cts);//等待炒锅到投料位置 - robot.MaterialPouringRequest[index].Wait(Cts: TaskList[et].Cts); //等待机器人到投料位置 - robot.AllowPourVegetables(et);//允许机器人开始投料 - robot.MaterialPouringComplete[index].Wait(Cts: TaskList[et].Cts); //等待机器人投料完成 - break; - case EFunc.炒锅回原点位: - device.FryingPanHome = true; - break; - case EFunc.出餐启动: - robot.RobotTaskControl("1", et);//取空盆 - robot.DiningOutRequest[index].Wait(Cts: TaskList[et].Cts);//等待机器人到出菜位置 - device.DiningOutStart = true; - break; - case EFunc.炒锅清洗: - device.FryingPanClear = true; - break; - case EFunc.炒锅回投料位置: - device.FryingPanFeedingLoc = true; - break; - case EFunc.去指定炒制位: - device.SetStirFryingLoc(keyValues.Value[0].ParValue); - break; - case EFunc.炒制: - if (int.TryParse(keyValues.Value[0].ParValue, out int time)) - Task.Delay(time * 1000).Wait(TaskList[et].Cts.Token); - break; - default: - break; + var device = (FryingPanServer)devices[et]; + var robot = (RobotServer)devices[EDeviceType.机器人]; + int index = (ushort)et - 1; + DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-步骤"); + switch (fm.eFunc) + { + case EFunc.搅拌启动: + device.MixingFrequencySet(fm.funcPars.ElementAt(0).ParValue); + device.StirStartOrStop = true; + break; + case EFunc.搅拌停止: + device.StirStartOrStop = false; + break; + case EFunc.加热启动: + device.HeatingGearSet(fm.funcPars.ElementAt(0).ParValue); + device.HeatStartOrStop = true; + break; + case EFunc.加热停止: + device.HeatStartOrStop = false; + break; + case EFunc.添加调料: + var Seasoning = SqliteHelper.GetInstance.GetSeasoning().FirstOrDefault(p => p.Id == fm.funcPars.ElementAt(0).Id); + if (Seasoning != null) + { + device.CuttingControl(Seasoning.Loc.ToString(), fm.funcPars.ElementAt(1).ParValue); + } + break; + case EFunc.添加主料: + case EFunc.添加辅料: + MaterialBase mb = new MaterialBase(); + if (fm.eFunc == EFunc.添加辅料) + mb = SqliteHelper.GetInstance.GetAccessories().FirstOrDefault(p => p.Id == fm.funcPars.ElementAt(0).Id); + else mb = SqliteHelper.GetInstance.GetIngredients().FirstOrDefault(p => p.Id == fm.funcPars.ElementAt(0).Id); + robot.RobotTaskControl(mb.Loc.ToString(), et); + device.FeedingLocFB.Wait(Cts: TaskList[et].Cts);//等待炒锅到投料位置 + robot.MaterialPouringRequest[index].Wait(Cts: TaskList[et].Cts); //等待机器人到投料位置 + robot.AllowPourVegetables(et);//允许机器人开始投料 + robot.MaterialPouringComplete[index].Wait(Cts: TaskList[et].Cts); //等待机器人投料完成 + break; + case EFunc.炒锅回原点位: + device.FryingPanHome = true; + break; + case EFunc.出餐启动: + robot.RobotTaskControl("1", et);//取空盆 + robot.DiningOutRequest[index].Wait(Cts: TaskList[et].Cts);//等待机器人到出菜位置 + device.DiningOutStart = true; + break; + case EFunc.炒锅清洗: + device.FryingPanClear = true; + break; + case EFunc.炒锅回投料位置: + device.FryingPanFeedingLoc = true; + break; + case EFunc.去指定炒制位: + device.SetStirFryingLoc(fm.funcPars.ElementAt(0).ParValue); + break; + case EFunc.炒制: + if (int.TryParse(fm.funcPars.ElementAt(0).ParValue, out int time)) + Task.Delay(time * 1000).Wait(TaskList[et].Cts.Token); + break; + default: + break; + } } - } + + + //for (int i = 0; i < cd.ControlFuncs.Count; i++) + //{ + // if (TaskList.ContainsKey(et) && TaskList[et].Cts.IsCancellationRequested) return; + // var device = (FryingPanServer)devices[et]; + // var robot = (RobotServer)devices[EDeviceType.机器人]; + // var keyValues = cd.ControlFuncs.ElementAt(i); + // int index = (ushort)et - 1; + // DeviceProcessLogShow($"{cd.Name}-任务执行-{keyValues.Key.ToString()}-步骤"); + // switch (keyValues.Key) + // { + // case EFunc.搅拌启动: + // device.MixingFrequencySet(keyValues.Value[0].ParValue); + // device.StirStartOrStop = true; + // break; + // case EFunc.搅拌停止: + // device.StirStartOrStop = false; + // break; + // case EFunc.加热启动: + // device.HeatingGearSet(keyValues.Value[0].ParValue); + // device.HeatStartOrStop = true; + // break; + // case EFunc.加热停止: + // device.HeatStartOrStop = false; + // break; + // case EFunc.添加调料: + // var Seasoning = SqliteHelper.GetInstance.GetSeasoning().FirstOrDefault(p => p.Id == keyValues.Value[0].Id); + // if (Seasoning != null) + // { + // device.CuttingControl(Seasoning.Loc.ToString(), keyValues.Value[1].ParValue); + // } + // break; + // case EFunc.添加主料: + // case EFunc.添加辅料: + // MaterialBase mb = new MaterialBase(); + // if (keyValues.Key == EFunc.添加辅料) + // mb = SqliteHelper.GetInstance.GetAccessories().FirstOrDefault(p => p.Id == keyValues.Value[0].Id); + // else mb = SqliteHelper.GetInstance.GetIngredients().FirstOrDefault(p => p.Id == keyValues.Value[0].Id); + // robot.RobotTaskControl(mb.Loc.ToString(), et); + // device.FeedingLocFB.Wait(Cts: TaskList[et].Cts);//等待炒锅到投料位置 + // robot.MaterialPouringRequest[index].Wait(Cts: TaskList[et].Cts); //等待机器人到投料位置 + // robot.AllowPourVegetables(et);//允许机器人开始投料 + // robot.MaterialPouringComplete[index].Wait(Cts: TaskList[et].Cts); //等待机器人投料完成 + // break; + // case EFunc.炒锅回原点位: + // device.FryingPanHome = true; + // break; + // case EFunc.出餐启动: + // robot.RobotTaskControl("1", et);//取空盆 + // robot.DiningOutRequest[index].Wait(Cts: TaskList[et].Cts);//等待机器人到出菜位置 + // device.DiningOutStart = true; + // break; + // case EFunc.炒锅清洗: + // device.FryingPanClear = true; + // break; + // case EFunc.炒锅回投料位置: + // device.FryingPanFeedingLoc = true; + // break; + // case EFunc.去指定炒制位: + // device.SetStirFryingLoc(keyValues.Value[0].ParValue); + // break; + // case EFunc.炒制: + // if (int.TryParse(keyValues.Value[0].ParValue, out int time)) + // Task.Delay(time * 1000).Wait(TaskList[et].Cts.Token); + // break; + // default: + // break; + // } + + //} } public override void ReadData()