终端一体化运控平台
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

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