终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

792 lines
31 KiB

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