|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818 |
- using System;
- using System.Collections.Generic;
- using BPA.Message.Enum;
- using BPASmartClient.Device;
- using BPASmartClient.EventBus;
- using BPASmartClient.Model;
- using BPASmartClient.Peripheral;
- using static BPASmartClient.EventBus.EventBus;
- using BPASmartClient.Helper;
- using System.Threading;
- using BPASmartClient.Message;
- using BPA.Message;
- using System.Linq;
- using BPASmartClient.Model.PLC;
- using System.Threading.Tasks;
- using System.Reflection;
- using BPASmartClient.MorkS.Model;
- using System.Collections.ObjectModel;
- using BPASmartClient.MorkS.ViewModel;
- using BPASmartClient.Business;
- using BPASmartClient.Model.小炒机;
- using BPA.Models;
- using System.Speech.Synthesis;
- using System.Windows.Forms;
- using System.Media;
-
- namespace BPASmartClient.MorkS
- {
- public class Control_Morks : BaseDevice
- {
- public override DeviceClientType DeviceType => DeviceClientType.MORKS;
- GVL_MORKS mORKS = new GVL_MORKS();
- Alarm alarm = new Alarm();
-
- public override void DoMain()
- {
-
-
- MonitorViewModel.DeviceId = DeviceId;
- ServerInit();
- DataParse();
-
- Json<MorksPar>.Read();
- if (Json<MorksPar>.Data.parSets == null) Json<MorksPar>.Data.parSets = new ObservableCollection<ParSet>();
- if (Json<MorksPar>.Data.parSets.Count < 6)
- {
- Json<MorksPar>.Data.parSets.Clear();
- for (int i = 0; i < 6; i++)
- {
- Json<MorksPar>.Data.parSets.Add(new ParSet()
- {
- CheckBoxContext = $"煮面口{i + 1}屏蔽",
- Minute = 1,
- Second = 0,
- IsShield = false,
- TextBlockContext = $"煮面口{i + 1}时间设定"
- });
- }
- }
-
- ActionManage.GetInstance.Register(new Action<object[]>((o) =>
- {
- if (o.Length > 0 )
- {
- Random rd = new Random();
- ThreadManage.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 = new Guid().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<object>((o) =>
- {
- if (o != null && o is WritePar writePar) WriteData(writePar.Address, writePar.Value);
- }), "WriteVW");
- ActionManage.GetInstance.Register(new Action<object>((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_MORKS();
- }
-
- public override void Stop()
- {
-
- }
-
- private void ServerInit()
- {
- //物料信息
- EventBus.EventBus.GetInstance().Subscribe<MaterialDeliveryEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
- {
- if (@event == null) return;
- if (@event is MaterialDeliveryEvent material)
- {
- orderMaterialDelivery = material.orderMaterialDelivery;
- }
- });
-
- //配方数据信息
- EventBus.EventBus.GetInstance().Subscribe<RecipeBomEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
- {
- if (@event == null) return;
- if (@event is RecipeBomEvent recipe)
- {
- recipeBoms = recipe.recipeBoms;
- WriteRecipeBoms();
- }
- });
-
-
- }
-
- private void OrderChange(string subid, ORDER_STATUS oRDER_STATUS)
- {
- 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.EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { SortNum = SortNum, GoodName = goodName, Status = oRDER_STATUS, SubOrderId = subid, deviceClientType = DeviceType });
- }
-
- private void GetStatus(string key, Action<object> action)
- {
- if (peripheralStatus.ContainsKey(key))
- {
- if (peripheralStatus[key] != null)
- {
- action?.Invoke(peripheralStatus[key]);
- }
- }
- }
-
- public override void ReadData()
- {
- GetStatus("M230.0", new Action<object>((obj) =>
- {
- if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 24)
- {
- alarm.MachineLeftLowTemperature = bools[0];
- alarm.MachineRightLowTemperature = bools[1];
- alarm.Supply1_LossBowl = bools[2];
- alarm.Supply2_LossBowl = bools[3];
- alarm.Supply1_ErrorOutBowl = bools[4];
- alarm.Supply2_ErrorOutBowl = bools[5];
- alarm.PushBowlCylinderError = bools[6];
- alarm.NoodleMacCommunicateError = bools[7];
- alarm.DosingMacCommunicateError = bools[8];
- alarm.RobotMacCommunicateError = bools[9];
- alarm.DeviceEstop = bools[10];
- alarm.RobotInitError = bools[11];
- alarm.RobotUrgentStop = bools[12];
- alarm.RobotNotInRemoteMode = bools[13];
- alarm.RobotNotInReady = bools[14];
- alarm.RobotSelfInException = bools[15];
- alarm.LeftLackWater = bools[16];
- alarm.RightLackWater = bools[17];
- alarm.SvrewInitFail = bools[18];
- alarm.TurntableInitFail = bools[19];
- alarm.RobotInitFail = bools[20];
- alarm.NoodleCookerInitFail = bools[21];
- alarm.PushBowlInitFail1 = bools[22];
- alarm.PushBowlInitFail2 = bools[23];
- }
- }));
-
- GetStatus("M0.3", new Action<object>((obj) =>
- {
- if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 3)
- {
- mORKS.RobotTakeNoodle = bools[0];
- mORKS.RobotOutMeal = bools[1];
- mORKS.MoveTurntable = bools[2];
- }
- }));
-
- GetStatus("M100.0", new Action<object>((obj) =>
- {
- if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 16)
- {
- mORKS.InitComplete = bools[0];
- mORKS.TakeBowlIdle = bools[1];
- mORKS.TemperatureReached = bools[2];
- mORKS.AllowFallNoodle = bools[3];
- mORKS.RbTakeNoodleComplete = bools[4];
- mORKS.RbFallNoodleComplete = bools[5];
- mORKS.RbOutMealComplete = bools[6];
- mORKS.RobotIdle = bools[7];
- mORKS.TakeMealDetect = bools[8];
- mORKS.MissingBowl = bools[9];
- Initing = bools[10];
- mORKS.TurntableLowerLimit = bools[11];
- mORKS.MissingBowlSignal2 = bools[12];
- mORKS.TurntableUpLimit = bools[13];
- mORKS.FeedComplete = bools[14];
- mORKS.TurntableMoveInPlace = bools[15];
- }
-
- }));
-
- GetStatus("M235.0", new Action<object>((obj) =>
- {
- if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 1)
- {
- mORKS.Error = bools[0];
- }
- }));
-
-
- GetStatus("M102.0", new Action<object>((obj) =>
- {
- if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 7)
- {
- for (int i = 0; i < 6; i++)
- {
- mORKS.NoodleCookerStatus[i] = bools[i];
- }
- mORKS.Feeding = bools[6];
- }
- }));
-
- GetStatus("M103.0", new Action<object>((obj) =>
- {
- if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 6)
- {
- for (int i = 0; i < 6; i++)
- {
- mORKS.CookNoodlesComplete[i] = bools[i];
- }
- }
-
- }));
-
- GetStatus("VW372", new Action<object>((obj) =>
- {
- if (obj is ushort[] UshortValue && UshortValue.Length > 0 && UshortValue.Length <= 1)
- mORKS.TurntableFeedbackloc = UshortValue[0];
- }));
- }
-
- /// <summary>
- /// 数据解析
- /// </summary>
- private void DataParse()
- {
- EventBus.EventBus.GetInstance().Subscribe<DoOrderEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle)
- {
- if (@event == null) return;
- if (@event is DoOrderEvent order)
- {
- mORKS.doOrderEvents.Add(order);
- if (order.MorkOrder.GoodBatchings == null) return;
- OrderCount++;
- OrderChange(order.MorkOrder.SuborderId, ORDER_STATUS.WAIT);
- DeviceProcessLogShow($"接收到{OrderCount}次订单");
- 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, 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,
- RecipeNumber = (index >= 1 && index <= 10) ? (ushort)index : (ushort)0
- });
- }
- }
- }
- }
- }
- });
- }
-
- public override void MainTask()
- {
- mORKS.AllowRun = mORKS.InitComplete;
- if (Json<KeepDataBase>.Data.IsVerify)
- IsHealth = mORKS.Error && mORKS.InitComplete;
- else
- IsHealth = true;
-
- TakeBowlTask();
-
- TakeNoodleTask();
-
- OutNoodleTask();
-
- SingleDetect();
-
- TurntableControl();
-
- var data = new List<bool>();
- for (int i = 0; i < Json<MorksPar>.Data.parSets.Count; i++)
- {
- data.Add(Json<MorksPar>.Data.parSets.ElementAt(i).IsShield);
- }
-
- WriteControl("M260.0", data.ToArray());
-
- }
-
- private void BowlControl(OrderLocInfo orderLocInfo)
- {
- if (orderLocInfo.Loc >= 10 && orderLocInfo.Loc <= 11)
- {
- mORKS.TakeBowlId = orderLocInfo.SuborderId;
- mORKS.TakeBowName = orderLocInfo.GoodName;
- TakeBowlControl(orderLocInfo.Loc);
- SetRecipeNumber(orderLocInfo.RecipeNumber);
- OrderChange(mORKS.TakeBowlId, ORDER_STATUS.COOKING);
- DeviceProcessLogShow($"订单【{ mORKS.TakeBowlId}】执行取碗控制,位置:[{orderLocInfo.Loc}]");
- mORKS.TakeBowlInterlock = true;
- }
- }
-
- /// <summary>
- /// 取碗控制
- /// </summary>
- private void TakeBowlTask()
- {
- if (mORKS.AllowRun && mORKS.TakeBowlTask.Count > 0 && !mORKS.TakeBowlIdle && !mORKS.TakeBowlInterlock)
- {
- DeviceProcessLogShow("开始取碗流程");
- 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))
- {
- //DeviceProcessLogShow($"位置:={loc},检测开关1:{alarm.Supply1_LossBowl},检测开关1:{alarm.Supply2_LossBowl}");
- if (loc == 10 && !alarm.Supply1_LossBowl)
- {
- BowLoc = loc;
- break;
- }
- else if (loc == 11 && !alarm.Supply2_LossBowl)
- {
- BowLoc = loc;
- break;
- }
- }
- }
-
- if (BowLoc >= 10 && BowLoc <= 11)
- {
- if (mORKS.TakeBowlTask.TryDequeue(out OrderLocInfo orderLocInfo))
- {
- orderLocInfo.Loc = BowLoc;
- BowlControl(orderLocInfo);
- }
- }
- }
- }
- }
-
- /// <summary>
- /// 转台控制
- /// </summary>
- private void TurntableControl()
- {
- if (Global.EnableLocalSimOrder)
- {
- //不做轮询,直接取面,模拟订单使用
- if (mORKS.TurntableMoveInPlace && !mORKS.Feeding && mORKS.InitComplete && !mORKS.AllowTakeNoodle && mORKS.RBTakeNoodleTask.Count > 0)
- {
- if (mORKS.TurntableLowerLimit)
- {
- TurntableStart(mORKS.RBTakeNoodleTask.ElementAt(0).Loc);
- mORKS.TurntableLocLists.Clear();
- mORKS.AllowTakeNoodle = true;
- DeviceProcessLogShow($"控制机器人去转台【{mORKS.RBTakeNoodleTask.ElementAt(0).Loc}】号位置取面");
- }
- }
- }
- else
- {
- //正常轮询
- if (mORKS.TurntableMoveInPlace && !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.TurntableFeedbackloc.ToString());
- if (mORKS.TurntableLowerLimit && res != null)
- {
- TurntableStart(mORKS.TurntableFeedbackloc);
- mORKS.TurntableLocLists.Clear();
- mORKS.AllowTakeNoodle = true;
- DeviceProcessLogShow($"控制机器人去转台【{mORKS.TurntableFeedbackloc}】号位置取面");
- }
- else
- {
- if (!mORKS.TurntableInterlock)
- {
- foreach (var item in result)
- {
- if (ushort.TryParse(item.BatchingLoc, out ushort loc))
- {
- if (mORKS.TurntableFeedbackloc != loc && !mORKS.TurntableLocLists.Contains(loc))
- {
- if (!mORKS.TurntableLowerLimit)
- {
- WriteData("M32.7", false);
- DeviceProcessLogShow($"执行了转台启动互锁信号复位");
- }
- TurntableStart(loc);
- DeviceProcessLogShow($"没有物料检测的启动转台控制,转台位置:[{loc}]");
- break;
- }
- else if (mORKS.TurntableFeedbackloc == loc && !mORKS.TurntableLocLists.Contains(loc)) mORKS.TurntableLocLists.Add(loc);
- }
- }
- }
- }
- }
- else DeviceProcessLogShow("未找到可用的物料信息");
- }
- }
-
- //if (DelayRTrig.GetInstance("互锁信号复位").Start(!mORKS.TurntableLowerLimit && mORKS.TurntableMoveInPlace, 2))
- //{
- // if (!mORKS.TurntableLowerLimit)
- // {
- // WriteData("M32.7", false);
- // DeviceProcessLogShow($"执行了转台启动互锁信号复位");
- // }
- //}
-
- //补料中检测
- if (RTrig.GetInstance("mORKS.Feeding").Start(mORKS.Feeding))
- {
- mORKS.AllowTakeNoodle = false;
- mORKS.TakeNoodleInterlock = false;
- }
-
- //转台到位检测
- if (RTrig.GetInstance("TurntableInPlace").Start(mORKS.TurntableMoveInPlace && mORKS.CurrentLoc == mORKS.TurntableFeedbackloc))
- {
- mORKS.CurrentLoc = 0;
- 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("补料完成检测");
- }
- }
-
- }
-
- /// <summary>
- /// 取面任务
- /// </summary>
- private void TakeNoodleTask()
- {
- //取面控制
- if (mORKS.AllowRun && mORKS.RobotIdle && !mORKS.Feeding && !mORKS.RobotTaskInterlock && mORKS.AllowTakeNoodle && mORKS.TurntableMoveInPlace && !mORKS.TakeNoodleInterlock && !mORKS.OutNoodleing && mORKS.RBTakeNoodleTask.Count > 0)
- {
- int loc = Array.FindIndex(mORKS.NoodleCookerStatus, p => p == false);//查找煮面炉空闲位置
- if (loc >= 0 && loc <= 5)
- {
- if (mORKS.RBTakeNoodleTask.TryDequeue(out OrderLocInfo orderLocInfo))
- {
- mORKS.CookNodelId[loc] = orderLocInfo.SuborderId;
- SetFallNoodleLoc((ushort)(loc + 1));
- //机器人开始取面
- RobotTakeNoodle();
- OrderChange(orderLocInfo.SuborderId, ORDER_STATUS.COOKING);
- DeviceProcessLogShow($"订单【{orderLocInfo.SuborderId}】,机器人倒面至【{loc + 1}】号煮面栏");
- //写入煮面时间
- List<ushort> values = new List<ushort>();
- values.Add(Json<MorksPar>.Data.parSets.ElementAt(loc).Minute);
- values.Add(Json<MorksPar>.Data.parSets.ElementAt(loc).Second);
- WriteData($"VW{116 + (loc * 6)}", values.ToArray());
- mORKS.TakeNoodleInterlock = true;
- }
- }
- }
- }
-
- /// <summary>
- /// 出餐控制
- /// </summary>
- private void OutNoodleTask()
- {
- if (mORKS.AllowFallNoodle && mORKS.RobotTaskInterlock && !mORKS.TakeNoodleInterlock && mORKS.RobotIdle && !mORKS.TakeMealDetect)
- {
- int loc = Array.FindIndex(mORKS.CookNodelId, p => p == mORKS.IngredientsCompleteId && p.Length > 0);
- if (loc >= 0 && loc <= 5)
- {
- if (mORKS.CookNoodlesComplete[loc])
- {
- SetTakeNoodleLoc((ushort)(loc + 1));
- RobotOutMeal();
- CookNoodleStatusReset((ushort)(loc + 1));
- ResetAllowFallNoodle();
-
-
- //新增,待测试
- if (mORKS.RbOutMealComplete)
- {
- ResetCookComplete();
- mORKS.CookCompleteFlatBit = false;
- DeviceProcessLogShow("取餐过程中复位出餐完成信号");
- }
-
-
- mORKS.OutMealId = mORKS.IngredientsCompleteId;
- mORKS.OutMealName = mORKS.IngredientsCompleteName;
- mORKS.IngredientsCompleteId = string.Empty;
- mORKS.CookNodelId[loc] = string.Empty;
- DeviceProcessLogShow($"{loc + 1} 号位置出餐控制,订单ID:{ mORKS.OutMealId}");
-
- mORKS.OutNoodleing = true;
- }
- }
- }
- }
-
- /// <summary>
- /// 信号检测
- /// </summary>
- private void SingleDetect()
- {
- //允许倒面信号检测
- if (RTrig.GetInstance("AllowFallNoodle").Start(mORKS.AllowFallNoodle))
- {
- mORKS.IngredientsCompleteId = mORKS.TakeBowlId;
- mORKS.IngredientsCompleteName = mORKS.TakeBowName;
- mORKS.TakeBowlId = string.Empty;
- mORKS.TakeBowName = string.Empty;
- DeviceProcessLogShow($"碗到位,允许到面,{mORKS.IngredientsCompleteId}");
- mORKS.TakeBowlInterlock = false;
- }
-
- //出餐完成信号检测
- if (RTrig.GetInstance("CompleteChange").Start(mORKS.RbOutMealComplete))
- {
- OrderChange(mORKS.OutMealId, ORDER_STATUS.COMPLETED_COOK);
- DeviceProcessLogShow($"订单【{mORKS.OutMealId}】制作完成");
- mORKS.CookCompleteFlatBit = true;
- mORKS.OutNoodleing = false;
- WaitMeaLSpeak(mORKS.OutMealName);
- }
-
- //取餐完成逻辑处理
- if (Delay.GetInstance("CompleteChange1").Start(mORKS.CookCompleteFlatBit && !mORKS.TakeMealDetect, 1))
- {
- OrderChange(mORKS.OutMealId, ORDER_STATUS.COMPLETED_TAKE);
- DeviceProcessLogShow($"订单【{mORKS.OutMealId}】取餐完成");
- ResetCookComplete();
- mORKS.CookCompleteFlatBit = false;
- mORKS.OutMealId = string.Empty;
- mORKS.OutMealName = string.Empty;
- }
-
- //机器人取面完成信号检测
- if (RTrig.GetInstance("TakeNoodleComplete").Start(mORKS.RbTakeNoodleComplete))
- {
- mORKS.TakeNoodleInterlock = false;
- mORKS.AllowTakeNoodle = false;
- mORKS.TurntableInterlock = false;
- DeviceProcessLogShow("机器人取面完成信号检测");
- TakeNoodleCompleteReset();
- }
-
- int OutMealRequstCount = mORKS.CookNoodlesComplete.Where(p => p == true).ToList().Count;
- int mlCount = mORKS.NoodleCookerStatus.Where(p => p == true).ToList().Count;
- int index = Array.FindIndex(mORKS.CookNodelId, p => p == mORKS.IngredientsCompleteId);
-
- bool isok = index >= 0 && index < mORKS.CookNoodlesComplete.Length && mORKS.CookNoodlesComplete[index];
-
- mORKS.PriorityJudgment = Delay.GetInstance("取餐优先级判断").Start(mORKS.TurntableLocLists.Count > 0 && !mORKS.TurntableLowerLimit, 4);
- //mORKS.RobotTaskInterlock = OutMealRequstCount > 0 && mORKS.AllowFallNoodle && (mlCount >= 2 || mORKS.RBTakeNoodleTask.Count == 0 || mORKS.PriorityJudgment);
- mORKS.RobotTaskInterlock = isok && mORKS.AllowFallNoodle && (mlCount >= 2 || mORKS.RBTakeNoodleTask.Count == 0 || mORKS.PriorityJudgment);
-
-
- }
- /// <summary>
- /// 语音提醒取餐
- /// </summary>
- /// <param name="meal"></param>
- private void WaitMeaLSpeak(string meal)
- {
- VoiceAPI.m_SystemPlayWav(@"Vioce\电子提示音.wav");
- Thread.Sleep(1000);
- mORKS.speech.Speak(meal);
- VoiceAPI.m_SystemPlayWav(@"Vioce\取餐通知.wav");
- }
-
- #region PLC 控制函数
-
- private void WriteData(string address, object value)
- {
- EventBus.EventBus.GetInstance().Publish(new WriteModel() { DeviceId = DeviceId, Address = address, Value = value });
- }
-
- /// <summary>
- /// 写入配方数据到 PLC
- /// </summary>
- private void WriteRecipeBoms()
- {
- List<ushort> recipeBoms = new List<ushort>();
- if (this.recipeBoms == null) return;
- foreach (var item in this.recipeBoms.RecipeIds)
- {
- foreach (var rec in item.Recipes)
- {
- recipeBoms.Add((ushort)rec);
- }
- }
- if (recipeBoms.Count > 0)
- {
- //配方数据地址范围:VW2000 - VW2278
- WriteData("VW2000", recipeBoms.ToArray());
- DeviceProcessLogShow("写配方成功");
- }
- else { DeviceProcessLogShow("配方数据为空"); }
- }
-
-
- /// <summary>
- /// 取面完成复位
- /// </summary>
- private void TakeNoodleCompleteReset()
- {
- WriteData("M100.4", false);
-
- }
-
- /// <summary>
- /// 指定煮面口状态复位
- /// </summary>
- /// <param name="num"></param>
- private void CookNoodleStatusReset(int num)
- {
- if (num >= 1 && num <= 6)
- {
- WriteData($"102.{num - 1}", false);
- DeviceProcessLogShow($"{num}号煮面口占用复位");
- }
-
- }
-
- /// <summary>
- /// 写配方编号
- /// </summary>
- /// <param name="num"></param>
- private void SetRecipeNumber(ushort num)
- {
- WriteData("VW0", num);
- }
-
- /// <summary>
- /// 启动转台
- /// </summary>
- /// <param name="loc"></param>
- private void TurntableStart(ushort loc)
- {
- mORKS.CurrentLoc = loc;
- mORKS.TurntableInterlock = true;
- mORKS.TurntableLocLists.Add(loc);
- WriteData("VW2", loc);
- WriteData("M0.5", true);
- }
-
- /// <summary>
- /// 设置倒面位置
- /// </summary>
- /// <param name="loc"></param>
- private void SetFallNoodleLoc(ushort loc)
- {
- WriteData("VW4", loc);
- }
-
- /// <summary>
- /// 设置取面位置
- /// </summary>
- /// <param name="loc"></param>
- private void SetTakeNoodleLoc(ushort loc)
- {
- WriteData("VW6", loc);
- }
-
- /// <summary>
- /// 取碗控制
- /// </summary>
- /// <param name="loc"></param>
- private void TakeBowlControl(ushort loc)
- {
- if (loc == 10)//小碗
- {
- WriteData("M0.1", true);
- }
- else if (loc == 11)//大碗
- {
- WriteData("M0.2", true);
- }
- }
-
- /// <summary>
- /// 机器人取面
- /// </summary>
- private void RobotTakeNoodle()
- {
- WriteData("M0.3", true);
- }
-
- /// <summary>
- /// 机器人取餐
- /// </summary>
- private void RobotOutMeal()
- {
- WriteData("M0.4", true);
- }
-
- /// <summary>
- /// 制作完成信号复位
- /// </summary>
- private void ResetCookComplete()
- {
- WriteData("M100.6", false);
- }
-
- /// <summary>
- /// 复位允许取面信号
- /// </summary>
- private void ResetAllowFallNoodle()
- {
- WriteData("M100.3", false);
- }
-
- /// <summary>
- /// 设备初始化
- /// </summary>
- public async void DeviceInit()
- {
- WriteData("M0.0", true);
- await Task.Delay(1000);
- WriteData("M0.0", false);
- }
-
- public override void SimOrder()
- {
- EventBus.EventBus.GetInstance().Subscribe<MorksSimorderModel>(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 });
- }
-
- if (msm.Bowloc >= 10 && msm.Bowloc <= 11)
- {
- mORKS.TakeBowlTask.Enqueue(new OrderLocInfo() { Loc = (ushort)msm.Bowloc, SuborderId = guid });
- }
- }
- });
- }
- #endregion
-
-
- }
- }
|