From 25729cc792a0985f23ad841d9c2545b4d40a1078 Mon Sep 17 00:00:00 2001 From: ZhaoGang <15196688790@163.com> Date: Tue, 8 Aug 2023 13:51:23 +0800 Subject: [PATCH] 1 --- .../Control_MorkSUpgradedVer.cs | 180 +++++------------- 1 file changed, 51 insertions(+), 129 deletions(-) diff --git a/BPASmartClient.MorkSUpgradedVer/Control_MorkSUpgradedVer.cs b/BPASmartClient.MorkSUpgradedVer/Control_MorkSUpgradedVer.cs index c3a85226..da75b6b6 100644 --- a/BPASmartClient.MorkSUpgradedVer/Control_MorkSUpgradedVer.cs +++ b/BPASmartClient.MorkSUpgradedVer/Control_MorkSUpgradedVer.cs @@ -1,29 +1,6 @@ -using System; -using System.Collections.Generic; -using BPA.Message.Enum; -using BPASmartClient.Device; - -using BPASmartClient.Model; -using BPASmartClient.Peripheral; - -using BPA.Helper; -using System.Threading; - -using BPA.Message; -using System.Linq; -using BPASmartClient.Model.PLC; -using System.Threading.Tasks; -using System.Reflection; -using BPASmartClient.MorkSUpgradedVer.Model; -using System.Collections.ObjectModel; -using BPASmartClient.MorkSUpgradedVer.ViewModel; -using BPASmartClient.Business; -using BPASmartClient.Model.小炒机; -using BPA.Models; -using System.Windows.Forms; -using System.Media; -using BPASmartClient.CustomResource; +using BPASmartClient.CustomResource; using static BPA.Helper.EventBus; + //using BPA.Helper; namespace BPASmartClient.MorkSUpgradedVer @@ -31,8 +8,8 @@ namespace BPASmartClient.MorkSUpgradedVer public class Control_MorkSUpgradedVer : BaseDevice { public override DeviceClientType DeviceType => DeviceClientType.MORKS; - GVL_MorkSUpgradedVer mORKS = new GVL_MorkSUpgradedVer(); - Alarm alarm = new Alarm(); + private GVL_MorkSUpgradedVer mORKS = new GVL_MorkSUpgradedVer(); + private Alarm alarm = new Alarm(); public override void DoMain() { @@ -41,7 +18,8 @@ namespace BPASmartClient.MorkSUpgradedVer DataParse(); Json.Read(); Json.Read(); - if (Json.Data.parSets == null) Json.Data.parSets = new ObservableCollection(); + if (Json.Data.parSets == null) + Json.Data.parSets = new ObservableCollection(); if (Json.Data.parSets.Count < 6) { Json.Data.parSets.Clear(); @@ -82,11 +60,13 @@ namespace BPASmartClient.MorkSUpgradedVer ActionManage.GetInstance.Register(new Action((o) => { - if (o != null && o is WritePar writePar) WriteData(writePar.Address, writePar.Value); + if (o != null && o is WritePar writePar) + WriteData(writePar.Address, writePar.Value); }), "WriteVW"); ActionManage.GetInstance.Register(new Action((o) => { - if (o != null && o is WritePar writePar) WriteData(writePar.Address, writePar.Value); + if (o != null && o is WritePar writePar) + WriteData(writePar.Address, writePar.Value); }), "WriteBools"); ActionManage.GetInstance.Register(new Action(() => { DeviceInit(); }), "InitDevice"); } @@ -99,7 +79,6 @@ namespace BPASmartClient.MorkSUpgradedVer public override void Stop() { - } private void ServerInit() @@ -107,7 +86,8 @@ namespace BPASmartClient.MorkSUpgradedVer //物料信息 EventBus.GetInstance().Subscribe(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack) { - if (@event == null) return; + if (@event == null) + return; if (@event is MaterialDeliveryEvent material) { orderMaterialDelivery = material.orderMaterialDelivery; @@ -117,14 +97,13 @@ namespace BPASmartClient.MorkSUpgradedVer //配方数据信息 EventBus.GetInstance().Subscribe(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack) { - if (@event == null) return; + if (@event == null) + return; if (@event is RecipeBomEvent recipe) { recipeBoms = recipe.recipeBoms; } }); - - } private void OrderChange(string subid, ORDER_STATUS oRDER_STATUS) @@ -145,7 +124,9 @@ namespace BPASmartClient.MorkSUpgradedVer if (!string.IsNullOrEmpty(goodName) && !string.IsNullOrEmpty(SortNum)) { EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { SortNum = SortNum, GoodName = goodName, Status = oRDER_STATUS, SubOrderId = subid, deviceClientType = DeviceType }); + var index = DataServer.GetInstance.morkS.MakeOrder.FindIndex(p => p.SortNum == SortNum); + //如果订单信息已经存在,则修改状态,否则新增。 if (index >= 0 && index < DataServer.GetInstance.morkS.MakeOrder.Count) { if (oRDER_STATUS == ORDER_STATUS.COMPLETED_COOK) @@ -162,7 +143,8 @@ namespace BPASmartClient.MorkSUpgradedVer else if (oRDER_STATUS == ORDER_STATUS.COMPLETED_TAKE) { var temp = DataServer.GetInstance.morkS.MakeOrderOver.FirstOrDefault(p => p.SortNum == SortNum); - if (temp != null) DataServer.GetInstance.morkS.MakeOrderOver.Remove(temp); + if (temp != null) + DataServer.GetInstance.morkS.MakeOrderOver.Remove(temp); } else { @@ -183,8 +165,6 @@ namespace BPASmartClient.MorkSUpgradedVer } //} - - //var res = mORKS.doOrderEvents.FirstOrDefault(p => p.MorkOrder.SuborderId == subid); //string goodName = string.Empty; //string SortNum = string.Empty; @@ -366,7 +346,6 @@ namespace BPASmartClient.MorkSUpgradedVer alarm.MachineLowTemperature = !mORKS.TemperatureReaches; } - })); GetStatus("VW770", new Action((obj) => @@ -375,7 +354,6 @@ namespace BPASmartClient.MorkSUpgradedVer { mORKS.CurrentFeedbackLoc = ushorts[0]; } - })); mORKS.TakeBowlTaskCount = mORKS.TakeBowlTask.Count; @@ -386,29 +364,23 @@ namespace BPASmartClient.MorkSUpgradedVer mORKS.nsm.ElementAt(i).IsShield = Json.Data.parSets.ElementAt(i).IsShield; mORKS.nsm.ElementAt(i).NoodleCookerStatus = mORKS.NoodleCookerStatus[i]; } - - //if (Status?.status?["PLC.PLCMachine.IsConnected"] is bool connected) - //{ - // mORKS.IsConnected = connected; - //} - - } - /// - /// 数据解析 - /// + /// 数据解析 private void DataParse() { EventBus.GetInstance().Subscribe(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle) { - if (@event == null) return; + if (@event == null) + return; if (@event is DoOrderEvent order) { mORKS.doOrderEvents.Add(order); //mORKS.doe.TryAdd(order.MorkOrder.SuborderId, order); - if (order.MorkOrder.GoodBatchings == null) return; - if (mORKS.HistorySuborderId.Contains(order.MorkOrder.SuborderId)) return; + if (order.MorkOrder.GoodBatchings == null) + return; + if (mORKS.HistorySuborderId.Contains(order.MorkOrder.SuborderId)) + return; OrderCount++; if (DateTime.Now.Subtract(Json.Data.StatisticsTime).Days != 0) Json.Data.Count = 0; @@ -503,9 +475,7 @@ namespace BPASmartClient.MorkSUpgradedVer } } - /// - /// 取碗控制 - /// + /// 取碗控制 private void TakeBowlTask() { if (mORKS.AllowRun && mORKS.TakeBowlTask.Count > 0 && !mORKS.DropBowlMechanismStatus && !mORKS.TakeBowlInterlock) @@ -514,7 +484,8 @@ namespace BPASmartClient.MorkSUpgradedVer var res = orderMaterialDelivery?.BatchingInfo?.Where(p => p.BatchingId == mORKS.TakeBowlTask.ElementAt(0).BatchingId).ToList(); if (res == null || res?.Count == 0) { - if (mORKS.TakeBowlTask.TryDequeue(out OrderLocInfo orderLocInfo)) BowlControl(orderLocInfo); + if (mORKS.TakeBowlTask.TryDequeue(out OrderLocInfo orderLocInfo)) + BowlControl(orderLocInfo); } else { @@ -547,9 +518,7 @@ namespace BPASmartClient.MorkSUpgradedVer } } - /// - /// 转台控制 - /// + /// 转台控制 private void TurntableControl() { if (Global.EnableLocalSimOrder) @@ -573,7 +542,6 @@ namespace BPASmartClient.MorkSUpgradedVer { if (mORKS.SiloInPlace && !mORKS.Feeding && mORKS.InitComplete && !mORKS.AllowTakeNoodle && mORKS.RBTakeNoodleTask.Count > 0) { - var result = orderMaterialDelivery.BatchingInfo.Where(p => p.BatchingId == mORKS.RBTakeNoodleTask.ElementAt(0).BatchingId).ToList(); if (result != null) { @@ -603,13 +571,15 @@ namespace BPASmartClient.MorkSUpgradedVer DeviceProcessLogShow($"没有物料检测的启动转台控制,转台位置:[{loc}]"); break; } - else if (mORKS.CurrentFeedbackLoc == loc && !mORKS.TurntableLocLists.Contains(loc)) mORKS.TurntableLocLists.Add(loc); + else if (mORKS.CurrentFeedbackLoc == loc && !mORKS.TurntableLocLists.Contains(loc)) + mORKS.TurntableLocLists.Add(loc); } } } } } - else DeviceProcessLogShow("未找到可用的物料信息"); + else + DeviceProcessLogShow("未找到可用的物料信息"); } } } @@ -624,7 +594,6 @@ namespace BPASmartClient.MorkSUpgradedVer //转台到位检测 if (RTrig.GetInstance("TurntableInPlace").Start(mORKS.SiloInPlace && mORKS.CurrentLoc == mORKS.CurrentFeedbackLoc)) { - mORKS.TurntableInterlock = false; DeviceProcessLogShow("转台到位检测"); } @@ -639,12 +608,9 @@ namespace BPASmartClient.MorkSUpgradedVer DeviceProcessLogShow("补料完成检测"); } } - } - /// - /// 取面任务 - /// + /// 取面任务 private void TakeNoodleTask() { //取面控制 @@ -692,14 +658,13 @@ namespace BPASmartClient.MorkSUpgradedVer } } - /// - /// 出餐控制 - /// + /// 出餐控制 private void OutNoodleTask() { if (mORKS.AllowInvertedFace && mORKS.RobotTaskInterlock && !mORKS.RobotOutDinnigLock && !mORKS.TakeNoodleInterlock && mORKS.RobotStatus) { #region 修改之前的代码 + //int loc = Array.FindIndex(mORKS.CookNodelId, p => p == mORKS.IngredientsCompleteId && p.Length > 0); //if (loc >= 0 && loc <= 5) //{ @@ -719,12 +684,12 @@ namespace BPASmartClient.MorkSUpgradedVer // DeviceProcessLogShow($"{loc + 1} 号位置出餐控制,订单ID:{mORKS.OutMealId}"); // mORKS.CookNoodleCom[loc] = false; // } - //} - #endregion + //} + + #endregion 修改之前的代码 for (int loc = 0; loc < mORKS.CookNodelId.Length; loc++) { - if (mORKS.CookNoodleCom[loc] && !mORKS.RobotOutDinnigLock) { SetTakeNoodleLoc((ushort)(loc + 1)); @@ -746,9 +711,7 @@ namespace BPASmartClient.MorkSUpgradedVer } } - /// - /// 信号检测 - /// + /// 信号检测 private void SingleDetect() { //允许倒面信号检测 @@ -766,21 +729,6 @@ namespace BPASmartClient.MorkSUpgradedVer mORKS.RobotOutDinnigLock = false; } - //2023-8-7:检测上升沿修改为延时。 - //if (DelayRTrig.GetInstance("AllowFallNoodle").Start(mORKS.AllowInvertedFace, 500)) - //{ - // //mORKS.IngredientsCompleteId = mORKS.TakeBowlId; - // mORKS.IngredientsCompleteName = mORKS.TakeBowName; - // mORKS.IngredientsCompleteSortNum = mORKS.TakeBowSortNum; - // mORKS.TakeBowSortNum = 0; - // mORKS.TakeBowlId = string.Empty; - // mORKS.TakeBowName = string.Empty; - // //DeviceProcessLogShow($"碗到位,允许到面,{mORKS.IngredientsCompleteId}"); - // DeviceProcessLogShow($"碗到位,允许倒面。"); - // mORKS.TakeBowlInterlock = false; - // mORKS.RobotOutDinnigLock = false; - //} - //取餐完成逻辑处理 if (RTrig.GetInstance("CompleteChange1").Start(mORKS.DiningComplete) && mORKS.CookCompleteFlatBit == true) { @@ -820,25 +768,13 @@ namespace BPASmartClient.MorkSUpgradedVer mORKS.PriorityJudgment = Delay.GetInstance("取餐优先级判断").Start(mORKS.TurntableLocLists.Count > 0 && !mORKS.TurntableLowPosition, 4); //mORKS.RobotTaskInterlock = OutMealRequstCount > 0 && mORKS.AllowInvertedFace && (mlCount >= 2 || mORKS.RBTakeNoodleTask.Count == 0 || mORKS.PriorityJudgment); //mORKS.RobotTaskInterlock = isok && mORKS.AllowInvertedFace && (mlCount >= 2 || mORKS.RBTakeNoodleTask.Count == 0 || mORKS.PriorityJudgment); - + //2023-8-5注释修改,并联出餐请求,出餐优先。 //mORKS.RobotTaskInterlock = mORKS.AllowInvertedFace && (mlCount >= 6 || mORKS.RBTakeNoodleTask.Count == 0 || mORKS.PriorityJudgment); - mORKS.RobotTaskInterlock = mORKS.AllowInvertedFace && (OutMealRequstCount>=1 /*|| mlCount >= 6*/ || mORKS.RBTakeNoodleTask.Count == 0 || mORKS.PriorityJudgment); - - //2023-8-7 添加PLC连接状态指示。 - //if (RTrig.GetInstance("IsConnected").Start(mORKS.IsConnected)) - //{ - // DeviceProcessLogShow("设备已连接。"); - //} - - //if (TTrig.GetInstance("IsConnected").Start(mORKS.IsConnected)) - //{ - // DeviceProcessLogShow("设备已断开连接。"); - //} + mORKS.RobotTaskInterlock = mORKS.AllowInvertedFace && (OutMealRequstCount >= 1 /*|| mlCount >= 6*/ || mORKS.RBTakeNoodleTask.Count == 0 || mORKS.PriorityJudgment); } - /// - /// 语音提醒取餐 - /// + + /// 语音提醒取餐 /// private void WaitMeaLSpeak(string meal) { @@ -855,9 +791,7 @@ namespace BPASmartClient.MorkSUpgradedVer EventBus.GetInstance().Publish(new WriteModel() { DeviceId = DeviceId, Address = address, Value = value }); } - /// - /// 设备初始化 - /// + /// 设备初始化 public async void DeviceInit() { WriteData("M0.0", true); @@ -865,9 +799,7 @@ namespace BPASmartClient.MorkSUpgradedVer WriteData("M0.0", false); } - /// - /// 取碗控制 - /// + /// 取碗控制 /// private void TakeBowlControl(ushort loc) { @@ -881,9 +813,7 @@ namespace BPASmartClient.MorkSUpgradedVer } } - /// - /// 启动转台 - /// + /// 启动转台 /// private void TurntableStart(ushort loc) { @@ -896,9 +826,7 @@ namespace BPASmartClient.MorkSUpgradedVer } } - /// - /// 设置倒面位置 - /// + /// 设置倒面位置 /// private void SetFallNoodleLoc(ushort loc) { @@ -906,9 +834,7 @@ namespace BPASmartClient.MorkSUpgradedVer WriteData($"M14.{loc - 1}", true); } - /// - /// 设置出餐位置 - /// + /// 设置出餐位置 /// private void SetTakeNoodleLoc(ushort loc) { @@ -916,8 +842,6 @@ namespace BPASmartClient.MorkSUpgradedVer WriteData($"M15.{loc - 1}", true); } - - public override void SimOrder() { EventBus.GetInstance().Subscribe(0, delegate (IEvent @event, EventCallBackHandle callBackHandle) @@ -936,12 +860,10 @@ namespace BPASmartClient.MorkSUpgradedVer mORKS.TakeBowlTask.Enqueue(new OrderLocInfo() { Loc = (ushort)msm.Bowloc, SuborderId = guid }); MessageLog.GetInstance.Show($"添加订单:碗位置【{(ushort)msm.Bowloc}】"); } - } }); } - #endregion - + #endregion PLC 控制函数 } -} +} \ No newline at end of file