终端一体化运控平台
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

826 行
32 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. 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. if (mORKS.HistorySuborderId.Contains(order.MorkOrder.SuborderId)) return;
  245. OrderCount++;
  246. Json<OrderStatistics>.Data.StatisticsTime=DateTime.Now;
  247. Json<OrderStatistics>.Data.Count++;
  248. OrderChange(order.MorkOrder.SuborderId, ORDER_STATUS.WAIT);
  249. DeviceProcessLogShow($"接收到{OrderCount}次订单,订单ID:{order.MorkOrder.SuborderId}");
  250. mORKS.HistorySuborderId.Add(order.MorkOrder.SuborderId);
  251. foreach (var item in order.MorkOrder.GoodBatchings)
  252. {
  253. var res = orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId);
  254. if (res != null)
  255. {
  256. if (ushort.TryParse(res.BatchingLoc, out ushort loc))
  257. {
  258. if (loc >= 1 && loc <= 5)
  259. {
  260. if (mORKS.RBTakeNoodleTask.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  261. mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { GoodName = order.MorkOrder.GoodsName, Loc = ushort.Parse(res.BatchingLoc), SuborderId = order.MorkOrder.SuborderId, BatchingId = res.BatchingId });
  262. }
  263. else if (loc >= 10 && loc <= 11)
  264. {
  265. int index = 0;
  266. if (recipeBoms != null)
  267. {
  268. index = Array.FindIndex(recipeBoms.RecipeIds?.ToArray(), p => p.RecipeId == order.MorkOrder.RecipeId);
  269. index++;
  270. }
  271. if (mORKS.TakeBowlTask.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  272. mORKS.TakeBowlTask.Enqueue(new OrderLocInfo()
  273. {
  274. BatchingId = res.BatchingId,
  275. GoodName = order.MorkOrder.GoodsName,
  276. Loc = ushort.Parse(res.BatchingLoc),
  277. SuborderId = order.MorkOrder.SuborderId,
  278. RecipeNumber = (index >= 1 && index <= 10) ? (ushort)index : (ushort)0
  279. });
  280. }
  281. }
  282. }
  283. }
  284. }
  285. });
  286. }
  287. public override void MainTask()
  288. {
  289. mORKS.AllowRun = mORKS.InitComplete;
  290. if (Json<KeepDataBase>.Data.IsVerify)
  291. IsHealth = mORKS.Error && mORKS.InitComplete;
  292. else
  293. IsHealth = true;
  294. TakeBowlTask();
  295. TakeNoodleTask();
  296. OutNoodleTask();
  297. SingleDetect();
  298. TurntableControl();
  299. var data = new List<bool>();
  300. for (int i = 0; i < Json<MorksPar>.Data.parSets.Count; i++)
  301. {
  302. data.Add(Json<MorksPar>.Data.parSets.ElementAt(i).IsShield);
  303. }
  304. WriteControl("M260.0", data.ToArray());
  305. }
  306. private void BowlControl(OrderLocInfo orderLocInfo)
  307. {
  308. if (orderLocInfo.Loc >= 10 && orderLocInfo.Loc <= 11)
  309. {
  310. mORKS.TakeBowlId = orderLocInfo.SuborderId;
  311. mORKS.TakeBowName = orderLocInfo.GoodName;
  312. TakeBowlControl(orderLocInfo.Loc);
  313. SetRecipeNumber(orderLocInfo.RecipeNumber);
  314. OrderChange(mORKS.TakeBowlId, ORDER_STATUS.COOKING);
  315. DeviceProcessLogShow($"订单【{ mORKS.TakeBowlId}】执行取碗控制,位置:[{orderLocInfo.Loc}]");
  316. mORKS.TakeBowlInterlock = true;
  317. }
  318. }
  319. /// <summary>
  320. /// 取碗控制
  321. /// </summary>
  322. private void TakeBowlTask()
  323. {
  324. if (mORKS.AllowRun && mORKS.TakeBowlTask.Count > 0 && !mORKS.TakeBowlIdle && !mORKS.TakeBowlInterlock)
  325. {
  326. DeviceProcessLogShow("开始取碗流程");
  327. ushort BowLoc = 0;
  328. var res = orderMaterialDelivery?.BatchingInfo?.Where(p => p.BatchingId == mORKS.TakeBowlTask.ElementAt(0).BatchingId).ToList();
  329. if (res == null || res?.Count == 0)
  330. {
  331. if (mORKS.TakeBowlTask.TryDequeue(out OrderLocInfo orderLocInfo)) BowlControl(orderLocInfo);
  332. }
  333. else
  334. {
  335. foreach (var item in res)
  336. {
  337. if (ushort.TryParse(item.BatchingLoc, out ushort loc))
  338. {
  339. //DeviceProcessLogShow($"位置:={loc},检测开关1:{alarm.Supply1_LossBowl},检测开关1:{alarm.Supply2_LossBowl}");
  340. if (loc == 10 && !alarm.Supply1_LossBowl)
  341. {
  342. BowLoc = loc;
  343. break;
  344. }
  345. else if (loc == 11 && !alarm.Supply2_LossBowl)
  346. {
  347. BowLoc = loc;
  348. break;
  349. }
  350. }
  351. }
  352. if (BowLoc >= 10 && BowLoc <= 11)
  353. {
  354. if (mORKS.TakeBowlTask.TryDequeue(out OrderLocInfo orderLocInfo))
  355. {
  356. orderLocInfo.Loc = BowLoc;
  357. BowlControl(orderLocInfo);
  358. }
  359. }
  360. }
  361. }
  362. }
  363. /// <summary>
  364. /// 转台控制
  365. /// </summary>
  366. private void TurntableControl()
  367. {
  368. if (Global.EnableLocalSimOrder)
  369. {
  370. //不做轮询,直接取面,模拟订单使用
  371. if (mORKS.TurntableMoveInPlace && !mORKS.Feeding && mORKS.InitComplete && !mORKS.AllowTakeNoodle && mORKS.RBTakeNoodleTask.Count > 0)
  372. {
  373. if (mORKS.TurntableLowerLimit)
  374. {
  375. TurntableStart(mORKS.RBTakeNoodleTask.ElementAt(0).Loc);
  376. mORKS.TurntableLocLists.Clear();
  377. mORKS.AllowTakeNoodle = true;
  378. DeviceProcessLogShow($"控制机器人去转台【{mORKS.RBTakeNoodleTask.ElementAt(0).Loc}】号位置取面");
  379. }
  380. }
  381. }
  382. else
  383. {
  384. //正常轮询
  385. if (mORKS.TurntableMoveInPlace && !mORKS.Feeding && mORKS.InitComplete && !mORKS.AllowTakeNoodle && mORKS.RBTakeNoodleTask.Count > 0)
  386. {
  387. var result = orderMaterialDelivery.BatchingInfo.Where(p => p.BatchingId == mORKS.RBTakeNoodleTask.ElementAt(0).BatchingId).ToList();
  388. if (result != null)
  389. {
  390. var res = result.FirstOrDefault(P => P.BatchingLoc == mORKS.TurntableFeedbackloc.ToString());
  391. if (mORKS.TurntableLowerLimit && res != null)
  392. {
  393. TurntableStart(mORKS.TurntableFeedbackloc);
  394. mORKS.TurntableLocLists.Clear();
  395. mORKS.AllowTakeNoodle = true;
  396. DeviceProcessLogShow($"控制机器人去转台【{mORKS.TurntableFeedbackloc}】号位置取面");
  397. }
  398. else
  399. {
  400. if (!mORKS.TurntableInterlock)
  401. {
  402. foreach (var item in result)
  403. {
  404. if (ushort.TryParse(item.BatchingLoc, out ushort loc))
  405. {
  406. if (mORKS.TurntableFeedbackloc != loc && !mORKS.TurntableLocLists.Contains(loc))
  407. {
  408. if (!mORKS.TurntableLowerLimit)
  409. {
  410. WriteData("M32.7", false);
  411. DeviceProcessLogShow($"执行了转台启动互锁信号复位");
  412. }
  413. TurntableStart(loc);
  414. DeviceProcessLogShow($"没有物料检测的启动转台控制,转台位置:[{loc}]");
  415. break;
  416. }
  417. else if (mORKS.TurntableFeedbackloc == loc && !mORKS.TurntableLocLists.Contains(loc)) mORKS.TurntableLocLists.Add(loc);
  418. }
  419. }
  420. }
  421. }
  422. }
  423. else DeviceProcessLogShow("未找到可用的物料信息");
  424. }
  425. }
  426. //if (DelayRTrig.GetInstance("互锁信号复位").Start(!mORKS.TurntableLowerLimit && mORKS.TurntableMoveInPlace, 2))
  427. //{
  428. // if (!mORKS.TurntableLowerLimit)
  429. // {
  430. // WriteData("M32.7", false);
  431. // DeviceProcessLogShow($"执行了转台启动互锁信号复位");
  432. // }
  433. //}
  434. //补料中检测
  435. if (RTrig.GetInstance("mORKS.Feeding").Start(mORKS.Feeding))
  436. {
  437. mORKS.AllowTakeNoodle = false;
  438. mORKS.TakeNoodleInterlock = false;
  439. }
  440. //转台到位检测
  441. if (RTrig.GetInstance("TurntableInPlace").Start(mORKS.TurntableMoveInPlace && mORKS.CurrentLoc == mORKS.TurntableFeedbackloc))
  442. {
  443. mORKS.CurrentLoc = 0;
  444. mORKS.TurntableInterlock = false;
  445. DeviceProcessLogShow("转台到位检测");
  446. }
  447. //补料完成检测
  448. if (RTrig.GetInstance("FeedComplete").Start(mORKS.FeedComplete))
  449. {
  450. if (!mORKS.AllowTakeNoodle && mORKS.TurntableLocLists.Count > 0)
  451. {
  452. mORKS.TurntableLocLists.Clear();
  453. mORKS.TurntableInterlock = false;
  454. DeviceProcessLogShow("补料完成检测");
  455. }
  456. }
  457. }
  458. /// <summary>
  459. /// 取面任务
  460. /// </summary>
  461. private void TakeNoodleTask()
  462. {
  463. //取面控制
  464. if (mORKS.AllowRun && mORKS.RobotIdle && !mORKS.Feeding && !mORKS.RobotTaskInterlock && mORKS.AllowTakeNoodle && mORKS.TurntableMoveInPlace && !mORKS.TakeNoodleInterlock && !mORKS.OutNoodleing && mORKS.RBTakeNoodleTask.Count > 0)
  465. {
  466. int loc = Array.FindIndex(mORKS.NoodleCookerStatus, p => p == false);//查找煮面炉空闲位置
  467. if (loc >= 0 && loc <= 5)
  468. {
  469. if (mORKS.RBTakeNoodleTask.TryDequeue(out OrderLocInfo orderLocInfo))
  470. {
  471. mORKS.CookNodelId[loc] = orderLocInfo.SuborderId;
  472. SetFallNoodleLoc((ushort)(loc + 1));
  473. //机器人开始取面
  474. RobotTakeNoodle();
  475. OrderChange(orderLocInfo.SuborderId, ORDER_STATUS.COOKING);
  476. DeviceProcessLogShow($"订单【{orderLocInfo.SuborderId}】,机器人倒面至【{loc + 1}】号煮面栏");
  477. //写入煮面时间
  478. List<ushort> values = new List<ushort>();
  479. values.Add(Json<MorksPar>.Data.parSets.ElementAt(loc).Minute);
  480. values.Add(Json<MorksPar>.Data.parSets.ElementAt(loc).Second);
  481. WriteData($"VW{116 + (loc * 6)}", values.ToArray());
  482. mORKS.TakeNoodleInterlock = true;
  483. }
  484. }
  485. }
  486. }
  487. /// <summary>
  488. /// 出餐控制
  489. /// </summary>
  490. private void OutNoodleTask()
  491. {
  492. if (mORKS.AllowFallNoodle && mORKS.RobotTaskInterlock && !mORKS.TakeNoodleInterlock && mORKS.RobotIdle && !mORKS.TakeMealDetect)
  493. {
  494. int loc = Array.FindIndex(mORKS.CookNodelId, p => p == mORKS.IngredientsCompleteId && p.Length > 0);
  495. if (loc >= 0 && loc <= 5)
  496. {
  497. if (mORKS.CookNoodlesComplete[loc])
  498. {
  499. SetTakeNoodleLoc((ushort)(loc + 1));
  500. RobotOutMeal();
  501. CookNoodleStatusReset((ushort)(loc + 1));
  502. ResetAllowFallNoodle();
  503. //新增,待测试
  504. if (mORKS.RbOutMealComplete)
  505. {
  506. ResetCookComplete();
  507. mORKS.CookCompleteFlatBit = false;
  508. DeviceProcessLogShow("取餐过程中复位出餐完成信号");
  509. }
  510. if (!string.IsNullOrEmpty(mORKS.OutMealId)) OrderChange(mORKS.OutMealId, ORDER_STATUS.COMPLETED_TAKE);
  511. mORKS.OutMealId = mORKS.IngredientsCompleteId;
  512. mORKS.OutMealName = mORKS.IngredientsCompleteName;
  513. mORKS.IngredientsCompleteId = string.Empty;
  514. mORKS.CookNodelId[loc] = string.Empty;
  515. DeviceProcessLogShow($"{loc + 1} 号位置出餐控制,订单ID:{ mORKS.OutMealId}");
  516. mORKS.OutNoodleing = true;
  517. }
  518. }
  519. }
  520. }
  521. /// <summary>
  522. /// 信号检测
  523. /// </summary>
  524. private void SingleDetect()
  525. {
  526. //允许倒面信号检测
  527. if (RTrig.GetInstance("AllowFallNoodle").Start(mORKS.AllowFallNoodle))
  528. {
  529. mORKS.IngredientsCompleteId = mORKS.TakeBowlId;
  530. mORKS.IngredientsCompleteName = mORKS.TakeBowName;
  531. mORKS.TakeBowlId = string.Empty;
  532. mORKS.TakeBowName = string.Empty;
  533. DeviceProcessLogShow($"碗到位,允许到面,{mORKS.IngredientsCompleteId}");
  534. mORKS.TakeBowlInterlock = false;
  535. }
  536. //出餐完成信号检测
  537. if (RTrig.GetInstance("CompleteChange").Start(mORKS.RbOutMealComplete))
  538. {
  539. OrderChange(mORKS.OutMealId, ORDER_STATUS.COMPLETED_COOK);
  540. DeviceProcessLogShow($"订单【{mORKS.OutMealId}】制作完成");
  541. mORKS.CookCompleteFlatBit = true;
  542. mORKS.OutNoodleing = false;
  543. WaitMeaLSpeak(mORKS.OutMealName);
  544. }
  545. //取餐完成逻辑处理
  546. if (Delay.GetInstance("CompleteChange1").Start( !mORKS.TakeMealDetect, 1)&&mORKS.CookCompleteFlatBit == true)
  547. {
  548. OrderChange(mORKS.OutMealId, ORDER_STATUS.COMPLETED_TAKE);
  549. DeviceProcessLogShow($"订单【{mORKS.OutMealId}】取餐完成");
  550. ResetCookComplete();
  551. mORKS.CookCompleteFlatBit = false;
  552. mORKS.OutMealId = string.Empty;
  553. mORKS.OutMealName = string.Empty;
  554. }
  555. //机器人取面完成信号检测
  556. if (RTrig.GetInstance("TakeNoodleComplete").Start(mORKS.RbTakeNoodleComplete))
  557. {
  558. mORKS.TakeNoodleInterlock = false;
  559. mORKS.AllowTakeNoodle = false;
  560. mORKS.TurntableInterlock = false;
  561. DeviceProcessLogShow("机器人取面完成信号检测");
  562. TakeNoodleCompleteReset();
  563. }
  564. int OutMealRequstCount = mORKS.CookNoodlesComplete.Where(p => p == true).ToList().Count;
  565. int mlCount = mORKS.NoodleCookerStatus.Where(p => p == true).ToList().Count;
  566. int index = Array.FindIndex(mORKS.CookNodelId, p => p == mORKS.IngredientsCompleteId);
  567. bool isok = index >= 0 && index < mORKS.CookNoodlesComplete.Length && mORKS.CookNoodlesComplete[index];
  568. mORKS.PriorityJudgment = Delay.GetInstance("取餐优先级判断").Start(mORKS.TurntableLocLists.Count > 0 && !mORKS.TurntableLowerLimit, 4);
  569. //mORKS.RobotTaskInterlock = OutMealRequstCount > 0 && mORKS.AllowFallNoodle && (mlCount >= 2 || mORKS.RBTakeNoodleTask.Count == 0 || mORKS.PriorityJudgment);
  570. mORKS.RobotTaskInterlock = isok && mORKS.AllowFallNoodle && (mlCount >= 2 || mORKS.RBTakeNoodleTask.Count == 0 || mORKS.PriorityJudgment);
  571. }
  572. /// <summary>
  573. /// 语音提醒取餐
  574. /// </summary>
  575. /// <param name="meal"></param>
  576. private void WaitMeaLSpeak(string meal)
  577. {
  578. VoiceAPI.m_SystemPlayWav(@"Vioce\电子提示音.wav");
  579. Thread.Sleep(1000);
  580. if (meal != null) mORKS.speech.Speak(meal);
  581. VoiceAPI.m_SystemPlayWav(@"Vioce\取餐通知.wav");
  582. }
  583. #region PLC 控制函数
  584. private void WriteData(string address, object value)
  585. {
  586. EventBus.EventBus.GetInstance().Publish(new WriteModel() { DeviceId = DeviceId, Address = address, Value = value });
  587. }
  588. /// <summary>
  589. /// 写入配方数据到 PLC
  590. /// </summary>
  591. private void WriteRecipeBoms()
  592. {
  593. List<ushort> recipeBoms = new List<ushort>();
  594. if (this.recipeBoms == null) return;
  595. foreach (var item in this.recipeBoms.RecipeIds)
  596. {
  597. foreach (var rec in item.Recipes)
  598. {
  599. recipeBoms.Add((ushort)rec);
  600. }
  601. }
  602. if (recipeBoms.Count > 0)
  603. {
  604. //配方数据地址范围:VW2000 - VW2278
  605. WriteData("VW2000", recipeBoms.ToArray());
  606. DeviceProcessLogShow("写配方成功");
  607. }
  608. else { DeviceProcessLogShow("配方数据为空"); }
  609. }
  610. /// <summary>
  611. /// 取面完成复位
  612. /// </summary>
  613. private void TakeNoodleCompleteReset()
  614. {
  615. WriteData("M100.4", false);
  616. }
  617. /// <summary>
  618. /// 指定煮面口状态复位
  619. /// </summary>
  620. /// <param name="num"></param>
  621. private void CookNoodleStatusReset(int num)
  622. {
  623. if (num >= 1 && num <= 6)
  624. {
  625. WriteData($"102.{num - 1}", false);
  626. DeviceProcessLogShow($"{num}号煮面口占用复位");
  627. }
  628. }
  629. /// <summary>
  630. /// 写配方编号
  631. /// </summary>
  632. /// <param name="num"></param>
  633. private void SetRecipeNumber(ushort num)
  634. {
  635. WriteData("VW0", num);
  636. }
  637. /// <summary>
  638. /// 启动转台
  639. /// </summary>
  640. /// <param name="loc"></param>
  641. private void TurntableStart(ushort loc)
  642. {
  643. mORKS.CurrentLoc = loc;
  644. mORKS.TurntableInterlock = true;
  645. mORKS.TurntableLocLists.Add(loc);
  646. WriteData("VW2", loc);
  647. WriteData("M0.5", true);
  648. }
  649. /// <summary>
  650. /// 设置倒面位置
  651. /// </summary>
  652. /// <param name="loc"></param>
  653. private void SetFallNoodleLoc(ushort loc)
  654. {
  655. WriteData("VW4", loc);
  656. }
  657. /// <summary>
  658. /// 设置取面位置
  659. /// </summary>
  660. /// <param name="loc"></param>
  661. private void SetTakeNoodleLoc(ushort loc)
  662. {
  663. WriteData("VW6", loc);
  664. }
  665. /// <summary>
  666. /// 取碗控制
  667. /// </summary>
  668. /// <param name="loc"></param>
  669. private void TakeBowlControl(ushort loc)
  670. {
  671. if (loc == 10)//小碗
  672. {
  673. WriteData("M0.1", true);
  674. }
  675. else if (loc == 11)//大碗
  676. {
  677. WriteData("M0.2", true);
  678. }
  679. }
  680. /// <summary>
  681. /// 机器人取面
  682. /// </summary>
  683. private void RobotTakeNoodle()
  684. {
  685. WriteData("M0.3", true);
  686. }
  687. /// <summary>
  688. /// 机器人取餐
  689. /// </summary>
  690. private void RobotOutMeal()
  691. {
  692. WriteData("M0.4", true);
  693. }
  694. /// <summary>
  695. /// 制作完成信号复位
  696. /// </summary>
  697. private void ResetCookComplete()
  698. {
  699. WriteData("M100.6", false);
  700. }
  701. /// <summary>
  702. /// 复位允许取面信号
  703. /// </summary>
  704. private void ResetAllowFallNoodle()
  705. {
  706. WriteData("M100.3", false);
  707. }
  708. /// <summary>
  709. /// 设备初始化
  710. /// </summary>
  711. public async void DeviceInit()
  712. {
  713. WriteData("M0.0", true);
  714. await Task.Delay(1000);
  715. WriteData("M0.0", false);
  716. }
  717. public override void SimOrder()
  718. {
  719. EventBus.EventBus.GetInstance().Subscribe<MorksSimorderModel>(0, delegate (IEvent @event, EventCallBackHandle callBackHandle)
  720. {
  721. if (@event != null && @event is MorksSimorderModel msm)
  722. {
  723. string guid = Guid.NewGuid().ToString();
  724. if (msm.NoodleLoc >= 1 && msm.NoodleLoc <= 5)
  725. {
  726. mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { Loc = (ushort)msm.NoodleLoc, SuborderId = guid });
  727. MessageLog.GetInstance.Show($"添加订单:面条位置【{(ushort)msm.NoodleLoc}】");
  728. }
  729. if (msm.Bowloc >= 10 && msm.Bowloc <= 11)
  730. {
  731. mORKS.TakeBowlTask.Enqueue(new OrderLocInfo() { Loc = (ushort)msm.Bowloc, SuborderId = guid });
  732. MessageLog.GetInstance.Show($"添加订单:碗位置【{(ushort)msm.Bowloc}】");
  733. }
  734. }
  735. });
  736. }
  737. #endregion
  738. }
  739. }