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

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