Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 

786 rader
30 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Linq;
  5. using System.Threading;
  6. using BPA.Message;
  7. using HBLConsole.Communication;
  8. using HBLConsole.Factory;
  9. using HBLConsole.GVL;
  10. using HBLConsole.Interface;
  11. using HBLConsole.Model;
  12. using HBLConsole.Service;
  13. using HBLDevice.Coffee;
  14. using Robotc;
  15. using System.Collections.Concurrent;
  16. using System.Diagnostics;
  17. using BPA.Message.IOT;
  18. using System.Threading.Tasks;
  19. namespace HBLConsole.MORKJC2
  20. {
  21. /*
  22. * 冰淇淋咖啡机组合套装
  23. * 物料位置:
  24. * 1:冰淇料
  25. * 2:冰淇淋杯
  26. * 5:咖啡
  27. * 6:咖啡杯
  28. * 9: 茶
  29. * 10: 茶杯
  30. */
  31. public class Control_MORKJC2 : IControl
  32. {
  33. private CoffeEndCook coffeEndCook = new CoffeEndCook();//模拟咖啡制作成功
  34. //咖啡机主控程序
  35. private CoffeeMachine coffeeMachine;
  36. //物料存放位置
  37. private Dictionary<string, PolymerBatching> batchings = new Dictionary<string, PolymerBatching>();
  38. //容器位置
  39. private string holderLoc;
  40. /// <summary>
  41. /// 获取乐百机器人的数据
  42. /// </summary>
  43. SignalResult lebai = new SignalResult();
  44. //主料位置
  45. private string mainMaterialLoc;
  46. //子订单ID
  47. private string subOrderId;
  48. private bool enableFunny = false;
  49. private DateTime lastRecvdOrder = DateTime.Now;
  50. private bool working = false;
  51. /// <summary>
  52. /// 果汁机做法,true:热饮,false:冷饮
  53. /// </summary>
  54. private bool GuMake = false;
  55. private SerialPortClient commProxy;
  56. public void ConnectOk()
  57. {
  58. }
  59. ConcurrentQueue<MorkOrderPush> morkOrderPushes = new ConcurrentQueue<MorkOrderPush>();
  60. public void Init()
  61. {
  62. ActionManage.GetInstance.Register(new Action<object>((s) =>
  63. {
  64. if (s is DrCoffeeDrinksCode cf)
  65. {
  66. DoCoffee();
  67. }
  68. else if (s is Dictionary<string, string> ms)
  69. {
  70. if (ms.ContainsKey("Button"))
  71. {
  72. switch (ms["Button"])
  73. {
  74. case "启动示教":
  75. LebaiHelper.GetInstance.StartTeachMode();
  76. break;
  77. case "停止示教":
  78. LebaiHelper.GetInstance.EndtTeachMode();
  79. break;
  80. case "启动机器人":
  81. LebaiHelper.GetInstance.StartRobot();
  82. break;
  83. case "急停":
  84. LebaiHelper.GetInstance.EStopRobot();
  85. break;
  86. default:
  87. break;
  88. }
  89. }
  90. }
  91. }), "SimCoffee");
  92. //构建所有商品物料信息
  93. batchings = PolymerBatching.BuildAll();
  94. EventBus.GetInstance().Subscribe<CoffeEndCook>(CoffeEndCookHandle);
  95. System.Configuration.Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None);
  96. //一系列外围基础配置
  97. var com_Coffee = config.AppSettings.Settings["COM_Coffee"].Value;
  98. var baud_Coffee = config.AppSettings.Settings["BAUD_Coffee"].Value;
  99. //咖啡机创建
  100. coffeeMachine = new CoffeeMachine(com_Coffee, (BaudRates)Enum.Parse(typeof(BaudRates), baud_Coffee));
  101. Main();
  102. ReadData();
  103. ThreadManage.GetInstance.StartLong(new Action(() =>
  104. {
  105. while (GeneralConfig.Healthy && (morkOrderPushes.Count > 0))
  106. {
  107. working = true;
  108. if (morkOrderPushes.TryDequeue(out MorkOrderPush order))
  109. {
  110. MessageLog.GetInstance.Show($"开始制作订单[{order.SortNum}]");
  111. //商品类型
  112. GOODS_TYPE currentGoodsType = GOODS_TYPE.NEITHER;
  113. //子订单ID
  114. subOrderId = order.SuborderId;
  115. //遍历物料
  116. foreach (var item in order.GoodBatchings)
  117. {
  118. var res = Json<BatchingInfoPar>.Data.orderMaterialDelivery.BatchingInfo.FirstOrDefault(p => p.BatchingId == item.BatchingId);
  119. if (res != null)
  120. {
  121. //获取主料和容器位置
  122. switch (batchings[res.BatchingLoc].BatchingClass)
  123. {
  124. case BATCHING_CLASS.HOLDER:
  125. holderLoc = res.BatchingLoc;
  126. break;
  127. case BATCHING_CLASS.MAIN_MATERIAL:
  128. // mainMaterialLoc ="1";
  129. mainMaterialLoc = res.BatchingLoc;
  130. //验证商品是咖啡还是冰淇淋
  131. if (ValidateGoodsByBatching(res.BatchingLoc) != GOODS_TYPE.NEITHER)
  132. {
  133. //获取当前物料所属商品类型
  134. currentGoodsType = ValidateGoodsByBatching(res.BatchingLoc);
  135. }
  136. break;
  137. }
  138. }
  139. }
  140. //根据商品类型执行具体制作流程
  141. switch (currentGoodsType)
  142. {
  143. case GOODS_TYPE.COFFEE:
  144. DoCoffee();
  145. break;
  146. case GOODS_TYPE.JUICE:
  147. GuMake = order.MakeID == "2";
  148. DoJuicer();
  149. break;
  150. case GOODS_TYPE.TEA:
  151. DoTea();
  152. break;
  153. case GOODS_TYPE.WATER:
  154. DoWater();
  155. break;
  156. case GOODS_TYPE.NEITHER:
  157. MessageLog.GetInstance.Show("未知的商品类型");
  158. break;
  159. }
  160. }
  161. working = false;
  162. lastRecvdOrder = DateTime.Now;
  163. }
  164. Thread.Sleep(1000);
  165. }), "订单制作");
  166. }
  167. public void Main()
  168. {
  169. //咖啡机开启主线程
  170. coffeeMachine.Start();
  171. //开始心跳刷新,根据咖啡机及冰淇淋机来判断
  172. ThreadManage.GetInstance.StartLong(new Action(() =>
  173. {
  174. //GeneralConfig.Healthy =
  175. // LebaiHelper.GetInstance.IsConnected &&
  176. // MorkCStatus.GetInstance().CanDo &&
  177. // JuicerHelper.GetInstance.IsOpen &&
  178. // MCUSerialHelper.GetInstance.IsOpen;
  179. GeneralConfig.Healthy = true;
  180. Thread.Sleep(100);
  181. }), "MORK-IC心跳刷新");
  182. ThreadManage.GetInstance.Start(new Action(() =>
  183. {
  184. while (!LebaiHelper.GetInstance.IsConnected)
  185. {
  186. Thread.Sleep(10);
  187. }
  188. //LebaiHelper.GetInstance.Scene(LebaiHelper.SENCE_欢迎);
  189. }), "MORK-JC欢迎");
  190. }
  191. public void DataParse<T>(T order)
  192. {
  193. if (order is MorkOrderPush morkOrderPush)
  194. {
  195. morkOrderPushes.Enqueue(morkOrderPush);
  196. }
  197. }
  198. /// <summary>
  199. /// 验证当前是做咖啡还是做冰淇淋
  200. /// </summary>
  201. /// <param name="batchingLoc">物料位置</param>
  202. private GOODS_TYPE ValidateGoodsByBatching(string batchingLoc)
  203. {
  204. if (batchings.ContainsKey(batchingLoc))
  205. return batchings[batchingLoc].GoodsType;
  206. return GOODS_TYPE.NEITHER;
  207. }
  208. private AutoResetEvent are = new AutoResetEvent(false);
  209. private void Wait(int value = 101)
  210. {
  211. while (!(lebai.Ok && lebai.Value == value))
  212. {
  213. Thread.Sleep(5);
  214. }
  215. }
  216. int[] devStatusBy = new int[2] { 0, 0 };
  217. bool outCupCheck = false;//放纸杯位置有无判断
  218. /// <summary>
  219. /// 传感器的输入信号 0:无意义 1:有信号 2:无信号 3:信号不正确
  220. /// </summary>
  221. int bSensorInput;
  222. /// <summary>
  223. /// 延迟的超时时间
  224. /// </summary>
  225. DateTime delayTimeOut;
  226. /// <summary>
  227. /// 做咖啡
  228. /// </summary>
  229. private void DoCoffee()
  230. {
  231. #region 接咖啡流程
  232. are.Reset();
  233. while (LebaiHelper.GetInstance.GetInput(1))//判断放杯位置是否有物品
  234. {
  235. if (!outCupCheck)
  236. MessageLog.GetInstance.ShowEx("成品处有纸杯存在,请取走!!");
  237. outCupCheck = true;
  238. }
  239. outCupCheck = false;
  240. SimpleFactory.GetInstance.OrderChanged(subOrderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
  241. int resultTakeCup = takeCup();
  242. if (resultTakeCup == 1)
  243. {
  244. MessageLog.GetInstance.Show("咖啡杯取杯完成");
  245. LebaiHelper.GetInstance.SetValue(0);
  246. LebaiHelper.GetInstance.Scene(LebaiHelper.JUICE2_接咖啡);
  247. Wait();
  248. new MakeCoffeeEvent() { DrinkCode = (DrCoffeeDrinksCode)int.Parse(mainMaterialLoc) }.Publish(); //接咖啡控制 //DrCoffeeDrinksCode.热水
  249. //Task.Delay(10000).Wait();//模拟接咖啡
  250. //coffeEndCook.Publish();//模拟咖啡制作完成
  251. are.WaitOne(1000 * 120);
  252. while (LebaiHelper.GetInstance.GetInput(1))//判断放杯位置是否有物品
  253. {
  254. if (!outCupCheck)
  255. MessageLog.GetInstance.ShowEx("成品处有纸杯存在,请取走!!");
  256. outCupCheck = true;
  257. }
  258. outCupCheck = false;
  259. LebaiHelper.GetInstance.SetValue(0);
  260. LebaiHelper.GetInstance.Scene(LebaiHelper.JUICE2_放咖啡杯);
  261. Wait();
  262. SimpleFactory.GetInstance.OrderChanged(subOrderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE);
  263. MessageLog.GetInstance.Show("咖啡制作完成");
  264. }
  265. else
  266. {
  267. return;
  268. }
  269. #endregion
  270. }
  271. /// <summary>
  272. /// 做茶
  273. /// </summary>
  274. private void DoTea()
  275. {
  276. #region 接茶流程
  277. while (LebaiHelper.GetInstance.GetInput(1))//判断放杯位置是否有物品
  278. {
  279. if (!outCupCheck)
  280. MessageLog.GetInstance.ShowEx("成品处有纸杯存在,请取走!!");
  281. outCupCheck = true;
  282. }
  283. outCupCheck = false;
  284. SimpleFactory.GetInstance.OrderChanged(subOrderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
  285. int resultTakeCup = takeCup();
  286. if (resultTakeCup == 1)
  287. {
  288. MessageLog.GetInstance.Show("取茶杯完成");
  289. LebaiHelper.GetInstance.SetValue(0);
  290. LebaiHelper.GetInstance.Scene(LebaiHelper.JUICE2_接茶叶);
  291. Wait();
  292. // MCUSerialHelper.GetInstance.ServoControl(1, 105);
  293. Thread.Sleep(1000);
  294. // MCUSerialHelper.GetInstance.ServoControl(1, 130);
  295. Thread.Sleep(1000);
  296. // MCUSerialHelper.GetInstance.ServoControl(1, 105);
  297. Thread.Sleep(3000);
  298. LebaiHelper.GetInstance.SetValue(0);
  299. LebaiHelper.GetInstance.Scene(LebaiHelper.JUICE2_接茶水);
  300. Wait();
  301. // MCUSerialHelper.GetInstance.OutputControl(4, false);
  302. LebaiHelper.GetInstance.SetOutput(false,1);
  303. // MCUSerialHelper.GetInstance.OutputControl(3, false);
  304. LebaiHelper.GetInstance.SetOutput(false, 0);
  305. Thread.Sleep(100);
  306. // MCUSerialHelper.GetInstance.OutputControl(3, true);
  307. LebaiHelper.GetInstance.SetOutput(true, 0);
  308. Thread.Sleep(3000);
  309. // MCUSerialHelper.GetInstance.OutputControl(3, false);
  310. LebaiHelper.GetInstance.SetOutput(false, 0);
  311. Thread.Sleep(100);
  312. LebaiHelper.GetInstance.SetOutput(false, 1);
  313. // MCUSerialHelper.GetInstance.OutputControl(4, false);
  314. Thread.Sleep(100);
  315. LebaiHelper.GetInstance.SetOutput(true, 1);
  316. // MCUSerialHelper.GetInstance.OutputControl(4, true);
  317. Thread.Sleep(500);
  318. // MCUSerialHelper.GetInstance.OutputControl(4, false);
  319. LebaiHelper.GetInstance.SetOutput(false, 1);
  320. Thread.Sleep(60000);
  321. while (LebaiHelper.GetInstance.GetInput(1))//判断放杯位置是否有物品
  322. {
  323. if (!outCupCheck)
  324. MessageLog.GetInstance.ShowEx("成品处有纸杯存在,请取走!!");
  325. outCupCheck = true;
  326. }
  327. outCupCheck = false;
  328. LebaiHelper.GetInstance.SetValue(0);
  329. LebaiHelper.GetInstance.Scene(LebaiHelper.JUICE2_放水杯);
  330. Wait();
  331. SimpleFactory.GetInstance.OrderChanged(subOrderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE);
  332. MessageLog.GetInstance.Show("茶水制作完成");
  333. }
  334. else
  335. {
  336. return;
  337. }
  338. #endregion
  339. }
  340. /// <summary>
  341. /// 接开水
  342. /// </summary>
  343. private void DoWater()
  344. {
  345. #region 接水流程
  346. while (LebaiHelper.GetInstance.GetInput(1))//判断放杯位置是否有物品
  347. {
  348. if (!outCupCheck)
  349. MessageLog.GetInstance.ShowEx("成品处有纸杯存在,请取走!!");
  350. outCupCheck = true;
  351. }
  352. outCupCheck = false;
  353. SimpleFactory.GetInstance.OrderChanged(subOrderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
  354. int resultTakeCup = takeCup();
  355. if (resultTakeCup == 1)
  356. {
  357. LebaiHelper.GetInstance.SetValue(0);
  358. LebaiHelper.GetInstance.Scene(LebaiHelper.JUICE2_接水);
  359. Wait();
  360. // LebaiHelper.GetInstance.SetOutput(true,0);
  361. //// MCUSerialHelper.GetInstance.OutputControl(3, true);
  362. // Thread.Sleep(1000);
  363. // LebaiHelper.GetInstance.SetOutput(false, 0);
  364. // // MCUSerialHelper.GetInstance.OutputControl(3, false);
  365. // Thread.Sleep(10000);
  366. // LebaiHelper.GetInstance.SetOutput(true,1);
  367. // // MCUSerialHelper.GetInstance.OutputControl(4, true);
  368. // Thread.Sleep(1000);
  369. // LebaiHelper.GetInstance.SetOutput(false, 1);
  370. // // MCUSerialHelper.GetInstance.OutputControl(4, false);
  371. // Thread.Sleep(3000);
  372. LebaiHelper.GetInstance.SetOutput(false, 1);
  373. // MCUSerialHelper.GetInstance.OutputControl(3, false);
  374. LebaiHelper.GetInstance.SetOutput(false, 0);
  375. Thread.Sleep(100);
  376. // MCUSerialHelper.GetInstance.OutputControl(3, true);
  377. LebaiHelper.GetInstance.SetOutput(true, 0);
  378. Thread.Sleep(3000);
  379. // MCUSerialHelper.GetInstance.OutputControl(3, false);
  380. LebaiHelper.GetInstance.SetOutput(false, 0);
  381. Thread.Sleep(100);
  382. LebaiHelper.GetInstance.SetOutput(false, 1);
  383. // MCUSerialHelper.GetInstance.OutputControl(4, false);
  384. Thread.Sleep(100);
  385. LebaiHelper.GetInstance.SetOutput(true, 1);
  386. // MCUSerialHelper.GetInstance.OutputControl(4, true);
  387. Thread.Sleep(500);
  388. // MCUSerialHelper.GetInstance.OutputControl(4, false);
  389. LebaiHelper.GetInstance.SetOutput(false, 1);
  390. Thread.Sleep(60000);
  391. while (LebaiHelper.GetInstance.GetInput(1))//判断放杯位置是否有物品
  392. {
  393. if (!outCupCheck)
  394. MessageLog.GetInstance.ShowEx("成品处有纸杯存在,请取走!!");
  395. outCupCheck = true;
  396. }
  397. outCupCheck = false;
  398. //添加控制接水机构程序
  399. LebaiHelper.GetInstance.SetValue(0);
  400. LebaiHelper.GetInstance.Scene(LebaiHelper.JUICE2_放水杯);
  401. Wait();
  402. SimpleFactory.GetInstance.OrderChanged(subOrderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE);
  403. MessageLog.GetInstance.Show("纯净水制作完成");
  404. }
  405. else
  406. {
  407. return;
  408. }
  409. #endregion
  410. }
  411. /// <summary>
  412. /// 果汁机控制信号
  413. /// </summary>
  414. private byte JuicerNum;
  415. /// <summary>
  416. /// 做果汁
  417. /// </summary>
  418. private void DoJuicer()
  419. {
  420. #region 接果汁流程
  421. are.Reset();
  422. while (LebaiHelper.GetInstance.GetInput(1))//判断放杯位置是否有物品
  423. {
  424. if (!outCupCheck)
  425. MessageLog.GetInstance.ShowEx("成品处有纸杯存在,请取走!!");
  426. outCupCheck = true;
  427. }
  428. SimpleFactory.GetInstance.OrderChanged(subOrderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
  429. int resultTakeCup = takeCup();
  430. if (resultTakeCup == 1)
  431. {
  432. int JuicerNum1 = int.Parse(mainMaterialLoc);
  433. switch (JuicerNum1)
  434. {
  435. case 52:
  436. if(GuMake)
  437. {
  438. JuicerNum = 0x00;
  439. }
  440. else
  441. {
  442. JuicerNum = 0x01;
  443. }
  444. LebaiHelper.GetInstance.SetValue(0);
  445. LebaiHelper.GetInstance.Scene(LebaiHelper.JUICE2_接果汁公共位);
  446. Wait();
  447. LebaiHelper.GetInstance.SetValue(0);
  448. LebaiHelper.GetInstance.Scene(LebaiHelper.JUICE2_接1号果汁);
  449. Wait();
  450. break;
  451. case 53:
  452. if (GuMake)
  453. {
  454. JuicerNum = 0x02;
  455. }
  456. else
  457. {
  458. JuicerNum = 0x03;
  459. }
  460. LebaiHelper.GetInstance.SetValue(0);
  461. LebaiHelper.GetInstance.Scene(LebaiHelper.JUICE2_接果汁公共位);
  462. Wait();
  463. LebaiHelper.GetInstance.SetValue(0);
  464. LebaiHelper.GetInstance.Scene(LebaiHelper.JUICE2_接2号果汁);
  465. Wait();
  466. break;
  467. case 54:
  468. if (GuMake)
  469. {
  470. JuicerNum = 0x04;
  471. }
  472. else
  473. {
  474. JuicerNum = 0x05;
  475. }
  476. LebaiHelper.GetInstance.SetValue(0);
  477. LebaiHelper.GetInstance.Scene(LebaiHelper.JUICE2_接果汁公共位);
  478. Wait();
  479. LebaiHelper.GetInstance.SetValue(0);
  480. LebaiHelper.GetInstance.Scene(LebaiHelper.JUICE2_接3号果汁);
  481. Wait();
  482. break;
  483. case 55:
  484. if (GuMake)
  485. {
  486. JuicerNum = 0x06;
  487. }
  488. else
  489. {
  490. JuicerNum = 0x07;
  491. }
  492. LebaiHelper.GetInstance.SetValue(0);
  493. LebaiHelper.GetInstance.Scene(LebaiHelper.JUICE2_接果汁公共位);
  494. Wait();
  495. LebaiHelper.GetInstance.SetValue(0);
  496. LebaiHelper.GetInstance.Scene(LebaiHelper.JUICE2_接4号果汁); ;
  497. Wait();
  498. break;
  499. default:
  500. JuicerNum = 0x00;
  501. LebaiHelper.GetInstance.SetValue(0);
  502. LebaiHelper.GetInstance.Scene(LebaiHelper.JUICE2_接果汁公共位);
  503. Wait();
  504. LebaiHelper.GetInstance.SetValue(0);
  505. LebaiHelper.GetInstance.Scene(LebaiHelper.JUICE_接1号果汁);
  506. Wait();
  507. break;
  508. }
  509. // var devStatus = JuicerHelper.GetInstance.GetDeviceStatus();
  510. //var devStatus1 = Convert.ToString(devStatus[0], 2);
  511. //var devStatus2 = devStatus[1];
  512. //if (devStatus1.IndexOf("0") == 1 && devStatus2 == 0)
  513. //{
  514. // JuicerHelper.GetInstance.StartCook(JuicerNum);
  515. // Thread.Sleep(100);
  516. // devStatusBy = JuicerHelper.GetInstance.GetDeviceStatus();
  517. // while (!(devStatusBy[1] == 0))
  518. // {
  519. // Thread.Sleep(100);
  520. // devStatusBy = JuicerHelper.GetInstance.GetDeviceStatus();
  521. // while (devStatusBy.Length != 2)
  522. // {
  523. // Thread.Sleep(100);
  524. // devStatusBy = JuicerHelper.GetInstance.GetDeviceStatus();
  525. // }
  526. // }
  527. // devStatusBy = JuicerHelper.GetInstance.GetDeviceStatus();
  528. // Thread.Sleep(5000);
  529. // LebaiHelper.GetInstance.SetValue(0);
  530. // LebaiHelper.GetInstance.Scene(LebaiHelper.JUICE2_放果汁杯);
  531. // Wait();
  532. // SimpleFactory.GetInstance.OrderChanged(subOrderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE);
  533. // MessageLog.GetInstance.Show("果汁制作完成");
  534. //}
  535. //模拟果汁
  536. Thread.Sleep(15000);
  537. while (LebaiHelper.GetInstance.GetInput(1))//判断放杯位置是否有物品
  538. {
  539. if (!outCupCheck)
  540. MessageLog.GetInstance.ShowEx("成品处有纸杯存在,请取走!!");
  541. outCupCheck = true;
  542. }
  543. outCupCheck = false;
  544. LebaiHelper.GetInstance.SetValue(0);
  545. LebaiHelper.GetInstance.Scene(LebaiHelper.JUICE2_放果汁杯);
  546. Wait();
  547. SimpleFactory.GetInstance.OrderChanged(subOrderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE);
  548. MessageLog.GetInstance.Show("果汁制作完成");
  549. }
  550. else
  551. {
  552. return;
  553. }
  554. #endregion
  555. }
  556. /// <summary>
  557. /// 取杯的次数
  558. /// </summary>
  559. private int nCnt;
  560. /// <summary>
  561. /// 取杯流程
  562. /// </summary>
  563. /// <returns>0:无意义,1:取杯成功 2:取杯失败</returns>
  564. private int takeCup()
  565. {
  566. try
  567. {
  568. nCnt = 0;
  569. LebaiHelper.GetInstance.SetValue(0);
  570. LebaiHelper.GetInstance.Scene(LebaiHelper.JUICE2_初始位);
  571. Wait();
  572. LebaiHelper.GetInstance.SetValue(0);
  573. LebaiHelper.GetInstance.Scene(LebaiHelper.JUICE2_取纸杯);
  574. Wait();
  575. LebaiHelper.GetInstance.SetValue(0);
  576. LebaiHelper.GetInstance.Scene(LebaiHelper.JUICE2_纸杯检测);
  577. Wait();
  578. nCnt++;
  579. while (!LebaiHelper.GetInstance.GetInput(0)) //读取传感器的值
  580. {
  581. if (nCnt > 3)
  582. {
  583. nCnt = 0;
  584. MessageLog.GetInstance.ShowEx("三次取杯失败,请查看");
  585. return 2;
  586. }
  587. else
  588. {
  589. nCnt++;
  590. LebaiHelper.GetInstance.SetValue(0);
  591. LebaiHelper.GetInstance.Scene(LebaiHelper.JUICE2_二次取杯);
  592. Wait();
  593. LebaiHelper.GetInstance.SetValue(0);
  594. LebaiHelper.GetInstance.Scene(LebaiHelper.JUICE2_纸杯检测);
  595. Wait();
  596. }
  597. Thread.Sleep(100);
  598. }
  599. }
  600. catch (Exception ex)
  601. {
  602. MessageLog.GetInstance.Show(ex.ToString());
  603. }
  604. return 1;
  605. }
  606. /// <summary>
  607. /// 放杯
  608. /// </summary>
  609. /// <returns>0:无意义 1:放杯成功 2:执行失败(传感器还有信号) 3:放杯异常</returns>
  610. private int putCup()
  611. {
  612. try
  613. {
  614. if (LebaiHelper.GetInstance.GetInput(1)) return 2;
  615. LebaiHelper.GetInstance.Scene(LebaiHelper.JUICE_放杯);
  616. Wait();
  617. LebaiHelper.GetInstance.SetValue(1);
  618. LebaiHelper.GetInstance.Scene(LebaiHelper.JUICE_放杯检测);
  619. Wait();
  620. LebaiHelper.GetInstance.SetValue(1);
  621. if (LebaiHelper.GetInstance.GetInput(2))
  622. {
  623. return 1;
  624. }
  625. else
  626. {
  627. return 3;
  628. }
  629. }
  630. catch (Exception ex)
  631. {
  632. MessageLog.GetInstance.Show(ex.ToString());
  633. return 0;
  634. }
  635. }
  636. /// <summary>
  637. /// 检测放杯位,是否有杯子
  638. /// </summary>
  639. /// <returns>0:无意义 1:没有杯子 2:有杯子 </returns>
  640. private int checkCup()
  641. {
  642. try
  643. {
  644. while (LebaiHelper.GetInstance.GetInput(1))
  645. {
  646. Thread.Sleep(100);
  647. if (DateTime.Now.Subtract(delayTimeOut).TotalSeconds >= 1) return 2;
  648. }
  649. MessageLog.GetInstance.Show("放杯位有杯子未取走,等待取走,最多等待60s,即跳出流程");
  650. return 1;
  651. }
  652. catch (Exception ex)
  653. {
  654. MessageLog.GetInstance.Show(ex.ToString());
  655. return 0;
  656. }
  657. }
  658. private void CoffeEndCookHandle(IEvent @event, EventBus.EventCallBackHandle callBack)
  659. {
  660. are.Set();
  661. }
  662. public void ReadData()
  663. {
  664. ThreadManage.GetInstance.StartLong(new Action(() =>
  665. {
  666. lebai = LebaiHelper.GetInstance.GetValueAsync();
  667. LebaiHelper.GetInstance.GetRobotModeStatus();
  668. //LebaiHelper.GetInstance.GetInput();
  669. Thread.Sleep(100);
  670. }), "乐百机器人数据读取", true);
  671. }
  672. public void SimOrder<T>(T simOrder)
  673. {
  674. //if (morkOrderPushes.Count > 0)
  675. //{
  676. // morkOrderPushes.Clear();
  677. //}
  678. //morkOrderPushes.Enqueue(simOrder as MorkOrderPush);
  679. }
  680. /// <summary>
  681. /// IOT 广播消息命令
  682. /// </summary>
  683. public void IotBroadcast<T>(T broadcast)
  684. {
  685. if (broadcast != null && broadcast is IOTCommandModel iOTCommand)
  686. {
  687. switch (iOTCommand.CommandName)
  688. {
  689. case 0://控制类
  690. if (iOTCommand.CommandValue != null)
  691. {
  692. if (iOTCommand.CommandValue.ContainsKey("SimOrder"))
  693. {
  694. //SimOrder(new SimOrderData { NoodleLoc = 1, BowlLoc = 10 });
  695. }
  696. }
  697. break;
  698. case 1://设置属性
  699. break;
  700. case 2://通知消息
  701. break;
  702. default:
  703. break;
  704. }
  705. }
  706. }
  707. public class SimOrderData
  708. {
  709. public string id { get; set; }
  710. public int OrderStatus { get; set; }
  711. public string Loc { get; set; }
  712. public MorkOrderPush morkOrder { get; set; }
  713. public SimOrderData()
  714. {
  715. id = Guid.NewGuid().ToString();
  716. OrderStatus = 0;
  717. }
  718. }
  719. }
  720. }