From 4b7f84b4e63c8d18cf0179e7330fae65bfcb2204 Mon Sep 17 00:00:00 2001 From: itachilee <3050155685@qq.com> Date: Tue, 22 Mar 2022 18:32:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=96=E6=9D=AF=E6=B5=81?= =?UTF-8?q?=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HBLConsole.MORKIC/Control_MORKIC.cs | 29 +++++++++++++++++++++++++---- HBLConsole.Service/ThreadOperate.cs | 15 +++++++++++++-- HBLConsole/App.config | 6 +++--- HBLConsole/View/MainView.xaml | 2 +- 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/HBLConsole.MORKIC/Control_MORKIC.cs b/HBLConsole.MORKIC/Control_MORKIC.cs index d01f24b..1e93aaa 100644 --- a/HBLConsole.MORKIC/Control_MORKIC.cs +++ b/HBLConsole.MORKIC/Control_MORKIC.cs @@ -107,6 +107,9 @@ namespace HBLConsole.MORKIC { if (morkOrderPushes.TryDequeue(out MorkOrderPush order)) { + //Thread.Sleep(5000); + //SimpleFactory.GetInstance.OrderChanged(subOrderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_COOK); + //商品类型 GOODS_TYPE currentGoodsType = GOODS_TYPE.NEITHER; //子订单ID @@ -183,8 +186,17 @@ namespace HBLConsole.MORKIC //订单状态改变:开始制作 SimpleFactory.GetInstance.OrderChanged(subOrderId, BPA.Message.Enum.ORDER_STATUS.COOKING); //todo:先调用机器人 + ThreadOperate.GetInstance.Start(new Action(() => { LebaiHelper.GetInstance.Scene(10002); }), "调用乐百机器人做咖啡场景"); + while (!(lebai.Ok && lebai.Value == 1)) + { + Thread.Sleep(5); + } + //todo:咖啡杯下杯 + MessageLog.GetInstance.Show("咖啡杯取杯完成"); + LebaiHelper.GetInstance.SetValue(100); + while (!(lebai.Ok && lebai.Value == 2)) { @@ -192,9 +204,14 @@ namespace HBLConsole.MORKIC } MessageLog.GetInstance.Show("机器人到达接咖啡口位置"); new MakeCoffeeEvent() { DrinkCode = (DrCoffeeDrinksCode)int.Parse(mainMaterialLoc) }.Publish(); - are.WaitOne(1000 * 90); + are.WaitOne(1000 * 180); MessageLog.GetInstance.Show("咖啡机制作咖啡完成"); LebaiHelper.GetInstance.SetValue(101); + while (!(lebai.Ok && lebai.Value == 3)) + { + Thread.Sleep(5); + } + MessageLog.GetInstance.Show("机器人到达接咖啡口位置"); //订单状态改变:完成 SimpleFactory.GetInstance.OrderChanged(subOrderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_COOK); } @@ -245,11 +262,15 @@ namespace HBLConsole.MORKIC //开始心跳刷新,根据咖啡机及冰淇淋机来判断 ThreadOperate.GetInstance.StartLong(new Action(() => { + //GeneralConfig.Healthy = true; + //GeneralConfig.Healthy = + // LebaiHelper.GetInstance.IsConnected && + // MorkIStatus.GetInstance().CanDo && + // MorkCStatus.GetInstance().CanDo; GeneralConfig.Healthy = - LebaiHelper.GetInstance.IsConnected && - MorkIStatus.GetInstance().CanDo && - MorkCStatus.GetInstance().CanDo; + LebaiHelper.GetInstance.IsConnected && + MorkCStatus.GetInstance().CanDo; Thread.Sleep(100); }), "MORK-IC心跳刷新"); diff --git a/HBLConsole.Service/ThreadOperate.cs b/HBLConsole.Service/ThreadOperate.cs index 1013455..442ae7e 100644 --- a/HBLConsole.Service/ThreadOperate.cs +++ b/HBLConsole.Service/ThreadOperate.cs @@ -43,9 +43,20 @@ namespace HBLConsole.Service CancellationTokenSources.TryAdd(TaskName, new CancellationTokenSource()); bool result = Threads.TryAdd(TaskName, Task.Factory.StartNew(new Action(() => { - while (!CancellationTokenSources[TaskName].IsCancellationRequested) + try { - if (action != null) action(); + while (!CancellationTokenSources[TaskName].IsCancellationRequested) + { + if (action != null) action(); + } + } + catch (Exception ex) + { + CancellationTokenSources.TryRemove(TaskName, out CancellationTokenSource temp); + Threads.TryRemove(TaskName, out Task temp1); + MessageLog.GetInstance.Show($"【{TaskName}】任务线程出现异常,已退出,并重启\r\n{ex.Message}"); + StartLong(action, TaskName, RunComplete); + } }), CancellationTokenSources[TaskName].Token).ContinueWith(new Action((t, o) => { diff --git a/HBLConsole/App.config b/HBLConsole/App.config index b48be48..f4b9b90 100644 --- a/HBLConsole/App.config +++ b/HBLConsole/App.config @@ -11,7 +11,7 @@ - + @@ -19,9 +19,9 @@ - + - + diff --git a/HBLConsole/View/MainView.xaml b/HBLConsole/View/MainView.xaml index c7c33a0..1943525 100644 --- a/HBLConsole/View/MainView.xaml +++ b/HBLConsole/View/MainView.xaml @@ -235,7 +235,7 @@ Grid.RowSpan="2" Margin="10"> - +