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

938 lines
38 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using BPA.Message.Enum;
  4. using BPASmartClient.Device;
  5. using BPASmartClient.EventBus;
  6. using BPASmartClient.Model;
  7. using BPASmartClient.Peripheral;
  8. using static BPASmartClient.EventBus.EventBus;
  9. using BPASmartClient.Helper;
  10. using System.Threading;
  11. using BPASmartClient.Message;
  12. using BPA.Message;
  13. using System.Linq;
  14. using BPASmartClient.Model.PLC;
  15. using System.Threading.Tasks;
  16. using System.Reflection;
  17. using BPASmartClient.MorkS.Model;
  18. using System.Collections.ObjectModel;
  19. using BPASmartClient.MorkS.ViewModel;
  20. using BPASmartClient.Business;
  21. using BPASmartClient.Model.小炒机;
  22. using BPA.Models;
  23. using System.Speech.Synthesis;
  24. using System.Windows.Forms;
  25. using System.Media;
  26. using BPASmartClient.CustomResource;
  27. namespace BPASmartClient.MorkS
  28. {
  29. public class Control_Morks : BaseDevice
  30. {
  31. public override DeviceClientType DeviceType => DeviceClientType.MORKS;
  32. GVL_MORKS mORKS = new GVL_MORKS();
  33. Alarm alarm = new Alarm();
  34. public override void DoMain()
  35. {
  36. MonitorViewModel.DeviceId = DeviceId;
  37. ServerInit();
  38. DataParse();
  39. Json<MorksPar>.Read();
  40. Json<OrderStatistics>.Read();
  41. if (Json<MorksPar>.Data.parSets == null) Json<MorksPar>.Data.parSets = new ObservableCollection<ParSet>();
  42. if (Json<MorksPar>.Data.parSets.Count < 6)
  43. {
  44. Json<MorksPar>.Data.parSets.Clear();
  45. for (int i = 0; i < 6; i++)
  46. {
  47. Json<MorksPar>.Data.parSets.Add(new ParSet()
  48. {
  49. CheckBoxContext = $"煮面口{i + 1}屏蔽",
  50. Minute = 1,
  51. Second = 0,
  52. IsShield = false,
  53. TextBlockContext = $"煮面口{i + 1}时间设定"
  54. });
  55. }
  56. }
  57. ActionManage.GetInstance.Register(new Action<object[]>((o) =>
  58. {
  59. if (o.Length > 0)
  60. {
  61. Random rd = new Random();
  62. ThreadManage.GetInstance().StartLong(new Action(() =>
  63. {
  64. int NoodleLoc = (int)o[0] == 0 ? rd.Next(1, 6) : (int)o[0];
  65. int BowlLoc = (int)o[1] == 0 ? rd.Next(10, 12) : (int)o[1];
  66. string guid = new Guid().ToString();
  67. mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { Loc = (ushort)NoodleLoc, SuborderId = guid });
  68. MessageLog.GetInstance.Show($"添加订单:面条位置【{NoodleLoc}】");
  69. mORKS.TakeBowlTask.Enqueue(new OrderLocInfo() { Loc = (ushort)BowlLoc, SuborderId = guid });
  70. MessageLog.GetInstance.Show($"添加订单:碗位置【{BowlLoc}】");
  71. Thread.Sleep(60000);
  72. }), "ForOrder");
  73. }
  74. }), "EnableForOrder");
  75. ActionManage.GetInstance.Register(new Action<object>((o) =>
  76. {
  77. if (o != null && o is WritePar writePar) WriteData(writePar.Address, writePar.Value);
  78. }), "WriteVW");
  79. ActionManage.GetInstance.Register(new Action<object>((o) =>
  80. {
  81. if (o != null && o is WritePar writePar) WriteData(writePar.Address, writePar.Value);
  82. }), "WriteBools");
  83. ActionManage.GetInstance.Register(new Action(() => { DeviceInit(); }), "InitDevice");
  84. }
  85. public override void ResetProgram()
  86. {
  87. mORKS = null;
  88. mORKS = new GVL_MORKS();
  89. }
  90. public override void Stop()
  91. {
  92. }
  93. private void ServerInit()
  94. {
  95. //物料信息
  96. EventBus.EventBus.GetInstance().Subscribe<MaterialDeliveryEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  97. {
  98. if (@event == null) return;
  99. if (@event is MaterialDeliveryEvent material)
  100. {
  101. orderMaterialDelivery = material.orderMaterialDelivery;
  102. }
  103. });
  104. //配方数据信息
  105. EventBus.EventBus.GetInstance().Subscribe<RecipeBomEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  106. {
  107. if (@event == null) return;
  108. if (@event is RecipeBomEvent recipe)
  109. {
  110. recipeBoms = recipe.recipeBoms;
  111. WriteRecipeBoms();
  112. }
  113. });
  114. }
  115. private void OrderChange(string subid, ORDER_STATUS oRDER_STATUS)
  116. {
  117. var res = mORKS.doOrderEvents.FirstOrDefault(p => p.MorkOrder.SuborderId == subid);
  118. string goodName = string.Empty;
  119. string SortNum = string.Empty;
  120. if (res != null)
  121. {
  122. goodName = res.MorkOrder.GoodsName;
  123. SortNum = res.MorkOrder.SortNum.ToString();
  124. }
  125. //if (mORKS.doe.ContainsKey(subid))
  126. //{
  127. //goodName = mORKS.doe[subid].MorkOrder.GoodsName;
  128. //SortNum = mORKS.doe[subid].MorkOrder.SortNum.ToString();
  129. if (!string.IsNullOrEmpty(goodName) && !string.IsNullOrEmpty(SortNum))
  130. {
  131. EventBus.EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { SortNum = SortNum, GoodName = goodName, Status = oRDER_STATUS, SubOrderId = subid, deviceClientType = DeviceType });
  132. var index = DataServer.GetInstance.morkS.MakeOrder.FindIndex(p => p.SortNum == SortNum);
  133. if (index >= 0 && index < DataServer.GetInstance.morkS.MakeOrder.Count)
  134. {
  135. if (oRDER_STATUS == ORDER_STATUS.COMPLETED_COOK)
  136. {
  137. DataServer.GetInstance.morkS.MakeOrder.RemoveAt(index);
  138. DataServer.GetInstance.morkS.MakeOrderOver.Add(new OrderMakeModel()
  139. {
  140. Status = oRDER_STATUS,
  141. GoodName = goodName,
  142. SortNum = SortNum,
  143. StopTime = DateTime.Now.ToString("HH:mm:ss")
  144. });
  145. }
  146. else if (oRDER_STATUS == ORDER_STATUS.COMPLETED_TAKE)
  147. {
  148. var temp = DataServer.GetInstance.morkS.MakeOrderOver.FirstOrDefault(p => p.SortNum == SortNum);
  149. if (temp != null) DataServer.GetInstance.morkS.MakeOrderOver.Remove(temp);
  150. }
  151. else
  152. {
  153. DataServer.GetInstance.morkS.MakeOrder.ElementAt(index).Status = oRDER_STATUS;
  154. }
  155. }
  156. else
  157. {
  158. DataServer.GetInstance.morkS.MakeOrder.Add(new OrderMakeModel()
  159. {
  160. Status = oRDER_STATUS,
  161. GoodName = goodName,
  162. SortNum = SortNum,
  163. StartTime = DateTime.Now.ToString("HH:mm:ss")
  164. });
  165. }
  166. //mORKS.doe.Remove(subid, out _);
  167. }
  168. //}
  169. }
  170. private void GetStatus(string key, Action<object> action)
  171. {
  172. if (peripheralStatus.ContainsKey(key))
  173. {
  174. if (peripheralStatus[key] != null)
  175. {
  176. action?.Invoke(peripheralStatus[key]);
  177. }
  178. }
  179. }
  180. public override void ReadData()
  181. {
  182. DataServer.GetInstance.morkS.Alarm.Clear();
  183. alarms.ForEach(item =>
  184. {
  185. DataServer.GetInstance.morkS.Alarm.Add(new AlarmModel()
  186. {
  187. AlarmTime = $"{item.Date} {item.Time}",
  188. AlarmMs = item.Info
  189. });
  190. });
  191. GetStatus("M230.0", new Action<object>((obj) =>
  192. {
  193. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 24)
  194. {
  195. alarm.MachineLeftLowTemperature = bools[0];
  196. alarm.MachineRightLowTemperature = bools[1];
  197. alarm.Supply1_LossBowl = bools[2];
  198. alarm.Supply2_LossBowl = bools[3];
  199. alarm.Supply1_ErrorOutBowl = bools[4];
  200. alarm.Supply2_ErrorOutBowl = bools[5];
  201. alarm.PushBowlCylinderError = bools[6];
  202. alarm.NoodleMacCommunicateError = bools[7];
  203. alarm.DosingMacCommunicateError = bools[8];
  204. alarm.RobotMacCommunicateError = bools[9];
  205. alarm.DeviceEstop = bools[10];
  206. alarm.RobotInitError = bools[11];
  207. alarm.RobotUrgentStop = bools[12];
  208. alarm.RobotNotInRemoteMode = bools[13];
  209. alarm.RobotNotInReady = bools[14];
  210. alarm.RobotSelfInException = bools[15];
  211. alarm.LeftLackWater = bools[16];
  212. alarm.RightLackWater = bools[17];
  213. alarm.SvrewInitFail = bools[18];
  214. alarm.TurntableInitFail = bools[19];
  215. alarm.RobotInitFail = bools[20];
  216. alarm.NoodleCookerInitFail = bools[21];
  217. alarm.PushBowlInitFail1 = bools[22];
  218. alarm.PushBowlInitFail2 = bools[23];
  219. }
  220. }));
  221. GetStatus("M0.3", new Action<object>((obj) =>
  222. {
  223. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 3)
  224. {
  225. mORKS.RobotTakeNoodle = bools[0];
  226. mORKS.RobotOutMeal = bools[1];
  227. mORKS.MoveTurntable = bools[2];
  228. }
  229. }));
  230. GetStatus("M100.0", new Action<object>((obj) =>
  231. {
  232. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 16)
  233. {
  234. mORKS.InitComplete = bools[0];
  235. mORKS.TakeBowlIdle = bools[1];
  236. mORKS.TemperatureReached = bools[2];
  237. mORKS.AllowFallNoodle = bools[3];
  238. mORKS.RbTakeNoodleComplete = bools[4];
  239. mORKS.RbFallNoodleComplete = bools[5];
  240. mORKS.RbOutMealComplete = bools[6];
  241. mORKS.RobotIdle = bools[7];
  242. mORKS.TakeMealDetect = bools[8];
  243. mORKS.MissingBowl = bools[9];
  244. Initing = bools[10];
  245. mORKS.TurntableLowerLimit = bools[11];
  246. mORKS.MissingBowlSignal2 = bools[12];
  247. mORKS.TurntableUpLimit = bools[13];
  248. mORKS.FeedComplete = bools[14];
  249. mORKS.TurntableMoveInPlace = bools[15];
  250. DataServer.GetInstance.morkS.MorkS_Temp = mORKS.TemperatureReached;
  251. DataServer.GetInstance.morkS.Morks_SiloMeasUp = mORKS.TurntableUpLimit;
  252. DataServer.GetInstance.morkS.Morks_SiloMeasDown = mORKS.TurntableLowerLimit;
  253. DataServer.GetInstance.morkS.MorkS_NoBowMeas1 = mORKS.MissingBowl;
  254. DataServer.GetInstance.morkS.MorkS_NoBowMeas2 = mORKS.MissingBowlSignal2;
  255. }
  256. }));
  257. GetStatus("M235.0", new Action<object>((obj) =>
  258. {
  259. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 1)
  260. {
  261. mORKS.Error = bools[0];
  262. }
  263. }));
  264. GetStatus("M102.0", new Action<object>((obj) =>
  265. {
  266. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 7)
  267. {
  268. for (int i = 0; i < 6; i++)
  269. {
  270. mORKS.NoodleCookerStatus[i] = bools[i];
  271. }
  272. mORKS.Feeding = bools[6];
  273. }
  274. }));
  275. GetStatus("M103.0", new Action<object>((obj) =>
  276. {
  277. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 6)
  278. {
  279. for (int i = 0; i < 6; i++)
  280. {
  281. mORKS.CookNoodlesComplete[i] = bools[i];
  282. DataServer.GetInstance.morkS.Morks_NoodleUpOrDown[i] = bools[i];
  283. }
  284. }
  285. }));
  286. GetStatus("VW372", new Action<object>((obj) =>
  287. {
  288. if (obj is ushort[] UshortValue && UshortValue.Length > 0 && UshortValue.Length <= 1)
  289. mORKS.TurntableFeedbackloc = UshortValue[0];
  290. DataServer.GetInstance.morkS.MorkS_BinLocation = mORKS.TurntableFeedbackloc;
  291. }));
  292. }
  293. /// <summary>
  294. /// 数据解析
  295. /// </summary>
  296. private void DataParse()
  297. {
  298. EventBus.EventBus.GetInstance().Subscribe<DoOrderEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle)
  299. {
  300. if (@event == null) return;
  301. if (@event is DoOrderEvent order)
  302. {
  303. mORKS.doOrderEvents.Add(order);
  304. //mORKS.doe.TryAdd(order.MorkOrder.SuborderId, order);
  305. DeviceProcessLogShow($"接收到{order.MorkOrder.SortNum}号订单");
  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. if (order.MorkOrder.GoodBatchings.Count <= 1)
  316. {
  317. DeviceProcessLogShow($"数据解析失败,商品物料信息为空,请检查后台配置!");
  318. return;
  319. }
  320. DeviceProcessLogShow($"接收到{OrderCount}次订单,订单ID:{order.MorkOrder.SuborderId}");
  321. mORKS.HistorySuborderId.Add(order.MorkOrder.SuborderId);
  322. foreach (var item in order.MorkOrder.GoodBatchings)
  323. {
  324. var res = orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId);
  325. if (res != null)
  326. {
  327. if (ushort.TryParse(res.BatchingLoc, out ushort loc))
  328. {
  329. if (loc >= 1 && loc <= 5)
  330. {
  331. if (mORKS.RBTakeNoodleTask.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  332. mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo()
  333. {
  334. GoodName = order.MorkOrder.GoodsName,
  335. Loc = ushort.Parse(res.BatchingLoc),
  336. SuborderId = order.MorkOrder.SuborderId,
  337. SortNum = order.MorkOrder.SortNum,
  338. BatchingId = res.BatchingId
  339. });
  340. }
  341. else if (loc >= 10 && loc <= 11)
  342. {
  343. int index = 0;
  344. if (recipeBoms != null)
  345. {
  346. index = Array.FindIndex(recipeBoms.RecipeIds?.ToArray(), p => p.RecipeId == order.MorkOrder.RecipeId);
  347. index++;
  348. }
  349. if (mORKS.TakeBowlTask.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  350. mORKS.TakeBowlTask.Enqueue(new OrderLocInfo()
  351. {
  352. BatchingId = res.BatchingId,
  353. GoodName = order.MorkOrder.GoodsName,
  354. Loc = ushort.Parse(res.BatchingLoc),
  355. SuborderId = order.MorkOrder.SuborderId,
  356. SortNum = order.MorkOrder.SortNum,
  357. RecipeNumber = (index >= 1 && index <= 10) ? (ushort)index : (ushort)0
  358. });
  359. }
  360. }
  361. }
  362. else
  363. {
  364. DeviceProcessLogShow($"数据解析失败,未找到商品信息,请检查后台配置!");
  365. }
  366. }
  367. }
  368. });
  369. }
  370. public override void MainTask()
  371. {
  372. mORKS.AllowRun = mORKS.InitComplete;
  373. if (Json<KeepDataBase>.Data.IsVerify)
  374. IsHealth = mORKS.Error && mORKS.InitComplete;
  375. else
  376. IsHealth = true;
  377. TakeBowlTask();
  378. TakeNoodleTask();
  379. OutNoodleTask();
  380. SingleDetect();
  381. TurntableControl();
  382. var data = new List<bool>();
  383. for (int i = 0; i < Json<MorksPar>.Data.parSets.Count; i++)
  384. {
  385. data.Add(Json<MorksPar>.Data.parSets.ElementAt(i).IsShield);
  386. }
  387. WriteControl("M260.0", data.ToArray());
  388. }
  389. private void BowlControl(OrderLocInfo orderLocInfo)
  390. {
  391. if (orderLocInfo.Loc >= 10 && orderLocInfo.Loc <= 11)
  392. {
  393. mORKS.TakeBowlId = orderLocInfo.SuborderId;
  394. mORKS.TakeBowName = orderLocInfo.GoodName;
  395. mORKS.TakeBowSortNum = orderLocInfo.SortNum;
  396. TakeBowlControl(orderLocInfo.Loc);
  397. SetRecipeNumber(orderLocInfo.RecipeNumber);
  398. OrderChange(mORKS.TakeBowlId, ORDER_STATUS.COOKING);
  399. DeviceProcessLogShow($"订单【{mORKS.TakeBowlId}】执行取碗控制,位置:[{orderLocInfo.Loc}]");
  400. mORKS.TakeBowlInterlock = true;
  401. }
  402. }
  403. /// <summary>
  404. /// 取碗控制
  405. /// </summary>
  406. private void TakeBowlTask()
  407. {
  408. if (mORKS.AllowRun && mORKS.TakeBowlTask.Count > 0 && !mORKS.TakeBowlIdle && !mORKS.TakeBowlInterlock)
  409. {
  410. DeviceProcessLogShow("开始取碗流程");
  411. ushort BowLoc = 0;
  412. var res = orderMaterialDelivery?.BatchingInfo?.Where(p => p.BatchingId == mORKS.TakeBowlTask.ElementAt(0).BatchingId).ToList();
  413. if (res == null || res?.Count == 0)
  414. {
  415. if (mORKS.TakeBowlTask.TryDequeue(out OrderLocInfo orderLocInfo)) BowlControl(orderLocInfo);
  416. }
  417. else
  418. {
  419. foreach (var item in res)
  420. {
  421. if (ushort.TryParse(item.BatchingLoc, out ushort loc))
  422. {
  423. //DeviceProcessLogShow($"位置:={loc},检测开关1:{alarm.Supply1_LossBowl},检测开关1:{alarm.Supply2_LossBowl}");
  424. if (loc == 10 && !alarm.Supply1_LossBowl)
  425. {
  426. BowLoc = loc;
  427. break;
  428. }
  429. else if (loc == 11 && !alarm.Supply2_LossBowl)
  430. {
  431. BowLoc = loc;
  432. break;
  433. }
  434. }
  435. }
  436. if (BowLoc >= 10 && BowLoc <= 11)
  437. {
  438. if (mORKS.TakeBowlTask.TryDequeue(out OrderLocInfo orderLocInfo))
  439. {
  440. orderLocInfo.Loc = BowLoc;
  441. BowlControl(orderLocInfo);
  442. }
  443. }
  444. }
  445. }
  446. }
  447. /// <summary>
  448. /// 转台控制
  449. /// </summary>
  450. private void TurntableControl()
  451. {
  452. if (Global.EnableLocalSimOrder)
  453. {
  454. //不做轮询,直接取面,模拟订单使用
  455. if (mORKS.TurntableMoveInPlace && !mORKS.Feeding && mORKS.InitComplete && !mORKS.AllowTakeNoodle && mORKS.RBTakeNoodleTask.Count > 0)
  456. {
  457. if (mORKS.TurntableLowerLimit)
  458. {
  459. TurntableStart(mORKS.RBTakeNoodleTask.ElementAt(0).Loc);
  460. mORKS.TurntableLocLists.Clear();
  461. mORKS.AllowTakeNoodle = true;
  462. DeviceProcessLogShow($"控制机器人去转台【{mORKS.RBTakeNoodleTask.ElementAt(0).Loc}】号位置取面");
  463. }
  464. }
  465. }
  466. else
  467. {
  468. //正常轮询
  469. if (mORKS.TurntableMoveInPlace && !mORKS.Feeding && mORKS.InitComplete && !mORKS.AllowTakeNoodle && mORKS.RBTakeNoodleTask.Count > 0)
  470. {
  471. var result = orderMaterialDelivery.BatchingInfo.Where(p => p.BatchingId == mORKS.RBTakeNoodleTask.ElementAt(0).BatchingId).ToList();
  472. if (result != null)
  473. {
  474. var res = result.FirstOrDefault(P => P.BatchingLoc == mORKS.TurntableFeedbackloc.ToString());
  475. if (mORKS.TurntableLowerLimit && res != null)
  476. {
  477. TurntableStart(mORKS.TurntableFeedbackloc);
  478. mORKS.TurntableLocLists.Clear();
  479. mORKS.AllowTakeNoodle = true;
  480. DeviceProcessLogShow($"控制机器人去转台【{mORKS.TurntableFeedbackloc}】号位置取面");
  481. }
  482. else
  483. {
  484. if (!mORKS.TurntableInterlock)
  485. {
  486. foreach (var item in result)
  487. {
  488. if (ushort.TryParse(item.BatchingLoc, out ushort loc))
  489. {
  490. if (mORKS.TurntableFeedbackloc != loc && !mORKS.TurntableLocLists.Contains(loc))
  491. {
  492. if (!mORKS.TurntableLowerLimit)
  493. {
  494. WriteData("M32.7", false);
  495. DeviceProcessLogShow($"执行了转台启动互锁信号复位");
  496. }
  497. TurntableStart(loc);
  498. DeviceProcessLogShow($"没有物料检测的启动转台控制,转台位置:[{loc}]");
  499. break;
  500. }
  501. else if (mORKS.TurntableFeedbackloc == loc && !mORKS.TurntableLocLists.Contains(loc)) mORKS.TurntableLocLists.Add(loc);
  502. }
  503. }
  504. }
  505. }
  506. }
  507. else DeviceProcessLogShow("未找到可用的物料信息");
  508. }
  509. }
  510. //if (DelayRTrig.GetInstance("互锁信号复位").Start(!mORKS.TurntableLowerLimit && mORKS.TurntableMoveInPlace, 2))
  511. //{
  512. // if (!mORKS.TurntableLowerLimit)
  513. // {
  514. // WriteData("M32.7", false);
  515. // DeviceProcessLogShow($"执行了转台启动互锁信号复位");
  516. // }
  517. //}
  518. //补料中检测
  519. if (RTrig.GetInstance("mORKS.Feeding").Start(mORKS.Feeding))
  520. {
  521. mORKS.AllowTakeNoodle = false;
  522. mORKS.TakeNoodleInterlock = false;
  523. }
  524. //转台到位检测
  525. if (RTrig.GetInstance("TurntableInPlace").Start(mORKS.TurntableMoveInPlace && mORKS.CurrentLoc == mORKS.TurntableFeedbackloc))
  526. {
  527. mORKS.CurrentLoc = 0;
  528. mORKS.TurntableInterlock = false;
  529. DeviceProcessLogShow("转台到位检测");
  530. }
  531. //补料完成检测
  532. if (RTrig.GetInstance("FeedComplete").Start(mORKS.FeedComplete))
  533. {
  534. if (!mORKS.AllowTakeNoodle && mORKS.TurntableLocLists.Count > 0)
  535. {
  536. mORKS.TurntableLocLists.Clear();
  537. mORKS.TurntableInterlock = false;
  538. DeviceProcessLogShow("补料完成检测");
  539. }
  540. }
  541. }
  542. /// <summary>
  543. /// 取面任务
  544. /// </summary>
  545. private void TakeNoodleTask()
  546. {
  547. //取面控制
  548. if (mORKS.AllowRun && mORKS.RobotIdle && !mORKS.Feeding && !mORKS.RobotTaskInterlock && mORKS.AllowTakeNoodle && mORKS.TurntableMoveInPlace && !mORKS.TakeNoodleInterlock && !mORKS.OutNoodleing && mORKS.RBTakeNoodleTask.Count > 0)
  549. {
  550. int loc = Array.FindIndex(mORKS.NoodleCookerStatus, p => p == false);//查找煮面炉空闲位置
  551. if (loc >= 0 && loc <= 5)
  552. {
  553. if (mORKS.RBTakeNoodleTask.TryDequeue(out OrderLocInfo orderLocInfo))
  554. {
  555. mORKS.CookNodelId[loc] = orderLocInfo.SuborderId;
  556. SetFallNoodleLoc((ushort)(loc + 1));
  557. //机器人开始取面
  558. RobotTakeNoodle();
  559. OrderChange(orderLocInfo.SuborderId, ORDER_STATUS.COOKING);
  560. DeviceProcessLogShow($"订单【{orderLocInfo.SuborderId}】,机器人倒面至【{loc + 1}】号煮面栏");
  561. //写入煮面时间
  562. List<ushort> values = new List<ushort>();
  563. values.Add(Json<MorksPar>.Data.parSets.ElementAt(loc).Minute);
  564. values.Add(Json<MorksPar>.Data.parSets.ElementAt(loc).Second);
  565. WriteData($"VW{116 + (loc * 6)}", values.ToArray());
  566. mORKS.TakeNoodleInterlock = true;
  567. }
  568. }
  569. }
  570. }
  571. /// <summary>
  572. /// 出餐控制
  573. /// </summary>
  574. private void OutNoodleTask()
  575. {
  576. if (mORKS.AllowFallNoodle && mORKS.RobotTaskInterlock && !mORKS.TakeNoodleInterlock && mORKS.RobotIdle && !mORKS.TakeMealDetect)
  577. {
  578. int loc = Array.FindIndex(mORKS.CookNodelId, p => p == mORKS.IngredientsCompleteId && p.Length > 0);
  579. if (loc >= 0 && loc <= 5)
  580. {
  581. if (mORKS.CookNoodlesComplete[loc])
  582. {
  583. SetTakeNoodleLoc((ushort)(loc + 1));
  584. RobotOutMeal();
  585. CookNoodleStatusReset((ushort)(loc + 1));
  586. ResetAllowFallNoodle();
  587. //新增,待测试
  588. if (mORKS.RbOutMealComplete)
  589. {
  590. ResetCookComplete();
  591. mORKS.CookCompleteFlatBit = false;
  592. DeviceProcessLogShow("取餐过程中复位出餐完成信号");
  593. }
  594. if (!string.IsNullOrEmpty(mORKS.OutMealId)) OrderChange(mORKS.OutMealId, ORDER_STATUS.COMPLETED_TAKE);
  595. mORKS.OutMealId = mORKS.IngredientsCompleteId;
  596. mORKS.OutMealName = mORKS.IngredientsCompleteName;
  597. mORKS.OutMealSortNum = mORKS.IngredientsCompleteSortNum;
  598. mORKS.IngredientsCompleteId = string.Empty;
  599. mORKS.CookNodelId[loc] = string.Empty;
  600. DeviceProcessLogShow($"{loc + 1} 号位置出餐控制,订单ID:{mORKS.OutMealId}");
  601. mORKS.OutNoodleing = true;
  602. }
  603. }
  604. }
  605. }
  606. /// <summary>
  607. /// 信号检测
  608. /// </summary>
  609. private void SingleDetect()
  610. {
  611. //允许倒面信号检测
  612. if (RTrig.GetInstance("AllowFallNoodle").Start(mORKS.AllowFallNoodle))
  613. {
  614. mORKS.IngredientsCompleteId = mORKS.TakeBowlId;
  615. mORKS.IngredientsCompleteName = mORKS.TakeBowName;
  616. mORKS.IngredientsCompleteSortNum = mORKS.TakeBowSortNum;
  617. mORKS.TakeBowlId = string.Empty;
  618. mORKS.TakeBowName = string.Empty;
  619. mORKS.TakeBowSortNum = 0;
  620. DeviceProcessLogShow($"碗到位,允许到面,{mORKS.IngredientsCompleteId}");
  621. mORKS.TakeBowlInterlock = false;
  622. }
  623. //出餐完成信号检测
  624. if (RTrig.GetInstance("CompleteChange").Start(mORKS.RbOutMealComplete))
  625. {
  626. OrderChange(mORKS.OutMealId, ORDER_STATUS.COMPLETED_COOK);
  627. DeviceProcessLogShow($"订单【{mORKS.OutMealId}】制作完成");
  628. mORKS.CookCompleteFlatBit = true;
  629. mORKS.OutNoodleing = false;
  630. }
  631. //加汤
  632. /*if (Delay.GetInstance("加汤延时判断").Start(mORKS.TakeMealDetect && mORKS.CookCompleteFlatBit, 1))
  633. {
  634. AddSoup();
  635. }*/
  636. //取餐完成逻辑处理
  637. if (Delay.GetInstance("CompleteChange1").Start(!mORKS.TakeMealDetect, 1) && mORKS.CookCompleteFlatBit == true)
  638. {
  639. OrderChange(mORKS.OutMealId, ORDER_STATUS.COMPLETED_TAKE);
  640. DeviceProcessLogShow($"订单【{mORKS.OutMealId}】取餐完成");
  641. ResetCookComplete();
  642. DeviceProcessLogShow($"出餐订单【{mORKS.OutMealSortNum.ToString()}】");
  643. DeviceProcessLogShow($"出餐订单序号【{mORKS.OutMealSortNum}】");
  644. VoiceAPI.Speak(mORKS.OutMealSortNum.ToString());
  645. //DeviceProcessLogShow($"叫号系统通知主题【MORKS/VoiceCall/{DeviceId}】");
  646. //Plugin.GetInstance().GetPlugin<MQTTMgr>().Publish($"MORKS/VoiceCall/{DeviceId}", mORKS.OutMealSortNum.ToString());
  647. mORKS.CookCompleteFlatBit = false;
  648. mORKS.OutMealId = string.Empty;
  649. mORKS.OutMealName = string.Empty;
  650. mORKS.OutMealSortNum = 0;
  651. }
  652. //机器人取面完成信号检测
  653. if (RTrig.GetInstance("TakeNoodleComplete").Start(mORKS.RbTakeNoodleComplete))
  654. {
  655. mORKS.TakeNoodleInterlock = false;
  656. mORKS.AllowTakeNoodle = false;
  657. mORKS.TurntableInterlock = false;
  658. DeviceProcessLogShow("机器人取面完成信号检测");
  659. TakeNoodleCompleteReset();
  660. }
  661. int OutMealRequstCount = mORKS.CookNoodlesComplete.Where(p => p == true).ToList().Count;
  662. int mlCount = mORKS.NoodleCookerStatus.Where(p => p == true).ToList().Count;
  663. int index = Array.FindIndex(mORKS.CookNodelId, p => p == mORKS.IngredientsCompleteId);
  664. bool isok = index >= 0 && index < mORKS.CookNoodlesComplete.Length && mORKS.CookNoodlesComplete[index];
  665. mORKS.PriorityJudgment = Delay.GetInstance("取餐优先级判断").Start(mORKS.TurntableLocLists.Count > 0 && !mORKS.TurntableLowerLimit, 4);
  666. //mORKS.RobotTaskInterlock = OutMealRequstCount > 0 && mORKS.AllowFallNoodle && (mlCount >= 2 || mORKS.RBTakeNoodleTask.Count == 0 || mORKS.PriorityJudgment);
  667. mORKS.InvertedNoodlesOpenBusy = Json<MorksPar>.Data.InvertedNoodles_OpenBusyNum;
  668. mORKS.RobotTaskInterlock = isok && mORKS.AllowFallNoodle && (mlCount >= mORKS.InvertedNoodlesOpenBusy || mORKS.RBTakeNoodleTask.Count == 0 || mORKS.PriorityJudgment) && !mORKS.TakeMealDetect;//加个取餐口检测判断是否去面
  669. }
  670. ///// <summary>
  671. ///// 语音提醒取餐
  672. ///// </summary>
  673. ///// <param name="meal"></param>
  674. //private void WaitMeaLSpeak(string meal)
  675. //{
  676. // VoiceAPI.m_SystemPlayWav(@"Vioce\电子提示音.wav");
  677. // Thread.Sleep(1000);
  678. // if (meal != null) mORKS.speech.Speak(meal);
  679. // VoiceAPI.m_SystemPlayWav(@"Vioce\取餐通知.wav");
  680. //}
  681. #region PLC 控制函数
  682. private void WriteData(string address, object value)
  683. {
  684. EventBus.EventBus.GetInstance().Publish(new WriteModel() { DeviceId = DeviceId, Address = address, Value = value });
  685. }
  686. /// <summary>
  687. /// 写入配方数据到 PLC
  688. /// </summary>
  689. private void WriteRecipeBoms()
  690. {
  691. List<ushort> recipeBoms = new List<ushort>();
  692. if (this.recipeBoms == null) return;
  693. foreach (var item in this.recipeBoms.RecipeIds)
  694. {
  695. foreach (var rec in item.Recipes)
  696. {
  697. recipeBoms.Add((ushort)rec);
  698. }
  699. }
  700. if (recipeBoms.Count > 0)
  701. {
  702. //配方数据地址范围:VW2000 - VW2278
  703. WriteData("VW2000", recipeBoms.ToArray());
  704. DeviceProcessLogShow("写配方成功");
  705. }
  706. else { DeviceProcessLogShow("配方数据为空"); }
  707. }
  708. /// <summary>
  709. /// 取面完成复位
  710. /// </summary>
  711. private void TakeNoodleCompleteReset()
  712. {
  713. WriteData("M100.4", false);
  714. }
  715. /// <summary>
  716. /// 指定煮面口状态复位
  717. /// </summary>
  718. /// <param name="num"></param>
  719. private void CookNoodleStatusReset(int num)
  720. {
  721. if (num >= 1 && num <= 6)
  722. {
  723. WriteData($"102.{num - 1}", false);
  724. DeviceProcessLogShow($"{num}号煮面口占用复位");
  725. }
  726. }
  727. /// <summary>
  728. /// 写配方编号
  729. /// </summary>
  730. /// <param name="num"></param>
  731. private void SetRecipeNumber(ushort num)
  732. {
  733. WriteData("VW0", num);
  734. }
  735. /// <summary>
  736. /// 启动转台
  737. /// </summary>
  738. /// <param name="loc"></param>
  739. private void TurntableStart(ushort loc)
  740. {
  741. mORKS.CurrentLoc = loc;
  742. mORKS.TurntableInterlock = true;
  743. mORKS.TurntableLocLists.Add(loc);
  744. WriteData("VW2", loc);
  745. WriteData("M0.5", true);
  746. }
  747. /// <summary>
  748. /// 设置倒面位置
  749. /// </summary>
  750. /// <param name="loc"></param>
  751. private void SetFallNoodleLoc(ushort loc)
  752. {
  753. WriteData("VW4", loc);
  754. }
  755. /// <summary>
  756. /// 设置取面位置
  757. /// </summary>
  758. /// <param name="loc"></param>
  759. private void SetTakeNoodleLoc(ushort loc)
  760. {
  761. WriteData("VW6", loc);
  762. }
  763. /// <summary>
  764. /// 加汤控制
  765. /// </summary>
  766. private async void AddSoup()
  767. {
  768. //M0.6
  769. WriteData("M0.6", true);
  770. await Task.Delay(Convert.ToInt32(Json<MorksPar>.Data.AddSoupTime * 1000));
  771. WriteData("M0.6", false);
  772. }
  773. /// <summary>
  774. /// 取碗控制
  775. /// </summary>
  776. /// <param name="loc"></param>
  777. private void TakeBowlControl(ushort loc)
  778. {
  779. if (loc == 10)//小碗
  780. {
  781. WriteData("M0.1", true);
  782. }
  783. else if (loc == 11)//大碗
  784. {
  785. WriteData("M0.2", true);
  786. }
  787. }
  788. /// <summary>
  789. /// 机器人取面
  790. /// </summary>
  791. private void RobotTakeNoodle()
  792. {
  793. WriteData("M0.3", true);
  794. }
  795. /// <summary>
  796. /// 机器人取餐
  797. /// </summary>
  798. private void RobotOutMeal()
  799. {
  800. WriteData("M0.4", true);
  801. }
  802. /// <summary>
  803. /// 制作完成信号复位
  804. /// </summary>
  805. private void ResetCookComplete()
  806. {
  807. WriteData("M100.6", false);
  808. }
  809. /// <summary>
  810. /// 复位允许取面信号
  811. /// </summary>
  812. private void ResetAllowFallNoodle()
  813. {
  814. WriteData("M100.3", false);
  815. }
  816. /// <summary>
  817. /// 设备初始化
  818. /// </summary>
  819. public async void DeviceInit()
  820. {
  821. WriteData("M0.0", true);
  822. await Task.Delay(1000);
  823. WriteData("M0.0", false);
  824. }
  825. public override void SimOrder()
  826. {
  827. EventBus.EventBus.GetInstance().Subscribe<MorksSimorderModel>(0, delegate (IEvent @event, EventCallBackHandle callBackHandle)
  828. {
  829. if (@event != null && @event is MorksSimorderModel msm)
  830. {
  831. string guid = Guid.NewGuid().ToString();
  832. if (msm.NoodleLoc >= 1 && msm.NoodleLoc <= 5)
  833. {
  834. mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { Loc = (ushort)msm.NoodleLoc, SuborderId = guid });
  835. MessageLog.GetInstance.Show($"添加订单:面条位置【{(ushort)msm.NoodleLoc}】");
  836. }
  837. if (msm.Bowloc >= 10 && msm.Bowloc <= 11)
  838. {
  839. mORKS.TakeBowlTask.Enqueue(new OrderLocInfo() { Loc = (ushort)msm.Bowloc, SuborderId = guid });
  840. MessageLog.GetInstance.Show($"添加订单:碗位置【{(ushort)msm.Bowloc}】");
  841. }
  842. }
  843. });
  844. }
  845. #endregion
  846. }
  847. }