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

870 line
33 KiB

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