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

916 lines
36 KiB

  1. using BPA.Message;
  2. using BPA.Message.Enum;
  3. using BPASmartClient.Device;
  4. using BPASmartClient.EventBus;
  5. using BPASmartClient.Helper;
  6. using BPASmartClient.Message;
  7. using BPASmartClient.Model;
  8. using BPASmartClient.Model.PLC;
  9. using BPA.Models;
  10. using static BPASmartClient.EventBus.EventBus;
  11. namespace BPASmartClient.MorkF
  12. {
  13. public class Control_MorkF : BaseDevice
  14. {
  15. public override DeviceClientType DeviceType => DeviceClientType.MORKSF;
  16. GVL_MorkF morkF = new GVL_MorkF();//全局对象声明
  17. public StirFryBom stirFryBom = new StirFryBom();//创建获取流程的对象
  18. //public bool ProcessError { get; set; }//流程错误
  19. /// <summary>
  20. /// 入口
  21. /// </summary>
  22. public override void DoMain()
  23. {
  24. ServerInit();
  25. DataParse();//数据解析
  26. ThreadManage.GetInstance().StartLong(new Action(() =>
  27. {
  28. IsHealth = true;
  29. ReadData();
  30. Thread.Sleep(10);
  31. }), "ReadPLCData");
  32. ThreadManage.GetInstance().StartLong(new Action(() =>
  33. {
  34. MainTask();
  35. Thread.Sleep(10);
  36. }), "MainTask");
  37. MessageLog.GetInstance.Show("MORKF 设备初始化完成");
  38. }
  39. public override void ResetProgram()
  40. {
  41. morkF = null;
  42. morkF = new GVL_MorkF();
  43. }
  44. /// <summary>
  45. /// PLC数据读取
  46. /// </summary>
  47. public override void ReadData()
  48. {
  49. //ThreadManage.GetInstance().StartLong(new Action(() =>
  50. //{
  51. GetStatus("M0.1", new Action<bool[]>((bools) =>
  52. {
  53. Initing = bools[0];
  54. morkF.InitialComplete = Initing;
  55. }));
  56. GetStatus("M1.0", new Action<bool[]>((bools) =>
  57. {
  58. morkF.ProvidePlateModule = bools[0];
  59. morkF.ProvidePlateComplete = bools[2];
  60. morkF.CleanModule = bools[3];
  61. morkF.CleanComplete = bools[5];
  62. }));
  63. GetStatus("M2.0", new Action<bool[]>((bools) =>
  64. {
  65. morkF.KitchenOneStatus = bools[1];
  66. morkF.FallOilComplete = bools[8];
  67. }));
  68. GetStatus("M8.0", new Action<bool[]>((bools) =>
  69. {
  70. morkF.TurnMachineUpComplete = bools[1];
  71. morkF.TurnMachineDownComplete = bools[3];
  72. }));
  73. GetStatus("M13.5", new Action<bool[]>((bools) =>
  74. {
  75. morkF.MaterialArriveComplete = bools[0];
  76. }));
  77. GetStatus("M16.0", new Action<bool[]>((bools) =>
  78. {
  79. morkF.PutPotToKitchenComlete = bools[1];
  80. morkF.TakeMaterialComplete = bools[2];
  81. morkF.PlaceRinseTableComplete = bools[5];
  82. morkF.RoobotIdle = bools[6];
  83. }));
  84. // Thread.Sleep(500);
  85. //}), "ReadPLCData");
  86. }
  87. private void ServerInit()
  88. {
  89. //物料信息
  90. EventBus.EventBus.GetInstance().Subscribe<MaterialDeliveryEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  91. {
  92. if (@event == null) return;
  93. if (@event is MaterialDeliveryEvent material)
  94. {
  95. orderMaterialDelivery = material.orderMaterialDelivery;
  96. }
  97. });
  98. //配方数据信息
  99. EventBus.EventBus.GetInstance().Subscribe<RecipeBomEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  100. {
  101. if (@event == null) return;
  102. if (@event is RecipeBomEvent recipe)
  103. {
  104. recipeBoms = recipe.recipeBoms;
  105. WriteRecipeBoms();
  106. }
  107. });
  108. }
  109. private void OrderChange(string subid, ORDER_STATUS oRDER_STATUS)
  110. {
  111. EventBus.EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { Status = oRDER_STATUS, SubOrderId = subid });
  112. }
  113. /// <summary>
  114. /// 写入配方数据到 PLC
  115. /// </summary>
  116. private void WriteRecipeBoms()
  117. {
  118. //List<ushort> recipeBoms = new List<ushort>();
  119. //if (this.recipeBoms == null) return;
  120. //foreach (var item in this.recipeBoms.RecipeIds)
  121. //{
  122. // foreach (var rec in item.Recipes)
  123. // {
  124. // recipeBoms.Add((ushort)rec);
  125. // }
  126. //}
  127. //if (recipeBoms.Count > 0)
  128. //{
  129. // //配方数据地址范围:VW2000 - VW2278
  130. // WriteData("VW2000", recipeBoms.ToArray());
  131. //}
  132. //else { MessageLog.GetInstance.Show("配方数据为空"); }
  133. }
  134. /// <summary>
  135. /// 数据解析
  136. /// </summary>
  137. private void DataParse()
  138. {
  139. EventBus.EventBus.GetInstance().Subscribe<DoOrderEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle)
  140. {
  141. if (@event == null) return;
  142. if (@event is DoOrderEvent order)
  143. {
  144. if (order.MorkOrder.GoodBatchings == null) return;
  145. OrderCount++;
  146. MessageLog.GetInstance.Show($"接收到{OrderCount}次订单");
  147. foreach (var item in order.MorkOrder.GoodBatchings)
  148. {
  149. var res = orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId);
  150. if (res != null)
  151. {
  152. if (ushort.TryParse(res.BatchingLoc, out ushort loc))
  153. {
  154. //if (morkF.TakeMaterialQueue.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  155. //将一个商品的ABC料位置存入队列
  156. morkF.TakeMaterialQueue.Enqueue(new OrderLocInfo() { SuborderId = order.MorkOrder.SuborderId, BatchingId = res.BatchingId, MaterialLoc = ushort.Parse(res.BatchingLoc) });
  157. }
  158. //int index = 0;
  159. //if (recipeBoms != null)
  160. //{
  161. // index = Array.FindIndex(recipeBoms.RecipeIds?.ToArray(), p => p.RecipeId == order.MorkOrder.RecipeId);
  162. // index++;
  163. //}
  164. if (morkF.TakePlateQueue.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  165. morkF.TakePlateQueue.Enqueue(new OrderLocInfo()
  166. {
  167. SuborderId = order.MorkOrder.SuborderId,
  168. BatchingId = res.BatchingId
  169. //RecipeNumber = (index >= 1 && index <= 10) ? (ushort)index : (ushort)0
  170. });
  171. }
  172. }
  173. }
  174. });
  175. }
  176. //}
  177. /// <summary>
  178. /// 主任务
  179. /// </summary>
  180. public override void MainTask()
  181. {
  182. TakePlatelTask();
  183. TurntableControl();
  184. ProcessExecute();
  185. SingleProcess();
  186. }
  187. //机器人,锅灶流程执行
  188. public void ProcessExecute()
  189. {
  190. if (!morkF.ProcessExcuteLock)
  191. {
  192. morkF.ProcessExcuteLock = true;
  193. Task.Run(new Action(() =>
  194. {
  195. if (!morkF.RoobotIdle && morkF.InitialComplete && morkF.TakeMaterialQueue.Count > 0 && morkF.TakePlateQueue.Count > 0)
  196. {
  197. foreach (var res in stirFryBom.StirFryActions)//遍历所有流程
  198. {
  199. MessageLog.GetInstance.Show($"执行流程{res.Time}");
  200. //机器人线程
  201. Task taskRobot = Task.Run(new Action(() =>
  202. {
  203. foreach (var temp in res.RobotActions)
  204. {
  205. switch (temp)
  206. {
  207. case StirFryRobotAction.清洗槽取锅:
  208. TakePotTask();//执行取锅操作
  209. break;
  210. case StirFryRobotAction.取A料:
  211. TakeBurdenATask();//执行取A料操作
  212. break;
  213. case StirFryRobotAction.加入B料:
  214. TakeBurdenBTask();//执行取B料操作
  215. break;
  216. case StirFryRobotAction.加入C料:
  217. TakeBurdenCTask();//执行取C料操作
  218. break;
  219. case StirFryRobotAction.灶取锅:
  220. OutDishTask();//执行出餐操作
  221. CleanPotTask();//洗锅操作
  222. break;
  223. }
  224. // Task.Delay(2000).Wait();//单一操作延时
  225. }
  226. }));
  227. //炒锅线程操作
  228. Task taskPot = Task.Run(new Action(() =>
  229. {
  230. foreach (var temp in res.PotActions)
  231. {
  232. switch (temp)
  233. {
  234. case StirFryPotAction.NONE:
  235. break;
  236. case StirFryPotAction.大火t1s:
  237. KitchenAdjustGears(3);
  238. Task.Delay(1000).Wait(); //大火加热1s//执行大火锅干操作
  239. break;
  240. case StirFryPotAction.加油:
  241. AddOil();//注油//执行加油操作
  242. break;
  243. case StirFryPotAction.中火t2s:
  244. KitchenAdjustGears(2);
  245. Task.Delay(2000).Wait();//执行操作
  246. break;
  247. case StirFryPotAction.小火持续:
  248. KitchenAdjustGears(1);
  249. break;
  250. case StirFryPotAction.大火持续:
  251. KitchenAdjustGears(3);
  252. break;
  253. case StirFryPotAction.停止火力:
  254. KitchenAdjustGears(0);//关闭灶加热
  255. break;
  256. case StirFryPotAction.搅拌臂上位:
  257. TurnUpStatusDetect();//执行搅拌臂上位操作
  258. break;
  259. case StirFryPotAction.搅拌臂下位:
  260. TurnDownStatusDetect();//执行搅拌臂下位操作
  261. break;
  262. case StirFryPotAction.低速旋转:
  263. TurnMachineGearsControl(1);//执行搅拌臂速度1挡操作
  264. break;
  265. case StirFryPotAction.快速旋转:
  266. TurnMachineGearsControl(3);//执行搅拌臂速度3挡操作
  267. break;
  268. case StirFryPotAction.停止旋转:
  269. TurnMachineGearsControl(0);//执行搅拌臂速度0挡操作
  270. break;
  271. }
  272. // Task.Delay(2000).Wait();//单一操作延时
  273. }
  274. }));
  275. Task.WhenAll(taskRobot, taskPot);//等待所有线程结束
  276. Task.Delay(res.During).Wait();//当前流程延迟
  277. }
  278. }
  279. else
  280. {
  281. morkF.ProcessExcuteLock = false;//解除流程互锁
  282. }
  283. }));
  284. }
  285. }
  286. /// <summary>
  287. /// 信号处理
  288. /// </summary>
  289. private void SingleProcess()
  290. {
  291. //出餐完成,相应变量复位
  292. if (morkF.OutMealComplete)
  293. {
  294. morkF.TakePlateLock = false;
  295. morkF.TakePotLock = false;
  296. morkF.PotInPlace = false;
  297. morkF.ProcessExcuteLock = false;
  298. }
  299. }
  300. /// <summary>
  301. /// 转台控制
  302. /// </summary>
  303. private void TurntableControl()
  304. {
  305. //正常轮询
  306. if (morkF.TakeMaterialQueue.Count > 0 && !morkF.TurnTableLock)
  307. {
  308. var result = orderMaterialDelivery.BatchingInfo.Where(p => p.BatchingId == morkF.TakeMaterialQueue.ElementAt(0).BatchingId).ToList();
  309. if (result != null)
  310. {
  311. if (ushort.TryParse(result[0].BatchingLoc, out ushort loc))
  312. {
  313. TurnMaterialStore(loc);
  314. MessageLog.GetInstance.Show($"转台转到【{loc}】位置");
  315. morkF.TurnTableLock = true; //取料完成后置false
  316. }
  317. }
  318. else MessageLog.GetInstance.Show("未找到可用的物料信息");
  319. }
  320. }
  321. /// <summary>
  322. /// 供盘
  323. /// </summary>
  324. /// <exception cref="NotImplementedException"></exception>
  325. private void TakePlatelTask()
  326. {
  327. if (!morkF.RoobotIdle && morkF.InitialComplete && morkF.TakePlateQueue.Count > 0 && !morkF.ProvidePlateModule && !morkF.TakePlateLock)
  328. {
  329. if (morkF.TakePlateQueue.TryDequeue(out OrderLocInfo order))
  330. {
  331. StartTakePlate();
  332. morkF.CurrentOrderId = order.SuborderId;
  333. morkF.TakePlateLock = true; //订单完成后置false
  334. morkF.OutMealComplete = false;
  335. OrderChange(morkF.CurrentOrderId, ORDER_STATUS.COOKING);
  336. MessageLog.GetInstance.Show($"订单【{ morkF.CurrentOrderId}】执行取碗控制");
  337. }
  338. }
  339. else
  340. {
  341. MessageLog.GetInstance.ShowEx($"订单【{ morkF.CurrentOrderId}】取碗失败");
  342. }
  343. }
  344. /// <summary>
  345. /// 取锅到灶台
  346. /// </summary>
  347. /// <exception cref="NotImplementedException"></exception>
  348. private async void TakePotTask()
  349. {
  350. if (morkF.TakePlateQueue.Count > 0)
  351. {
  352. while (!(!morkF.CleanModule && morkF.CleanComplete && !morkF.KitchenOneStatus))//等待清洗1准备就绪
  353. {
  354. Task.Delay(5).Wait();
  355. }
  356. while (morkF.RoobotIdle)//等待机器人空闲
  357. {
  358. Task.Delay(5).Wait();
  359. }
  360. TakePotToKitchen();
  361. // morkF.TakePotLock = true; //订单完成后置false
  362. EventBus.EventBus.GetInstance().Publish(new WriteModel() { Address = "M1.5", Value = false });//清洗模组1完成复位
  363. MessageLog.GetInstance.Show($"订单【{ morkF.CurrentOrderId}】执行取锅到灶台控制");
  364. while (!morkF.PutPotToKitchenComlete)
  365. {
  366. Task.Delay(5).Wait();
  367. }
  368. morkF.PotInPlace = morkF.PutPotToKitchenComlete;//锅到位
  369. }
  370. }
  371. /// <summary>
  372. /// 取素菜A料
  373. /// </summary>
  374. private void TakeBurdenATask()
  375. {
  376. if (morkF.TakeMaterialQueue.Count > 0)
  377. {
  378. TurnUpStatusDetect();
  379. //while (!morkF.TurnMachineUpComplete)//等待翻转机上升完成以及取料完成
  380. //{
  381. // Task.Delay(5).Wait();
  382. //}
  383. //EventBus.EventBus.GetInstance().Publish(new WriteModel() { Address = "M8.1", Value = false });//翻转机上升完成复位
  384. //MessageLog.GetInstance.Show($"翻转机上升执行完成");
  385. while (morkF.RoobotIdle || !morkF.PotInPlace)//等待机器人空闲以及锅到位
  386. {
  387. Task.Delay(5).Wait();
  388. }
  389. if (morkF.TakeMaterialQueue.TryDequeue(out OrderLocInfo order))
  390. {
  391. int loc = order.MaterialLoc;
  392. TakeBurden(loc);
  393. //morkF.TakeVegALock = true;//订单完成置false
  394. // morkF.AllowTakeMaterial = false;
  395. MessageLog.GetInstance.Show($"订单【{ order.SuborderId},执行取A料");
  396. }
  397. //等待取料完成
  398. while (!morkF.TakeMaterialComplete)
  399. {
  400. Task.Delay(5).Wait();
  401. }
  402. //转台互锁解除
  403. if (morkF.TurnTableLock)
  404. {
  405. morkF.TurnTableLock = false;
  406. }
  407. }
  408. }
  409. ///// <summary>
  410. ///// 取荤菜A料
  411. ///// </summary>
  412. //private void TakeBurdenATask()
  413. //{
  414. // if (!morkF.RoobotIdle && morkF.PotInPlace && morkF.TurnMachineUpComplete && morkF.TakeVegALock && !morkF.TakeMeatALock && morkF.AllowTakeMaterial&& morkF.TakeMaterialQueue.Count > 0)
  415. // {
  416. // if (morkF.TakeMaterialQueue.TryDequeue(out OrderLocInfo order))
  417. // {
  418. // int loc = 0;
  419. // TakeBurden(loc);
  420. // morkF.TakeMeatALock = true;//订单完成置false
  421. // morkF.AllowTakeMaterial = false;
  422. // MessageLog.GetInstance.Show($"订单【{ order.SuborderId}】,,翻转机上升完成,执行取荤菜A控制");
  423. // }
  424. // }
  425. //}
  426. /// <summary>
  427. /// 取素菜B料
  428. /// </summary>
  429. private void TakeBurdenBTask()
  430. {
  431. if (morkF.TakeMaterialQueue.Count > 0)
  432. {
  433. TurnUpStatusDetect();
  434. //while (!morkF.TurnMachineUpComplete)//等待翻转机上升完成以及取料完成
  435. //{
  436. // Task.Delay(5).Wait();
  437. //}
  438. //EventBus.EventBus.GetInstance().Publish(new WriteModel() { Address = "M8.1", Value = false });//翻转机上升完成复位
  439. //MessageLog.GetInstance.Show($"翻转机上升执行完成");
  440. while (morkF.RoobotIdle || !morkF.PotInPlace)//等待机器人空闲以及锅到位
  441. {
  442. Task.Delay(5).Wait();
  443. }
  444. if (morkF.TakeMaterialQueue.TryDequeue(out OrderLocInfo order))
  445. {
  446. int loc = order.MaterialLoc;
  447. TakeBurden(loc);
  448. //morkF.TakeVegBLock = true;//订单完成置false
  449. //morkF.AllowTakeMaterial = false;
  450. MessageLog.GetInstance.Show($"订单【{ order.SuborderId}】,,翻转机上升完成,执行取素菜B控制");
  451. }
  452. //等待取料完成
  453. while (!morkF.TakeMaterialComplete)
  454. {
  455. Task.Delay(5).Wait();
  456. }
  457. //转台互锁解除
  458. if (morkF.TurnTableLock)
  459. {
  460. morkF.TurnTableLock = false;
  461. }
  462. }
  463. }
  464. /// <summary>
  465. /// 取调味品C料
  466. /// </summary>
  467. /// <exception cref="NotImplementedException"></exception>
  468. private void TakeBurdenCTask()
  469. {
  470. if (morkF.TakeMaterialQueue.Count > 0)
  471. {
  472. TurnUpStatusDetect();
  473. //while (!morkF.TurnMachineUpComplete)//等待翻转机上升完成以及取料完成
  474. //{
  475. // Task.Delay(5).Wait();
  476. //}
  477. //EventBus.EventBus.GetInstance().Publish(new WriteModel() { Address = "M8.1", Value = false });//翻转机上升完成复位
  478. //MessageLog.GetInstance.Show($"翻转机上升执行完成");
  479. while (morkF.RoobotIdle || !morkF.PotInPlace)//等待机器人空闲以及锅到位
  480. {
  481. Task.Delay(5).Wait();
  482. }
  483. if (morkF.TakeMaterialQueue.TryDequeue(out OrderLocInfo order))
  484. {
  485. int loc = order.MaterialLoc;
  486. TakeBurden(loc);
  487. //morkF.TakeBurdenCLcok = true;//订单完成置false
  488. //morkF.AllowTakeMaterial = false;
  489. //morkF.TakeAllBurdenComplete = false;
  490. MessageLog.GetInstance.Show($"订单【{ order.SuborderId}】,,翻转机上升完成,执行取调味品C料控制");
  491. }
  492. //等待取料完成
  493. while (!morkF.TakeMaterialComplete)
  494. {
  495. Task.Delay(5).Wait();
  496. }
  497. //转台互锁解除
  498. if (morkF.TurnTableLock)
  499. {
  500. morkF.TurnTableLock = false;
  501. }
  502. }
  503. }
  504. /// <summary>
  505. /// 开始烹饪
  506. /// </summary>
  507. /// <exception cref="NotImplementedException"></exception>
  508. private void StartCookingTask()
  509. {
  510. if (morkF.InitialComplete && morkF.TakeMaterialQueue.Count > 0 && morkF.PutPotToKitchenComlete && !morkF.CookingLock)
  511. {
  512. MessageLog.GetInstance.Show($"订单【{morkF.CurrentOrderId}】开始烹饪");
  513. morkF.CookingLock = true;
  514. morkF.PotInPlace = morkF.PutPotToKitchenComlete;//锅到位
  515. Task.Run(new Action(() =>
  516. {
  517. KitchenAdjustGears(3);
  518. Task.Delay(1000).Wait(); //大火加热1s
  519. AddOil();//注油
  520. KitchenAdjustGears(2);
  521. Task.Delay(2000).Wait(); //中火2s
  522. TurnDownStatusDetect();//翻转机下降及检测
  523. KitchenAdjustGears(1);//灶台1挡
  524. TurnMachineGearsControl(1);//翻炒机1挡
  525. Task.Delay(2000).Wait();
  526. TurnMachineGearsControl(0);//关闭翻炒机
  527. TurnUpStatusDetect();//翻转机上升及检测
  528. TurnDownStatusDetect();//翻转机下降及检测
  529. KitchenAdjustGears(3);//灶台3挡
  530. TurnMachineGearsControl(3);//翻炒机3挡
  531. Task.Delay(2000).Wait();//葱姜蒜断生
  532. KitchenAdjustGears(1);//灶台1挡
  533. TurnMachineGearsControl(0);//关闭翻炒机
  534. TurnUpStatusDetect();//翻转机上升及检测
  535. TurnDownStatusDetect();//翻转机下降及检测
  536. KitchenAdjustGears(3);//灶台3挡
  537. TurnMachineGearsControl(3);//翻炒机3挡
  538. Task.Delay(2000).Wait();//B料断生
  539. KitchenAdjustGears(1);//灶台1挡
  540. TurnMachineGearsControl(0);//关闭翻炒机
  541. TurnUpStatusDetect();//翻转机上升及检测
  542. TurnDownStatusDetect();//翻转机下降及检测
  543. KitchenAdjustGears(2);//灶台3挡
  544. TurnMachineGearsControl(3);//翻炒机3挡
  545. Task.Delay(2000).Wait();//煸炒入味
  546. KitchenAdjustGears(0);//灶台0挡
  547. TurnMachineGearsControl(0);//关闭翻炒机
  548. TurnMachineOrientControl("Top");//翻转机上升
  549. while (!morkF.TurnMachineUpComplete)
  550. {
  551. Task.Delay(5).Wait();
  552. }
  553. EventBus.EventBus.GetInstance().Publish(new WriteModel() { Address = "M8.1", Value = false });
  554. morkF.CookingComplete = true; //烹饪完成
  555. MessageLog.GetInstance.Show($"订单【{morkF.CurrentOrderId}】烹饪完成");
  556. }));
  557. }
  558. }
  559. /// <summary>
  560. /// 出餐
  561. /// </summary>
  562. private void OutDishTask()
  563. {
  564. TurnUpStatusDetect();
  565. //while (!morkF.TurnMachineUpComplete)//等待翻转机上升完成以及取料完成
  566. //{
  567. // Task.Delay(5).Wait();
  568. //}
  569. //EventBus.EventBus.GetInstance().Publish(new WriteModel() { Address = "M8.1", Value = false });//翻转机上升完成复位
  570. //MessageLog.GetInstance.Show($"翻转机上升执行完成");
  571. while (morkF.RoobotIdle || morkF.CleanModule || !morkF.ProvidePlateComplete)//等待条件满足
  572. {
  573. Task.Delay(5).Wait();
  574. }
  575. RobotOutMeal();
  576. EventBus.EventBus.GetInstance().Publish(new WriteModel() { Address = "M1.2", Value = false });//供盘复位
  577. MessageLog.GetInstance.Show($"订单【{morkF.CurrentOrderId}】正在出餐");
  578. }
  579. /// <summary>
  580. /// 洗锅放锅
  581. /// </summary>
  582. private void CleanPotTask()
  583. {
  584. while (!morkF.PlaceRinseTableComplete || morkF.CleanModule)
  585. {
  586. Task.Delay(5).Wait();
  587. }
  588. OrderChange(morkF.CurrentOrderId, ORDER_STATUS.COMPLETED_COOK);
  589. MessageLog.GetInstance.Show($"订单【{morkF.CurrentOrderId}】出餐完成");
  590. CleanModuleControl("Start");
  591. morkF.OutMealComplete = true;
  592. Task.Delay(5000).Wait();
  593. CleanModuleControl("Stop");
  594. }
  595. /// <summary>
  596. /// 任务复位重启
  597. /// </summary>
  598. //private void ResetProgram()
  599. //{
  600. // ThreadManage.GetInstance().StartLong(new Action(() =>
  601. // {
  602. // if (RTrig.GetInstance("ResetProgram").Start(morkF.DevicDataInite))
  603. // {
  604. // ThreadManage.GetInstance().StopTask("MainTask", new Action(() =>
  605. // {
  606. // ThreadManage.GetInstance().StopTask("ReadPLCData", new Action(() =>
  607. // {
  608. // morkF = null;
  609. // morkF = new GVL_MorkF();
  610. // ActionManage.GetInstance.Send("ResetProgram");
  611. // ActionManage.GetInstance.Send("ClearOrders");
  612. // ReadData();
  613. // Main();
  614. // }));
  615. // }));
  616. // }
  617. // Thread.Sleep(10);
  618. // }), "ResetProgram");
  619. //}
  620. /// <summary>
  621. /// 翻转机下降及状态检测
  622. /// </summary>
  623. public void TurnDownStatusDetect()
  624. {
  625. //if (ProcessError)
  626. //{
  627. // return;
  628. //}
  629. if (morkF.PotInPlace)
  630. {
  631. //等待取料完成
  632. while (!morkF.TakeMaterialComplete)
  633. {
  634. Task.Delay(5).Wait();
  635. }
  636. TurnMachineOrientControl("Down");
  637. while (!morkF.TurnMachineDownComplete)//等待翻转机下降完成
  638. {
  639. Task.Delay(5).Wait();
  640. }
  641. EventBus.EventBus.GetInstance().Publish(new WriteModel() { Address = "M8.3", Value = false });//复位
  642. MessageLog.GetInstance.Show($"翻转机下降完成");
  643. }
  644. }
  645. /// <summary>
  646. /// 翻转机上升及状态检测
  647. /// </summary>
  648. public void TurnUpStatusDetect()
  649. {
  650. //if (ProcessError)
  651. //{
  652. // return;
  653. //}
  654. if (morkF.PotInPlace)
  655. {
  656. TurnMachineOrientControl("Top");//翻转机上升
  657. while (!morkF.TurnMachineUpComplete || !morkF.TakeMaterialComplete)//等待翻转机上升完成以及取料完成
  658. {
  659. Task.Delay(5).Wait();
  660. }
  661. EventBus.EventBus.GetInstance().Publish(new WriteModel() { Address = "M8.1", Value = false });
  662. MessageLog.GetInstance.Show("翻转机上升完成");
  663. }
  664. }
  665. private void GetStatus(string key, Action<bool[]> action)
  666. {
  667. if (peripheralStatus.ContainsKey(key))
  668. {
  669. action((bool[])peripheralStatus[key]);//获取PLC指定地址的状态值
  670. }
  671. }
  672. /// <summary>
  673. /// 写数据
  674. /// </summary>
  675. /// <param name="address"></param>
  676. /// <param name="value"></param>
  677. private void WriteData(string address, object value)
  678. {
  679. EventBus.EventBus.GetInstance().Publish(new WriteModel() { DeviceId = DeviceId, Address = address, Value = value });
  680. }
  681. /// <summary>
  682. /// 灶台档位调节
  683. /// </summary>
  684. public void KitchenAdjustGears(int number)
  685. {
  686. //if (ProcessError)
  687. //{
  688. // return;
  689. //}
  690. if (morkF.PotInPlace)
  691. {
  692. switch (number)
  693. {
  694. case 0:
  695. WriteData("352", new bool[] { false, false, false, false, false, false, false, false });//0000 0000
  696. break;
  697. case 1:
  698. WriteData("352", new bool[] { true, false, false, false, false, false, false, false });//0000 0001
  699. break;
  700. case 2:
  701. WriteData("352", new bool[] { false, true, false, false, false, false, false, false });//0000 0010
  702. break;
  703. case 3:
  704. WriteData("352", new bool[] { true, true, false, false, false, false, false, false });//0000 0011
  705. break;
  706. case 4:
  707. WriteData("352", new bool[] { false, false, true, false, false, false, false, false });//0000 0100
  708. break;
  709. case 5:
  710. WriteData("352", new bool[] { true, false, true, false, false, false, false, false });//0000 0101
  711. break;
  712. case 6:
  713. WriteData("352", new bool[] { false, true, true, false, false, false, false, false });//0000 0110
  714. break;
  715. case 7:
  716. WriteData("352", new bool[] { true, true, true, false, false, false, false, false });//0000 0111
  717. break;
  718. case 8:
  719. WriteData("355", new bool[] { false, false, false, true, false, false, false, false });//0000 1000
  720. break;
  721. case 9:
  722. WriteData("352", new bool[] { true, false, false, true, false, false, false, false });//0000 1001
  723. break;
  724. }
  725. MessageLog.GetInstance.Show($"订单【{morkF.CurrentOrderId}】,加热档位调至{number}挡");
  726. }
  727. }
  728. public void TurnMaterialStore(int loc)
  729. {
  730. switch (loc)
  731. {
  732. case 1:
  733. WriteData("M13.0", true);
  734. break;
  735. case 2:
  736. WriteData("M13.1", true);
  737. break;
  738. case 3:
  739. WriteData("M13.2", true);
  740. break;
  741. case 4:
  742. WriteData("M13.3", true);
  743. break;
  744. case 5:
  745. WriteData("M13.4", true);
  746. break;
  747. }
  748. }
  749. /// <summary>
  750. /// 供盘启动
  751. /// </summary>
  752. public void StartTakePlate()
  753. {
  754. WriteData("M1.1", true);
  755. }
  756. /// <summary>
  757. /// 取锅到灶台
  758. /// </summary>
  759. public void TakePotToKitchen()
  760. {
  761. WriteData("M14.0", true);
  762. }
  763. /// <summary>
  764. /// 机器人出餐并将锅放置清洗台位置
  765. /// </summary>
  766. public void RobotOutMeal()
  767. {
  768. WriteData("M14.2", true);
  769. }
  770. /// <summary>
  771. /// 注油
  772. /// </summary>
  773. public void AddOil()
  774. {
  775. //if (ProcessError)
  776. //{
  777. // return;
  778. //}
  779. if (morkF.PotInPlace)
  780. {
  781. WriteData("M2.7", true);
  782. MessageLog.GetInstance.Show("开始注油");
  783. while (!morkF.FallOilComplete)
  784. {
  785. Task.Delay(5).Wait();
  786. }
  787. MessageLog.GetInstance.Show("注油完成");
  788. }
  789. }
  790. /// <summary>
  791. /// 翻转机方向控制
  792. /// </summary>
  793. /// <param name="orientation"></param>
  794. public void TurnMachineOrientControl(string orientation)
  795. {
  796. switch (orientation)
  797. {
  798. case "Top": WriteData("M8.0", true); break;
  799. // case "Middle": WriteData("", 1); break;
  800. case "Down": WriteData("M8.2", true); break;
  801. }
  802. MessageLog.GetInstance.Show($"翻转机执行{orientation}操作");
  803. }
  804. /// <summary>
  805. /// 翻转机档位控制
  806. /// </summary>
  807. public void TurnMachineGearsControl(int gear)
  808. {
  809. //if (gear != 0)
  810. //{
  811. // while (!morkF.TurnMachineDownComplete)//等待翻转机下降完成
  812. // {
  813. // Task.Delay(5).Wait();
  814. // }
  815. // EventBus.EventBus.GetInstance().Publish(new WriteModel() { Address = "M8.3", Value = false });//复位
  816. // MessageLog.GetInstance.Show($"翻转机下降完成");
  817. //}
  818. //if (ProcessError)
  819. //{
  820. // return;
  821. //}
  822. if (morkF.PotInPlace)
  823. {
  824. //while (!morkF.TurnMachineDownComplete)//等待翻转机下降完成
  825. //{
  826. // Task.Delay(5).Wait();
  827. //}
  828. //EventBus.EventBus.GetInstance().Publish(new WriteModel() { Address = "M8.3", Value = false });//复位
  829. switch (gear)
  830. {
  831. case 0: WriteData("M7.0", true); Task.Delay(1000).Wait(); break;//关闭翻炒机
  832. case 1: WriteData("M7.1", true); break;//翻炒机1挡
  833. case 2: WriteData("M7.2", true); break;//翻炒机2挡
  834. case 3: WriteData("M7.3", true); break;//翻炒机3挡
  835. }
  836. MessageLog.GetInstance.Show($"翻转机档位调至{gear}挡");
  837. }
  838. }
  839. /// <summary>
  840. /// 取A,B,C料
  841. /// </summary>
  842. public void TakeBurden(int loc)
  843. {
  844. WriteData("M14.1", true);//机器人取料
  845. }
  846. /// <summary>
  847. /// 清洗模组1启停控制
  848. /// </summary>
  849. public void CleanModuleControl(string status)
  850. {
  851. if (status == "Start")
  852. {
  853. WriteData("M1.4", true);
  854. }
  855. if (status == "Stop")
  856. {
  857. WriteData("M1.4", false);
  858. }
  859. MessageLog.GetInstance.Show($"清洗模组执行【{status}】操作");
  860. }
  861. public override void Stop()
  862. {
  863. }
  864. }
  865. }