diff --git a/HBLConsole.Business/AbstractServer/Base.cs b/HBLConsole.Business/AbstractServer/Base.cs index f8f3ba4..c454d42 100644 --- a/HBLConsole.Business/AbstractServer/Base.cs +++ b/HBLConsole.Business/AbstractServer/Base.cs @@ -22,10 +22,24 @@ namespace HBLConsole.Business.AbstractServer if (orderInfo == null) return; if (orderInfo is MorkOrderPush morkOrderpush) { - OrderData order = Json.Data.morkOrderPushes.Find(par => par.OrderPush?.SuborderId == morkOrderpush.SuborderId); + //OrderData order = Json.Data.morkOrderPushes.Find(par => par.OrderPush?.SuborderId == morkOrderpush.SuborderId); + //if (order == null)//防止重复订单 + //{ + // Json.Data.morkOrderPushes.Add(new OrderData() + // { + // OrderStatus = ORDER_STATUS.WAIT, + // IsSelected = true, + // OrderPush = morkOrderpush + // }); + // ActionManage.GetInstance.Send("AddOrder", morkOrderpush); + // ActionManage.GetInstance.Send("DataParse", morkOrderpush); + //} + + + OrderData order = Json.Data.orderLists.FirstOrDefault(par => par.OrderPush?.SuborderId == morkOrderpush.SuborderId); if (order == null)//防止重复订单 { - Json.Data.morkOrderPushes.Add(new OrderData() + Json.Data.orderLists.Add(new OrderData() { OrderStatus = ORDER_STATUS.WAIT, IsSelected = true, diff --git a/HBLConsole.Business/M2MqttHelper.cs b/HBLConsole.Business/M2MqttHelper.cs index b503e56..6b29b05 100644 --- a/HBLConsole.Business/M2MqttHelper.cs +++ b/HBLConsole.Business/M2MqttHelper.cs @@ -68,7 +68,7 @@ namespace HBLConsole.Business MqttM2.GetInstance.PublishInfo(PublishContent); //mqttClient.Publish($"/sys/grgp0rFA2uu/{deviceName}/thing/event/property/post", Encoding.UTF8.GetBytes(PublishContent), 0, false); - }), "阿里云数据上报", new Action(() => { MqttM2.GetInstance.DisConnect(); })); + }), "阿里云数据上报", false, new Action(() => { MqttM2.GetInstance.DisConnect(); })); } } diff --git a/HBLConsole.Business/ServerData.cs b/HBLConsole.Business/ServerData.cs index 41012c8..fcd67d8 100644 --- a/HBLConsole.Business/ServerData.cs +++ b/HBLConsole.Business/ServerData.cs @@ -41,7 +41,7 @@ namespace HBLConsole.Business } } Thread.Sleep(100); - }), "mqtt消息处理"); + }), "mqtt消息处理", true); } diff --git a/HBLConsole.Communication/ModbusTcpHelper.cs b/HBLConsole.Communication/ModbusTcpHelper.cs index 2307652..248fd02 100644 --- a/HBLConsole.Communication/ModbusTcpHelper.cs +++ b/HBLConsole.Communication/ModbusTcpHelper.cs @@ -79,19 +79,33 @@ namespace HBLConsole.Communication public int GetBoolAddress(string address) { - if (address != null && address.Length > 4) + if (address != null && address.Length >= 4) { var res = address.Substring(1).Split('.'); if (res != null && res.Length == 2) { - + if (int.TryParse(res[0], out int firstAddress) && int.TryParse(res[1], out int ExitAddress)) + { + if (ExitAddress >= 0 && ExitAddress <= 7) + { + return (firstAddress * 8) + 320 + ExitAddress; + } + } } } - return 0; + return -1; } public int GetWordAddress(string address) { + if (address != null && address.Length > 3) + { + var res = address.Substring(2); + if (res != null && int.TryParse(res, out int tempAddress)) + { + return (tempAddress / 2) + 100; + } + } return -1; } diff --git a/HBLConsole.MORKS/Control_MORKS.cs b/HBLConsole.MORKS/Control_MORKS.cs index ebcc451..8e5acab 100644 --- a/HBLConsole.MORKS/Control_MORKS.cs +++ b/HBLConsole.MORKS/Control_MORKS.cs @@ -135,14 +135,14 @@ namespace HBLConsole.MORKS })); - //var ResLoc = ModbusTcpHelper.GetInstance.Read(286, ReadType.HoldingRegisters); - //if (ResLoc != null) - //{ - // if (ResLoc is ushort loc) - // { - // mORKS.TurntableFeedbackloc = loc; - // } - //} + var ResLoc = ModbusTcpHelper.GetInstance.Read(286, ReadType.HoldingRegisters); + if (ResLoc != null) + { + if (ResLoc is ushort loc) + { + mORKS.TurntableFeedbackloc = loc; + } + } Thread.Sleep(500); }), "ReadPLCData"); @@ -236,22 +236,22 @@ namespace HBLConsole.MORKS { if (loc >= 1 && loc <= 5) { - //mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { Loc = ushort.Parse(res.BatchingLoc), SuborderId = morkOrderPush.SuborderId, BatchingId = res.BatchingId }); + mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { Loc = ushort.Parse(res.BatchingLoc), SuborderId = morkOrderPush.SuborderId, BatchingId = res.BatchingId }); } else if (loc >= 10 && loc <= 11) { - //int index = 0; - //if (Json.Data.recipeBoms != null) - //{ - // index = Array.FindIndex(Json.Data.recipeBoms?.RecipeIds.ToArray(), p => p.RecipeId == morkOrderPush.RecipeId); - // index++; - //} - //mORKS.TakeBowlTask.Enqueue(new OrderLocInfo() - //{ - // Loc = ushort.Parse(res.BatchingLoc), - // SuborderId = morkOrderPush.SuborderId, - // RecipeNumber = (index >= 1 && index <= 10) ? (ushort)index : (ushort)0 - //}); + int index = 0; + if (Json.Data.recipeBoms != null) + { + index = Array.FindIndex(Json.Data.recipeBoms?.RecipeIds.ToArray(), p => p.RecipeId == morkOrderPush.RecipeId); + index++; + } + mORKS.TakeBowlTask.Enqueue(new OrderLocInfo() + { + Loc = ushort.Parse(res.BatchingLoc), + SuborderId = morkOrderPush.SuborderId, + RecipeNumber = (index >= 1 && index <= 10) ? (ushort)index : (ushort)0 + }); } } } @@ -493,10 +493,15 @@ namespace HBLConsole.MORKS { SimpleFactory.GetInstance.OrderChanged(mORKS.OutMealId, ORDER_STATUS.COMPLETED_TAKE); MessageLog.GetInstance.Show($"订单【{mORKS.OutMealId}】取餐完成"); - var RemoveItem = Json.Data.morkOrderPushes.FirstOrDefault(p => p.OrderPush.SuborderId == mORKS.OutMealId); + //var RemoveItem = Json.Data.morkOrderPushes.FirstOrDefault(p => p.OrderPush.SuborderId == mORKS.OutMealId); + //if (RemoveItem != null) + //{ + // Json.Data.morkOrderPushes.Remove(RemoveItem); + //} + var RemoveItem = Json.Data.orderLists.FirstOrDefault(p => p.OrderPush.SuborderId == mORKS.OutMealId); if (RemoveItem != null) { - Json.Data.morkOrderPushes.Remove(RemoveItem); + Json.Data.orderLists.Remove(RemoveItem); } ResetCookComplete(); mORKS.OutMealId = string.Empty; diff --git a/HBLConsole.Model/KeepParameter/MorkOrderPushPar.cs b/HBLConsole.Model/KeepParameter/MorkOrderPushPar.cs index b807fe4..3f75c43 100644 --- a/HBLConsole.Model/KeepParameter/MorkOrderPushPar.cs +++ b/HBLConsole.Model/KeepParameter/MorkOrderPushPar.cs @@ -9,6 +9,6 @@ namespace HBLConsole.Model { public class MorkOrderPushPar { - public List morkOrderPushes = new List(); + public List morkOrderPushes { get; set; } = new List(); } } diff --git a/HBLConsole.Service/ThreadManage.cs b/HBLConsole.Service/ThreadManage.cs index 3ef6179..46d20bd 100644 --- a/HBLConsole.Service/ThreadManage.cs +++ b/HBLConsole.Service/ThreadManage.cs @@ -41,11 +41,12 @@ namespace HBLConsole.Service /// /// /// - public void StartLong(Action action, string key, Action RunComplete = null) + public void StartLong(Action action, string key, bool IsRestart = false, Action RunComplete = null) { CancellationTokenSources.TryAdd(guid + key, new CancellationTokenSource()); - bool result = Threads.TryAdd(guid + key, Task.Factory.StartNew(new Action(async () => + bool result = Threads.TryAdd(guid + key, Task.Factory.StartNew(new Action(() => { + ccc: try { while (!CancellationTokenSources[guid + key].IsCancellationRequested) @@ -58,11 +59,16 @@ namespace HBLConsole.Service } catch (Exception ex) { + MessageLog.GetInstance.Show(ex.ToString()); - MessageLog.GetInstance.Show($"线程 【{key}】运行发生异常,已重启"); - CancellationTokenSources.TryRemove(guid + key, out CancellationTokenSource temp); - Threads.TryRemove(guid + key, out Task temp1); + if (IsRestart) goto ccc; + else + { + CancellationTokenSources.TryRemove(guid + key, out CancellationTokenSource temp); + Threads.TryRemove(guid + key, out Task temp1); + MessageLog.GetInstance.Show($"线程 【{key}】运行发生异常,已重启"); + } } }), CancellationTokenSources[guid + key].Token).ContinueWith(new Action((t, o) => { diff --git a/HBLConsole/App.config b/HBLConsole/App.config index ca12755..4286ab6 100644 --- a/HBLConsole/App.config +++ b/HBLConsole/App.config @@ -11,7 +11,7 @@ - + diff --git a/HBLConsole/DialogWindow/ViewModel/ListDialogViewModel.cs b/HBLConsole/DialogWindow/ViewModel/ListDialogViewModel.cs index 75b2c1f..01813df 100644 --- a/HBLConsole/DialogWindow/ViewModel/ListDialogViewModel.cs +++ b/HBLConsole/DialogWindow/ViewModel/ListDialogViewModel.cs @@ -20,51 +20,6 @@ namespace HBLConsole.DialogWindow.ViewModel public static bool IsAutoClose = false; public ListDialogViewModel() { - //CloseCommand = new RelayCommand(() => - //{ - // Json.Data.morkOrderPushes.Clear(); - // orderStatusLists.Clear(); - // WeakReferenceMessenger.Default.Send("false", "Close"); - //}); - - //CancelCommand = new RelayCommand(() => - //{ - // Json.Data.morkOrderPushes.Clear(); - // orderStatusLists.Clear(); - // WeakReferenceMessenger.Default.Send("false", "Close"); - //}); - - //ConfirmCommand = new RelayCommand(() => - //{ - // foreach (var item in orderStatusLists) - // { - // if (!item.IsSelected) - // { - // var reslut = Json.Data.morkOrderPushes.FirstOrDefault(p => p.OrderPush.SuborderId == item.OrderPush.SuborderId); - // if (reslut != null) Json.Data.morkOrderPushes.Remove(reslut); - // } - // } - // foreach (var item in Json.Data.morkOrderPushes) - // { - // orderStatusLists.Add(new OrderData() { IsSelected = true, OrderPush = item.OrderPush, OrderStatus = item.OrderStatus }); - // } - // WeakReferenceMessenger.Default.Send("true", "Close"); - //}); - - //foreach (var item in Json.Data.morkOrderPushes) - //{ - // orderStatusLists.Add(new OrderData() { IsSelected = true, OrderPush = item.OrderPush, OrderStatus = item.OrderStatus }); - //} - - //if (Json.Data.morkOrderPushes.Count > 0) - //{ - // ThreadManage.GetInstance.Start(new Action(() => - // { - // Thread.Sleep(10000); - // if (!IsAutoClose) WeakReferenceMessenger.Default.Send("false", "Close"); - // }), "延时退出"); - //} - //AllSelected = true; Init(); } @@ -86,8 +41,6 @@ namespace HBLConsole.DialogWindow.ViewModel ConfirmCommand = new RelayCommand(() => { - //if (Json.Data.orderLists.ContainsKey(GVL.GeneralConfig.DeviceType.ToString())) - //{ var res = orderStatusLists.Where(p => p.IsSelected == true).ToList(); if (res != null) { @@ -99,11 +52,11 @@ namespace HBLConsole.DialogWindow.ViewModel ActionManage.GetInstance.Send("DataParse", item.OrderPush); } } - //} WeakReferenceMessenger.Default.Send("true", "Close"); }); - if (Json.Data.morkOrderPushes.Count > 0) + //if (Json.Data.morkOrderPushes.Count > 0) + if (Json.Data.orderLists.Count > 0) { ThreadManage.GetInstance.Start(new Action(() => { diff --git a/HBLConsole/ViewModel/ViewModelBase.cs b/HBLConsole/ViewModel/ViewModelBase.cs index ebc3801..4045181 100644 --- a/HBLConsole/ViewModel/ViewModelBase.cs +++ b/HBLConsole/ViewModel/ViewModelBase.cs @@ -30,7 +30,8 @@ namespace HBLConsole.ViewModel { LogMessage = MessageLog.GetInstance.LogInfo; - IotReport.GetInstance.SendLogMessage(new BPA.Message.API请求.LogTable { + IotReport.GetInstance.SendLogMessage(new BPA.Message.API请求.LogTable + { ClientId = InternetInfo.ClientId.ToString(), LogTime = DateTime.Now, LogType = "1", @@ -201,7 +202,8 @@ namespace HBLConsole.ViewModel if (re != null) { WaitTakeMeal.Remove(re); - Json.Data.morkOrderPushes.Remove(re); + //Json.Data.morkOrderPushes.Remove(re); + Json.Data.orderLists.Remove(re); } break;