From 41471e3ea6d9ba989c14e49c6997b1edabe81302 Mon Sep 17 00:00:00 2001 From: taoye Date: Fri, 8 Jul 2022 15:30:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BPASmartClient.Helper/ThreadManage.cs | 2 +- .../Control/DosingLogicControl.cs | 121 ++++++++---------- FryPot_DosingSystem/View/RecipeSetView.xaml | 4 +- 3 files changed, 59 insertions(+), 68 deletions(-) diff --git a/BPASmartClient.Helper/ThreadManage.cs b/BPASmartClient.Helper/ThreadManage.cs index 47598773..c66dfee4 100644 --- a/BPASmartClient.Helper/ThreadManage.cs +++ b/BPASmartClient.Helper/ThreadManage.cs @@ -32,7 +32,7 @@ namespace BPASmartClient.Helper if (CancellationTokenSources.ContainsKey(guid + key)) { CancellationTokenSources[guid + key]?.Cancel(); - if (key.Equals("MainTask")) + if (key.Equals("滚筒线1任务线程")||key.Equals("滚筒线2任务线程")||key.Equals("滚筒线3任务线程")) { ActionManage.GetInstance.Send("FryPotDosingMainTaskExit"); } diff --git a/FryPot_DosingSystem/Control/DosingLogicControl.cs b/FryPot_DosingSystem/Control/DosingLogicControl.cs index c4c3a4af..1de3ce95 100644 --- a/FryPot_DosingSystem/Control/DosingLogicControl.cs +++ b/FryPot_DosingSystem/Control/DosingLogicControl.cs @@ -218,7 +218,7 @@ namespace FryPot_DosingSystem.Control globalVar = new GlobalVariable(); hardWareStatusModel = HardWareStatusViewModel.GetInstance; ActionManage.GetInstance.Register(new Action(RecipeDataParse), "RecipeSetDown"); - ActionManage.GetInstance.Register(new Action(() => { RecipeQuene.Clear(); InputMaterialQuene.Clear(); OutputMaterialQuene.Clear(); }), "ClearRecipes"); + ActionManage.GetInstance.Register(new Action(() => { RecipeQuene.Clear(); InputMaterialQuene.Clear(); OutputMaterialQuene.Clear(); LTwoInputMaterialQuene.Clear(); LTwoOutputMaterialQuene.Clear(); LThreeInputMaterialQuene.Clear(); LThreeOutputMaterialQuene.Clear(); }), "ClearRecipes"); ActionManage.GetInstance.Register(new Action(() => { globalVar.PlcInite = 1; }), "StartPlcInite"); ActionManage.GetInstance.Register(new Action(() => { globalVar.PlcInite = 0; }), "EndPlcInite"); ActionManage.GetInstance.Register(new Action(() => { globalVar.ExitMainTask = true; }), "FryPotDosingMainTaskExit"); @@ -226,7 +226,7 @@ namespace FryPot_DosingSystem.Control HubHelper.GetInstance.Upstreamrequest = new Action(AgvFeedBackUpReportDataAnalysis); ResetProgram(); ReadPlcData(); - IniteTask(); + MainTask(); CommandRegist(); } @@ -433,19 +433,28 @@ namespace FryPot_DosingSystem.Control if (RTrig.GetInstance("ResetProgram").Start(globalVar.PlcInite == 1))//判断是否初始化 一初始化就重启主任务 { MessageLog.GetInstance.ShowUserLog("主任务正在重启"); - ThreadManage.GetInstance().StopTask("MainTask", new Action(() => + + ThreadManage.GetInstance().StopTask("MainViewReadPlcData", new Action(() => { - ThreadManage.GetInstance().StopTask("MainViewReadPlcData", new Action(() => + ActionManage.GetInstance.CancelRegister("RecipeSetDown"); + ActionManage.GetInstance.Register(new Action(RecipeDataParse), "RecipeSetDown"); + ActionManage.GetInstance.Send("ClearRecipes"); + ThreadManage.GetInstance().StopTask("滚筒线1任务线程", new Action(() => { - globalVar = null; - globalVar = new GlobalVariable(); - ReicpeNum = 0; - ActionManage.GetInstance.CancelRegister("RecipeSetDown"); - ActionManage.GetInstance.Register(new Action(RecipeDataParse), "RecipeSetDown"); - ActionManage.GetInstance.Send("ClearRecipes"); - ReadPlcData(); - IniteTask(); - MessageLog.GetInstance.ShowUserLog("主任务重启完成"); + ThreadManage.GetInstance().StopTask("滚筒线2任务线程", new Action(() => + { + ThreadManage.GetInstance().StopTask("滚筒线3任务线程", new Action(() => + { + globalVar = null; + globalVar = new GlobalVariable(); + ReicpeNum = 0; + ReadPlcData(); + //MainTask(); + MessageLog.GetInstance.ShowUserLog("主任务重启完成"); + + })); + })); + })); })); } @@ -689,13 +698,13 @@ namespace FryPot_DosingSystem.Control /// /// 初始化任务 /// - public void IniteTask() - { - ThreadManage.GetInstance().StartLong(new Action(() => - { - MainTask(); - }), "MainTask"); - } + //public void IniteTask() + //{ + // ThreadManage.GetInstance().StartLong(new Action(() => + // { + // MainTask(); + // }), "MainTask"); + //} /// /// 配方数据接收 /// @@ -705,20 +714,6 @@ namespace FryPot_DosingSystem.Control { if (obj != null && obj is NewRecipeModel[] recipes) { - //int? res = (recipe.materialCollection.ElementAt(0).MaterialLoc) / 100; - //if (res != null) - //{ - // switch (res) - // { - // case 1: - // case 4: RecipeQuene.Enqueue(recipe); break; - // case 3: LThreeRecipeQuene.Enqueue(recipe); break; - // case 2: - // case 5: LTwoRecipeQuene.Enqueue(recipe); break; - // } - // ReicpeNum++; - // MessageLog.GetInstance.ShowUserLog($"接收到第{ReicpeNum}个配方"); - //} ReicpeNum = ReicpeNum + recipes.Length; MessageLog.GetInstance.ShowUserLog($"新接收到{recipes.Length}个配方,总共{ReicpeNum}个配方"); for (int i = 0; i < recipes.Length; i++) @@ -762,9 +757,11 @@ namespace FryPot_DosingSystem.Control //LOneFryPotOutputMaterial(); //LTwoFryPotOutputMaterial(); //LThreeFryPotOutputMaterial(); - LineOneProcessExecute(); - LineTwoProcessExecute(); - LineThreeProcessExecute(); + ThreadManage.GetInstance().StartLong(new Action(() => { LineOneProcessExecute();Thread.Sleep(10);}) , "滚筒线1任务线程"); + ThreadManage.GetInstance().StartLong(new Action(() => { LineTwoProcessExecute(); Thread.Sleep(10); }), "滚筒线2任务线程"); + ThreadManage.GetInstance().StartLong(new Action(() => { LineThreeProcessExecute(); Thread.Sleep(10); }), "滚筒线3任务线程"); + + } /// /// 线体1的执行流程 @@ -774,14 +771,12 @@ namespace FryPot_DosingSystem.Control if (!globalVar.LOneTaskLock) { globalVar.LOneTaskLock = true; - Task.Run(new Action(() => - { - LOneRecipeDataToPlc(); - LOneLoadRoller(); - LOneFryPotInputMaterial(); - LOneFryPotOutputMaterial(); - globalVar.LOneTaskLock = false; - })); + LOneRecipeDataToPlc(); + LOneLoadRoller(); + LOneFryPotInputMaterial(); + LOneFryPotOutputMaterial(); + globalVar.LOneTaskLock = false; + } @@ -794,14 +789,12 @@ namespace FryPot_DosingSystem.Control if (!globalVar.LTwoTaskLock) { globalVar.LTwoTaskLock = true; - Task.Run(new Action(() => - { - LTwoRecipeDataToPlc(); - LTwoAgvLoadRoller(); - LTwoFryPotInputMaterial(); - LTwoFryPotOutputMaterial(); - globalVar.LTwoTaskLock = false; - })); + LTwoRecipeDataToPlc(); + LTwoAgvLoadRoller(); + LTwoFryPotInputMaterial(); + LTwoFryPotOutputMaterial(); + globalVar.LTwoTaskLock = false; + } } /// @@ -812,14 +805,12 @@ namespace FryPot_DosingSystem.Control if (!globalVar.LThreeTaskLock) { globalVar.LThreeTaskLock = true; - Task.Run(new Action(() => - { - LThreeRecipeDataToPlc(); - LThreeAgvLoadRoller(); - LThreeFryPotInputMaterial(); - LThreeFryPotOutputMaterial(); - globalVar.LThreeTaskLock = false; - })); + LThreeRecipeDataToPlc(); + LThreeAgvLoadRoller(); + LThreeFryPotInputMaterial(); + LThreeFryPotOutputMaterial(); + globalVar.LThreeTaskLock = false; + } } @@ -950,7 +941,7 @@ namespace FryPot_DosingSystem.Control MessageLog.GetInstance.ShowUserLog($"【1】号滚筒线开始制作【{result.RecipeName}】 配方"); for (int i = 0; i < result.materialCollection.Count; i++) //遍历单个配方中所有物料 { - if (result.materialCollection.Count<=8&&result.materialCollection[i].MaterialLoc % 100 == i + 1 && result.materialCollection[i].MaterialLoc / 100 == headNum && (headNum == 1 || headNum == 4)) + if (result.materialCollection.Count <= 8 && result.materialCollection[i].MaterialLoc % 100 == i + 1 && result.materialCollection[i].MaterialLoc / 100 == headNum && (headNum == 1 || headNum == 4)) { //将配方中原料加入新的队列 InputMaterialQuene.Enqueue(new MaterialInfo() @@ -1430,14 +1421,14 @@ namespace FryPot_DosingSystem.Control Thread.Sleep(5); if (globalVar.ExitMainTask) return; } - MessageLog.GetInstance.ShowRunLog($"炒锅【2】原料:{OutputMaterialQuene.ElementAt(0).materialType.MaterialName}已到进料位置,准备倒料"); break; + MessageLog.GetInstance.ShowRunLog($"炒锅【2】原料:{LTwoOutputMaterialQuene.ElementAt(0).materialType.MaterialName}已到进料位置,准备倒料"); break; case 5: while (globalVar.fryPotFive.InputMaterialArrivedSingle == 0) { Thread.Sleep(5); if (globalVar.ExitMainTask) return; } - MessageLog.GetInstance.ShowRunLog($"炒锅【5】原料:{OutputMaterialQuene.ElementAt(0).materialType.MaterialName}已到进料位置,准备倒料"); break; + MessageLog.GetInstance.ShowRunLog($"炒锅【5】原料:{LTwoOutputMaterialQuene.ElementAt(0).materialType.MaterialName}已到进料位置,准备倒料"); break; } } public void FryPotThreeInputMaterialRollerOperate() @@ -1447,7 +1438,7 @@ namespace FryPot_DosingSystem.Control Thread.Sleep(5); if (globalVar.ExitMainTask) return; } - MessageLog.GetInstance.ShowRunLog($"炒锅【3】原料:{OutputMaterialQuene.ElementAt(0).materialType.MaterialName}已到进料位置,准备倒料"); + MessageLog.GetInstance.ShowRunLog($"炒锅【3】原料:{LThreeOutputMaterialQuene.ElementAt(0).materialType.MaterialName}已到进料位置,准备倒料"); } /// /// 炒锅滚筒空桶出桶处理 diff --git a/FryPot_DosingSystem/View/RecipeSetView.xaml b/FryPot_DosingSystem/View/RecipeSetView.xaml index eaf09b2c..8fec4df3 100644 --- a/FryPot_DosingSystem/View/RecipeSetView.xaml +++ b/FryPot_DosingSystem/View/RecipeSetView.xaml @@ -58,7 +58,7 @@ Foreground="Aqua" IcoText="" Cursor="Hand" - Style="{StaticResource NewButtonStyle}" + Style="{StaticResource IcoButtonStyle}" Command="{Binding NewRecipe}">