using BPASmartClient.CustomResource; using static BPA.Helper.EventBus; using System.Collections.Concurrent; //using BPA.Helper; namespace BPASmartClient.MorkSUpgradedVer { public class Control_MorkSUpgradedVer : BaseDevice { public override DeviceClientType DeviceType => DeviceClientType.MORKS; private GVL_MorkSUpgradedVer mORKS = new GVL_MorkSUpgradedVer(); private Alarm alarm = new Alarm(); public override void DoMain() { MonitorViewModel.DeviceId = DeviceId; ServerInit(); DataParse(); Json.Read(); Json.Read(); if (Json.Data.parSets == null) Json.Data.parSets = new ObservableCollection(); if (Json.Data.parSets.Count < 6) { Json.Data.parSets.Clear(); for (int i = 0; i < 6; i++) { Json.Data.parSets.Add(new ParSet() { CheckBoxContext = $"煮面口{i + 1}屏蔽", Minute = 1, Second = 0, IsShield = false, TextBlockContext = $"煮面口{i + 1}时间设定" }); } } ActionManage.GetInstance.Register(new Action((o) => { if (o.Length > 0) { Random rd = new Random(); TaskManage.GetInstance.StartLong(new Action(() => { int NoodleLoc = (int)o[0] == 0 ? rd.Next(1, 6) : (int)o[0]; int BowlLoc = (int)o[1] == 0 ? rd.Next(10, 12) : (int)o[1]; string guid = Guid.NewGuid().ToString(); mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { Loc = (ushort)NoodleLoc, SuborderId = guid }); MessageLog.GetInstance.Show($"添加订单:面条位置【{NoodleLoc}】"); mORKS.TakeBowlTask.Enqueue(new OrderLocInfo() { Loc = (ushort)BowlLoc, SuborderId = guid }); MessageLog.GetInstance.Show($"添加订单:碗位置【{BowlLoc}】"); Thread.Sleep(60000); }), "ForOrder"); } }), "EnableForOrder"); ActionManage.GetInstance.Register(new Action((o) => { 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); }), "WriteBools"); ActionManage.GetInstance.Register(new Action(() => { DeviceInit(); }), "InitDevice"); } public override void ResetProgram() { mORKS = null; mORKS = new GVL_MorkSUpgradedVer(); } public override void Stop() { } private void ServerInit() { //物料信息 EventBus.GetInstance.Subscribe(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack) { if (@event == null) return; if (@event is MaterialDeliveryEvent material) { orderMaterialDelivery = material.orderMaterialDelivery; } }); //配方数据信息 EventBus.GetInstance.Subscribe(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack) { if (@event == null) return; if (@event is RecipeBomEvent recipe) { recipeBoms = recipe.recipeBoms; } }); OrderNotifyInit(); } #region 接口通知任务处理 ConcurrentQueue osm = new ConcurrentQueue(); private void OrderNotifyInit() { TaskManage.GetInstance.StartLong(() => { while (osm.Count > 0) { TempOrderChange(osm.ElementAt(0).SubOrderId, osm.ElementAt(0).Status, () => { osm.TryDequeue(out OrderStatusModel tempOSM); DeviceProcessLogShow($"订单:【{tempOSM.SubOrderId}】, 状态:【{tempOSM.Status}】, API状态修改成功"); }); } Thread.Sleep(100); }, $"订单状态更新接口{DeviceId}", true); } private void TempOrderChange(string subid, ORDER_STATUS oRDER_STATUS, Action complete) { var res = mORKS.doOrderEvents.FirstOrDefault(p => p.MorkOrder.SuborderId == subid); string goodName = string.Empty; string SortNum = string.Empty; if (res != null) { goodName = res.MorkOrder.GoodsName; SortNum = res.MorkOrder.SortNum.ToString(); } if (!string.IsNullOrEmpty(goodName) && !string.IsNullOrEmpty(SortNum)) { EventBus.GetInstance.Publish(new OrderStatusChangedEvent() { SortNum = SortNum, GoodName = goodName, Status = oRDER_STATUS, SubOrderId = subid, deviceClientType = DeviceType }, e => { complete?.Invoke(); }); 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) { DataServer.GetInstance.morkS.MakeOrder.RemoveAt(index); DataServer.GetInstance.morkS.MakeOrderOver.Add(new OrderMakeModel() { Status = oRDER_STATUS, GoodName = goodName, SortNum = SortNum, StopTime = DateTime.Now.ToString("HH:mm:ss") }); } 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); } else DataServer.GetInstance.morkS.MakeOrder.ElementAt(index).Status = oRDER_STATUS; } else { DataServer.GetInstance.morkS.MakeOrder.Add(new OrderMakeModel() { Status = oRDER_STATUS, GoodName = goodName, SortNum = SortNum, StartTime = DateTime.Now.ToString("HH:mm:ss") }); } } } #endregion private void OrderChange(string subid, ORDER_STATUS oRDER_STATUS) { osm.Enqueue(new OrderStatusModel() { SubOrderId = subid, Status = oRDER_STATUS }); return; var res = mORKS.doOrderEvents.FirstOrDefault(p => p.MorkOrder.SuborderId == subid); string goodName = string.Empty; string SortNum = string.Empty; if (res != null) { goodName = res.MorkOrder.GoodsName; SortNum = res.MorkOrder.SortNum.ToString(); } //if (mORKS.doe.ContainsKey(subid)) //{ // goodName = mORKS.doe[subid].MorkOrder.GoodsName; // SortNum = mORKS.doe[subid].MorkOrder.SortNum.ToString(); 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) { DataServer.GetInstance.morkS.MakeOrder.RemoveAt(index); DataServer.GetInstance.morkS.MakeOrderOver.Add(new OrderMakeModel() { Status = oRDER_STATUS, GoodName = goodName, SortNum = SortNum, StopTime = DateTime.Now.ToString("HH:mm:ss") }); } 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); } else { DataServer.GetInstance.morkS.MakeOrder.ElementAt(index).Status = oRDER_STATUS; } } else { DataServer.GetInstance.morkS.MakeOrder.Add(new OrderMakeModel() { Status = oRDER_STATUS, GoodName = goodName, SortNum = SortNum, StartTime = DateTime.Now.ToString("HH:mm:ss") }); } //mORKS.doe.Remove(subid, out _); } //} //var res = mORKS.doOrderEvents.FirstOrDefault(p => p.MorkOrder.SuborderId == subid); //string goodName = string.Empty; //string SortNum = string.Empty; //if (res != null) //{ // goodName = res.MorkOrder.GoodsName; // SortNum = res.MorkOrder.SortNum.ToString(); //} //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) // { // DataServer.GetInstance.morkS.MakeOrder.RemoveAt(index); // DataServer.GetInstance.morkS.MakeOrderOver.Add(new OrderMakeModel() // { // Status = oRDER_STATUS, // GoodName = goodName, // SortNum = SortNum, // StopTime = DateTime.Now.ToString("HH:mm:ss") // }); // } // 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); // } // else // { // DataServer.GetInstance.morkS.MakeOrder.ElementAt(index).Status = oRDER_STATUS; // } //} //else //{ // DataServer.GetInstance.morkS.MakeOrder.Add(new OrderMakeModel() // { // Status = oRDER_STATUS, // GoodName = goodName, // SortNum = SortNum, // StartTime = DateTime.Now.ToString("HH:mm:ss") // }); //} } private void GetStatus(string key, Action action) { if (peripheralStatus.ContainsKey(key)) { if (peripheralStatus[key] != null) { action?.Invoke(peripheralStatus[key]); } } } public override void ReadData() { //DataServer.GetInstance.morkS.Alarm.Clear(); //alarms.ForEach(item => //{ // DataServer.GetInstance.morkS.Alarm.Add(new AlarmModel() // { // AlarmTime = $"{item.Date} {item.Time}", // AlarmMs = item.Info // }); //}); GetStatus("M0.1", new Action((obj) => { if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 7) { Initing = !bools[0]; mORKS.InitComplete = bools[0]; mORKS.MoveScrewRodInitCom = bools[1]; mORKS.SacrificialVesselInitCom = bools[2]; mORKS.CylinderInitCom = bools[3]; mORKS.NoodleCookerInitCom = bools[4]; mORKS.RobotInitCom = bools[5]; mORKS.SiloInitCom = bools[6]; alarm.DeviceNoInit = !mORKS.InitComplete; alarm.MoveScrewRodNoInit = !mORKS.MoveScrewRodInitCom; alarm.SacrificialVesselNoInit = !mORKS.SacrificialVesselInitCom; alarm.CylinderNoInit = !mORKS.CylinderInitCom; alarm.NoodleCookerNoInit = !mORKS.NoodleCookerInitCom; alarm.RobotNoInit = !mORKS.RobotInitCom; alarm.SiloNoInit = !mORKS.SiloInitCom; } })); GetStatus("M10.0", new Action((obj) => { if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 2) { mORKS.AllowInvertedFace = bools[0]; mORKS.DiningComplete = bools[1]; } })); GetStatus("M10.4", new Action((obj) => { if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 1) { mORKS.DropBowlMechanismStatus = bools[0]; } })); GetStatus("M12.2", new Action((obj) => { if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 1) { mORKS.FixedFlag = bools[0]; } })); GetStatus("M13.5", new Action((obj) => { if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 1) { mORKS.SiloInPlace = bools[0]; } })); GetStatus("M16.7", new Action((obj) => { if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 1) { mORKS.RobotTakeNoodleCom = bools[0]; } })); GetStatus("M17.4", new Action((obj) => { if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 1) { mORKS.RobotStatus = bools[0]; } })); GetStatus("M18.0", new Action((obj) => { if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 5) { mORKS.SmallBowlYesOrNoCheck = bools[0]; mORKS.LargeBowYesOrNoCheck = bools[1]; mORKS.TurntableLowPosition = bools[2]; mORKS.TurntableHighPosition = bools[3]; alarm.Supply2_LossBowl = !mORKS.SmallBowlYesOrNoCheck; alarm.Supply1_LossBowl = !mORKS.LargeBowYesOrNoCheck; } })); GetStatus("VW17", new Action((obj) => { if (obj is ushort[] ushorts && ushorts.Length > 0 && ushorts.Length <= 1) { var tt = ushorts.ToBytes().ToUShorts(); for (byte i = 0; i < 6; i++) { if (RTrig.GetInstance($"CookNoodleCom{i + 1}").Start(tt[0].GetBitValue((byte)(i + 1)))) { if (!string.IsNullOrEmpty(mORKS.CookNodelId[i])) mORKS.CookNoodleCom[i] = true; } } //mORKS.CookNoodleCom[0] = tt[0].GetBitValue(1); //mORKS.CookNoodleCom[1] = tt[0].GetBitValue(2); //mORKS.CookNoodleCom[2] = tt[0].GetBitValue(3); //mORKS.CookNoodleCom[3] = tt[0].GetBitValue(4); //mORKS.CookNoodleCom[4] = tt[0].GetBitValue(5); //mORKS.CookNoodleCom[5] = tt[0].GetBitValue(6); mORKS.Heating = ushorts[0].GetBitValue(15); mORKS.TemperatureReaches = ushorts[0].GetBitValue(16); alarm.MachineLowTemperature = !mORKS.TemperatureReaches; } })); GetStatus("VW770", new Action((obj) => { if (obj is ushort[] ushorts && ushorts.Length > 0 && ushorts.Length <= 1) { mORKS.CurrentFeedbackLoc = ushorts[0]; } })); mORKS.TakeBowlTaskCount = mORKS.TakeBowlTask.Count; mORKS.RBTakeNoodleTaskCount = mORKS.RBTakeNoodleTask.Count; for (int i = 0; i < Json.Data.parSets.Count; i++) { mORKS.nsm.ElementAt(i).IsShield = Json.Data.parSets.ElementAt(i).IsShield; mORKS.nsm.ElementAt(i).NoodleCookerStatus = mORKS.NoodleCookerStatus[i]; } } /// 数据解析 private void DataParse() { EventBus.GetInstance.Subscribe(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle) { 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; OrderCount++; if (DateTime.Now.Subtract(Json.Data.StatisticsTime).Days != 0) Json.Data.Count = 0; Json.Data.StatisticsTime = DateTime.Now; Json.Data.Count++; Json.Save(); OrderChange(order.MorkOrder.SuborderId, ORDER_STATUS.WAIT); DeviceProcessLogShow($"接收到{OrderCount}次订单,订单ID:{order.MorkOrder.SuborderId}"); mORKS.HistorySuborderId.Add(order.MorkOrder.SuborderId); foreach (var item in order.MorkOrder.GoodBatchings) { var res = orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId); if (res != null) { if (ushort.TryParse(res.BatchingLoc, out ushort loc)) { if (loc >= 1 && loc <= 5) { if (mORKS.RBTakeNoodleTask.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null) mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { GoodName = order.MorkOrder.GoodsName, Loc = ushort.Parse(res.BatchingLoc), SuborderId = order.MorkOrder.SuborderId, SortNum = order.MorkOrder.SortNum, BatchingId = res.BatchingId }); } else if (loc >= 10 && loc <= 11) { int index = 0; if (recipeBoms != null) { index = Array.FindIndex(recipeBoms.RecipeIds?.ToArray(), p => p.RecipeId == order.MorkOrder.RecipeId); index++; } if (mORKS.TakeBowlTask.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null) mORKS.TakeBowlTask.Enqueue(new OrderLocInfo() { BatchingId = res.BatchingId, GoodName = order.MorkOrder.GoodsName, Loc = ushort.Parse(res.BatchingLoc), SuborderId = order.MorkOrder.SuborderId, SortNum = order.MorkOrder.SortNum, RecipeNumber = (index >= 1 && index <= 10) ? (ushort)index : (ushort)0 }); } } } } } }); } public override void MainTask() { mORKS.AllowRun = mORKS.InitComplete; if (Json.Data.IsVerify) IsHealth = mORKS.InitComplete; else IsHealth = true; TakeBowlTask(); TakeNoodleTask(); OutNoodleTask(); SingleDetect(); TurntableControl(); } private void BowlControl(OrderLocInfo orderLocInfo) { if (orderLocInfo.Loc >= 10 && orderLocInfo.Loc <= 11) { //mORKS.TakeBowlId = orderLocInfo.SuborderId; mORKS.TakeBowName = orderLocInfo.GoodName; mORKS.TakeBowSortNum = orderLocInfo.SortNum; TakeBowlControl(orderLocInfo.Loc); //OrderChange(mORKS.TakeBowlId, ORDER_STATUS.COOKING); OrderChange(orderLocInfo.SuborderId, ORDER_STATUS.COOKING); //DeviceProcessLogShow($"订单【{mORKS.TakeBowlId}】执行取碗控制,位置:[{orderLocInfo.Loc}]"); //2023-8-5修改修改取碗打印日志。 //DeviceProcessLogShow($"订单【{orderLocInfo.SuborderId}】执行取碗控制,位置:[{orderLocInfo.Loc}]"); DeviceProcessLogShow($"执行取碗控制,位置:[{orderLocInfo.Loc}]"); mORKS.TakeBowlInterlock = true; } } /// 取碗控制 private void TakeBowlTask() { if (mORKS.AllowRun && mORKS.TakeBowlTask.Count > 0 && !mORKS.DropBowlMechanismStatus && !mORKS.TakeBowlInterlock) { ushort BowLoc = 0; 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); } else { foreach (var item in res) { if (ushort.TryParse(item.BatchingLoc, out ushort loc)) { if (loc == 10 && mORKS.SmallBowlYesOrNoCheck) { BowLoc = loc; break; } else if (loc == 11 && mORKS.LargeBowYesOrNoCheck) { BowLoc = loc; break; } } } if (BowLoc >= 10 && BowLoc <= 11) { if (mORKS.TakeBowlTask.TryDequeue(out OrderLocInfo orderLocInfo)) { orderLocInfo.Loc = BowLoc; BowlControl(orderLocInfo); } } } } } /// 转台控制 private void TurntableControl() { if (Global.EnableLocalSimOrder) { //不做轮询,直接取面,模拟订单使用 if (mORKS.SiloInPlace && !mORKS.Feeding && mORKS.InitComplete && !mORKS.AllowTakeNoodle && mORKS.RBTakeNoodleTask.Count > 0) { if (mORKS.TurntableLowPosition) { TurntableStart(mORKS.RBTakeNoodleTask.ElementAt(0).Loc); mORKS.TurntableLocLists.Clear(); mORKS.AllowTakeNoodle = true; DeviceProcessLogShow($"控制机器人去转台【{mORKS.RBTakeNoodleTask.ElementAt(0).Loc}】号位置取面"); } } } else { //正常轮询 if (Delay.GetInstance("到位检测延时").Start(mORKS.SiloInPlace, 2)) { 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) { var res = result.FirstOrDefault(P => P.BatchingLoc == mORKS.CurrentFeedbackLoc.ToString()); if (mORKS.TurntableLowPosition && res != null) { TurntableStart(mORKS.CurrentFeedbackLoc); mORKS.TurntableLocLists.Clear(); mORKS.AllowTakeNoodle = true; DeviceProcessLogShow($"控制机器人去转台【{mORKS.CurrentFeedbackLoc}】号位置取面"); } else { if (!mORKS.TurntableInterlock) { foreach (var item in result) { if (ushort.TryParse(item.BatchingLoc, out ushort loc)) { if (mORKS.CurrentFeedbackLoc != loc && !mORKS.TurntableLocLists.Contains(loc)) { if (!mORKS.TurntableLowPosition) { DeviceProcessLogShow($"执行了转台启动互锁信号复位"); } TurntableStart(loc); DeviceProcessLogShow($"没有物料检测的启动转台控制,转台位置:[{loc}]"); break; } else if (mORKS.CurrentFeedbackLoc == loc && !mORKS.TurntableLocLists.Contains(loc)) mORKS.TurntableLocLists.Add(loc); } } } } } else DeviceProcessLogShow("未找到可用的物料信息"); } } } //补料中检测 if (RTrig.GetInstance("mORKS.Feeding").Start(mORKS.Feeding)) { mORKS.AllowTakeNoodle = false; mORKS.TakeNoodleInterlock = false; } //转台到位检测 if (RTrig.GetInstance("TurntableInPlace").Start(mORKS.SiloInPlace && mORKS.CurrentLoc == mORKS.CurrentFeedbackLoc)) { mORKS.TurntableInterlock = false; DeviceProcessLogShow("转台到位检测"); } //补料完成检测 if (RTrig.GetInstance("FeedComplete").Start(mORKS.FeedComplete)) { if (!mORKS.AllowTakeNoodle && mORKS.TurntableLocLists.Count > 0) { mORKS.TurntableLocLists.Clear(); mORKS.TurntableInterlock = false; DeviceProcessLogShow("补料完成检测"); } } } /// 取面任务 private void TakeNoodleTask() { //取面控制 if (mORKS.AllowRun && mORKS.RobotStatus && !mORKS.Feeding && !mORKS.RobotTaskInterlock && mORKS.AllowTakeNoodle && mORKS.SiloInPlace && !mORKS.TakeNoodleInterlock && mORKS.RBTakeNoodleTask.Count > 0) { if (mORKS.CurrentLoc == mORKS.CurrentFeedbackLoc) { //int loc = Array.FindIndex(mORKS.NoodleCookerStatus, p => p == false);//查找煮面炉空闲位置 int loc = mORKS.nsm.ToList().FindIndex(p => p.NoodleCookerStatus == false && p.IsShield == false);//查找煮面炉空闲位置 if (loc >= 0 && loc <= 5) { //if (!Json.Data.parSets.ElementAt(loc).IsShield)//检查该煮面篮是否被屏蔽 //{ if (mORKS.RBTakeNoodleTask.TryDequeue(out OrderLocInfo orderLocInfo)) { //写入煮面时间 //List values = new List(); //values.Add(Json.Data.parSets.ElementAt(loc).Minute); //values.Add(Json.Data.parSets.ElementAt(loc).Second); //WriteData($"VW{324 + (loc * 4)}", values.ToArray()); if (mORKS.CurrentFeedbackLoc >= 1 && mORKS.CurrentFeedbackLoc <= 5) { var x = Json.Data.DishLibraryParSets.FirstOrDefault(p => p.TextBlockContext == mORKS.CurrentFeedbackLoc.ToString()); if (x != null) { List values = new List(); values.Add(x.Minute); values.Add(x.Second); WriteData($"VW{324 + (loc * 4)}", values.ToArray()); DeviceProcessLogShow($"转盘位置[{mORKS.CurrentFeedbackLoc}]:写入煮面时间{x.Minute}分{x.Second}秒。"); } } mORKS.CurrentLoc = 0; mORKS.CookNodelId[loc] = orderLocInfo.SuborderId; mORKS.NoodleCookerStatus[loc] = true; SetFallNoodleLoc((ushort)(loc + 1)); //机器人开始取面 OrderChange(orderLocInfo.SuborderId, ORDER_STATUS.COOKING); DeviceProcessLogShow($"订单【{orderLocInfo.SuborderId}】,机器人倒面至【{loc + 1}】号煮面栏"); mORKS.TakeNoodleInterlock = true; } } } } } /// 出餐控制 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) //{ // if (mORKS.CookNoodleCom[loc]) // { // SetTakeNoodleLoc((ushort)(loc + 1)); // mORKS.NoodleCookerStatus[loc] = false; // WriteData($"VW260", (ushort)0);//设置出汤时间 // OrderChange(mORKS.IngredientsCompleteId, ORDER_STATUS.COMPLETED_COOK); // DeviceProcessLogShow($"订单【{mORKS.IngredientsCompleteId}】制作完成"); // mORKS.CookCompleteFlatBit = true; // mORKS.OutMealId = mORKS.IngredientsCompleteId; // mORKS.OutMealName = mORKS.IngredientsCompleteName; // mORKS.OutMealSortNum = mORKS.IngredientsCompleteSortNum; // mORKS.IngredientsCompleteId = string.Empty; // mORKS.CookNodelId[loc] = string.Empty; // DeviceProcessLogShow($"{loc + 1} 号位置出餐控制,订单ID:{mORKS.OutMealId}"); // mORKS.CookNoodleCom[loc] = false; // } //} #endregion 修改之前的代码 for (int loc = 0; loc < mORKS.CookNodelId.Length; loc++) { if (mORKS.CookNoodleCom[loc] && !mORKS.RobotOutDinnigLock) { SetTakeNoodleLoc((ushort)(loc + 1)); mORKS.NoodleCookerStatus[loc] = false; WriteData($"VW260", (ushort)0);//设置出汤时间 OrderChange(mORKS.CookNodelId[loc], ORDER_STATUS.COMPLETED_COOK); DeviceProcessLogShow($"订单【{mORKS.CookNodelId[loc]}】制作完成"); mORKS.CookCompleteFlatBit = true; mORKS.OutMealId = mORKS.CookNodelId[loc]; mORKS.OutMealName = mORKS.IngredientsCompleteName; mORKS.OutMealSortNum = mORKS.IngredientsCompleteSortNum; mORKS.IngredientsCompleteId = string.Empty; mORKS.CookNodelId[loc] = string.Empty; DeviceProcessLogShow($"{loc + 1} 号位置出餐控制,订单ID:{mORKS.OutMealId}"); mORKS.CookNoodleCom[loc] = false; mORKS.RobotOutDinnigLock = true; } } } } /// 信号检测 private void SingleDetect() { //允许倒面信号检测 if (RTrig.GetInstance("AllowFallNoodle").Start(mORKS.AllowInvertedFace)) { //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) { OrderChange(mORKS.OutMealId, ORDER_STATUS.COMPLETED_TAKE); DeviceProcessLogShow($"订单【{mORKS.OutMealId}】取餐完成"); WriteData("M10.1", false); var orderEvent = mORKS.doOrderEvents.FirstOrDefault(order => order.MorkOrder.SuborderId == mORKS.OutMealId); mORKS.OutMealSortNum = orderEvent?.MorkOrder.SortNum ?? 0; DeviceProcessLogShow($"出餐订单序号【{mORKS.OutMealSortNum}】"); VoiceAPI.Speak(mORKS.OutMealSortNum.ToString()); //DeviceProcessLogShow($"叫号系统通知主题【MORKS/VoiceCall/{DeviceId}】"); //Plugin.GetInstance.GetPlugin().Publish($"MORKS/VoiceCall/{DeviceId}", mORKS.OutMealSortNum.ToString()); mORKS.CookCompleteFlatBit = false; mORKS.OutMealId = string.Empty; mORKS.OutMealName = string.Empty; mORKS.OutMealSortNum = 0; } //机器人取面完成信号检测 if (RTrig.GetInstance("TakeNoodleComplete").Start(mORKS.RobotTakeNoodleCom)) { mORKS.TakeNoodleInterlock = false; mORKS.AllowTakeNoodle = false; mORKS.TurntableInterlock = false; DeviceProcessLogShow("检测到机器人取面完成信号"); } int OutMealRequstCount = mORKS.CookNoodleCom.Where(p => p == true).ToList().Count; //int mlCount = mORKS.NoodleCookerStatus.Where(p => p == true).ToList().Count - Json.Data.parSets.Where(x => x.IsShield == true).ToList().Count; int mlCount = mORKS.nsm.Where(p => p.NoodleCookerStatus == true && p.IsShield == false).ToList().Count; int index = Array.FindIndex(mORKS.CookNodelId, p => p == mORKS.IngredientsCompleteId); bool isok = index >= 0 && index < mORKS.CookNoodleCom.Length && mORKS.CookNoodleCom[index]; 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); } /// 语音提醒取餐 /// private void WaitMeaLSpeak(string meal) { //VoiceAPI.m_SystemPlayWav(@"Vioce\电子提示音.wav"); //Thread.Sleep(1000); //if (meal != null) mORKS.speech.Speak(meal); //VoiceAPI.m_SystemPlayWav(@"Vioce\取餐通知.wav"); } #region PLC 控制函数 private void WriteData(string address, object value) { EventBus.GetInstance.Publish(new WriteModel() { DeviceId = DeviceId, Address = address, Value = value }); } /// 设备初始化 public async void DeviceInit() { WriteData("M0.0", true); await Task.Delay(1000); WriteData("M0.0", false); } /// 取碗控制 /// private void TakeBowlControl(ushort loc) { if (loc == 10)//一次性碗 { WriteData("M9.1", true); } else if (loc == 11)//大碗 { WriteData("M9.0", true); } } /// 启动转台 /// private void TurntableStart(ushort loc) { if (loc >= 1 && loc <= 5) { mORKS.CurrentLoc = loc; mORKS.TurntableInterlock = true; mORKS.TurntableLocLists.Add(loc); WriteData($"M13.{loc - 1}", true); } } /// 设置倒面位置 /// private void SetFallNoodleLoc(ushort loc) { if (loc >= 1 && loc <= 6) WriteData($"M14.{loc - 1}", true); } /// 设置出餐位置 /// private void SetTakeNoodleLoc(ushort loc) { if (loc >= 1 && loc <= 6) WriteData($"M15.{loc - 1}", true); } public override void SimOrder() { EventBus.GetInstance.Subscribe(0, delegate (IEvent @event, EventCallBackHandle callBackHandle) { if (@event != null && @event is MorksSimorderModel msm) { string guid = Guid.NewGuid().ToString(); if (msm.NoodleLoc >= 1 && msm.NoodleLoc <= 5) { mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { Loc = (ushort)msm.NoodleLoc, SuborderId = guid }); MessageLog.GetInstance.Show($"添加订单:面条位置【{(ushort)msm.NoodleLoc}】"); } if (msm.Bowloc >= 10 && msm.Bowloc <= 11) { mORKS.TakeBowlTask.Enqueue(new OrderLocInfo() { Loc = (ushort)msm.Bowloc, SuborderId = guid }); MessageLog.GetInstance.Show($"添加订单:碗位置【{(ushort)msm.Bowloc}】"); } } }); } #endregion PLC 控制函数 } }