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

784 lines
30 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 (mORKS.TakeBowlTask.TryDequeue(out OrderLocInfo orderLocInfo))
  341. {
  342. orderLocInfo.Loc = BowLoc;
  343. BowlControl(orderLocInfo);
  344. }
  345. }
  346. }
  347. }
  348. /// <summary>
  349. /// 转台控制
  350. /// </summary>
  351. private void TurntableControl()
  352. {
  353. if (Global.EnableLocalSimOrder)
  354. {
  355. //不做轮询,直接取面,模拟订单使用
  356. if (mORKS.TurntableMoveInPlace && !mORKS.Feeding && mORKS.InitComplete && !mORKS.AllowTakeNoodle && mORKS.RBTakeNoodleTask.Count > 0)
  357. {
  358. if (mORKS.TurntableLowerLimit)
  359. {
  360. TurntableStart(mORKS.RBTakeNoodleTask.ElementAt(0).Loc);
  361. mORKS.TurntableLocLists.Clear();
  362. mORKS.AllowTakeNoodle = true;
  363. DeviceProcessLogShow($"控制机器人去转台【{mORKS.RBTakeNoodleTask.ElementAt(0).Loc}】号位置取面");
  364. }
  365. }
  366. }
  367. else
  368. {
  369. //正常轮询
  370. if (mORKS.TurntableMoveInPlace && !mORKS.Feeding && mORKS.InitComplete && !mORKS.AllowTakeNoodle && mORKS.RBTakeNoodleTask.Count > 0)
  371. {
  372. var result = orderMaterialDelivery.BatchingInfo.Where(p => p.BatchingId == mORKS.RBTakeNoodleTask.ElementAt(0).BatchingId).ToList();
  373. if (result != null)
  374. {
  375. var res = result.FirstOrDefault(P => P.BatchingLoc == mORKS.TurntableFeedbackloc.ToString());
  376. if (mORKS.TurntableLowerLimit && res != null)
  377. {
  378. TurntableStart(mORKS.TurntableFeedbackloc);
  379. mORKS.TurntableLocLists.Clear();
  380. mORKS.AllowTakeNoodle = true;
  381. DeviceProcessLogShow($"控制机器人去转台【{mORKS.TurntableFeedbackloc}】号位置取面");
  382. }
  383. else
  384. {
  385. if (!mORKS.TurntableInterlock)
  386. {
  387. foreach (var item in result)
  388. {
  389. if (ushort.TryParse(item.BatchingLoc, out ushort loc))
  390. {
  391. if (mORKS.TurntableFeedbackloc != loc && !mORKS.TurntableLocLists.Contains(loc))
  392. {
  393. if (!mORKS.TurntableLowerLimit)
  394. {
  395. WriteData("M32.7", false);
  396. DeviceProcessLogShow($"执行了转台启动互锁信号复位");
  397. }
  398. TurntableStart(loc);
  399. DeviceProcessLogShow($"没有物料检测的启动转台控制,转台位置:[{loc}]");
  400. break;
  401. }
  402. else if (mORKS.TurntableFeedbackloc == loc && !mORKS.TurntableLocLists.Contains(loc)) mORKS.TurntableLocLists.Add(loc);
  403. }
  404. }
  405. }
  406. }
  407. }
  408. else DeviceProcessLogShow("未找到可用的物料信息");
  409. }
  410. }
  411. //if (DelayRTrig.GetInstance("互锁信号复位").Start(!mORKS.TurntableLowerLimit && mORKS.TurntableMoveInPlace, 2))
  412. //{
  413. // if (!mORKS.TurntableLowerLimit)
  414. // {
  415. // WriteData("M32.7", false);
  416. // DeviceProcessLogShow($"执行了转台启动互锁信号复位");
  417. // }
  418. //}
  419. //补料中检测
  420. if (RTrig.GetInstance("mORKS.Feeding").Start(mORKS.Feeding))
  421. {
  422. mORKS.AllowTakeNoodle = false;
  423. mORKS.TakeNoodleInterlock = false;
  424. }
  425. //转台到位检测
  426. if (RTrig.GetInstance("TurntableInPlace").Start(mORKS.TurntableMoveInPlace && mORKS.CurrentLoc == mORKS.TurntableFeedbackloc))
  427. {
  428. mORKS.CurrentLoc = 0;
  429. mORKS.TurntableInterlock = false;
  430. DeviceProcessLogShow("转台到位检测");
  431. }
  432. //补料完成检测
  433. if (RTrig.GetInstance("FeedComplete").Start(mORKS.FeedComplete))
  434. {
  435. if (!mORKS.AllowTakeNoodle && mORKS.TurntableLocLists.Count > 0)
  436. {
  437. mORKS.TurntableLocLists.Clear();
  438. mORKS.TurntableInterlock = false;
  439. DeviceProcessLogShow("补料完成检测");
  440. }
  441. }
  442. }
  443. /// <summary>
  444. /// 取面任务
  445. /// </summary>
  446. private void TakeNoodleTask()
  447. {
  448. //取面控制
  449. if (mORKS.AllowRun && mORKS.RobotIdle && !mORKS.Feeding && !mORKS.RobotTaskInterlock && mORKS.AllowTakeNoodle && mORKS.TurntableMoveInPlace && !mORKS.TakeNoodleInterlock && !mORKS.OutNoodleing && mORKS.RBTakeNoodleTask.Count > 0)
  450. {
  451. int loc = Array.FindIndex(mORKS.NoodleCookerStatus, p => p == false);//查找煮面炉空闲位置
  452. if (loc >= 0 && loc <= 5)
  453. {
  454. if (mORKS.RBTakeNoodleTask.TryDequeue(out OrderLocInfo orderLocInfo))
  455. {
  456. mORKS.CookNodelId[loc] = orderLocInfo.SuborderId;
  457. SetFallNoodleLoc((ushort)(loc + 1));
  458. //机器人开始取面
  459. RobotTakeNoodle();
  460. OrderChange(orderLocInfo.SuborderId, ORDER_STATUS.COOKING);
  461. DeviceProcessLogShow($"订单【{orderLocInfo.SuborderId}】,机器人倒面至【{loc + 1}】号煮面栏");
  462. //写入煮面时间
  463. List<ushort> values = new List<ushort>();
  464. values.Add(Json<MorksPar>.Data.parSets.ElementAt(loc).Minute);
  465. values.Add(Json<MorksPar>.Data.parSets.ElementAt(loc).Second);
  466. WriteData($"VW{116 + (loc * 6)}", values.ToArray());
  467. mORKS.TakeNoodleInterlock = true;
  468. }
  469. }
  470. }
  471. }
  472. /// <summary>
  473. /// 出餐控制
  474. /// </summary>
  475. private void OutNoodleTask()
  476. {
  477. if (mORKS.AllowFallNoodle && mORKS.RobotTaskInterlock && !mORKS.TakeNoodleInterlock && mORKS.RobotIdle && !mORKS.TakeMealDetect)
  478. {
  479. int loc = Array.FindIndex(mORKS.CookNodelId, p => p == mORKS.IngredientsCompleteId && p.Length > 0);
  480. if (loc >= 0 && loc <= 5)
  481. {
  482. if (mORKS.CookNoodlesComplete[loc])
  483. {
  484. SetTakeNoodleLoc((ushort)(loc + 1));
  485. RobotOutMeal();
  486. CookNoodleStatusReset((ushort)(loc + 1));
  487. ResetAllowFallNoodle();
  488. //新增,待测试
  489. if (mORKS.RbOutMealComplete)
  490. {
  491. ResetCookComplete();
  492. mORKS.CookCompleteFlatBit = false;
  493. DeviceProcessLogShow("取餐过程中复位出餐完成信号");
  494. }
  495. mORKS.OutMealId = mORKS.IngredientsCompleteId;
  496. mORKS.IngredientsCompleteId = string.Empty;
  497. mORKS.CookNodelId[loc] = string.Empty;
  498. DeviceProcessLogShow($"{loc + 1} 号位置出餐控制,订单ID:{ mORKS.OutMealId}");
  499. mORKS.OutNoodleing = true;
  500. }
  501. }
  502. }
  503. }
  504. /// <summary>
  505. /// 信号检测
  506. /// </summary>
  507. private void SingleDetect()
  508. {
  509. //允许倒面信号检测
  510. if (RTrig.GetInstance("AllowFallNoodle").Start(mORKS.AllowFallNoodle))
  511. {
  512. mORKS.IngredientsCompleteId = mORKS.TakeBowlId;
  513. mORKS.TakeBowlId = string.Empty;
  514. DeviceProcessLogShow($"碗到位,允许到面,{mORKS.IngredientsCompleteId}");
  515. mORKS.TakeBowlInterlock = false;
  516. }
  517. //出餐完成信号检测
  518. if (RTrig.GetInstance("CompleteChange").Start(mORKS.RbOutMealComplete))
  519. {
  520. OrderChange(mORKS.OutMealId, ORDER_STATUS.COMPLETED_COOK);
  521. DeviceProcessLogShow($"订单【{mORKS.OutMealId}】制作完成");
  522. mORKS.CookCompleteFlatBit = true;
  523. mORKS.OutNoodleing = false;
  524. }
  525. //取餐完成逻辑处理
  526. if (Delay.GetInstance("CompleteChange1").Start(mORKS.CookCompleteFlatBit && !mORKS.TakeMealDetect, 1))
  527. {
  528. OrderChange(mORKS.OutMealId, ORDER_STATUS.COMPLETED_TAKE);
  529. DeviceProcessLogShow($"订单【{mORKS.OutMealId}】取餐完成");
  530. ResetCookComplete();
  531. mORKS.CookCompleteFlatBit = false;
  532. mORKS.OutMealId = string.Empty;
  533. }
  534. //机器人取面完成信号检测
  535. if (RTrig.GetInstance("TakeNoodleComplete").Start(mORKS.RbTakeNoodleComplete))
  536. {
  537. mORKS.TakeNoodleInterlock = false;
  538. mORKS.AllowTakeNoodle = false;
  539. mORKS.TurntableInterlock = false;
  540. DeviceProcessLogShow("机器人取面完成信号检测");
  541. TakeNoodleCompleteReset();
  542. }
  543. int OutMealRequstCount = mORKS.CookNoodlesComplete.Where(p => p == true).ToList().Count;
  544. int mlCount = mORKS.NoodleCookerStatus.Where(p => p == true).ToList().Count;
  545. mORKS.PriorityJudgment = Delay.GetInstance("取餐优先级判断").Start(mORKS.TurntableLocLists.Count > 0 && !mORKS.TurntableLowerLimit, 4);
  546. mORKS.RobotTaskInterlock = OutMealRequstCount > 0 && mORKS.AllowFallNoodle && (mlCount >= 2 || mORKS.RBTakeNoodleTask.Count == 0 || mORKS.PriorityJudgment);
  547. }
  548. #region PLC 控制函数
  549. private void WriteData(string address, object value)
  550. {
  551. EventBus.EventBus.GetInstance().Publish(new WriteModel() { DeviceId = DeviceId, Address = address, Value = value });
  552. }
  553. /// <summary>
  554. /// 写入配方数据到 PLC
  555. /// </summary>
  556. private void WriteRecipeBoms()
  557. {
  558. List<ushort> recipeBoms = new List<ushort>();
  559. if (this.recipeBoms == null) return;
  560. foreach (var item in this.recipeBoms.RecipeIds)
  561. {
  562. foreach (var rec in item.Recipes)
  563. {
  564. recipeBoms.Add((ushort)rec);
  565. }
  566. }
  567. if (recipeBoms.Count > 0)
  568. {
  569. //配方数据地址范围:VW2000 - VW2278
  570. WriteData("VW2000", recipeBoms.ToArray());
  571. DeviceProcessLogShow("写配方成功");
  572. }
  573. else { DeviceProcessLogShow("配方数据为空"); }
  574. }
  575. /// <summary>
  576. /// 取面完成复位
  577. /// </summary>
  578. private void TakeNoodleCompleteReset()
  579. {
  580. WriteData("M100.4", false);
  581. }
  582. /// <summary>
  583. /// 指定煮面口状态复位
  584. /// </summary>
  585. /// <param name="num"></param>
  586. private void CookNoodleStatusReset(int num)
  587. {
  588. if (num >= 1 && num <= 6)
  589. {
  590. WriteData($"102.{num - 1}", false);
  591. DeviceProcessLogShow($"{num}号煮面口占用复位");
  592. }
  593. }
  594. /// <summary>
  595. /// 写配方编号
  596. /// </summary>
  597. /// <param name="num"></param>
  598. private void SetRecipeNumber(ushort num)
  599. {
  600. WriteData("VW0", num);
  601. }
  602. /// <summary>
  603. /// 启动转台
  604. /// </summary>
  605. /// <param name="loc"></param>
  606. private void TurntableStart(ushort loc)
  607. {
  608. mORKS.CurrentLoc = loc;
  609. mORKS.TurntableInterlock = true;
  610. mORKS.TurntableLocLists.Add(loc);
  611. WriteData("VW2", loc);
  612. WriteData("M0.5", true);
  613. }
  614. /// <summary>
  615. /// 设置倒面位置
  616. /// </summary>
  617. /// <param name="loc"></param>
  618. private void SetFallNoodleLoc(ushort loc)
  619. {
  620. WriteData("VW4", loc);
  621. }
  622. /// <summary>
  623. /// 设置取面位置
  624. /// </summary>
  625. /// <param name="loc"></param>
  626. private void SetTakeNoodleLoc(ushort loc)
  627. {
  628. WriteData("VW6", loc);
  629. }
  630. /// <summary>
  631. /// 取碗控制
  632. /// </summary>
  633. /// <param name="loc"></param>
  634. private void TakeBowlControl(ushort loc)
  635. {
  636. if (loc == 10)//小碗
  637. {
  638. WriteData("M0.1", true);
  639. }
  640. else if (loc == 11)//大碗
  641. {
  642. WriteData("M0.2", true);
  643. }
  644. }
  645. /// <summary>
  646. /// 机器人取面
  647. /// </summary>
  648. private void RobotTakeNoodle()
  649. {
  650. WriteData("M0.3", true);
  651. }
  652. /// <summary>
  653. /// 机器人取餐
  654. /// </summary>
  655. private void RobotOutMeal()
  656. {
  657. WriteData("M0.4", true);
  658. }
  659. /// <summary>
  660. /// 制作完成信号复位
  661. /// </summary>
  662. private void ResetCookComplete()
  663. {
  664. WriteData("M100.6", false);
  665. }
  666. /// <summary>
  667. /// 复位允许取面信号
  668. /// </summary>
  669. private void ResetAllowFallNoodle()
  670. {
  671. WriteData("M100.3", false);
  672. }
  673. /// <summary>
  674. /// 设备初始化
  675. /// </summary>
  676. public async void DeviceInit()
  677. {
  678. WriteData("M0.0", true);
  679. await Task.Delay(1000);
  680. WriteData("M0.0", false);
  681. }
  682. public override void SimOrder()
  683. {
  684. EventBus.EventBus.GetInstance().Subscribe<MorksSimorderModel>(0, delegate (IEvent @event, EventCallBackHandle callBackHandle)
  685. {
  686. if (@event != null && @event is MorksSimorderModel msm)
  687. {
  688. string guid = Guid.NewGuid().ToString();
  689. if (msm.NoodleLoc >= 1 && msm.NoodleLoc <= 5)
  690. {
  691. mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { Loc = (ushort)msm.NoodleLoc, SuborderId = guid });
  692. }
  693. if (msm.Bowloc >= 10 && msm.Bowloc <= 11)
  694. {
  695. mORKS.TakeBowlTask.Enqueue(new OrderLocInfo() { Loc = (ushort)msm.Bowloc, SuborderId = guid });
  696. }
  697. }
  698. });
  699. }
  700. #endregion
  701. }
  702. }