终端一体化运控平台
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Control_Morks.cs 32 KiB

2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  1. using System;
  2. using System.Collections.Generic;
  3. using BPA.Message.Enum;
  4. using BPASmartClient.Device;
  5. using BPASmartClient.EventBus;
  6. using BPASmartClient.Model;
  7. using BPASmartClient.Peripheral;
  8. using static BPASmartClient.EventBus.EventBus;
  9. using BPASmartClient.Helper;
  10. using System.Threading;
  11. using BPASmartClient.Message;
  12. using BPA.Message;
  13. using System.Linq;
  14. using BPASmartClient.Model.PLC;
  15. using System.Threading.Tasks;
  16. using System.Reflection;
  17. using BPASmartClient.MorkS.Model;
  18. using System.Collections.ObjectModel;
  19. using BPASmartClient.MorkS.ViewModel;
  20. using BPASmartClient.Business;
  21. using BPASmartClient.Model.小炒机;
  22. using BPA.Models;
  23. using System.Speech.Synthesis;
  24. using System.Windows.Forms;
  25. using System.Media;
  26. namespace BPASmartClient.MorkS
  27. {
  28. public class Control_Morks : BaseDevice
  29. {
  30. public override DeviceClientType DeviceType => DeviceClientType.MORKS;
  31. GVL_MORKS mORKS = new GVL_MORKS();
  32. Alarm alarm = new Alarm();
  33. public override void DoMain()
  34. {
  35. MonitorViewModel.DeviceId = DeviceId;
  36. ServerInit();
  37. DataParse();
  38. Json<MorksPar>.Read();
  39. if (Json<MorksPar>.Data.parSets == null) Json<MorksPar>.Data.parSets = new ObservableCollection<ParSet>();
  40. if (Json<MorksPar>.Data.parSets.Count < 6)
  41. {
  42. Json<MorksPar>.Data.parSets.Clear();
  43. for (int i = 0; i < 6; i++)
  44. {
  45. Json<MorksPar>.Data.parSets.Add(new ParSet()
  46. {
  47. CheckBoxContext = $"煮面口{i + 1}屏蔽",
  48. Minute = 1,
  49. Second = 0,
  50. IsShield = false,
  51. TextBlockContext = $"煮面口{i + 1}时间设定"
  52. });
  53. }
  54. }
  55. ActionManage.GetInstance.Register(new Action<object[]>((o) =>
  56. {
  57. if (o.Length > 0 )
  58. {
  59. Random rd = new Random();
  60. ThreadManage.GetInstance().StartLong(new Action(() =>
  61. {
  62. int NoodleLoc = (int)o[0] == 0? rd.Next(1, 6) : (int)o[0];
  63. int BowlLoc = (int)o[1] == 0 ? rd.Next(10, 12) : (int)o[1];
  64. string guid = new Guid().ToString();
  65. mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { Loc = (ushort)NoodleLoc, SuborderId = guid });
  66. MessageLog.GetInstance.Show($"添加订单:面条位置【{NoodleLoc}】");
  67. mORKS.TakeBowlTask.Enqueue(new OrderLocInfo() { Loc = (ushort)BowlLoc, SuborderId = guid });
  68. MessageLog.GetInstance.Show($"添加订单:碗位置【{BowlLoc}】");
  69. Thread.Sleep(60000);
  70. }), "ForOrder");
  71. }
  72. }), "EnableForOrder");
  73. ActionManage.GetInstance.Register(new Action<object>((o) =>
  74. {
  75. if (o != null && o is WritePar writePar) WriteData(writePar.Address, writePar.Value);
  76. }), "WriteVW");
  77. ActionManage.GetInstance.Register(new Action<object>((o) =>
  78. {
  79. if (o != null && o is WritePar writePar) WriteData(writePar.Address, writePar.Value);
  80. }), "WriteBools");
  81. ActionManage.GetInstance.Register(new Action(() => { DeviceInit(); }), "InitDevice");
  82. }
  83. public override void ResetProgram()
  84. {
  85. mORKS = null;
  86. mORKS = new GVL_MORKS();
  87. }
  88. public override void Stop()
  89. {
  90. }
  91. private void ServerInit()
  92. {
  93. //物料信息
  94. EventBus.EventBus.GetInstance().Subscribe<MaterialDeliveryEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  95. {
  96. if (@event == null) return;
  97. if (@event is MaterialDeliveryEvent material)
  98. {
  99. orderMaterialDelivery = material.orderMaterialDelivery;
  100. }
  101. });
  102. //配方数据信息
  103. EventBus.EventBus.GetInstance().Subscribe<RecipeBomEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  104. {
  105. if (@event == null) return;
  106. if (@event is RecipeBomEvent recipe)
  107. {
  108. recipeBoms = recipe.recipeBoms;
  109. WriteRecipeBoms();
  110. }
  111. });
  112. }
  113. private void OrderChange(string subid, ORDER_STATUS oRDER_STATUS)
  114. {
  115. var res = mORKS.doOrderEvents.FirstOrDefault(p => p.MorkOrder.SuborderId == subid);
  116. string goodName = string.Empty;
  117. string SortNum = string.Empty;
  118. if (res != null)
  119. {
  120. goodName = res.MorkOrder.GoodsName;
  121. SortNum = res.MorkOrder.SortNum.ToString();
  122. }
  123. EventBus.EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { SortNum = SortNum, GoodName = goodName, Status = oRDER_STATUS, SubOrderId = subid, deviceClientType = DeviceType });
  124. }
  125. private void GetStatus(string key, Action<object> action)
  126. {
  127. if (peripheralStatus.ContainsKey(key))
  128. {
  129. if (peripheralStatus[key] != null)
  130. {
  131. action?.Invoke(peripheralStatus[key]);
  132. }
  133. }
  134. }
  135. public override void ReadData()
  136. {
  137. GetStatus("M230.0", new Action<object>((obj) =>
  138. {
  139. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 24)
  140. {
  141. alarm.MachineLeftLowTemperature = bools[0];
  142. alarm.MachineRightLowTemperature = bools[1];
  143. alarm.Supply1_LossBowl = bools[2];
  144. alarm.Supply2_LossBowl = bools[3];
  145. alarm.Supply1_ErrorOutBowl = bools[4];
  146. alarm.Supply2_ErrorOutBowl = bools[5];
  147. alarm.PushBowlCylinderError = bools[6];
  148. alarm.NoodleMacCommunicateError = bools[7];
  149. alarm.DosingMacCommunicateError = bools[8];
  150. alarm.RobotMacCommunicateError = bools[9];
  151. alarm.DeviceEstop = bools[10];
  152. alarm.RobotInitError = bools[11];
  153. alarm.RobotUrgentStop = bools[12];
  154. alarm.RobotNotInRemoteMode = bools[13];
  155. alarm.RobotNotInReady = bools[14];
  156. alarm.RobotSelfInException = bools[15];
  157. alarm.LeftLackWater = bools[16];
  158. alarm.RightLackWater = bools[17];
  159. alarm.SvrewInitFail = bools[18];
  160. alarm.TurntableInitFail = bools[19];
  161. alarm.RobotInitFail = bools[20];
  162. alarm.NoodleCookerInitFail = bools[21];
  163. alarm.PushBowlInitFail1 = bools[22];
  164. alarm.PushBowlInitFail2 = bools[23];
  165. }
  166. }));
  167. GetStatus("M0.3", new Action<object>((obj) =>
  168. {
  169. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 3)
  170. {
  171. mORKS.RobotTakeNoodle = bools[0];
  172. mORKS.RobotOutMeal = bools[1];
  173. mORKS.MoveTurntable = bools[2];
  174. }
  175. }));
  176. GetStatus("M100.0", new Action<object>((obj) =>
  177. {
  178. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 16)
  179. {
  180. mORKS.InitComplete = bools[0];
  181. mORKS.TakeBowlIdle = bools[1];
  182. mORKS.TemperatureReached = bools[2];
  183. mORKS.AllowFallNoodle = bools[3];
  184. mORKS.RbTakeNoodleComplete = bools[4];
  185. mORKS.RbFallNoodleComplete = bools[5];
  186. mORKS.RbOutMealComplete = bools[6];
  187. mORKS.RobotIdle = bools[7];
  188. mORKS.TakeMealDetect = bools[8];
  189. mORKS.MissingBowl = bools[9];
  190. Initing = bools[10];
  191. mORKS.TurntableLowerLimit = bools[11];
  192. mORKS.MissingBowlSignal2 = bools[12];
  193. mORKS.TurntableUpLimit = bools[13];
  194. mORKS.FeedComplete = bools[14];
  195. mORKS.TurntableMoveInPlace = bools[15];
  196. }
  197. }));
  198. GetStatus("M235.0", new Action<object>((obj) =>
  199. {
  200. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 1)
  201. {
  202. mORKS.Error = bools[0];
  203. }
  204. }));
  205. GetStatus("M102.0", new Action<object>((obj) =>
  206. {
  207. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 7)
  208. {
  209. for (int i = 0; i < 6; i++)
  210. {
  211. mORKS.NoodleCookerStatus[i] = bools[i];
  212. }
  213. mORKS.Feeding = bools[6];
  214. }
  215. }));
  216. GetStatus("M103.0", new Action<object>((obj) =>
  217. {
  218. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 6)
  219. {
  220. for (int i = 0; i < 6; i++)
  221. {
  222. mORKS.CookNoodlesComplete[i] = bools[i];
  223. }
  224. }
  225. }));
  226. GetStatus("VW372", new Action<object>((obj) =>
  227. {
  228. if (obj is ushort[] UshortValue && UshortValue.Length > 0 && UshortValue.Length <= 1)
  229. mORKS.TurntableFeedbackloc = UshortValue[0];
  230. }));
  231. }
  232. /// <summary>
  233. /// 数据解析
  234. /// </summary>
  235. private void DataParse()
  236. {
  237. EventBus.EventBus.GetInstance().Subscribe<DoOrderEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle)
  238. {
  239. if (@event == null) return;
  240. if (@event is DoOrderEvent order)
  241. {
  242. mORKS.doOrderEvents.Add(order);
  243. if (order.MorkOrder.GoodBatchings == null) return;
  244. OrderCount++;
  245. OrderChange(order.MorkOrder.SuborderId, ORDER_STATUS.WAIT);
  246. DeviceProcessLogShow($"接收到{OrderCount}次订单");
  247. foreach (var item in order.MorkOrder.GoodBatchings)
  248. {
  249. var res = orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId);
  250. if (res != null)
  251. {
  252. if (ushort.TryParse(res.BatchingLoc, out ushort loc))
  253. {
  254. if (loc >= 1 && loc <= 5)
  255. {
  256. if (mORKS.RBTakeNoodleTask.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  257. mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { GoodName = order.MorkOrder.GoodsName, Loc = ushort.Parse(res.BatchingLoc), SuborderId = order.MorkOrder.SuborderId, BatchingId = res.BatchingId });
  258. }
  259. else if (loc >= 10 && loc <= 11)
  260. {
  261. int index = 0;
  262. if (recipeBoms != null)
  263. {
  264. index = Array.FindIndex(recipeBoms.RecipeIds?.ToArray(), p => p.RecipeId == order.MorkOrder.RecipeId);
  265. index++;
  266. }
  267. if (mORKS.TakeBowlTask.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  268. mORKS.TakeBowlTask.Enqueue(new OrderLocInfo()
  269. {
  270. BatchingId = res.BatchingId,
  271. GoodName = order.MorkOrder.GoodsName,
  272. Loc = ushort.Parse(res.BatchingLoc),
  273. SuborderId = order.MorkOrder.SuborderId,
  274. RecipeNumber = (index >= 1 && index <= 10) ? (ushort)index : (ushort)0
  275. });
  276. }
  277. }
  278. }
  279. }
  280. }
  281. });
  282. }
  283. public override void MainTask()
  284. {
  285. mORKS.AllowRun = mORKS.InitComplete;
  286. if (Json<KeepDataBase>.Data.IsVerify)
  287. IsHealth = mORKS.Error && mORKS.InitComplete;
  288. else
  289. IsHealth = true;
  290. TakeBowlTask();
  291. TakeNoodleTask();
  292. OutNoodleTask();
  293. SingleDetect();
  294. TurntableControl();
  295. var data = new List<bool>();
  296. for (int i = 0; i < Json<MorksPar>.Data.parSets.Count; i++)
  297. {
  298. data.Add(Json<MorksPar>.Data.parSets.ElementAt(i).IsShield);
  299. }
  300. WriteControl("M260.0", data.ToArray());
  301. }
  302. private void BowlControl(OrderLocInfo orderLocInfo)
  303. {
  304. if (orderLocInfo.Loc >= 10 && orderLocInfo.Loc <= 11)
  305. {
  306. mORKS.TakeBowlId = orderLocInfo.SuborderId;
  307. mORKS.TakeBowName = orderLocInfo.GoodName;
  308. TakeBowlControl(orderLocInfo.Loc);
  309. SetRecipeNumber(orderLocInfo.RecipeNumber);
  310. OrderChange(mORKS.TakeBowlId, ORDER_STATUS.COOKING);
  311. DeviceProcessLogShow($"订单【{ mORKS.TakeBowlId}】执行取碗控制,位置:[{orderLocInfo.Loc}]");
  312. mORKS.TakeBowlInterlock = true;
  313. }
  314. }
  315. /// <summary>
  316. /// 取碗控制
  317. /// </summary>
  318. private void TakeBowlTask()
  319. {
  320. if (mORKS.AllowRun && mORKS.TakeBowlTask.Count > 0 && !mORKS.TakeBowlIdle && !mORKS.TakeBowlInterlock)
  321. {
  322. DeviceProcessLogShow("开始取碗流程");
  323. ushort BowLoc = 0;
  324. var res = orderMaterialDelivery?.BatchingInfo?.Where(p => p.BatchingId == mORKS.TakeBowlTask.ElementAt(0).BatchingId).ToList();
  325. if (res == null || res?.Count == 0)
  326. {
  327. if (mORKS.TakeBowlTask.TryDequeue(out OrderLocInfo orderLocInfo)) BowlControl(orderLocInfo);
  328. }
  329. else
  330. {
  331. foreach (var item in res)
  332. {
  333. if (ushort.TryParse(item.BatchingLoc, out ushort loc))
  334. {
  335. //DeviceProcessLogShow($"位置:={loc},检测开关1:{alarm.Supply1_LossBowl},检测开关1:{alarm.Supply2_LossBowl}");
  336. if (loc == 10 && !alarm.Supply1_LossBowl)
  337. {
  338. BowLoc = loc;
  339. break;
  340. }
  341. else if (loc == 11 && !alarm.Supply2_LossBowl)
  342. {
  343. BowLoc = loc;
  344. break;
  345. }
  346. }
  347. }
  348. if (BowLoc >= 10 && BowLoc <= 11)
  349. {
  350. if (mORKS.TakeBowlTask.TryDequeue(out OrderLocInfo orderLocInfo))
  351. {
  352. orderLocInfo.Loc = BowLoc;
  353. BowlControl(orderLocInfo);
  354. }
  355. }
  356. }
  357. }
  358. }
  359. /// <summary>
  360. /// 转台控制
  361. /// </summary>
  362. private void TurntableControl()
  363. {
  364. if (Global.EnableLocalSimOrder)
  365. {
  366. //不做轮询,直接取面,模拟订单使用
  367. if (mORKS.TurntableMoveInPlace && !mORKS.Feeding && mORKS.InitComplete && !mORKS.AllowTakeNoodle && mORKS.RBTakeNoodleTask.Count > 0)
  368. {
  369. if (mORKS.TurntableLowerLimit)
  370. {
  371. TurntableStart(mORKS.RBTakeNoodleTask.ElementAt(0).Loc);
  372. mORKS.TurntableLocLists.Clear();
  373. mORKS.AllowTakeNoodle = true;
  374. DeviceProcessLogShow($"控制机器人去转台【{mORKS.RBTakeNoodleTask.ElementAt(0).Loc}】号位置取面");
  375. }
  376. }
  377. }
  378. else
  379. {
  380. //正常轮询
  381. if (mORKS.TurntableMoveInPlace && !mORKS.Feeding && mORKS.InitComplete && !mORKS.AllowTakeNoodle && mORKS.RBTakeNoodleTask.Count > 0)
  382. {
  383. var result = orderMaterialDelivery.BatchingInfo.Where(p => p.BatchingId == mORKS.RBTakeNoodleTask.ElementAt(0).BatchingId).ToList();
  384. if (result != null)
  385. {
  386. var res = result.FirstOrDefault(P => P.BatchingLoc == mORKS.TurntableFeedbackloc.ToString());
  387. if (mORKS.TurntableLowerLimit && res != null)
  388. {
  389. TurntableStart(mORKS.TurntableFeedbackloc);
  390. mORKS.TurntableLocLists.Clear();
  391. mORKS.AllowTakeNoodle = true;
  392. DeviceProcessLogShow($"控制机器人去转台【{mORKS.TurntableFeedbackloc}】号位置取面");
  393. }
  394. else
  395. {
  396. if (!mORKS.TurntableInterlock)
  397. {
  398. foreach (var item in result)
  399. {
  400. if (ushort.TryParse(item.BatchingLoc, out ushort loc))
  401. {
  402. if (mORKS.TurntableFeedbackloc != loc && !mORKS.TurntableLocLists.Contains(loc))
  403. {
  404. if (!mORKS.TurntableLowerLimit)
  405. {
  406. WriteData("M32.7", false);
  407. DeviceProcessLogShow($"执行了转台启动互锁信号复位");
  408. }
  409. TurntableStart(loc);
  410. DeviceProcessLogShow($"没有物料检测的启动转台控制,转台位置:[{loc}]");
  411. break;
  412. }
  413. else if (mORKS.TurntableFeedbackloc == loc && !mORKS.TurntableLocLists.Contains(loc)) mORKS.TurntableLocLists.Add(loc);
  414. }
  415. }
  416. }
  417. }
  418. }
  419. else DeviceProcessLogShow("未找到可用的物料信息");
  420. }
  421. }
  422. //if (DelayRTrig.GetInstance("互锁信号复位").Start(!mORKS.TurntableLowerLimit && mORKS.TurntableMoveInPlace, 2))
  423. //{
  424. // if (!mORKS.TurntableLowerLimit)
  425. // {
  426. // WriteData("M32.7", false);
  427. // DeviceProcessLogShow($"执行了转台启动互锁信号复位");
  428. // }
  429. //}
  430. //补料中检测
  431. if (RTrig.GetInstance("mORKS.Feeding").Start(mORKS.Feeding))
  432. {
  433. mORKS.AllowTakeNoodle = false;
  434. mORKS.TakeNoodleInterlock = false;
  435. }
  436. //转台到位检测
  437. if (RTrig.GetInstance("TurntableInPlace").Start(mORKS.TurntableMoveInPlace && mORKS.CurrentLoc == mORKS.TurntableFeedbackloc))
  438. {
  439. mORKS.CurrentLoc = 0;
  440. mORKS.TurntableInterlock = false;
  441. DeviceProcessLogShow("转台到位检测");
  442. }
  443. //补料完成检测
  444. if (RTrig.GetInstance("FeedComplete").Start(mORKS.FeedComplete))
  445. {
  446. if (!mORKS.AllowTakeNoodle && mORKS.TurntableLocLists.Count > 0)
  447. {
  448. mORKS.TurntableLocLists.Clear();
  449. mORKS.TurntableInterlock = false;
  450. DeviceProcessLogShow("补料完成检测");
  451. }
  452. }
  453. }
  454. /// <summary>
  455. /// 取面任务
  456. /// </summary>
  457. private void TakeNoodleTask()
  458. {
  459. //取面控制
  460. if (mORKS.AllowRun && mORKS.RobotIdle && !mORKS.Feeding && !mORKS.RobotTaskInterlock && mORKS.AllowTakeNoodle && mORKS.TurntableMoveInPlace && !mORKS.TakeNoodleInterlock && !mORKS.OutNoodleing && mORKS.RBTakeNoodleTask.Count > 0)
  461. {
  462. int loc = Array.FindIndex(mORKS.NoodleCookerStatus, p => p == false);//查找煮面炉空闲位置
  463. if (loc >= 0 && loc <= 5)
  464. {
  465. if (mORKS.RBTakeNoodleTask.TryDequeue(out OrderLocInfo orderLocInfo))
  466. {
  467. mORKS.CookNodelId[loc] = orderLocInfo.SuborderId;
  468. SetFallNoodleLoc((ushort)(loc + 1));
  469. //机器人开始取面
  470. RobotTakeNoodle();
  471. OrderChange(orderLocInfo.SuborderId, ORDER_STATUS.COOKING);
  472. DeviceProcessLogShow($"订单【{orderLocInfo.SuborderId}】,机器人倒面至【{loc + 1}】号煮面栏");
  473. //写入煮面时间
  474. List<ushort> values = new List<ushort>();
  475. values.Add(Json<MorksPar>.Data.parSets.ElementAt(loc).Minute);
  476. values.Add(Json<MorksPar>.Data.parSets.ElementAt(loc).Second);
  477. WriteData($"VW{116 + (loc * 6)}", values.ToArray());
  478. mORKS.TakeNoodleInterlock = true;
  479. }
  480. }
  481. }
  482. }
  483. /// <summary>
  484. /// 出餐控制
  485. /// </summary>
  486. private void OutNoodleTask()
  487. {
  488. if (mORKS.AllowFallNoodle && mORKS.RobotTaskInterlock && !mORKS.TakeNoodleInterlock && mORKS.RobotIdle && !mORKS.TakeMealDetect)
  489. {
  490. int loc = Array.FindIndex(mORKS.CookNodelId, p => p == mORKS.IngredientsCompleteId && p.Length > 0);
  491. if (loc >= 0 && loc <= 5)
  492. {
  493. if (mORKS.CookNoodlesComplete[loc])
  494. {
  495. SetTakeNoodleLoc((ushort)(loc + 1));
  496. RobotOutMeal();
  497. CookNoodleStatusReset((ushort)(loc + 1));
  498. ResetAllowFallNoodle();
  499. //新增,待测试
  500. if (mORKS.RbOutMealComplete)
  501. {
  502. ResetCookComplete();
  503. mORKS.CookCompleteFlatBit = false;
  504. DeviceProcessLogShow("取餐过程中复位出餐完成信号");
  505. }
  506. mORKS.OutMealId = mORKS.IngredientsCompleteId;
  507. mORKS.OutMealName = mORKS.IngredientsCompleteName;
  508. mORKS.IngredientsCompleteId = string.Empty;
  509. mORKS.CookNodelId[loc] = string.Empty;
  510. DeviceProcessLogShow($"{loc + 1} 号位置出餐控制,订单ID:{ mORKS.OutMealId}");
  511. mORKS.OutNoodleing = true;
  512. }
  513. }
  514. }
  515. }
  516. /// <summary>
  517. /// 信号检测
  518. /// </summary>
  519. private void SingleDetect()
  520. {
  521. //允许倒面信号检测
  522. if (RTrig.GetInstance("AllowFallNoodle").Start(mORKS.AllowFallNoodle))
  523. {
  524. mORKS.IngredientsCompleteId = mORKS.TakeBowlId;
  525. mORKS.IngredientsCompleteName = mORKS.TakeBowName;
  526. mORKS.TakeBowlId = string.Empty;
  527. mORKS.TakeBowName = string.Empty;
  528. DeviceProcessLogShow($"碗到位,允许到面,{mORKS.IngredientsCompleteId}");
  529. mORKS.TakeBowlInterlock = false;
  530. }
  531. //出餐完成信号检测
  532. if (RTrig.GetInstance("CompleteChange").Start(mORKS.RbOutMealComplete))
  533. {
  534. OrderChange(mORKS.OutMealId, ORDER_STATUS.COMPLETED_COOK);
  535. DeviceProcessLogShow($"订单【{mORKS.OutMealId}】制作完成");
  536. mORKS.CookCompleteFlatBit = true;
  537. mORKS.OutNoodleing = false;
  538. WaitMeaLSpeak(mORKS.OutMealName);
  539. }
  540. //取餐完成逻辑处理
  541. if (Delay.GetInstance("CompleteChange1").Start(mORKS.CookCompleteFlatBit && !mORKS.TakeMealDetect, 1))
  542. {
  543. OrderChange(mORKS.OutMealId, ORDER_STATUS.COMPLETED_TAKE);
  544. DeviceProcessLogShow($"订单【{mORKS.OutMealId}】取餐完成");
  545. ResetCookComplete();
  546. mORKS.CookCompleteFlatBit = false;
  547. mORKS.OutMealId = string.Empty;
  548. mORKS.OutMealName = string.Empty;
  549. }
  550. //机器人取面完成信号检测
  551. if (RTrig.GetInstance("TakeNoodleComplete").Start(mORKS.RbTakeNoodleComplete))
  552. {
  553. mORKS.TakeNoodleInterlock = false;
  554. mORKS.AllowTakeNoodle = false;
  555. mORKS.TurntableInterlock = false;
  556. DeviceProcessLogShow("机器人取面完成信号检测");
  557. TakeNoodleCompleteReset();
  558. }
  559. int OutMealRequstCount = mORKS.CookNoodlesComplete.Where(p => p == true).ToList().Count;
  560. int mlCount = mORKS.NoodleCookerStatus.Where(p => p == true).ToList().Count;
  561. int index = Array.FindIndex(mORKS.CookNodelId, p => p == mORKS.IngredientsCompleteId);
  562. bool isok = index >= 0 && index < mORKS.CookNoodlesComplete.Length && mORKS.CookNoodlesComplete[index];
  563. mORKS.PriorityJudgment = Delay.GetInstance("取餐优先级判断").Start(mORKS.TurntableLocLists.Count > 0 && !mORKS.TurntableLowerLimit, 4);
  564. //mORKS.RobotTaskInterlock = OutMealRequstCount > 0 && mORKS.AllowFallNoodle && (mlCount >= 2 || mORKS.RBTakeNoodleTask.Count == 0 || mORKS.PriorityJudgment);
  565. mORKS.RobotTaskInterlock = isok && mORKS.AllowFallNoodle && (mlCount >= 2 || mORKS.RBTakeNoodleTask.Count == 0 || mORKS.PriorityJudgment);
  566. }
  567. /// <summary>
  568. /// 语音提醒取餐
  569. /// </summary>
  570. /// <param name="meal"></param>
  571. private void WaitMeaLSpeak(string meal)
  572. {
  573. VoiceAPI.m_SystemPlayWav(@"Vioce\电子提示音.wav");
  574. Thread.Sleep(1000);
  575. if(meal!= null) mORKS.speech.Speak(meal);
  576. VoiceAPI.m_SystemPlayWav(@"Vioce\取餐通知.wav");
  577. }
  578. #region PLC 控制函数
  579. private void WriteData(string address, object value)
  580. {
  581. EventBus.EventBus.GetInstance().Publish(new WriteModel() { DeviceId = DeviceId, Address = address, Value = value });
  582. }
  583. /// <summary>
  584. /// 写入配方数据到 PLC
  585. /// </summary>
  586. private void WriteRecipeBoms()
  587. {
  588. List<ushort> recipeBoms = new List<ushort>();
  589. if (this.recipeBoms == null) return;
  590. foreach (var item in this.recipeBoms.RecipeIds)
  591. {
  592. foreach (var rec in item.Recipes)
  593. {
  594. recipeBoms.Add((ushort)rec);
  595. }
  596. }
  597. if (recipeBoms.Count > 0)
  598. {
  599. //配方数据地址范围:VW2000 - VW2278
  600. WriteData("VW2000", recipeBoms.ToArray());
  601. DeviceProcessLogShow("写配方成功");
  602. }
  603. else { DeviceProcessLogShow("配方数据为空"); }
  604. }
  605. /// <summary>
  606. /// 取面完成复位
  607. /// </summary>
  608. private void TakeNoodleCompleteReset()
  609. {
  610. WriteData("M100.4", false);
  611. }
  612. /// <summary>
  613. /// 指定煮面口状态复位
  614. /// </summary>
  615. /// <param name="num"></param>
  616. private void CookNoodleStatusReset(int num)
  617. {
  618. if (num >= 1 && num <= 6)
  619. {
  620. WriteData($"102.{num - 1}", false);
  621. DeviceProcessLogShow($"{num}号煮面口占用复位");
  622. }
  623. }
  624. /// <summary>
  625. /// 写配方编号
  626. /// </summary>
  627. /// <param name="num"></param>
  628. private void SetRecipeNumber(ushort num)
  629. {
  630. WriteData("VW0", num);
  631. }
  632. /// <summary>
  633. /// 启动转台
  634. /// </summary>
  635. /// <param name="loc"></param>
  636. private void TurntableStart(ushort loc)
  637. {
  638. mORKS.CurrentLoc = loc;
  639. mORKS.TurntableInterlock = true;
  640. mORKS.TurntableLocLists.Add(loc);
  641. WriteData("VW2", loc);
  642. WriteData("M0.5", true);
  643. }
  644. /// <summary>
  645. /// 设置倒面位置
  646. /// </summary>
  647. /// <param name="loc"></param>
  648. private void SetFallNoodleLoc(ushort loc)
  649. {
  650. WriteData("VW4", loc);
  651. }
  652. /// <summary>
  653. /// 设置取面位置
  654. /// </summary>
  655. /// <param name="loc"></param>
  656. private void SetTakeNoodleLoc(ushort loc)
  657. {
  658. WriteData("VW6", loc);
  659. }
  660. /// <summary>
  661. /// 取碗控制
  662. /// </summary>
  663. /// <param name="loc"></param>
  664. private void TakeBowlControl(ushort loc)
  665. {
  666. if (loc == 10)//小碗
  667. {
  668. WriteData("M0.1", true);
  669. }
  670. else if (loc == 11)//大碗
  671. {
  672. WriteData("M0.2", true);
  673. }
  674. }
  675. /// <summary>
  676. /// 机器人取面
  677. /// </summary>
  678. private void RobotTakeNoodle()
  679. {
  680. WriteData("M0.3", true);
  681. }
  682. /// <summary>
  683. /// 机器人取餐
  684. /// </summary>
  685. private void RobotOutMeal()
  686. {
  687. WriteData("M0.4", true);
  688. }
  689. /// <summary>
  690. /// 制作完成信号复位
  691. /// </summary>
  692. private void ResetCookComplete()
  693. {
  694. WriteData("M100.6", false);
  695. }
  696. /// <summary>
  697. /// 复位允许取面信号
  698. /// </summary>
  699. private void ResetAllowFallNoodle()
  700. {
  701. WriteData("M100.3", false);
  702. }
  703. /// <summary>
  704. /// 设备初始化
  705. /// </summary>
  706. public async void DeviceInit()
  707. {
  708. WriteData("M0.0", true);
  709. await Task.Delay(1000);
  710. WriteData("M0.0", false);
  711. }
  712. public override void SimOrder()
  713. {
  714. EventBus.EventBus.GetInstance().Subscribe<MorksSimorderModel>(0, delegate (IEvent @event, EventCallBackHandle callBackHandle)
  715. {
  716. if (@event != null && @event is MorksSimorderModel msm)
  717. {
  718. string guid = Guid.NewGuid().ToString();
  719. if (msm.NoodleLoc >= 1 && msm.NoodleLoc <= 5)
  720. {
  721. mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { Loc = (ushort)msm.NoodleLoc, SuborderId = guid });
  722. }
  723. if (msm.Bowloc >= 10 && msm.Bowloc <= 11)
  724. {
  725. mORKS.TakeBowlTask.Enqueue(new OrderLocInfo() { Loc = (ushort)msm.Bowloc, SuborderId = guid });
  726. }
  727. }
  728. });
  729. }
  730. #endregion
  731. }
  732. }