终端一体化运控平台
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

790 行
33 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.MorkSUpgradedVer.Model;
  18. using System.Collections.ObjectModel;
  19. using BPASmartClient.MorkSUpgradedVer.ViewModel;
  20. using BPASmartClient.Business;
  21. using BPASmartClient.Model.小炒机;
  22. using BPA.Models;
  23. using System.Windows.Forms;
  24. using System.Media;
  25. //using BPA.Helper;
  26. namespace BPASmartClient.MorkSUpgradedVer
  27. {
  28. public class Control_MorkSUpgradedVer : BaseDevice
  29. {
  30. public override DeviceClientType DeviceType => DeviceClientType.MORKS;
  31. GVL_MorkSUpgradedVer mORKS = new GVL_MorkSUpgradedVer();
  32. Alarm alarm = new Alarm();
  33. public override void DoMain()
  34. {
  35. MonitorViewModel.DeviceId = DeviceId;
  36. ServerInit();
  37. DataParse();
  38. Json<MorksPar>.Read();
  39. Json<OrderStatistics>.Read();
  40. if (Json<MorksPar>.Data.parSets == null) Json<MorksPar>.Data.parSets = new ObservableCollection<ParSet>();
  41. if (Json<MorksPar>.Data.parSets.Count < 6)
  42. {
  43. Json<MorksPar>.Data.parSets.Clear();
  44. for (int i = 0; i < 6; i++)
  45. {
  46. Json<MorksPar>.Data.parSets.Add(new ParSet()
  47. {
  48. CheckBoxContext = $"煮面口{i + 1}屏蔽",
  49. Minute = 1,
  50. Second = 0,
  51. IsShield = false,
  52. TextBlockContext = $"煮面口{i + 1}时间设定"
  53. });
  54. }
  55. }
  56. ActionManage.GetInstance.Register(new Action<object[]>((o) =>
  57. {
  58. if (o.Length > 0)
  59. {
  60. Random rd = new Random();
  61. ThreadManage.GetInstance().StartLong(new Action(() =>
  62. {
  63. int NoodleLoc = (int)o[0] == 0 ? rd.Next(1, 6) : (int)o[0];
  64. int BowlLoc = (int)o[1] == 0 ? rd.Next(10, 12) : (int)o[1];
  65. string guid = new Guid().ToString();
  66. mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { Loc = (ushort)NoodleLoc, SuborderId = guid });
  67. MessageLog.GetInstance.Show($"添加订单:面条位置【{NoodleLoc}】");
  68. mORKS.TakeBowlTask.Enqueue(new OrderLocInfo() { Loc = (ushort)BowlLoc, SuborderId = guid });
  69. MessageLog.GetInstance.Show($"添加订单:碗位置【{BowlLoc}】");
  70. Thread.Sleep(60000);
  71. }), "ForOrder");
  72. }
  73. }), "EnableForOrder");
  74. ActionManage.GetInstance.Register(new Action<object>((o) =>
  75. {
  76. if (o != null && o is WritePar writePar) WriteData(writePar.Address, writePar.Value);
  77. }), "WriteVW");
  78. ActionManage.GetInstance.Register(new Action<object>((o) =>
  79. {
  80. if (o != null && o is WritePar writePar) WriteData(writePar.Address, writePar.Value);
  81. }), "WriteBools");
  82. ActionManage.GetInstance.Register(new Action(() => { DeviceInit(); }), "InitDevice");
  83. }
  84. public override void ResetProgram()
  85. {
  86. mORKS = null;
  87. mORKS = new GVL_MorkSUpgradedVer();
  88. }
  89. public override void Stop()
  90. {
  91. }
  92. private void ServerInit()
  93. {
  94. //物料信息
  95. EventBus.EventBus.GetInstance().Subscribe<MaterialDeliveryEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  96. {
  97. if (@event == null) return;
  98. if (@event is MaterialDeliveryEvent material)
  99. {
  100. orderMaterialDelivery = material.orderMaterialDelivery;
  101. }
  102. });
  103. //配方数据信息
  104. EventBus.EventBus.GetInstance().Subscribe<RecipeBomEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  105. {
  106. if (@event == null) return;
  107. if (@event is RecipeBomEvent recipe)
  108. {
  109. recipeBoms = recipe.recipeBoms;
  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. var index = DataServer.GetInstance.morkS.MakeOrder.FindIndex(p => p.SortNum == SortNum);
  125. if (index >= 0 && index < DataServer.GetInstance.morkS.MakeOrder.Count)
  126. {
  127. if (oRDER_STATUS == ORDER_STATUS.COMPLETED_COOK)
  128. {
  129. DataServer.GetInstance.morkS.MakeOrder.RemoveAt(index);
  130. DataServer.GetInstance.morkS.MakeOrderOver.Add(new OrderMakeModel()
  131. {
  132. Status = oRDER_STATUS,
  133. GoodName = goodName,
  134. SortNum = SortNum,
  135. StopTime = DateTime.Now.ToString("HH:mm:ss")
  136. });
  137. }
  138. else if (oRDER_STATUS == ORDER_STATUS.COMPLETED_TAKE)
  139. {
  140. var temp = DataServer.GetInstance.morkS.MakeOrderOver.FirstOrDefault(p => p.SortNum == SortNum);
  141. if (temp != null) DataServer.GetInstance.morkS.MakeOrderOver.Remove(temp);
  142. }
  143. else
  144. {
  145. DataServer.GetInstance.morkS.MakeOrder.ElementAt(index).Status = oRDER_STATUS;
  146. }
  147. }
  148. else
  149. {
  150. DataServer.GetInstance.morkS.MakeOrder.Add(new OrderMakeModel()
  151. {
  152. Status = oRDER_STATUS,
  153. GoodName = goodName,
  154. SortNum = SortNum,
  155. StartTime = DateTime.Now.ToString("HH:mm:ss")
  156. });
  157. }
  158. }
  159. private void GetStatus(string key, Action<object> action)
  160. {
  161. if (peripheralStatus.ContainsKey(key))
  162. {
  163. if (peripheralStatus[key] != null)
  164. {
  165. action?.Invoke(peripheralStatus[key]);
  166. }
  167. }
  168. }
  169. public override void ReadData()
  170. {
  171. DataServer.GetInstance.morkS.Alarm.Clear();
  172. alarms.ForEach(item =>
  173. {
  174. DataServer.GetInstance.morkS.Alarm.Add(new AlarmModel()
  175. {
  176. AlarmTime = $"{item.Date} {item.Time}",
  177. AlarmMs = item.Info
  178. });
  179. });
  180. GetStatus("M0.1", new Action<object>((obj) =>
  181. {
  182. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 7)
  183. {
  184. Initing = !bools[0];
  185. mORKS.InitComplete = bools[0];
  186. mORKS.MoveScrewRodInitCom = bools[1];
  187. mORKS.SacrificialVesselInitCom = bools[2];
  188. mORKS.CylinderInitCom = bools[3];
  189. mORKS.NoodleCookerInitCom = bools[4];
  190. mORKS.RobotInitCom = bools[5];
  191. mORKS.SiloInitCom = bools[6];
  192. alarm.DeviceNoInit = !mORKS.InitComplete;
  193. alarm.MoveScrewRodNoInit = !mORKS.MoveScrewRodInitCom;
  194. alarm.SacrificialVesselNoInit = !mORKS.SacrificialVesselInitCom;
  195. alarm.CylinderNoInit = !mORKS.CylinderInitCom;
  196. alarm.NoodleCookerNoInit = !mORKS.NoodleCookerInitCom;
  197. alarm.RobotNoInit = !mORKS.RobotInitCom;
  198. alarm.SiloNoInit = !mORKS.SiloInitCom;
  199. }
  200. }));
  201. GetStatus("M10.0", new Action<object>((obj) =>
  202. {
  203. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 2)
  204. {
  205. mORKS.AllowInvertedFace = bools[0];
  206. mORKS.DiningComplete = bools[1];
  207. }
  208. }));
  209. GetStatus("M10.4", new Action<object>((obj) =>
  210. {
  211. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 1)
  212. {
  213. mORKS.DropBowlMechanismStatus = bools[0];
  214. }
  215. }));
  216. GetStatus("M12.2", new Action<object>((obj) =>
  217. {
  218. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 1)
  219. {
  220. mORKS.FixedFlag = bools[0];
  221. }
  222. }));
  223. GetStatus("M13.5", new Action<object>((obj) =>
  224. {
  225. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 1)
  226. {
  227. mORKS.SiloInPlace = bools[0];
  228. }
  229. }));
  230. GetStatus("M16.7", new Action<object>((obj) =>
  231. {
  232. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 1)
  233. {
  234. mORKS.RobotTakeNoodleCom = bools[0];
  235. }
  236. }));
  237. GetStatus("M17.4", new Action<object>((obj) =>
  238. {
  239. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 1)
  240. {
  241. mORKS.RobotStatus = bools[0];
  242. }
  243. }));
  244. GetStatus("M18.0", new Action<object>((obj) =>
  245. {
  246. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 5)
  247. {
  248. mORKS.SmallBowlYesOrNoCheck = bools[0];
  249. mORKS.LargeBowYesOrNoCheck = bools[1];
  250. mORKS.TurntableLowPosition = bools[2];
  251. mORKS.TurntableHighPosition = bools[3];
  252. alarm.Supply2_LossBowl = !mORKS.SmallBowlYesOrNoCheck;
  253. alarm.Supply1_LossBowl = !mORKS.LargeBowYesOrNoCheck;
  254. }
  255. }));
  256. GetStatus("VW17", new Action<object>((obj) =>
  257. {
  258. if (obj is ushort[] ushorts && ushorts.Length > 0 && ushorts.Length <= 1)
  259. {
  260. var tt = ushorts.UshortsToBytes(true).BytesToUshorts();
  261. for (byte i = 0; i < 6; i++)
  262. {
  263. if (RTrig.GetInstance($"CookNoodleCom{i + 1}").Start(tt[0].GetBitValue((byte)(i + 1))))
  264. {
  265. if (!string.IsNullOrEmpty(mORKS.CookNodelId[i]))
  266. mORKS.CookNoodleCom[i] = true;
  267. }
  268. }
  269. //mORKS.CookNoodleCom[0] = tt[0].GetBitValue(1);
  270. //mORKS.CookNoodleCom[1] = tt[0].GetBitValue(2);
  271. //mORKS.CookNoodleCom[2] = tt[0].GetBitValue(3);
  272. //mORKS.CookNoodleCom[3] = tt[0].GetBitValue(4);
  273. //mORKS.CookNoodleCom[4] = tt[0].GetBitValue(5);
  274. //mORKS.CookNoodleCom[5] = tt[0].GetBitValue(6);
  275. mORKS.Heating = ushorts[0].GetBitValue(15);
  276. mORKS.TemperatureReaches = ushorts[0].GetBitValue(16);
  277. alarm.MachineLowTemperature = !mORKS.TemperatureReaches;
  278. }
  279. }));
  280. GetStatus("VW770", new Action<object>((obj) =>
  281. {
  282. if (obj is ushort[] ushorts && ushorts.Length > 0 && ushorts.Length <= 1)
  283. {
  284. mORKS.CurrentFeedbackLoc = ushorts[0];
  285. }
  286. }));
  287. mORKS.TakeBowlTaskCount = mORKS.TakeBowlTask.Count;
  288. mORKS.RBTakeNoodleTaskCount = mORKS.RBTakeNoodleTask.Count;
  289. for (int i = 0; i < Json<MorksPar>.Data.parSets.Count; i++)
  290. {
  291. mORKS.nsm.ElementAt(i).IsShield = Json<MorksPar>.Data.parSets.ElementAt(i).IsShield;
  292. mORKS.nsm.ElementAt(i).NoodleCookerStatus = mORKS.NoodleCookerStatus[i];
  293. }
  294. }
  295. /// <summary>
  296. /// 数据解析
  297. /// </summary>
  298. private void DataParse()
  299. {
  300. EventBus.EventBus.GetInstance().Subscribe<DoOrderEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle)
  301. {
  302. if (@event == null) return;
  303. if (@event is DoOrderEvent order)
  304. {
  305. mORKS.doOrderEvents.Add(order);
  306. if (order.MorkOrder.GoodBatchings == null) return;
  307. if (mORKS.HistorySuborderId.Contains(order.MorkOrder.SuborderId)) return;
  308. OrderCount++;
  309. if (DateTime.Now.Subtract(Json<OrderStatistics>.Data.StatisticsTime).Days != 0)
  310. Json<OrderStatistics>.Data.Count = 0;
  311. Json<OrderStatistics>.Data.StatisticsTime = DateTime.Now;
  312. Json<OrderStatistics>.Data.Count++;
  313. Json<OrderStatistics>.Save();
  314. OrderChange(order.MorkOrder.SuborderId, ORDER_STATUS.WAIT);
  315. DeviceProcessLogShow($"接收到{OrderCount}次订单,订单ID:{order.MorkOrder.SuborderId}");
  316. mORKS.HistorySuborderId.Add(order.MorkOrder.SuborderId);
  317. foreach (var item in order.MorkOrder.GoodBatchings)
  318. {
  319. var res = orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId);
  320. if (res != null)
  321. {
  322. if (ushort.TryParse(res.BatchingLoc, out ushort loc))
  323. {
  324. if (loc >= 1 && loc <= 5)
  325. {
  326. if (mORKS.RBTakeNoodleTask.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  327. mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { GoodName = order.MorkOrder.GoodsName, Loc = ushort.Parse(res.BatchingLoc), SuborderId = order.MorkOrder.SuborderId, BatchingId = res.BatchingId });
  328. }
  329. else if (loc >= 10 && loc <= 11)
  330. {
  331. int index = 0;
  332. if (recipeBoms != null)
  333. {
  334. index = Array.FindIndex(recipeBoms.RecipeIds?.ToArray(), p => p.RecipeId == order.MorkOrder.RecipeId);
  335. index++;
  336. }
  337. if (mORKS.TakeBowlTask.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  338. mORKS.TakeBowlTask.Enqueue(new OrderLocInfo()
  339. {
  340. BatchingId = res.BatchingId,
  341. GoodName = order.MorkOrder.GoodsName,
  342. Loc = ushort.Parse(res.BatchingLoc),
  343. SuborderId = order.MorkOrder.SuborderId,
  344. RecipeNumber = (index >= 1 && index <= 10) ? (ushort)index : (ushort)0
  345. });
  346. }
  347. }
  348. }
  349. }
  350. }
  351. });
  352. }
  353. public override void MainTask()
  354. {
  355. mORKS.AllowRun = mORKS.InitComplete;
  356. if (Json<KeepDataBase>.Data.IsVerify)
  357. IsHealth = mORKS.InitComplete;
  358. else
  359. IsHealth = true;
  360. TakeBowlTask();
  361. TakeNoodleTask();
  362. OutNoodleTask();
  363. SingleDetect();
  364. TurntableControl();
  365. }
  366. private void BowlControl(OrderLocInfo orderLocInfo)
  367. {
  368. if (orderLocInfo.Loc >= 10 && orderLocInfo.Loc <= 11)
  369. {
  370. mORKS.TakeBowlId = orderLocInfo.SuborderId;
  371. mORKS.TakeBowName = orderLocInfo.GoodName;
  372. TakeBowlControl(orderLocInfo.Loc);
  373. OrderChange(mORKS.TakeBowlId, ORDER_STATUS.COOKING);
  374. DeviceProcessLogShow($"订单【{mORKS.TakeBowlId}】执行取碗控制,位置:[{orderLocInfo.Loc}]");
  375. mORKS.TakeBowlInterlock = true;
  376. }
  377. }
  378. /// <summary>
  379. /// 取碗控制
  380. /// </summary>
  381. private void TakeBowlTask()
  382. {
  383. if (mORKS.AllowRun && mORKS.TakeBowlTask.Count > 0 && !mORKS.DropBowlMechanismStatus && !mORKS.TakeBowlInterlock)
  384. {
  385. ushort BowLoc = 0;
  386. var res = orderMaterialDelivery?.BatchingInfo?.Where(p => p.BatchingId == mORKS.TakeBowlTask.ElementAt(0).BatchingId).ToList();
  387. if (res == null || res?.Count == 0)
  388. {
  389. if (mORKS.TakeBowlTask.TryDequeue(out OrderLocInfo orderLocInfo)) BowlControl(orderLocInfo);
  390. }
  391. else
  392. {
  393. foreach (var item in res)
  394. {
  395. if (ushort.TryParse(item.BatchingLoc, out ushort loc))
  396. {
  397. if (loc == 10 && mORKS.SmallBowlYesOrNoCheck)
  398. {
  399. BowLoc = loc;
  400. break;
  401. }
  402. else if (loc == 11 && mORKS.LargeBowYesOrNoCheck)
  403. {
  404. BowLoc = loc;
  405. break;
  406. }
  407. }
  408. }
  409. if (BowLoc >= 10 && BowLoc <= 11)
  410. {
  411. if (mORKS.TakeBowlTask.TryDequeue(out OrderLocInfo orderLocInfo))
  412. {
  413. orderLocInfo.Loc = BowLoc;
  414. BowlControl(orderLocInfo);
  415. }
  416. }
  417. }
  418. }
  419. }
  420. /// <summary>
  421. /// 转台控制
  422. /// </summary>
  423. private void TurntableControl()
  424. {
  425. if (Global.EnableLocalSimOrder)
  426. {
  427. //不做轮询,直接取面,模拟订单使用
  428. if (mORKS.SiloInPlace && !mORKS.Feeding && mORKS.InitComplete && !mORKS.AllowTakeNoodle && mORKS.RBTakeNoodleTask.Count > 0)
  429. {
  430. if (mORKS.TurntableLowPosition)
  431. {
  432. TurntableStart(mORKS.RBTakeNoodleTask.ElementAt(0).Loc);
  433. mORKS.TurntableLocLists.Clear();
  434. mORKS.AllowTakeNoodle = true;
  435. DeviceProcessLogShow($"控制机器人去转台【{mORKS.RBTakeNoodleTask.ElementAt(0).Loc}】号位置取面");
  436. }
  437. }
  438. }
  439. else
  440. {
  441. //正常轮询
  442. if (Delay.GetInstance("到位检测延时").Start(mORKS.SiloInPlace, 2))
  443. {
  444. if (mORKS.SiloInPlace && !mORKS.Feeding && mORKS.InitComplete && !mORKS.AllowTakeNoodle && mORKS.RBTakeNoodleTask.Count > 0)
  445. {
  446. var result = orderMaterialDelivery.BatchingInfo.Where(p => p.BatchingId == mORKS.RBTakeNoodleTask.ElementAt(0).BatchingId).ToList();
  447. if (result != null)
  448. {
  449. var res = result.FirstOrDefault(P => P.BatchingLoc == mORKS.CurrentFeedbackLoc.ToString());
  450. if (mORKS.TurntableLowPosition && res != null)
  451. {
  452. TurntableStart(mORKS.CurrentFeedbackLoc);
  453. mORKS.TurntableLocLists.Clear();
  454. mORKS.AllowTakeNoodle = true;
  455. DeviceProcessLogShow($"控制机器人去转台【{mORKS.CurrentFeedbackLoc}】号位置取面");
  456. }
  457. else
  458. {
  459. if (!mORKS.TurntableInterlock)
  460. {
  461. foreach (var item in result)
  462. {
  463. if (ushort.TryParse(item.BatchingLoc, out ushort loc))
  464. {
  465. if (mORKS.CurrentFeedbackLoc != loc && !mORKS.TurntableLocLists.Contains(loc))
  466. {
  467. if (!mORKS.TurntableLowPosition)
  468. {
  469. DeviceProcessLogShow($"执行了转台启动互锁信号复位");
  470. }
  471. TurntableStart(loc);
  472. DeviceProcessLogShow($"没有物料检测的启动转台控制,转台位置:[{loc}]");
  473. break;
  474. }
  475. else if (mORKS.CurrentFeedbackLoc == loc && !mORKS.TurntableLocLists.Contains(loc)) mORKS.TurntableLocLists.Add(loc);
  476. }
  477. }
  478. }
  479. }
  480. }
  481. else DeviceProcessLogShow("未找到可用的物料信息");
  482. }
  483. }
  484. }
  485. //补料中检测
  486. if (RTrig.GetInstance("mORKS.Feeding").Start(mORKS.Feeding))
  487. {
  488. mORKS.AllowTakeNoodle = false;
  489. mORKS.TakeNoodleInterlock = false;
  490. }
  491. //转台到位检测
  492. if (RTrig.GetInstance("TurntableInPlace").Start(mORKS.SiloInPlace && mORKS.CurrentLoc == mORKS.CurrentFeedbackLoc))
  493. {
  494. mORKS.TurntableInterlock = false;
  495. DeviceProcessLogShow("转台到位检测");
  496. }
  497. //补料完成检测
  498. if (RTrig.GetInstance("FeedComplete").Start(mORKS.FeedComplete))
  499. {
  500. if (!mORKS.AllowTakeNoodle && mORKS.TurntableLocLists.Count > 0)
  501. {
  502. mORKS.TurntableLocLists.Clear();
  503. mORKS.TurntableInterlock = false;
  504. DeviceProcessLogShow("补料完成检测");
  505. }
  506. }
  507. }
  508. /// <summary>
  509. /// 取面任务
  510. /// </summary>
  511. private void TakeNoodleTask()
  512. {
  513. //取面控制
  514. if (mORKS.AllowRun && mORKS.RobotStatus && !mORKS.Feeding && !mORKS.RobotTaskInterlock && mORKS.AllowTakeNoodle && mORKS.SiloInPlace && !mORKS.TakeNoodleInterlock && mORKS.RBTakeNoodleTask.Count > 0)
  515. {
  516. if (mORKS.CurrentLoc == mORKS.CurrentFeedbackLoc)
  517. {
  518. //int loc = Array.FindIndex(mORKS.NoodleCookerStatus, p => p == false);//查找煮面炉空闲位置
  519. int loc = mORKS.nsm.ToList().FindIndex(p => p.NoodleCookerStatus == false && p.IsShield == false);//查找煮面炉空闲位置
  520. if (loc >= 0 && loc <= 5)
  521. {
  522. //if (!Json<MorksPar>.Data.parSets.ElementAt(loc).IsShield)//检查该煮面篮是否被屏蔽
  523. //{
  524. if (mORKS.RBTakeNoodleTask.TryDequeue(out OrderLocInfo orderLocInfo))
  525. {
  526. //写入煮面时间
  527. List<ushort> values = new List<ushort>();
  528. values.Add(Json<MorksPar>.Data.parSets.ElementAt(loc).Minute);
  529. values.Add(Json<MorksPar>.Data.parSets.ElementAt(loc).Second);
  530. WriteData($"VW{324 + (loc * 4)}", values.ToArray());
  531. mORKS.CurrentLoc = 0;
  532. mORKS.CookNodelId[loc] = orderLocInfo.SuborderId;
  533. mORKS.NoodleCookerStatus[loc] = true;
  534. SetFallNoodleLoc((ushort)(loc + 1));
  535. //机器人开始取面
  536. OrderChange(orderLocInfo.SuborderId, ORDER_STATUS.COOKING);
  537. DeviceProcessLogShow($"订单【{orderLocInfo.SuborderId}】,机器人倒面至【{loc + 1}】号煮面栏");
  538. mORKS.TakeNoodleInterlock = true;
  539. }
  540. }
  541. }
  542. }
  543. }
  544. /// <summary>
  545. /// 出餐控制
  546. /// </summary>
  547. private void OutNoodleTask()
  548. {
  549. if (mORKS.AllowInvertedFace && mORKS.RobotTaskInterlock && !mORKS.TakeNoodleInterlock && mORKS.RobotStatus)
  550. {
  551. int loc = Array.FindIndex(mORKS.CookNodelId, p => p == mORKS.IngredientsCompleteId && p.Length > 0);
  552. if (loc >= 0 && loc <= 5)
  553. {
  554. if (mORKS.CookNoodleCom[loc])
  555. {
  556. SetTakeNoodleLoc((ushort)(loc + 1));
  557. mORKS.NoodleCookerStatus[loc] = false;
  558. WriteData($"VW260", (ushort)0);//设置出汤时间
  559. OrderChange(mORKS.IngredientsCompleteId, ORDER_STATUS.COMPLETED_COOK);
  560. DeviceProcessLogShow($"订单【{mORKS.IngredientsCompleteId}】制作完成");
  561. mORKS.CookCompleteFlatBit = true;
  562. mORKS.OutMealId = mORKS.IngredientsCompleteId;
  563. mORKS.OutMealName = mORKS.IngredientsCompleteName;
  564. mORKS.IngredientsCompleteId = string.Empty;
  565. mORKS.CookNodelId[loc] = string.Empty;
  566. DeviceProcessLogShow($"{loc + 1} 号位置出餐控制,订单ID:{mORKS.OutMealId}");
  567. mORKS.CookNoodleCom[loc] = false;
  568. }
  569. }
  570. }
  571. }
  572. /// <summary>
  573. /// 信号检测
  574. /// </summary>
  575. private void SingleDetect()
  576. {
  577. //允许倒面信号检测
  578. if (RTrig.GetInstance("AllowFallNoodle").Start(mORKS.AllowInvertedFace))
  579. {
  580. mORKS.IngredientsCompleteId = mORKS.TakeBowlId;
  581. mORKS.IngredientsCompleteName = mORKS.TakeBowName;
  582. mORKS.TakeBowlId = string.Empty;
  583. mORKS.TakeBowName = string.Empty;
  584. DeviceProcessLogShow($"碗到位,允许到面,{mORKS.IngredientsCompleteId}");
  585. mORKS.TakeBowlInterlock = false;
  586. }
  587. //取餐完成逻辑处理
  588. if (RTrig.GetInstance("CompleteChange1").Start(mORKS.DiningComplete) && mORKS.CookCompleteFlatBit == true)
  589. {
  590. OrderChange(mORKS.OutMealId, ORDER_STATUS.COMPLETED_TAKE);
  591. DeviceProcessLogShow($"订单【{mORKS.OutMealId}】取餐完成");
  592. WriteData("M10.1", false);
  593. mORKS.CookCompleteFlatBit = false;
  594. mORKS.OutMealId = string.Empty;
  595. mORKS.OutMealName = string.Empty;
  596. }
  597. //机器人取面完成信号检测
  598. if (RTrig.GetInstance("TakeNoodleComplete").Start(mORKS.RobotTakeNoodleCom))
  599. {
  600. mORKS.TakeNoodleInterlock = false;
  601. mORKS.AllowTakeNoodle = false;
  602. mORKS.TurntableInterlock = false;
  603. DeviceProcessLogShow("机器人取面完成信号检测");
  604. }
  605. int OutMealRequstCount = mORKS.CookNoodleCom.Where(p => p == true).ToList().Count;
  606. //int mlCount = mORKS.NoodleCookerStatus.Where(p => p == true).ToList().Count - Json<MorksPar>.Data.parSets.Where(x => x.IsShield == true).ToList().Count;
  607. int mlCount = mORKS.nsm.Where(p => p.NoodleCookerStatus == true && p.IsShield == false).ToList().Count;
  608. int index = Array.FindIndex(mORKS.CookNodelId, p => p == mORKS.IngredientsCompleteId);
  609. bool isok = index >= 0 && index < mORKS.CookNoodleCom.Length && mORKS.CookNoodleCom[index];
  610. mORKS.PriorityJudgment = Delay.GetInstance("取餐优先级判断").Start(mORKS.TurntableLocLists.Count > 0 && !mORKS.TurntableLowPosition, 4);
  611. //mORKS.RobotTaskInterlock = OutMealRequstCount > 0 && mORKS.AllowInvertedFace && (mlCount >= 2 || mORKS.RBTakeNoodleTask.Count == 0 || mORKS.PriorityJudgment);
  612. mORKS.RobotTaskInterlock = isok && mORKS.AllowInvertedFace && (mlCount >= 2 || mORKS.RBTakeNoodleTask.Count == 0 || mORKS.PriorityJudgment);
  613. }
  614. /// <summary>
  615. /// 语音提醒取餐
  616. /// </summary>
  617. /// <param name="meal"></param>
  618. private void WaitMeaLSpeak(string meal)
  619. {
  620. //VoiceAPI.m_SystemPlayWav(@"Vioce\电子提示音.wav");
  621. //Thread.Sleep(1000);
  622. //if (meal != null) mORKS.speech.Speak(meal);
  623. //VoiceAPI.m_SystemPlayWav(@"Vioce\取餐通知.wav");
  624. }
  625. #region PLC 控制函数
  626. private void WriteData(string address, object value)
  627. {
  628. EventBus.EventBus.GetInstance().Publish(new WriteModel() { DeviceId = DeviceId, Address = address, Value = value });
  629. }
  630. /// <summary>
  631. /// 设备初始化
  632. /// </summary>
  633. public async void DeviceInit()
  634. {
  635. WriteData("M0.0", true);
  636. await Task.Delay(1000);
  637. WriteData("M0.0", false);
  638. }
  639. /// <summary>
  640. /// 取碗控制
  641. /// </summary>
  642. /// <param name="loc"></param>
  643. private void TakeBowlControl(ushort loc)
  644. {
  645. if (loc == 10)//一次性碗
  646. {
  647. WriteData("M9.1", true);
  648. }
  649. else if (loc == 11)//大碗
  650. {
  651. WriteData("M9.0", true);
  652. }
  653. }
  654. /// <summary>
  655. /// 启动转台
  656. /// </summary>
  657. /// <param name="loc"></param>
  658. private void TurntableStart(ushort loc)
  659. {
  660. if (loc >= 1 && loc <= 5)
  661. {
  662. mORKS.CurrentLoc = loc;
  663. mORKS.TurntableInterlock = true;
  664. mORKS.TurntableLocLists.Add(loc);
  665. WriteData($"M13.{loc - 1}", true);
  666. }
  667. }
  668. /// <summary>
  669. /// 设置倒面位置
  670. /// </summary>
  671. /// <param name="loc"></param>
  672. private void SetFallNoodleLoc(ushort loc)
  673. {
  674. if (loc >= 1 && loc <= 6)
  675. WriteData($"M14.{loc - 1}", true);
  676. }
  677. /// <summary>
  678. /// 设置取面位置
  679. /// </summary>
  680. /// <param name="loc"></param>
  681. private void SetTakeNoodleLoc(ushort loc)
  682. {
  683. if (loc >= 1 && loc <= 6)
  684. WriteData($"M15.{loc - 1}", true);
  685. }
  686. public override void SimOrder()
  687. {
  688. EventBus.EventBus.GetInstance().Subscribe<MorksSimorderModel>(0, delegate (IEvent @event, EventCallBackHandle callBackHandle)
  689. {
  690. if (@event != null && @event is MorksSimorderModel msm)
  691. {
  692. string guid = Guid.NewGuid().ToString();
  693. if (msm.NoodleLoc >= 1 && msm.NoodleLoc <= 5)
  694. {
  695. mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { Loc = (ushort)msm.NoodleLoc, SuborderId = guid });
  696. MessageLog.GetInstance.Show($"添加订单:面条位置【{(ushort)msm.NoodleLoc}】");
  697. }
  698. if (msm.Bowloc >= 10 && msm.Bowloc <= 11)
  699. {
  700. mORKS.TakeBowlTask.Enqueue(new OrderLocInfo() { Loc = (ushort)msm.Bowloc, SuborderId = guid });
  701. MessageLog.GetInstance.Show($"添加订单:碗位置【{(ushort)msm.Bowloc}】");
  702. }
  703. }
  704. });
  705. }
  706. #endregion
  707. }
  708. }