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

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