终端一体化运控平台
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.
 
 
 

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