终端一体化运控平台
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1348 lines
64 KiB

  1. using BPASmartClient.CustomResource;
  2. using static BPA.Helper.EventBus;
  3. using System.Collections.Concurrent;
  4. using BPASmartClient.Model.煮面机;
  5. using BPASmartClient.ViewModel;
  6. using AlarModel = BPA.Message.AlarmModel;
  7. using Microsoft.VisualBasic.Logging;
  8. using System.Collections.ObjectModel;
  9. //using BPA.Helper;
  10. namespace BPASmartClient.MorkSUpgradedVer
  11. {
  12. public class Control_MorkSUpgradedVer : BaseDevice
  13. {
  14. public override DeviceClientType DeviceType => DeviceClientType.MORKS;
  15. private GVL_MorkSUpgradedVer mORKS = new GVL_MorkSUpgradedVer();
  16. private Alarm alarm = new Alarm();
  17. public override void DoMain()
  18. {
  19. base.IsConnected = false;
  20. base.stateAction = o =>
  21. {
  22. if (o)
  23. NoodOrderCtrl.GetInstance.StateShow("设备正常运行");
  24. else
  25. NoodOrderCtrl.GetInstance.StateShow("设备未连接");
  26. };
  27. MonitorViewModel.DeviceId = DeviceId;
  28. ServerInit();
  29. DataParse();
  30. Json<MorksPar>.Read();
  31. Json<OrderStatistics>.Read();
  32. if (Json<MorksPar>.Data.parSets == null)
  33. 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>((obj) =>
  50. {
  51. ObservableCollection<MorkOrder> morks = (ObservableCollection<MorkOrder>)obj;
  52. if (morks.Count > 0)
  53. {
  54. morks.ToList().ForEach(t =>
  55. {
  56. var res = FoodMenuViewModel.orderStatusLists.FirstOrDefault(o=>o.OrderPush.SortNum == t.OrderPush.SortNum);
  57. if (res != null)
  58. {
  59. if (string.IsNullOrEmpty(res.OrderPush.SuborderId))
  60. {
  61. NoodOrderCtrl.GetInstance.WorkList(res);
  62. mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { Loc = (ushort)Json<NoodOrder>.Data.localOrder[res.OrderPush.GoodsName].NoodleLoc, SuborderId = res.OrderPush.SuborderId });
  63. MessageLog.GetInstance.Show($"添加订单:面条位置【{Json<NoodOrder>.Data.localOrder[res.OrderPush.GoodsName].NoodleLoc}】");
  64. mORKS.TakeBowlTask.Enqueue(new OrderLocInfo() { Loc = (ushort)Json<NoodOrder>.Data.localOrder[res.OrderPush.GoodsName].Bowloc, SuborderId = res.OrderPush.SuborderId });
  65. MessageLog.GetInstance.Show($"添加订单:碗位置【{Json<NoodOrder>.Data.localOrder[res.OrderPush.GoodsName].Bowloc}】");
  66. Global.EnableLocalSimOrder = true;
  67. }
  68. }
  69. });
  70. //foreach (var item in FoodMenuViewModel.orderStatusLists)
  71. //{
  72. // if (string.IsNullOrEmpty(item.OrderPush.SuborderId))
  73. // {
  74. // item.OrderPush.SortNum = FoodMenuViewModel.SortNum++;
  75. // item.OrderPush.SuborderId = Guid.NewGuid().ToString();
  76. // var res = mORKS.RBTakeNoodleTask.FirstOrDefault(o => o.SuborderId == item.OrderPush.SuborderId);
  77. // if (res == null)
  78. // {
  79. // mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { Loc = (ushort)Json<NoodOrder>.Data.localOrder[item.OrderPush.GoodsName].NoodleLoc, SuborderId = item.OrderPush.SuborderId });
  80. // MessageLog.GetInstance.Show($"添加订单:面条位置【{Json<NoodOrder>.Data.localOrder[item.OrderPush.GoodsName].NoodleLoc}】");
  81. // mORKS.TakeBowlTask.Enqueue(new OrderLocInfo() { Loc = (ushort)Json<NoodOrder>.Data.localOrder[item.OrderPush.GoodsName].Bowloc, SuborderId = item.OrderPush.SuborderId });
  82. // MessageLog.GetInstance.Show($"添加订单:碗位置【{Json<NoodOrder>.Data.localOrder[item.OrderPush.GoodsName].Bowloc}】");
  83. // Global.EnableLocalSimOrder = true;
  84. // }
  85. // }
  86. //}
  87. }
  88. }), "EnableForOrder");
  89. //ActionManage.GetInstance.Register(new Action<object[]>((o) =>
  90. //{
  91. // if (o.Length > 0)
  92. // {
  93. // Random rd = new Random();
  94. // TaskManage.GetInstance.StartLong(new Action(() =>
  95. // {
  96. // int NoodleLoc = (int)o[0] == 0 ? rd.Next(1, 6) : (int)o[0];
  97. // int BowlLoc = (int)o[1] == 0 ? rd.Next(10, 12) : (int)o[1];
  98. // string guid = Guid.NewGuid().ToString();
  99. // mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { Loc = (ushort)NoodleLoc, SuborderId = guid });
  100. // MessageLog.GetInstance.Show($"添加订单:面条位置【{NoodleLoc}】");
  101. // mORKS.TakeBowlTask.Enqueue(new OrderLocInfo() { Loc = (ushort)BowlLoc, SuborderId = guid });
  102. // MessageLog.GetInstance.Show($"添加订单:碗位置【{BowlLoc}】");
  103. // Thread.Sleep(60000);
  104. // }), "ForOrder");
  105. // }
  106. //}), "EnableForOrder");
  107. ActionManage.GetInstance.Register(new Action<object>((o) =>
  108. {
  109. if (o != null && o is WritePar writePar)
  110. WriteData(writePar.Address, writePar.Value);
  111. }), "WriteVW");
  112. ActionManage.GetInstance.Register(new Action<object>((o) =>
  113. {
  114. if (o != null && o is WritePar writePar)
  115. WriteData(writePar.Address, writePar.Value);
  116. }), "WriteBools");
  117. ActionManage.GetInstance.Register(new Action(() => { DeviceInit(); }), "InitDevice");
  118. #region 单步控制
  119. ActionManage.GetInstance.Register(new Action<object>((o) =>
  120. {
  121. if (o!=null&& o is int BowLoc)
  122. {
  123. if (!mORKS.DropBowlMechanismStatus&& BowLoc!=0)
  124. {
  125. TakeBowlControl((ushort)BowLoc);
  126. }
  127. else
  128. NoodOrderCtrl.GetInstance.Show("等待取碗未完成,请稍候重试!");
  129. }
  130. }),"BowCtrl");
  131. ActionManage.GetInstance.Register(new Action<object>((o) =>
  132. {
  133. if (o != null && o is int turn)
  134. {
  135. if (mORKS.SiloInPlace && !mORKS.FixedFlag && mORKS.InitComplete&&turn !=0)
  136. {
  137. TurntableStart((ushort)turn);
  138. var res = DeviceCtrlViewModel.CtrlTurns.FirstOrDefault(o => o.Set == $"{turn} 号位");
  139. res.UnderSet = true;
  140. }
  141. else
  142. {
  143. NoodOrderCtrl.GetInstance.Show("转台工作中,请稍候重试!");
  144. var res = DeviceCtrlViewModel.CtrlTurns.FirstOrDefault(o => o.Set == $"{turn} 号位");
  145. res.UnderSet = false;
  146. }
  147. }
  148. }), "TurnableCtrl");
  149. ActionManage.GetInstance.Register(new Action<object>((o) =>
  150. {
  151. if (o != null && o is DoNoodle doN)
  152. {
  153. List<ushort> values = new List<ushort>();
  154. ushort s = 0;
  155. values.Add((ushort)doN.Min);
  156. values.Add((ushort)doN.Senc);
  157. WriteData($"VW{324 + ((doN.Reset - 1) * 4)}", values.ToArray());
  158. WriteData($"VW4", s.SetBitValue(Convert.ToByte(doN.Reset + 6), true));
  159. s = 0;
  160. WriteData($"VW4", s.SetBitValue(Convert.ToByte(doN.Reset), true));
  161. }
  162. }), "Startset");
  163. #endregion
  164. }
  165. public override void ResetProgram()
  166. {
  167. mORKS = null;
  168. mORKS = new GVL_MorkSUpgradedVer();
  169. }
  170. public override void Stop()
  171. {
  172. }
  173. private void ServerInit()
  174. {
  175. //物料信息
  176. EventBus.GetInstance().Subscribe<MaterialDeliveryEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  177. {
  178. if (@event == null)
  179. return;
  180. if (@event is MaterialDeliveryEvent material)
  181. {
  182. orderMaterialDelivery = material.orderMaterialDelivery;
  183. }
  184. });
  185. //配方数据信息
  186. EventBus.GetInstance().Subscribe<RecipeBomEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  187. {
  188. if (@event == null)
  189. return;
  190. if (@event is RecipeBomEvent recipe)
  191. {
  192. recipeBoms = recipe.recipeBoms;
  193. }
  194. });
  195. OrderNotifyInit();
  196. }
  197. #region 接口通知任务处理
  198. ConcurrentQueue<OrderStatusModel> osm = new ConcurrentQueue<OrderStatusModel>();
  199. private void OrderNotifyInit()
  200. {
  201. TaskManage.GetInstance.StartLong(() =>
  202. {
  203. while (osm.Count > 0)
  204. {
  205. TempOrderChange(osm.ElementAt(0).SubOrderId, osm.ElementAt(0).Status, () =>
  206. {
  207. osm.TryDequeue(out OrderStatusModel tempOSM);
  208. DeviceProcessLogShow($"订单:【{tempOSM.SubOrderId}】, 状态:【{tempOSM.Status}】, API状态修改成功");
  209. });
  210. }
  211. Thread.Sleep(100);
  212. }, $"订单状态更新接口{DeviceId}", true);
  213. }
  214. private void TempOrderChange(string subid, ORDER_STATUS oRDER_STATUS, Action complete)
  215. {
  216. if (mORKS.doOrderEvents!=null&&mORKS.doOrderEvents.Count>0&&!string.IsNullOrEmpty(subid))
  217. {
  218. var res = mORKS.doOrderEvents.Find(p => p.MorkOrder.SuborderId == subid);
  219. string goodName = string.Empty;
  220. string SortNum = string.Empty;
  221. if (res != null)
  222. {
  223. goodName = res.MorkOrder.GoodsName;
  224. SortNum = res.MorkOrder.SortNum.ToString();
  225. }
  226. if (!string.IsNullOrEmpty(goodName) && !string.IsNullOrEmpty(SortNum))
  227. {
  228. EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { SortNum = SortNum, GoodName = goodName, Status = oRDER_STATUS, SubOrderId = subid, deviceClientType = DeviceType }, e => { complete?.Invoke(); });
  229. var index = DataServer.GetInstance.morkS.MakeOrder.FindIndex(p => p.SortNum == SortNum);
  230. //如果订单信息已经存在,则修改状态,否则新增。
  231. if (index >= 0 && index < DataServer.GetInstance.morkS.MakeOrder.Count)
  232. {
  233. if (oRDER_STATUS == ORDER_STATUS.COMPLETED_COOK)
  234. {
  235. DataServer.GetInstance.morkS.MakeOrder.RemoveAt(index);
  236. DataServer.GetInstance.morkS.MakeOrderOver.Add(new OrderMakeModel()
  237. {
  238. Status = oRDER_STATUS,
  239. GoodName = goodName,
  240. SortNum = SortNum,
  241. StopTime = DateTime.Now.ToString("HH:mm:ss")
  242. });
  243. }
  244. else if (oRDER_STATUS == ORDER_STATUS.COMPLETED_TAKE)
  245. {
  246. var temp = DataServer.GetInstance.morkS.MakeOrderOver.FirstOrDefault(p => p.SortNum == SortNum);
  247. if (temp != null) DataServer.GetInstance.morkS.MakeOrderOver.Remove(temp);
  248. }
  249. else DataServer.GetInstance.morkS.MakeOrder.ElementAt(index).Status = oRDER_STATUS;
  250. }
  251. else
  252. {
  253. DataServer.GetInstance.morkS.MakeOrder.Add(new OrderMakeModel()
  254. {
  255. Status = oRDER_STATUS,
  256. GoodName = goodName,
  257. SortNum = SortNum,
  258. StartTime = DateTime.Now.ToString("HH:mm:ss")
  259. });
  260. }
  261. }
  262. }
  263. }
  264. #endregion
  265. private void OrderChange(string subid, ORDER_STATUS oRDER_STATUS)
  266. {
  267. osm.Enqueue(new OrderStatusModel() { SubOrderId = subid, Status = oRDER_STATUS });
  268. return;
  269. var res = mORKS.doOrderEvents.FirstOrDefault(p => p.MorkOrder.SuborderId == subid);
  270. string goodName = string.Empty;
  271. string SortNum = string.Empty;
  272. if (res != null)
  273. {
  274. goodName = res.MorkOrder.GoodsName;
  275. SortNum = res.MorkOrder.SortNum.ToString();
  276. }
  277. //if (mORKS.doe.ContainsKey(subid))
  278. //{
  279. // goodName = mORKS.doe[subid].MorkOrder.GoodsName;
  280. // SortNum = mORKS.doe[subid].MorkOrder.SortNum.ToString();
  281. if (!string.IsNullOrEmpty(goodName) && !string.IsNullOrEmpty(SortNum))
  282. {
  283. EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { SortNum = SortNum, GoodName = goodName, Status = oRDER_STATUS, SubOrderId = subid, deviceClientType = DeviceType });
  284. var index = DataServer.GetInstance.morkS.MakeOrder.FindIndex(p => p.SortNum == SortNum);
  285. //如果订单信息已经存在,则修改状态,否则新增。
  286. if (index >= 0 && index < DataServer.GetInstance.morkS.MakeOrder.Count)
  287. {
  288. if (oRDER_STATUS == ORDER_STATUS.COMPLETED_COOK)
  289. {
  290. DataServer.GetInstance.morkS.MakeOrder.RemoveAt(index);
  291. DataServer.GetInstance.morkS.MakeOrderOver.Add(new OrderMakeModel()
  292. {
  293. Status = oRDER_STATUS,
  294. GoodName = goodName,
  295. SortNum = SortNum,
  296. StopTime = DateTime.Now.ToString("HH:mm:ss")
  297. });
  298. }
  299. else if (oRDER_STATUS == ORDER_STATUS.COMPLETED_TAKE)
  300. {
  301. var temp = DataServer.GetInstance.morkS.MakeOrderOver.FirstOrDefault(p => p.SortNum == SortNum);
  302. if (temp != null)
  303. DataServer.GetInstance.morkS.MakeOrderOver.Remove(temp);
  304. }
  305. else
  306. {
  307. DataServer.GetInstance.morkS.MakeOrder.ElementAt(index).Status = oRDER_STATUS;
  308. }
  309. }
  310. else
  311. {
  312. DataServer.GetInstance.morkS.MakeOrder.Add(new OrderMakeModel()
  313. {
  314. Status = oRDER_STATUS,
  315. GoodName = goodName,
  316. SortNum = SortNum,
  317. StartTime = DateTime.Now.ToString("HH:mm:ss")
  318. });
  319. }
  320. //mORKS.doe.Remove(subid, out _);
  321. }
  322. //}
  323. //var res = mORKS.doOrderEvents.FirstOrDefault(p => p.MorkOrder.SuborderId == subid);
  324. //string goodName = string.Empty;
  325. //string SortNum = string.Empty;
  326. //if (res != null)
  327. //{
  328. // goodName = res.MorkOrder.GoodsName;
  329. // SortNum = res.MorkOrder.SortNum.ToString();
  330. //}
  331. //EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { SortNum = SortNum, GoodName = goodName, Status = oRDER_STATUS, SubOrderId = subid, deviceClientType = DeviceType });
  332. //var index = DataServer.GetInstance.morkS.MakeOrder.FindIndex(p => p.SortNum == SortNum);
  333. //if (index >= 0 && index < DataServer.GetInstance.morkS.MakeOrder.Count)
  334. //{
  335. // if (oRDER_STATUS == ORDER_STATUS.COMPLETED_COOK)
  336. // {
  337. // DataServer.GetInstance.morkS.MakeOrder.RemoveAt(index);
  338. // DataServer.GetInstance.morkS.MakeOrderOver.Add(new OrderMakeModel()
  339. // {
  340. // Status = oRDER_STATUS,
  341. // GoodName = goodName,
  342. // SortNum = SortNum,
  343. // StopTime = DateTime.Now.ToString("HH:mm:ss")
  344. // });
  345. // }
  346. // else if (oRDER_STATUS == ORDER_STATUS.COMPLETED_TAKE)
  347. // {
  348. // var temp = DataServer.GetInstance.morkS.MakeOrderOver.FirstOrDefault(p => p.SortNum == SortNum);
  349. // if (temp != null) DataServer.GetInstance.morkS.MakeOrderOver.Remove(temp);
  350. // }
  351. // else
  352. // {
  353. // DataServer.GetInstance.morkS.MakeOrder.ElementAt(index).Status = oRDER_STATUS;
  354. // }
  355. //}
  356. //else
  357. //{
  358. // DataServer.GetInstance.morkS.MakeOrder.Add(new OrderMakeModel()
  359. // {
  360. // Status = oRDER_STATUS,
  361. // GoodName = goodName,
  362. // SortNum = SortNum,
  363. // StartTime = DateTime.Now.ToString("HH:mm:ss")
  364. // });
  365. //}
  366. }
  367. private void GetStatus(string key, Action<object> action)
  368. {
  369. if (peripheralStatus.ContainsKey(key))
  370. {
  371. if (peripheralStatus[key] != null)
  372. {
  373. action?.Invoke(peripheralStatus[key]);
  374. }
  375. }
  376. }
  377. public override void ReadData()
  378. {
  379. #region 检测是否正常运行
  380. if (DataServer.GetInstance.morkS.Alarm.Count > 0)
  381. {
  382. NoodOrderCtrl.GetInstance.StateShow("设备异常");
  383. }
  384. #endregion
  385. DataServer.GetInstance.morkS.Alarm.Clear();
  386. alarms.ForEach(item =>
  387. {
  388. DataServer.GetInstance.morkS.Alarm.Add(new BPA.Message.AlarmModel()
  389. {
  390. AlarmTime = $"{item.Date} {item.Time}",
  391. AlarmMs = item.Info
  392. });
  393. });
  394. GetStatus("M0.1", new Action<object>((obj) =>
  395. {
  396. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 7)
  397. {
  398. Initing = !bools[0];
  399. mORKS.InitComplete = bools[0];
  400. mORKS.MoveScrewRodInitCom = bools[1];
  401. mORKS.SacrificialVesselInitCom = bools[2];
  402. mORKS.CylinderInitCom = bools[3];
  403. mORKS.NoodleCookerInitCom = bools[4];
  404. mORKS.RobotInitCom = bools[5];
  405. mORKS.SiloInitCom = bools[6];
  406. alarm.DeviceNoInit = !mORKS.InitComplete;
  407. alarm.MoveScrewRodNoInit = !mORKS.MoveScrewRodInitCom;
  408. alarm.SacrificialVesselNoInit = !mORKS.SacrificialVesselInitCom;
  409. alarm.CylinderNoInit = !mORKS.CylinderInitCom;
  410. alarm.NoodleCookerNoInit = !mORKS.NoodleCookerInitCom;
  411. alarm.RobotNoInit = !mORKS.RobotInitCom;
  412. alarm.SiloNoInit = !mORKS.SiloInitCom;
  413. }
  414. }));
  415. GetStatus("M20.0", new Action<object>((obj) =>
  416. {
  417. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 6)
  418. {
  419. mORKS.Nsm = bools;
  420. for (int i = 0; i < bools.Length; i++)
  421. {
  422. var res = NoodOrderCtrl.GetInstance.doNoodles.FirstOrDefault(o => o.Reset == (i + 1));
  423. if (bools[i])
  424. {
  425. if (res.Docook)
  426. {
  427. res.Docook = false;
  428. res.BtnIsChecked = false;
  429. NoodOrderCtrl.GetInstance.Flush(res);
  430. }
  431. }
  432. else
  433. {
  434. if (!res.Docook)
  435. {
  436. res.Docook = true;
  437. res.BtnIsChecked = true;
  438. NoodOrderCtrl.GetInstance.Flush(res);
  439. }
  440. }
  441. }
  442. }
  443. }));
  444. GetStatus("M10.0", new Action<object>((obj) =>
  445. {
  446. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 2)
  447. {
  448. mORKS.AllowInvertedFace = bools[0];
  449. mORKS.DiningComplete = bools[1];
  450. }
  451. }));
  452. GetStatus("M10.4", new Action<object>((obj) =>
  453. {
  454. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 1)
  455. {
  456. mORKS.DropBowlMechanismStatus = bools[0];
  457. }
  458. }));
  459. GetStatus("M12.2", new Action<object>((obj) =>
  460. {
  461. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 1)
  462. {
  463. mORKS.FixedFlag = bools[0];
  464. if (!mORKS.FixedFlag&& NoodOrderCtrl.GetInstance.stateInfo== "补料中")
  465. NoodOrderCtrl.GetInstance.StateShow("设备正常运行");
  466. }
  467. }));
  468. GetStatus("M13.5", new Action<object>((obj) =>
  469. {
  470. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 1)
  471. {
  472. mORKS.SiloInPlace = bools[0];
  473. }
  474. }));
  475. GetStatus("M16.7", new Action<object>((obj) =>
  476. {
  477. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 1)
  478. {
  479. mORKS.RobotTakeNoodleCom = bools[0];
  480. }
  481. }));
  482. GetStatus("M17.4", new Action<object>((obj) =>
  483. {
  484. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 1)
  485. {
  486. mORKS.RobotStatus = bools[0];
  487. }
  488. }));
  489. GetStatus("M18.0", new Action<object>((obj) =>
  490. {
  491. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 5)
  492. {
  493. mORKS.SmallBowlYesOrNoCheck = bools[0];
  494. mORKS.LargeBowYesOrNoCheck = bools[1];
  495. mORKS.TurntableLowPosition = bools[2];
  496. mORKS.TurntableHighPosition = bools[3];
  497. alarm.Supply2_LossBowl = !mORKS.SmallBowlYesOrNoCheck;
  498. alarm.Supply1_LossBowl = !mORKS.LargeBowYesOrNoCheck;
  499. }
  500. }));
  501. GetStatus("VW17", new Action<object>((obj) =>
  502. {
  503. if (obj is ushort[] ushorts && ushorts.Length > 0 && ushorts.Length <= 1)
  504. {
  505. var tt = ushorts.ToBytes(true).ToUshorts();
  506. for (byte i = 0; i < 6; i++)
  507. {
  508. if (RTrig.GetInstance($"CookNoodleCom{i + 1}").Start(tt[0].GetBitValue((byte)(i + 1))))
  509. {
  510. if (!string.IsNullOrEmpty(mORKS.CookNodelId[i]))
  511. mORKS.CookNoodleCom[i] = true;
  512. }
  513. }
  514. //mORKS.CookNoodleCom[0] = tt[0].GetBitValue(1);
  515. //mORKS.CookNoodleCom[1] = tt[0].GetBitValue(2);
  516. //mORKS.CookNoodleCom[2] = tt[0].GetBitValue(3);
  517. //mORKS.CookNoodleCom[3] = tt[0].GetBitValue(4);
  518. //mORKS.CookNoodleCom[4] = tt[0].GetBitValue(5);
  519. //mORKS.CookNoodleCom[5] = tt[0].GetBitValue(6);
  520. mORKS.Heating = ushorts[0].GetBitValue(15);
  521. mORKS.TemperatureReaches = ushorts[0].GetBitValue(16);
  522. alarm.MachineLowTemperature = !mORKS.TemperatureReaches;
  523. }
  524. }));
  525. GetStatus("VW770", new Action<object>((obj) =>
  526. {
  527. if (obj is ushort[] ushorts && ushorts.Length > 0 && ushorts.Length <= 1)
  528. {
  529. if (mORKS.CurrentFeedbackLoc != ushorts[0])
  530. {
  531. var res = DeviceCtrlViewModel.CtrlTurns.FirstOrDefault(o => o.Set == $"{ushorts[0]} 号位");
  532. if (res != null)
  533. {
  534. foreach (var value in DeviceCtrlViewModel.CtrlTurns)
  535. {
  536. if (value.Set!= $"{ushorts[0]} 号位"&&value.UnderSet)
  537. {
  538. value.UnderSet =false;
  539. }
  540. }
  541. res.UnderSet = true;
  542. NoodOrderCtrl.GetInstance.Show($"料仓当前位置:{res.Set}");
  543. }
  544. }
  545. mORKS.CurrentFeedbackLoc = ushorts[0];
  546. }
  547. }));
  548. mORKS.TakeBowlTaskCount = mORKS.TakeBowlTask.Count;
  549. mORKS.RBTakeNoodleTaskCount = mORKS.RBTakeNoodleTask.Count;
  550. for (int i = 0; i < Json<MorksPar>.Data.parSets.Count; i++)
  551. {
  552. mORKS.nsm.ElementAt(i).IsShield = Json<MorksPar>.Data.parSets.ElementAt(i).IsShield;
  553. mORKS.nsm.ElementAt(i).NoodleCookerStatus = mORKS.NoodleCookerStatus[i];
  554. }
  555. }
  556. /// <summary>数据解析</summary>
  557. private void DataParse()
  558. {
  559. EventBus.GetInstance().Subscribe<DoOrderEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle)
  560. {
  561. if (@event == null)
  562. return;
  563. if (@event is DoOrderEvent order)
  564. {
  565. mORKS.doOrderEvents.Add(order);
  566. //mORKS.doe.TryAdd(order.MorkOrder.SuborderId, order);
  567. if (order.MorkOrder.GoodBatchings == null)
  568. return;
  569. if (mORKS.HistorySuborderId.Contains(order.MorkOrder.SuborderId))
  570. return;
  571. OrderCount++;
  572. if (DateTime.Now.Subtract(Json<OrderStatistics>.Data.StatisticsTime).Days != 0)
  573. Json<OrderStatistics>.Data.Count = 0;
  574. Json<OrderStatistics>.Data.StatisticsTime = DateTime.Now;
  575. Json<OrderStatistics>.Data.Count++;
  576. Json<OrderStatistics>.Save();
  577. OrderChange(order.MorkOrder.SuborderId, ORDER_STATUS.WAIT);
  578. DeviceProcessLogShow($"接收到{OrderCount}次订单,订单ID:{order.MorkOrder.SuborderId}");
  579. mORKS.HistorySuborderId.Add(order.MorkOrder.SuborderId);
  580. foreach (var item in order.MorkOrder.GoodBatchings)
  581. {
  582. var res = orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId);
  583. if (res != null)
  584. {
  585. if (ushort.TryParse(res.BatchingLoc, out ushort loc))
  586. {
  587. //在此处处理网络订单(订单本地化)
  588. if (loc >= 1 && loc <= 5)
  589. {
  590. if (mORKS.RBTakeNoodleTask.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  591. mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo()
  592. {
  593. GoodName = order.MorkOrder.GoodsName,
  594. Loc = ushort.Parse(res.BatchingLoc),
  595. SuborderId = order.MorkOrder.SuborderId,
  596. SortNum = order.MorkOrder.SortNum,
  597. IsLocal = false,
  598. BatchingId = res.BatchingId
  599. });
  600. }
  601. else if (loc >= 10 && loc <= 11)
  602. {
  603. int index = 0;
  604. if (recipeBoms != null)
  605. {
  606. index = Array.FindIndex(recipeBoms.RecipeIds?.ToArray(), p => p.RecipeId == order.MorkOrder.RecipeId);
  607. index++;
  608. }
  609. if (mORKS.TakeBowlTask.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  610. mORKS.TakeBowlTask.Enqueue(new OrderLocInfo()
  611. {
  612. BatchingId = res.BatchingId,
  613. GoodName = order.MorkOrder.GoodsName,
  614. Loc = ushort.Parse(res.BatchingLoc),
  615. SuborderId = order.MorkOrder.SuborderId,
  616. SortNum = order.MorkOrder.SortNum,
  617. IsLocal = false,
  618. RecipeNumber = (index >= 1 && index <= 10) ? (ushort)index : (ushort)0
  619. });
  620. }
  621. }
  622. }
  623. }
  624. }
  625. });
  626. #region 添加网络订单至本地展示
  627. //ActionManage.GetInstance.Register(new Action<object[]>((o) =>
  628. //{
  629. // if (o is object[] obj)
  630. // {
  631. // if (o.Length == 2)
  632. // {
  633. // if (o[0] is MorkOrderPush morkOrderpush && o[1] is IDevice device)
  634. // {
  635. // ObservableCollection<MorkOrder> observableCollection = new ObservableCollection<MorkOrder>();
  636. // MorkOrder morkOrder = new MorkOrder()
  637. // {
  638. // OrderPush = morkOrderpush,
  639. // OrderStatus = ORDER_STATUS.WAIT,
  640. // StartDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  641. // FoodMenuModel = new FoodMenuModel() { }
  642. // };
  643. // FoodMenuViewModel.orderStatusLists.Add(morkOrder);
  644. // observableCollection.Add(morkOrder);
  645. // Application.Current?.Dispatcher.BeginInvoke((Action)delegate
  646. // {
  647. // int index = Array.FindIndex(Json<KeepDataBase>.Data.orderLists.ToArray(), p => p.DeviceId == device.DeviceId.ToString());
  648. // if (index < 0)
  649. // {
  650. // Json<KeepDataBase>.Data.orderLists.Add(new OrderData()
  651. // {
  652. // DeviceId = device.DeviceId.ToString(),
  653. // IsAllSelect = true,
  654. // morkOrderPushes = observableCollection,
  655. // });
  656. // }
  657. // else
  658. // {
  659. // Json<KeepDataBase>.Data.orderLists.ElementAt(index).morkOrderPushes.Add(morkOrder);
  660. // }
  661. // orderStatusLists.Add(new MorkOrder()
  662. // {
  663. // OrderPush = morkOrderpush,
  664. // OrderStatus = ORDER_STATUS.WAIT,
  665. // StartDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  666. // });
  667. // });
  668. // }
  669. // }
  670. // }
  671. //}), "AddOrder");
  672. #endregion
  673. }
  674. public override void MainTask()
  675. {
  676. if (mORKS.InitComplete&&NoodOrderCtrl.GetInstance.stateInfo== "设备未初始化")
  677. {
  678. NoodOrderCtrl.GetInstance.StateShow("设备正常运行");
  679. }
  680. if (!mORKS.InitComplete)
  681. {
  682. NoodOrderCtrl.GetInstance.StateShow("设备未初始化");
  683. }
  684. mORKS.AllowRun = mORKS.InitComplete;
  685. if (Json<KeepDataBase>.Data.IsVerify)
  686. IsHealth = mORKS.InitComplete;
  687. else
  688. IsHealth = true;
  689. TakeBowlTask();
  690. TakeNoodleTask();
  691. OutNoodleTask();
  692. SingleDetect();
  693. TurntableControl();
  694. }
  695. private void BowlControl(OrderLocInfo orderLocInfo)
  696. {
  697. if (orderLocInfo.Loc >= 10 && orderLocInfo.Loc <= 11)
  698. {
  699. //mORKS.TakeBowlId = orderLocInfo.SuborderId;
  700. mORKS.TakeBowName = orderLocInfo.GoodName;
  701. mORKS.TakeBowSortNum = orderLocInfo.SortNum;
  702. TakeBowlControl(orderLocInfo.Loc);
  703. //OrderChange(mORKS.TakeBowlId, ORDER_STATUS.COOKING);
  704. OrderChange(orderLocInfo.SuborderId, ORDER_STATUS.COOKING);
  705. var res = FoodMenuViewModel.orderStatusLists.FirstOrDefault(o => o.OrderPush.SuborderId == orderLocInfo.SuborderId );
  706. if (res != null)
  707. res.OrderStatus = ORDER_STATUS.COOKING;
  708. else
  709. DeviceProcessLogShow($"订单【{orderLocInfo.SuborderId}】异常");
  710. //DeviceProcessLogShow($"订单【{mORKS.TakeBowlId}】执行取碗控制,位置:[{orderLocInfo.Loc}]");
  711. //2023-8-5修改修改取碗打印日志。
  712. //DeviceProcessLogShow($"订单【{orderLocInfo.SuborderId}】执行取碗控制,位置:[{orderLocInfo.Loc}]");
  713. DeviceProcessLogShow($"执行取碗控制,位置:[{orderLocInfo.Loc}]");
  714. mORKS.TakeBowlInterlock = true;
  715. }
  716. }
  717. /// <summary>取碗控制</summary>
  718. private void TakeBowlTask()
  719. {
  720. if (mORKS.AllowRun && mORKS.TakeBowlTask.Count > 0 && !mORKS.DropBowlMechanismStatus && !mORKS.TakeBowlInterlock)
  721. {
  722. ushort BowLoc = 0;
  723. var re = FoodMenuViewModel.orderStatusLists.FirstOrDefault(o => o.OrderPush.SuborderId == mORKS.TakeBowlTask.ElementAt(0).SuborderId);
  724. if (re != null)
  725. {
  726. if (mORKS.TakeBowlTask.TryDequeue(out OrderLocInfo orderLocInfo))
  727. {
  728. BowLoc = (ushort)re.FoodMenuModel.BowLoc;
  729. BowlControl(orderLocInfo);
  730. }
  731. }
  732. //var res = orderMaterialDelivery?.BatchingInfo?.Where(p => p.BatchingId == mORKS.TakeBowlTask.ElementAt(0).BatchingId).ToList();
  733. //if (res == null || res?.Count == 0)
  734. //{
  735. // if (mORKS.TakeBowlTask.TryDequeue(out OrderLocInfo orderLocInfo))
  736. // {
  737. // var re = FoodMenuViewModel.orderStatusLists.FirstOrDefault(o => o.OrderPush.SuborderId == orderLocInfo.SuborderId);
  738. // if (re!=null)
  739. // {
  740. // BowlControl(orderLocInfo);
  741. // }
  742. // }
  743. //}
  744. //else
  745. //{
  746. // foreach (var item in res)
  747. // {
  748. // if (ushort.TryParse(item.BatchingLoc, out ushort loc))
  749. // {
  750. // if (loc == 10 && mORKS.SmallBowlYesOrNoCheck)
  751. // {
  752. // BowLoc = loc;
  753. // break;
  754. // }
  755. // else if (loc == 11 && mORKS.LargeBowYesOrNoCheck)
  756. // {
  757. // BowLoc = loc;
  758. // break;
  759. // }
  760. // }
  761. // }
  762. // if (BowLoc >= 10 && BowLoc <= 11)
  763. // {
  764. // if (mORKS.TakeBowlTask.TryDequeue(out OrderLocInfo orderLocInfo))
  765. // {
  766. // orderLocInfo.Loc = BowLoc;
  767. // var re = FoodMenuViewModel.orderStatusLists.FirstOrDefault(o => o.OrderPush.SuborderId == orderLocInfo.SuborderId);
  768. // if (re != null)
  769. // {
  770. // BowlControl(orderLocInfo);
  771. // }
  772. // }
  773. // }
  774. //}
  775. }
  776. }
  777. /// <summary>转台控制</summary>
  778. private void TurntableControl()
  779. {
  780. Global.EnableLocalSimOrder=true;
  781. if (Global.EnableLocalSimOrder)
  782. {
  783. //不做轮询,直接取面,本地订单使用
  784. if (mORKS.SiloInPlace && !mORKS.FixedFlag && mORKS.InitComplete && !mORKS.AllowTakeNoodle && mORKS.RBTakeNoodleTask.Count > 0&& !mORKS.TurntableInterlock)
  785. {
  786. if (!mORKS.TurntableLowPosition)
  787. {
  788. if (mORKS.RBTakeNoodleTask.ElementAt(0).IsLocal)
  789. {
  790. if (mORKS.RBTakeNoodleTask.ElementAt(0).Loc != 0)
  791. {
  792. TurntableStart(mORKS.RBTakeNoodleTask.ElementAt(0).Loc);
  793. //if (!mORKS.TurntableLocLists.Contains(mORKS.RBTakeNoodleTask.ElementAt(0).Loc))
  794. //{
  795. // TurntableStart(mORKS.RBTakeNoodleTask.ElementAt(0).Loc);
  796. //}
  797. //else
  798. //{
  799. // DeviceProcessLogShow("未找到可用的物料信息");
  800. // mORKS.TurntableLocLists.Clear();
  801. //}
  802. }
  803. else
  804. {
  805. if (mORKS.CurrentFeedbackLoc == 5)
  806. {
  807. TurntableStart((ushort)1);
  808. }
  809. else
  810. {
  811. TurntableStart((ushort)(mORKS.CurrentFeedbackLoc + 1));
  812. }
  813. }
  814. }
  815. else
  816. {
  817. if (mORKS.CurrentFeedbackLoc == 5)
  818. {
  819. TurntableStart((ushort)1);
  820. }
  821. else
  822. {
  823. TurntableStart((ushort)(mORKS.CurrentFeedbackLoc + 1));
  824. }
  825. }
  826. }
  827. else
  828. {
  829. if (mORKS.RBTakeNoodleTask.ElementAt(0).IsLocal)
  830. {
  831. if (mORKS.RBTakeNoodleTask.ElementAt(0).Loc == 0)
  832. {
  833. mORKS.RBTakeNoodleTask.ElementAt(0).Loc = mORKS.CurrentFeedbackLoc;
  834. }
  835. TurntableStart(mORKS.RBTakeNoodleTask.ElementAt(0).Loc);
  836. mORKS.AllowTakeNoodle = true;
  837. DeviceProcessLogShow($"控制机器人去转台【{mORKS.RBTakeNoodleTask.ElementAt(0).Loc}】号位置取面");
  838. }
  839. else
  840. {
  841. mORKS.RBTakeNoodleTask.ElementAt(0).Loc = mORKS.CurrentFeedbackLoc;
  842. TurntableStart(mORKS.RBTakeNoodleTask.ElementAt(0).Loc);
  843. mORKS.AllowTakeNoodle = true;
  844. DeviceProcessLogShow($"控制机器人去转台【{mORKS.RBTakeNoodleTask.ElementAt(0).Loc}】号位置取面");
  845. }
  846. }
  847. //if (mORKS.TurntableLowPosition)
  848. //{
  849. // TurntableStart(mORKS.RBTakeNoodleTask.ElementAt(0).Loc);
  850. // mORKS.TurntableLocLists.Clear();
  851. // mORKS.AllowTakeNoodle = true;
  852. // DeviceProcessLogShow($"控制机器人去转台【{mORKS.RBTakeNoodleTask.ElementAt(0).Loc}】号位置取面");
  853. //}
  854. }
  855. }
  856. else
  857. {
  858. //正常轮询
  859. if (Delay.GetInstance("到位检测延时").Start(mORKS.SiloInPlace, 2))
  860. {
  861. if (mORKS.SiloInPlace && !mORKS.Feeding && mORKS.InitComplete && !mORKS.AllowTakeNoodle && mORKS.RBTakeNoodleTask.Count > 0)
  862. {
  863. var result = orderMaterialDelivery.BatchingInfo.Where(p => p.BatchingId == mORKS.RBTakeNoodleTask.ElementAt(0).BatchingId).ToList();
  864. if (result != null)
  865. {
  866. var res = result.FirstOrDefault(P => P.BatchingLoc == mORKS.CurrentFeedbackLoc.ToString());
  867. if (mORKS.TurntableLowPosition && res != null)
  868. {
  869. TurntableStart(mORKS.CurrentFeedbackLoc);
  870. mORKS.TurntableLocLists.Clear();
  871. mORKS.AllowTakeNoodle = true;
  872. DeviceProcessLogShow($"控制机器人去转台【{mORKS.CurrentFeedbackLoc}】号位置取面");
  873. }
  874. else
  875. {
  876. if (!mORKS.TurntableInterlock)
  877. {
  878. foreach (var item in result)
  879. {
  880. if (ushort.TryParse(item.BatchingLoc, out ushort loc))
  881. {
  882. if (mORKS.CurrentFeedbackLoc != loc && !mORKS.TurntableLocLists.Contains(loc))
  883. {
  884. if (!mORKS.TurntableLowPosition)
  885. {
  886. DeviceProcessLogShow($"执行了转台启动互锁信号复位");
  887. }
  888. TurntableStart(loc);
  889. DeviceProcessLogShow($"没有物料检测的启动转台控制,转台位置:[{loc}]");
  890. break;
  891. }
  892. else if (mORKS.CurrentFeedbackLoc == loc && !mORKS.TurntableLocLists.Contains(loc))
  893. mORKS.TurntableLocLists.Add(loc);
  894. }
  895. }
  896. }
  897. }
  898. }
  899. else
  900. DeviceProcessLogShow("未找到可用的物料信息");
  901. }
  902. }
  903. }
  904. //补料中检测 新版未用
  905. if (RTrig.GetInstance("mORKS.Feeding").Start(mORKS.Feeding))
  906. {
  907. NoodOrderCtrl.GetInstance.StateShow("补料中");
  908. mORKS.AllowTakeNoodle = false;
  909. mORKS.TakeNoodleInterlock = false;
  910. }
  911. if (RTrig.GetInstance("mORKS.FixedFlag").Start(mORKS.FixedFlag))
  912. {
  913. NoodOrderCtrl.GetInstance.StateShow("补料中");
  914. mORKS.AllowTakeNoodle = false;
  915. mORKS.TakeNoodleInterlock = false;
  916. }
  917. //转台到位检测
  918. if (RTrig.GetInstance("TurntableInPlace").Start(mORKS.SiloInPlace && mORKS.CurrentLoc == mORKS.CurrentFeedbackLoc))
  919. {
  920. mORKS.TurntableInterlock = false;
  921. DeviceProcessLogShow("转台到位检测");
  922. }
  923. //补料完成检测 新版未用
  924. if (RTrig.GetInstance("FeedComplete").Start(mORKS.FeedComplete))
  925. {
  926. NoodOrderCtrl.GetInstance.StateShow("设备运行正常");
  927. if (!mORKS.AllowTakeNoodle && mORKS.TurntableLocLists.Count > 0)
  928. {
  929. mORKS.TurntableLocLists.Clear();
  930. mORKS.TurntableInterlock = false;
  931. DeviceProcessLogShow("补料完成检测");
  932. }
  933. }
  934. }
  935. /// <summary>取面任务</summary>
  936. private void TakeNoodleTask()
  937. {
  938. //取面控制
  939. if (mORKS.AllowRun && mORKS.RobotStatus && !mORKS.FixedFlag && !mORKS.RobotTaskInterlock && mORKS.AllowTakeNoodle && mORKS.SiloInPlace && !mORKS.TakeNoodleInterlock && mORKS.RBTakeNoodleTask.Count > 0)
  940. {
  941. if (mORKS.CurrentLoc == mORKS.CurrentFeedbackLoc)
  942. {
  943. //int loc = Array.FindIndex(mORKS.NoodleCookerStatus, p => p == false);//查找煮面炉空闲位置r
  944. int loc = mORKS.nsm.ToList().FindIndex(p => p.NoodleCookerStatus == false && p.IsShield == false);//查找煮面炉空闲位置
  945. if (loc >= 0 && loc <= 5)
  946. {
  947. //if (!Json<MorksPar>.Data.parSets.ElementAt(loc).IsShield)//检查该煮面篮是否被屏蔽
  948. //{
  949. var res = FoodMenuViewModel.orderStatusLists.FirstOrDefault(o => o.OrderPush.SuborderId == mORKS.RBTakeNoodleTask.ElementAt(0).SuborderId);
  950. if (res != null)
  951. {
  952. if (mORKS.RBTakeNoodleTask.TryDequeue(out OrderLocInfo orderLocInfo))
  953. {
  954. //写入煮面时间
  955. //List<ushort> values = new List<ushort>();
  956. //values.Add(Json<MorksPar>.Data.parSets.ElementAt(loc).Minute);
  957. //values.Add(Json<MorksPar>.Data.parSets.ElementAt(loc).Second);
  958. //WriteData($"VW{324 + (loc * 4)}", values.ToArray());
  959. if (mORKS.CurrentFeedbackLoc >= 1 && mORKS.CurrentFeedbackLoc <= 5)
  960. {
  961. //var x = Json<MorksPar>.Data.DishLibraryParSets.FirstOrDefault(p => p.TextBlockContext == mORKS.CurrentFeedbackLoc.ToString());
  962. //if (x != null)
  963. //{
  964. List<ushort> values = new List<ushort>();
  965. if (Json<NoodOrder>.Data.localOrder.ContainsKey(res.OrderPush.GoodsName))
  966. {
  967. values.Add((ushort)Json<NoodOrder>.Data.localOrder[res.OrderPush.GoodsName].FryTimeMin);
  968. values.Add((ushort)Json<NoodOrder>.Data.localOrder[res.OrderPush.GoodsName].FryTimeS);
  969. }
  970. else
  971. {
  972. values.Add(2);
  973. values.Add(0);
  974. }
  975. /*
  976. values.Add(re);
  977. values.Add(x.Second);*/
  978. WriteData($"VW{324 + (loc * 4)}", values.ToArray());
  979. //DeviceProcessLogShow($"转盘位置[{mORKS.CurrentFeedbackLoc}]:写入煮面时间{x.Minute}分{x.Second}秒。");
  980. //}
  981. }
  982. mORKS.CurrentLoc = 0;
  983. mORKS.CookNodelId[loc] = orderLocInfo.SuborderId;
  984. mORKS.NoodleCookerStatus[loc] = true;
  985. SetFallNoodleLoc((ushort)(loc + 1));
  986. //机器人开始取面
  987. OrderChange(orderLocInfo.SuborderId, ORDER_STATUS.COOKING);
  988. if (res != null)
  989. res.OrderStatus = ORDER_STATUS.COOKING;
  990. else
  991. DeviceProcessLogShow($"订单【{orderLocInfo.SuborderId}】异常");
  992. DeviceProcessLogShow($"订单【{orderLocInfo.SuborderId}】,机器人倒面至【{loc + 1}】号煮面栏");
  993. mORKS.TakeNoodleInterlock = true;
  994. }
  995. }
  996. }
  997. }
  998. }
  999. }
  1000. /// <summary>出餐控制</summary>
  1001. private void OutNoodleTask()
  1002. {
  1003. if (mORKS.AllowInvertedFace && mORKS.RobotTaskInterlock && !mORKS.RobotOutDinnigLock && !mORKS.TakeNoodleInterlock && mORKS.RobotStatus)
  1004. {
  1005. #region 修改之前的代码
  1006. //int loc = Array.FindIndex(mORKS.CookNodelId, p => p == mORKS.IngredientsCompleteId && p.Length > 0);
  1007. //if (loc >= 0 && loc <= 5)
  1008. //{
  1009. // if (mORKS.CookNoodleCom[loc])
  1010. // {
  1011. // SetTakeNoodleLoc((ushort)(loc + 1));
  1012. // mORKS.NoodleCookerStatus[loc] = false;
  1013. // WriteData($"VW260", (ushort)0);//设置出汤时间
  1014. // OrderChange(mORKS.IngredientsCompleteId, ORDER_STATUS.COMPLETED_COOK);
  1015. // DeviceProcessLogShow($"订单【{mORKS.IngredientsCompleteId}】制作完成");
  1016. // mORKS.CookCompleteFlatBit = true;
  1017. // mORKS.OutMealId = mORKS.IngredientsCompleteId;
  1018. // mORKS.OutMealName = mORKS.IngredientsCompleteName;
  1019. // mORKS.OutMealSortNum = mORKS.IngredientsCompleteSortNum;
  1020. // mORKS.IngredientsCompleteId = string.Empty;
  1021. // mORKS.CookNodelId[loc] = string.Empty;
  1022. // DeviceProcessLogShow($"{loc + 1} 号位置出餐控制,订单ID:{mORKS.OutMealId}");
  1023. // mORKS.CookNoodleCom[loc] = false;
  1024. // }
  1025. //}
  1026. #region 出餐新
  1027. if (FoodMenuViewModel.orderStatusLists.Count>0)
  1028. {
  1029. int loc = mORKS.CookNodelId.ToList().FindIndex(o => o == FoodMenuViewModel.orderStatusLists.Last().OrderPush.SuborderId);
  1030. if (loc>=0&&mORKS.CookNoodleCom[loc] && !mORKS.RobotOutDinnigLock)
  1031. {
  1032. var res = FoodMenuViewModel.orderStatusLists.FirstOrDefault(o => o.OrderPush.SuborderId == mORKS.CookNodelId[loc]);
  1033. if (res != null)
  1034. {
  1035. SetTakeNoodleLoc((ushort)(loc + 1));
  1036. mORKS.NoodleCookerStatus[loc] = false;
  1037. WriteData($"VW260", (ushort)0);//设置出汤时间
  1038. OrderChange(mORKS.CookNodelId[loc], ORDER_STATUS.COMPLETED_COOK);
  1039. NoodOrderCtrl.GetInstance.statusList(res);
  1040. DeviceProcessLogShow($"订单【{mORKS.CookNodelId[loc]}】制作完成");
  1041. mORKS.CookCompleteFlatBit = true;
  1042. mORKS.OutMealId = mORKS.CookNodelId[loc];
  1043. mORKS.OutMealName = mORKS.IngredientsCompleteName;
  1044. mORKS.OutMealSortNum = mORKS.IngredientsCompleteSortNum;
  1045. mORKS.IngredientsCompleteId = string.Empty;
  1046. mORKS.CookNodelId[loc] = string.Empty;
  1047. DeviceProcessLogShow($"{loc + 1} 号位置出餐控制,订单ID:{mORKS.OutMealId}");
  1048. mORKS.CookNoodleCom[loc] = false;
  1049. mORKS.RobotOutDinnigLock = true;
  1050. }
  1051. else
  1052. DeviceProcessLogShow($"订单【{mORKS.CookNodelId[loc]}】异常");
  1053. }
  1054. }
  1055. #endregion
  1056. #endregion 修改之前的代码
  1057. //int loc = mORKS.CookNodelId.ToList().FindIndex(o => o == FoodMenuViewModel.orderStatusLists.First().OrderPush.SuborderId);
  1058. //for (int loc = 0; loc < mORKS.CookNodelId.Length; loc++)
  1059. //{
  1060. // if (mORKS.CookNoodleCom[loc] && !mORKS.RobotOutDinnigLock)
  1061. // {
  1062. // var res = FoodMenuViewModel.orderStatusLists.FirstOrDefault(o => o.OrderPush.SuborderId == mORKS.CookNodelId[loc]);
  1063. // if (res != null)
  1064. // {
  1065. // SetTakeNoodleLoc((ushort)(loc + 1));
  1066. // mORKS.NoodleCookerStatus[loc] = false;
  1067. // WriteData($"VW260", (ushort)0);//设置出汤时间
  1068. // OrderChange(mORKS.CookNodelId[loc], ORDER_STATUS.COMPLETED_COOK);
  1069. // NoodOrderCtrl.GetInstance.statusList(res);
  1070. // DeviceProcessLogShow($"订单【{mORKS.CookNodelId[loc]}】制作完成");
  1071. // mORKS.CookCompleteFlatBit = true;
  1072. // mORKS.OutMealId = mORKS.CookNodelId[loc];
  1073. // mORKS.OutMealName = mORKS.IngredientsCompleteName;
  1074. // mORKS.OutMealSortNum = mORKS.IngredientsCompleteSortNum;
  1075. // mORKS.IngredientsCompleteId = string.Empty;
  1076. // mORKS.CookNodelId[loc] = string.Empty;
  1077. // DeviceProcessLogShow($"{loc + 1} 号位置出餐控制,订单ID:{mORKS.OutMealId}");
  1078. // mORKS.CookNoodleCom[loc] = false;
  1079. // mORKS.RobotOutDinnigLock = true;
  1080. // }
  1081. // else
  1082. // DeviceProcessLogShow($"订单【{mORKS.CookNodelId[loc]}】异常");
  1083. // }
  1084. //}
  1085. }
  1086. }
  1087. /// <summary>信号检测</summary>
  1088. private void SingleDetect()
  1089. {
  1090. //允许倒面信号检测
  1091. if (RTrig.GetInstance("AllowFallNoodle").Start(mORKS.AllowInvertedFace))
  1092. {
  1093. //mORKS.IngredientsCompleteId = mORKS.TakeBowlId;
  1094. mORKS.IngredientsCompleteName = mORKS.TakeBowName;
  1095. mORKS.IngredientsCompleteSortNum = mORKS.TakeBowSortNum;
  1096. mORKS.TakeBowSortNum = 0;
  1097. mORKS.TakeBowlId = string.Empty;
  1098. mORKS.TakeBowName = string.Empty;
  1099. //DeviceProcessLogShow($"碗到位,允许到面,{mORKS.IngredientsCompleteId}");
  1100. DeviceProcessLogShow($"碗到位,允许倒面。");
  1101. mORKS.TakeBowlInterlock = false;
  1102. mORKS.RobotOutDinnigLock = false;
  1103. }
  1104. //取餐完成逻辑处理
  1105. if (RTrig.GetInstance("CompleteChange1").Start(mORKS.DiningComplete) && mORKS.CookCompleteFlatBit == true)
  1106. {
  1107. OrderChange(mORKS.OutMealId, ORDER_STATUS.COMPLETED_TAKE);
  1108. var res = FoodMenuViewModel.WaitTakeMeal.FirstOrDefault(o => o.OrderPush.SuborderId == mORKS.OutMealId);
  1109. if (res != null)
  1110. {
  1111. res.OrderStatus = ORDER_STATUS.COMPLETED_TAKE;
  1112. res.CompleteDate = DateTime.Now.ToString("HH:mm:ss");
  1113. //NoodOrderCtrl.GetInstance.FinishOrder(res);
  1114. }
  1115. else
  1116. DeviceProcessLogShow($"订单【{mORKS.OutMealId}】异常");
  1117. DeviceProcessLogShow($"订单【{mORKS.OutMealId}】取餐完成");
  1118. WriteData("M10.1", false);
  1119. var orderEvent = mORKS.doOrderEvents.FirstOrDefault(order => order.MorkOrder.SuborderId == mORKS.OutMealId);
  1120. mORKS.OutMealSortNum = orderEvent?.MorkOrder.SortNum ?? 0;
  1121. DeviceProcessLogShow($"出餐订单序号【{mORKS.OutMealSortNum}】");
  1122. VoiceAPI.Speak(mORKS.OutMealSortNum.ToString());
  1123. //DeviceProcessLogShow($"叫号系统通知主题【MORKS/VoiceCall/{DeviceId}】");
  1124. //Plugin.GetInstance().GetPlugin<MQTTMgr>().Publish($"MORKS/VoiceCall/{DeviceId}", mORKS.OutMealSortNum.ToString());
  1125. mORKS.CookCompleteFlatBit = false;
  1126. mORKS.OutMealId = string.Empty;
  1127. mORKS.OutMealName = string.Empty;
  1128. mORKS.OutMealSortNum = 0;
  1129. }
  1130. //机器人取面完成信号检测
  1131. if (RTrig.GetInstance("TakeNoodleComplete").Start(mORKS.RobotTakeNoodleCom))
  1132. {
  1133. mORKS.TakeNoodleInterlock = false;
  1134. mORKS.AllowTakeNoodle = false;
  1135. mORKS.TurntableInterlock = false;
  1136. DeviceProcessLogShow("检测到机器人取面完成信号");
  1137. }
  1138. int OutMealRequstCount = mORKS.CookNoodleCom.Where(p => p == true).ToList().Count;
  1139. //int mlCount = mORKS.NoodleCookerStatus.Where(p => p == true).ToList().Count - Json<MorksPar>.Data.parSets.Where(x => x.IsShield == true).ToList().Count;
  1140. int mlCount = mORKS.nsm.Where(p => p.NoodleCookerStatus == true && p.IsShield == false).ToList().Count;
  1141. int index = Array.FindIndex(mORKS.CookNodelId, p => p == mORKS.IngredientsCompleteId);
  1142. bool isok = index >= 0 && index < mORKS.CookNoodleCom.Length && mORKS.CookNoodleCom[index];
  1143. mORKS.PriorityJudgment = Delay.GetInstance("取餐优先级判断").Start(mORKS.TurntableLocLists.Count > 0 && !mORKS.TurntableLowPosition, 4);
  1144. //mORKS.RobotTaskInterlock = OutMealRequstCount > 0 && mORKS.AllowInvertedFace && (mlCount >= 2 || mORKS.RBTakeNoodleTask.Count == 0 || mORKS.PriorityJudgment);
  1145. //mORKS.RobotTaskInterlock = isok && mORKS.AllowInvertedFace && (mlCount >= 2 || mORKS.RBTakeNoodleTask.Count == 0 || mORKS.PriorityJudgment);
  1146. //2023-8-5注释修改,并联出餐请求,出餐优先。
  1147. //mORKS.RobotTaskInterlock = mORKS.AllowInvertedFace && (mlCount >= 6 || mORKS.RBTakeNoodleTask.Count == 0 || mORKS.PriorityJudgment);
  1148. mORKS.RobotTaskInterlock = mORKS.AllowInvertedFace && (OutMealRequstCount >= 1 /*|| mlCount >= 6*/ || mORKS.RBTakeNoodleTask.Count == 0 || mORKS.PriorityJudgment);
  1149. }
  1150. /// <summary>语音提醒取餐</summary>
  1151. /// <param name="meal"></param>
  1152. private void WaitMeaLSpeak(string meal)
  1153. {
  1154. //VoiceAPI.m_SystemPlayWav(@"Vioce\电子提示音.wav");
  1155. //Thread.Sleep(1000);
  1156. //if (meal != null) mORKS.speech.Speak(meal);
  1157. //VoiceAPI.m_SystemPlayWav(@"Vioce\取餐通知.wav");
  1158. }
  1159. #region PLC 控制函数
  1160. private void WriteData(string address, object value)
  1161. {
  1162. EventBus.GetInstance().Publish(new WriteModel() { DeviceId = DeviceId, Address = address, Value = value });
  1163. }
  1164. /// <summary>设备初始化</summary>
  1165. public async void DeviceInit()
  1166. {
  1167. WriteData("M0.0", true);
  1168. await Task.Delay(1000);
  1169. WriteData("M0.0", false);
  1170. }
  1171. /// <summary>取碗控制</summary>
  1172. /// <param name="loc"></param>
  1173. private void TakeBowlControl(ushort loc)
  1174. {
  1175. if (loc == 10)//小碗
  1176. {
  1177. WriteData("M9.1", true);
  1178. }
  1179. else if (loc == 11)//大碗
  1180. {
  1181. WriteData("M9.0", true);
  1182. }
  1183. }
  1184. /// <summary>启动转台</summary>
  1185. /// <param name="loc"></param>
  1186. private void TurntableStart(ushort loc)
  1187. {
  1188. if (loc >= 1 && loc <= 5 )
  1189. {
  1190. mORKS.CurrentLoc = loc;
  1191. mORKS.TurntableInterlock = true;
  1192. if (!mORKS.TurntableLocLists.Contains(loc))
  1193. {
  1194. mORKS.TurntableLocLists.Add(loc);
  1195. }
  1196. //mORKS.TurntableLocLists.Add(loc);
  1197. WriteData($"M13.{loc - 1}", true);
  1198. }
  1199. }
  1200. /// <summary>设置倒面位置</summary>
  1201. /// <param name="loc"></param>
  1202. private void SetFallNoodleLoc(ushort loc)
  1203. {
  1204. if (loc >= 1 && loc <= 6)
  1205. WriteData($"M14.{loc - 1}", true);
  1206. }
  1207. /// <summary>设置出餐位置</summary>
  1208. /// <param name="loc"></param>
  1209. private void SetTakeNoodleLoc(ushort loc)
  1210. {
  1211. if (loc >= 1 && loc <= 6)
  1212. WriteData($"M15.{loc - 1}", true);
  1213. }
  1214. public override void SimOrder()
  1215. {
  1216. EventBus.GetInstance().Subscribe<MorksSimorderModel>(0, delegate (IEvent @event, EventCallBackHandle callBackHandle)
  1217. {
  1218. if (@event != null && @event is MorksSimorderModel msm)
  1219. {
  1220. string guid = Guid.NewGuid().ToString();
  1221. if (msm.NoodleLoc >= 1 && msm.NoodleLoc <= 5)
  1222. {
  1223. mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { Loc = (ushort)msm.NoodleLoc, SuborderId = guid });
  1224. MessageLog.GetInstance.Show($"添加订单:面条位置【{(ushort)msm.NoodleLoc}】");
  1225. }
  1226. if (msm.Bowloc >= 10 && msm.Bowloc <= 11)
  1227. {
  1228. mORKS.TakeBowlTask.Enqueue(new OrderLocInfo() { Loc = (ushort)msm.Bowloc, SuborderId = guid });
  1229. MessageLog.GetInstance.Show($"添加订单:碗位置【{(ushort)msm.Bowloc}】");
  1230. }
  1231. }
  1232. });
  1233. }
  1234. #endregion PLC 控制函数
  1235. }
  1236. }