终端一体化运控平台
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

852 строки
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 BPA.Helper;
  13. using BPASmartClient.Model.咖啡机.Enum;
  14. using BPASmartClient.Model;
  15. using BPASmartClient.Model.乐白机器人;
  16. using BPASmartClient.Model.单片机;
  17. using static BPA.Helper.EventBus;
  18. namespace BPASmartClient.MorkTLebaiJC
  19. {
  20. /*
  21. * 冰淇淋咖啡机组合套装
  22. * 物料位置:
  23. * 1:冰淇料
  24. * 2:冰淇淋杯
  25. * 5:咖啡
  26. * 6:咖啡杯
  27. * 9: 茶
  28. * 10: 茶杯
  29. */
  30. public class Control_MORKJC2 : BaseDevice
  31. {
  32. private Dictionary<string, PolymerBatching> batchings = new Dictionary<string, PolymerBatching>();
  33. //容器位置
  34. private string holderLoc;
  35. //主料位置
  36. private string mainMaterialLoc;
  37. public override global::BPA.Message.Enum.DeviceClientType DeviceType { get { return BPA.Message.Enum.DeviceClientType.MORKT; } }
  38. GVL_MorkTLebaiJC morkTLebaiJC =new GVL_MorkTLebaiJC();
  39. /// <summary>
  40. /// 果汁机做法,true:热饮,false:冷饮
  41. /// </summary>
  42. private bool GuMake = false;
  43. public override void DoMain()
  44. {
  45. if (Json<KeepDataBase>.Data.IsVerify)
  46. {
  47. IsHealth = true;
  48. }
  49. IsHealth = true;
  50. serverInit();
  51. DataParse();
  52. ActionManage.GetInstance.Register(new Action<object>((o) => { SimOrder(o); }), "SimOrder");//模拟订单委托注册
  53. }
  54. private void serverInit()
  55. {
  56. EventBus.GetInstance.Subscribe<MaterialDeliveryEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  57. {
  58. if (@event == null) return;
  59. if (@event is MaterialDeliveryEvent material)
  60. {
  61. orderMaterialDelivery = material.orderMaterialDelivery;
  62. }
  63. });
  64. }
  65. private void DataParse()
  66. {
  67. EventBus.GetInstance.Subscribe<DoOrderEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle)
  68. {
  69. if (@event == null) return;
  70. if (@event is DoOrderEvent order)
  71. {
  72. if (order.MorkOrder.GoodBatchings == null) return;
  73. OrderCount++;
  74. DeviceProcessLogShow($"接收到{OrderCount}次订单");
  75. batchings = PolymerBatching.BuildAll();
  76. //商品类型
  77. GOODS_TYPE currentGoodsType = GOODS_TYPE.NEITHER;
  78. foreach (var item in order.MorkOrder.GoodBatchings)
  79. {
  80. var res = orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId);
  81. if (res != null)
  82. {
  83. //验证商品是做的某种饮料
  84. if (ValidateGoodsByBatching(res.BatchingLoc) != GOODS_TYPE.NEITHER)
  85. {
  86. //获取当前物料所属商品类型
  87. currentGoodsType = ValidateGoodsByBatching(res.BatchingLoc);
  88. }
  89. //
  90. switch (batchings[res.BatchingLoc].BatchingClass)
  91. {
  92. case BATCHING_CLASS.HOLDER:
  93. holderLoc = res.BatchingLoc;
  94. break;
  95. case BATCHING_CLASS.MAIN_MATERIAL:
  96. mainMaterialLoc = res.BatchingLoc;
  97. break;
  98. }
  99. //根据商品类型执行具体制作流程
  100. switch (currentGoodsType)
  101. {
  102. case GOODS_TYPE.COFFEE:
  103. if (morkTLebaiJC.morkOrderPushesCoffee.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  104. {
  105. morkTLebaiJC.morkOrderPushesCoffee.Enqueue(new OrderLocInfo()
  106. {
  107. SuborderId = order.MorkOrder.SuborderId,
  108. BatchingId = res.BatchingId,
  109. Loc = ushort.Parse( mainMaterialLoc),
  110. GoodName = order.MorkOrder.GoodsName,
  111. });
  112. }
  113. break;
  114. case GOODS_TYPE.JUICE:
  115. GuMake = order.MorkOrder.MakeID == "2";//判断果汁的冷热
  116. if (morkTLebaiJC.morkOrderPushesJuicer.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  117. {
  118. morkTLebaiJC.morkOrderPushesJuicer.Enqueue(new OrderLocInfo()
  119. {
  120. SuborderId = order.MorkOrder.SuborderId,
  121. BatchingId = res.BatchingId,
  122. Loc = ushort.Parse(mainMaterialLoc),
  123. GoodName = order.MorkOrder.GoodsName,
  124. });
  125. }
  126. break;
  127. case GOODS_TYPE.TEA:
  128. if (morkTLebaiJC.morkOrderPushesTea.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  129. {
  130. morkTLebaiJC.morkOrderPushesTea.Enqueue(new OrderLocInfo()
  131. {
  132. SuborderId = order.MorkOrder.SuborderId,
  133. BatchingId = res.BatchingId,
  134. Loc = ushort.Parse(mainMaterialLoc),
  135. GoodName = order.MorkOrder.GoodsName,
  136. });
  137. }
  138. break;
  139. case GOODS_TYPE.WATER:
  140. if (morkTLebaiJC.morkOrderPushesWater.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  141. {
  142. morkTLebaiJC.morkOrderPushesWater.Enqueue(new OrderLocInfo()
  143. {
  144. SuborderId = order.MorkOrder.SuborderId,
  145. BatchingId = res.BatchingId,
  146. Loc = ushort.Parse(mainMaterialLoc),
  147. GoodName = order.MorkOrder.GoodsName,
  148. });
  149. }
  150. break;
  151. case GOODS_TYPE.NEITHER:
  152. DeviceProcessLogShow("未知的商品类型");
  153. break;
  154. }
  155. }
  156. }
  157. }
  158. });
  159. }
  160. private bool bFirstTrig_TeaWater = false;
  161. /// <summary>
  162. /// 延迟的超时时间
  163. /// </summary>
  164. DateTime delayTimeOut;
  165. private bool bFirstTrig_Coffee = false;
  166. DateTime delayTimeOut_Coffee;
  167. private bool bFirstTrig_Juice = false;
  168. DateTime delayTimeOut_Juice;
  169. public override void MainTask()
  170. {
  171. EventBus.GetInstance.Subscribe<DRCoffee_CoffeEndCookEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  172. {
  173. if (morkTLebaiJC.IsHaveCoffeeCup)
  174. morkTLebaiJC.MakeCoffeeEnd = true;
  175. });
  176. if (pickUpCoffeeHaveCup)
  177. {
  178. if (!bFirstTrig_Coffee)
  179. {
  180. bFirstTrig_Coffee = true;
  181. delayTimeOut_Coffee = DateTime.Now;
  182. }
  183. else if (DateTime.Now.Subtract(delayTimeOut_Coffee).TotalSeconds > 180 && bFirstTrig_Coffee == true)
  184. {
  185. bFirstTrig_Coffee = false;
  186. if (morkTLebaiJC.IsHaveCoffeeCup)
  187. morkTLebaiJC.MakeCoffeeEnd = true;
  188. }
  189. }
  190. if (morkTLebaiJC.IsHaveJuiceCup)
  191. {
  192. var Juicestate = GetStatus<int[]>("GetDeviceStatus");
  193. if (Juicestate != null)
  194. {
  195. if (Juicestate.Length > 0)
  196. {
  197. var Juicestate1 = Convert.ToString(Juicestate[0], 2);
  198. var Juicestate2 = Juicestate[1];
  199. if (Juicestate1.IndexOf("0") == 1 && Juicestate2 == 0)
  200. {
  201. morkTLebaiJC.MakeJuiceEnd = true;
  202. }
  203. }
  204. }
  205. //若无状态返回 则加延迟
  206. if (!bFirstTrig_Juice)
  207. {
  208. bFirstTrig_Juice = true;
  209. delayTimeOut_Juice = DateTime.Now;
  210. }
  211. else if (DateTime.Now.Subtract(delayTimeOut_Juice).TotalSeconds > 30 && bFirstTrig_Juice == true)
  212. {
  213. bFirstTrig_Juice = false;
  214. morkTLebaiJC.MakeJuiceEnd = true;
  215. }
  216. }
  217. if (morkTLebaiJC.IsHaveTeaWaterCup)
  218. {
  219. if (!bFirstTrig_TeaWater)
  220. {
  221. bFirstTrig_TeaWater = true;
  222. delayTimeOut = DateTime.Now;
  223. }
  224. else if (DateTime.Now.Subtract(delayTimeOut).TotalSeconds >= 50 && bFirstTrig_TeaWater == true)
  225. {
  226. bFirstTrig_TeaWater = false;
  227. morkTLebaiJC.MakeTeaEnd = true;
  228. }
  229. }
  230. DoCoffee();
  231. DoJuice();
  232. DoBoiledTea();
  233. DoBoiledWater();
  234. }
  235. /// <summary>
  236. /// 订单状态改变
  237. /// </summary>
  238. /// <param name="subid"></param>
  239. /// <param name="oRDER_STATUS"></param>
  240. private void OrderChange(string subid, ORDER_STATUS oRDER_STATUS)
  241. {
  242. EventBus.GetInstance.Publish(new OrderStatusChangedEvent() { Status = oRDER_STATUS, SubOrderId = subid, deviceClientType = DeviceType });
  243. }
  244. /// <summary>
  245. /// 验证商品是做的某种饮料
  246. /// </summary>
  247. /// <param name="batchingLoc">物料位置</param>
  248. private GOODS_TYPE ValidateGoodsByBatching(string batchingLoc)
  249. {
  250. if (batchings.ContainsKey(batchingLoc))
  251. return batchings[batchingLoc].GoodsType;
  252. return GOODS_TYPE.NEITHER;
  253. }
  254. /// <summary>
  255. /// 乐白的场景结束等待
  256. /// </summary>
  257. /// <param name="value"></param>
  258. private void Wait(int value = 101)
  259. {
  260. while (!((bool)peripheralStatus["RobotOK"] && (int)peripheralStatus["RobotValue"] == value))
  261. {
  262. Thread.Sleep(5);
  263. }
  264. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  265. }
  266. /// <summary>
  267. /// 乐白的场景
  268. /// </summary>
  269. /// <param name="sen"></param>
  270. private void Sence(int sen)
  271. {
  272. new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = sen }.Publish();
  273. }
  274. /// <summary>
  275. /// 乐白的数字量输出
  276. /// </summary>
  277. /// <param name="value"></param>
  278. /// <param name="pin"></param>
  279. private void Output(bool value,int pin)
  280. {
  281. new LebaiRobot_SetOutPutEvent { DeviceId = DeviceId, Pin = pin,Value=value }.Publish();
  282. }
  283. private T GetStatus<T>(string key)
  284. {
  285. if (peripheralStatus.ContainsKey(key))
  286. {
  287. if (peripheralStatus[key] != null)
  288. {
  289. return (T)(peripheralStatus[key]);
  290. }
  291. }
  292. return default;
  293. }
  294. int[] devStatusBy = new int[2] { 0, 0 };
  295. bool outCupCheck = false;//放纸杯位置有无判断
  296. /// <summary>
  297. /// 判断接咖啡的位置是否有杯子
  298. /// </summary>
  299. bool pickUpCoffeeHaveCup = false;
  300. /// <summary>
  301. /// 判断接果汁的位置是否有杯子
  302. /// </summary>
  303. bool pickUpJuiceHaveCup = false;
  304. /// <summary>
  305. /// 判断接开水的位置是否有杯子
  306. /// </summary>
  307. bool pickUpHotWaterHaveCup = false;
  308. /// <summary>
  309. /// 传感器的输入信号 0:无意义 1:有信号 2:无信号 3:信号不正确
  310. /// </summary>
  311. int bSensorInput;
  312. private bool IsMakeCoffee()
  313. {
  314. bool bMake = (IsHealth && morkTLebaiJC.morkOrderPushesCoffee.Count > 0 && !morkTLebaiJC.IsHaveCoffeeCup) ? true : false;
  315. return bMake;
  316. }
  317. private bool IsMakeJuice()
  318. {
  319. bool bMake = (IsHealth && morkTLebaiJC.morkOrderPushesJuicer.Count > 0 && !morkTLebaiJC.IsHaveJuiceCup) ? true : false;
  320. return bMake;
  321. }
  322. private bool IsMakeTeaWater()
  323. {
  324. bool bMake = (IsHealth && morkTLebaiJC.morkOrderPushesTea.Count > 0 && !morkTLebaiJC.IsHaveTeaWaterCup) ? true : false;
  325. return bMake;
  326. }
  327. private bool IsMakeWater()
  328. {
  329. bool bMake = (IsHealth && morkTLebaiJC.morkOrderPushesWater.Count > 0 && !morkTLebaiJC.IsHaveTeaWaterCup) ? true : false;
  330. return bMake;
  331. }
  332. /// <summary>
  333. /// 做咖啡流程
  334. /// </summary>
  335. private void DoCoffee()
  336. {
  337. if (IsMakeCoffee())
  338. {
  339. if (morkTLebaiJC.morkOrderPushesCoffee.TryDequeue(out OrderLocInfo orderLoc))
  340. {
  341. PickUpCoffee();//接咖啡
  342. morkTLebaiJC.IsHaveCoffeeCup = true;
  343. }
  344. }
  345. else if(morkTLebaiJC.MakeCoffeeEnd)
  346. {
  347. PutCoffeeCup();
  348. pickUpCoffeeHaveCup = false;
  349. morkTLebaiJC.IsHaveCoffeeCup = false;
  350. }
  351. }
  352. private void DoJuice()
  353. {
  354. if (IsMakeJuice())
  355. {
  356. if (morkTLebaiJC.morkOrderPushesJuicer.TryDequeue(out OrderLocInfo orderLoc))
  357. {
  358. PickUpJuicer();
  359. morkTLebaiJC.IsHaveJuiceCup = true;
  360. }
  361. }
  362. else if (morkTLebaiJC.MakeJuiceEnd)
  363. {
  364. Thread.Sleep(5000);//延迟五秒,防止接饮料口滴饮料
  365. putJuice();
  366. pickUpJuiceHaveCup = false;
  367. morkTLebaiJC.IsHaveJuiceCup = false;
  368. morkTLebaiJC.MakeJuiceEnd = false;
  369. }
  370. }
  371. private void DoBoiledTea()
  372. {
  373. if (IsMakeTeaWater())
  374. {
  375. if (morkTLebaiJC.morkOrderPushesTea.TryDequeue(out OrderLocInfo orderLoc))
  376. {
  377. PickUpTea();
  378. morkTLebaiJC.IsHaveTeaWaterCup = true;
  379. }
  380. }
  381. else if(morkTLebaiJC.MakeTeaEnd)
  382. {
  383. PutWaterCup();
  384. pickUpHotWaterHaveCup = false;
  385. morkTLebaiJC.IsHaveTeaWaterCup = false ;
  386. morkTLebaiJC.MakeTeaEnd = false;
  387. }
  388. }
  389. private void DoBoiledWater()
  390. {
  391. if (IsMakeWater())
  392. {
  393. if (morkTLebaiJC.morkOrderPushesWater.TryDequeue(out OrderLocInfo orderLoc))
  394. {
  395. PickUpWater();
  396. }
  397. }
  398. else if (morkTLebaiJC.MakeTeaEnd)
  399. {
  400. PutWaterCup();
  401. pickUpHotWaterHaveCup = false;
  402. morkTLebaiJC.IsHaveTeaWaterCup = false;
  403. morkTLebaiJC.MakeTeaEnd = false;
  404. }
  405. }
  406. #region 做咖啡流程
  407. /// <summary>
  408. /// 接咖啡
  409. /// </summary>
  410. private void PickUpCoffee()
  411. {
  412. //while (GetStatus<bool>("RobotValue1"))//判断放杯位置是否有物品
  413. //{
  414. // if (!outCupCheck)
  415. // DeviceProcessLogShow("成品处有纸杯存在,请取走!!");
  416. // outCupCheck = true;
  417. //}
  418. if (!pickUpCoffeeHaveCup)
  419. {
  420. outCupCheck = false;
  421. OrderChange(morkTLebaiJC.morkOrderPushesCoffee.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
  422. int resultTakeCup = takeCup();
  423. if (resultTakeCup == 1)
  424. {
  425. DeviceProcessLogShow("咖啡杯取杯完成");
  426. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  427. Sence(GVL_MorkTLebaiJC.接咖啡);
  428. Wait();
  429. pickUpCoffeeHaveCup = true;
  430. new DRCoffee_MakeCoffeeEvent() { DrinkCode = (DrCoffeeDrinksCode)int.Parse(mainMaterialLoc) }.Publish(); //接咖啡控制 //DrCoffeeDrinksCode.热水
  431. }
  432. else
  433. {
  434. DeviceProcessLogShow("取杯失败 回到初始位,请及时处理!!");
  435. Sence(GVL_MorkTLebaiJC.机器人初始位);
  436. }
  437. }
  438. }
  439. /// <summary>
  440. /// 咖啡杯接好,放咖啡杯
  441. /// </summary>
  442. private void PutCoffeeCup()
  443. {
  444. while (GetStatus<bool>("RobotValue1"))//判断放杯位置是否有物品
  445. {
  446. if (!outCupCheck)
  447. DeviceProcessLogShow("成品处有纸杯存在,请取走!!");
  448. outCupCheck = true;
  449. }
  450. outCupCheck = false;
  451. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  452. Sence(GVL_MorkTLebaiJC.放咖啡杯);
  453. Wait();
  454. OrderChange(morkTLebaiJC.morkOrderPushesCoffee.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE);
  455. DeviceProcessLogShow("咖啡制作完成");
  456. }
  457. #endregion
  458. #region 做开水流程
  459. /// <summary>
  460. /// 接开水
  461. /// </summary>
  462. private void PickUpWater()
  463. {
  464. #region 接水流程
  465. if (!pickUpHotWaterHaveCup)
  466. {
  467. OrderChange(morkTLebaiJC.morkOrderPushesWater.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
  468. int resultTakeCup = takeCup();
  469. if (resultTakeCup == 1)
  470. {
  471. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  472. Sence(GVL_MorkTLebaiJC.接开水);
  473. Wait();
  474. Output(false, 1);
  475. Output(false, 0);
  476. Thread.Sleep(100);
  477. Output(true, 0);
  478. Thread.Sleep(3000);
  479. Output(false, 0);
  480. Thread.Sleep(100);
  481. Output(false, 1);
  482. Thread.Sleep(100);
  483. Output(true, 1);
  484. Thread.Sleep(500);
  485. Output(false, 1);
  486. }
  487. else
  488. {
  489. return;
  490. }
  491. }
  492. #endregion
  493. }
  494. #endregion
  495. #region 做茶流程
  496. /// <summary>
  497. /// 做茶
  498. /// </summary>
  499. private void PickUpTea()
  500. {
  501. #region 接茶流程
  502. if (!pickUpHotWaterHaveCup)
  503. {
  504. OrderChange(morkTLebaiJC.morkOrderPushesTea.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
  505. int resultTakeCup = takeCup();
  506. if (resultTakeCup == 1)
  507. {
  508. DeviceProcessLogShow("取茶杯完成");
  509. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  510. Sence(GVL_MorkTLebaiJC.接茶叶);
  511. Wait();
  512. new WriteMcu() { TagName = "ServoControl", Address = "1", Value = 90 }.Publish();
  513. Thread.Sleep(1000);
  514. new WriteMcu() { TagName = "ServoControl", Address = "1", Value = 150 }.Publish();
  515. Thread.Sleep(1000);
  516. new WriteMcu() { TagName = "ServoControl", Address = "1", Value = 90 }.Publish();
  517. Thread.Sleep(3000);
  518. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  519. Sence(GVL_MorkTLebaiJC.接茶水);
  520. Wait();
  521. Output(false, 1);
  522. Output(false, 0);
  523. Thread.Sleep(100);
  524. Output(true, 0);
  525. Thread.Sleep(3000);
  526. Output(false, 0);
  527. Thread.Sleep(100);
  528. Output(false, 1);
  529. Thread.Sleep(100);
  530. Output(true, 1);
  531. Thread.Sleep(500);
  532. Output(false, 1);
  533. pickUpHotWaterHaveCup = true;
  534. }
  535. else
  536. {
  537. return;
  538. }
  539. }
  540. #endregion
  541. }
  542. /// <summary>
  543. /// 放水杯流程
  544. /// </summary>
  545. private void PutWaterCup()
  546. {
  547. while (GetStatus<bool>("RobotValue1"))//判断放杯位置是否有物品
  548. {
  549. if (!outCupCheck)
  550. DeviceProcessLogShow("成品处有纸杯存在,请取走!!");
  551. outCupCheck = true;
  552. }
  553. outCupCheck = false;
  554. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  555. Sence(GVL_MorkTLebaiJC.放水杯);
  556. Wait();
  557. OrderChange(morkTLebaiJC.morkOrderPushesWater.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE);
  558. DeviceProcessLogShow("茶水制作完成");
  559. }
  560. #endregion
  561. #region 做果汁流程
  562. /// <summary>
  563. /// 果汁机控制信号
  564. /// </summary>
  565. private byte JuicerNum;
  566. private int JuiceCH;
  567. /// <summary>
  568. /// 接果汁
  569. /// </summary>
  570. private void PickUpJuicer()
  571. {
  572. #region 接果汁流程
  573. if (!pickUpJuiceHaveCup)
  574. {
  575. OrderChange(morkTLebaiJC.morkOrderPushesJuicer.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
  576. int resultTakeCup = takeCup();
  577. JuiceCH = int.Parse(mainMaterialLoc);
  578. if (resultTakeCup == 1)
  579. {
  580. switch (JuiceCH)
  581. {
  582. case 52:
  583. if (GuMake)
  584. JuicerNum = 0x00;
  585. else
  586. JuicerNum = 0x01;
  587. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  588. Sence(GVL_MorkTLebaiJC.接果汁1);
  589. Wait();
  590. break;
  591. case 53:
  592. if (GuMake)
  593. JuicerNum = 0x02;
  594. else
  595. JuicerNum = 0x03;
  596. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  597. Sence(GVL_MorkTLebaiJC.接果汁2);
  598. Wait();
  599. break;
  600. case 54:
  601. if (GuMake)
  602. JuicerNum = 0x04;
  603. else
  604. JuicerNum = 0x05;
  605. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  606. Sence(GVL_MorkTLebaiJC.接果汁3);
  607. Wait();
  608. break;
  609. case 55:
  610. if (GuMake)
  611. JuicerNum = 0x06;
  612. else
  613. JuicerNum = 0x07;
  614. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  615. Sence(GVL_MorkTLebaiJC.接果汁4);
  616. Wait();
  617. break;
  618. default:
  619. JuicerNum = 0x00;
  620. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  621. Sence(GVL_MorkTLebaiJC.接果汁1);
  622. Wait();
  623. break;
  624. }
  625. new WriteJuicer() { Value = JuicerNum }.Publish();
  626. pickUpJuiceHaveCup = true;
  627. }
  628. else
  629. {
  630. return;
  631. }
  632. }
  633. #endregion
  634. }
  635. /// <summary>
  636. /// 取接好果汁杯
  637. /// </summary>
  638. private void putJuice()
  639. {
  640. while (GetStatus<bool>("RobotValue1"))//判断放杯位置是否有物品
  641. {
  642. if (!outCupCheck)
  643. DeviceProcessLogShow("成品处有纸杯存在,请取走!!");
  644. outCupCheck = true;
  645. }
  646. outCupCheck = false;
  647. switch (JuiceCH)
  648. {
  649. case 52:
  650. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  651. Sence(GVL_MorkTLebaiJC.放果汁杯1);
  652. Wait();
  653. break;
  654. case 53:
  655. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  656. Sence(GVL_MorkTLebaiJC.放果汁杯2);
  657. Wait();
  658. break;
  659. case 54:
  660. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  661. Sence(GVL_MorkTLebaiJC.放果汁杯3);
  662. Wait();
  663. break;
  664. case 55:
  665. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  666. Sence(GVL_MorkTLebaiJC.放果汁杯4);
  667. Wait();
  668. break;
  669. default:
  670. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  671. Sence(GVL_MorkTLebaiJC.放果汁杯1);
  672. Wait();
  673. break;
  674. }
  675. OrderChange(morkTLebaiJC.morkOrderPushesJuicer.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE);
  676. DeviceProcessLogShow("果汁制作完成");
  677. }
  678. #endregion
  679. /// <summary>
  680. /// 取杯的次数
  681. /// </summary>
  682. private int nCnt;
  683. /// <summary>
  684. /// 传感器的检测次数
  685. /// </summary>
  686. private int checkCnt;
  687. /// <summary>
  688. /// 取杯流程
  689. /// </summary>
  690. /// <returns>0:无意义,1:取杯成功 2:取杯失败</returns>
  691. private int takeCup()
  692. {
  693. try
  694. {
  695. nCnt = 0;
  696. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  697. Sence(GVL_MorkTLebaiJC.机器人初始位);
  698. Wait();
  699. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  700. Sence(GVL_MorkTLebaiJC.取纸杯);
  701. Wait();
  702. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  703. Sence(GVL_MorkTLebaiJC.取纸杯检测);
  704. Wait();
  705. nCnt++;
  706. Thread.Sleep(2000);
  707. while (!GetStatus<bool>("GetInput")) //读取传感器的值
  708. {
  709. if (nCnt > 3)
  710. {
  711. nCnt = 0;
  712. DeviceProcessLogShow("三次取杯失败,回原点");
  713. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  714. Sence(GVL_MorkTLebaiJC.机器人初始位);
  715. Wait();
  716. return 2;
  717. }
  718. else
  719. {
  720. nCnt++;
  721. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  722. Sence(GVL_MorkTLebaiJC.二次取杯);
  723. Wait();
  724. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  725. Sence(GVL_MorkTLebaiJC.取纸杯检测);
  726. Wait();
  727. }
  728. Thread.Sleep(1000);
  729. }
  730. }
  731. catch (Exception ex)
  732. {
  733. DeviceProcessLogShow(ex.ToString());
  734. }
  735. return 2;
  736. }
  737. /// <summary>
  738. /// 放杯
  739. /// </summary>
  740. /// <returns>0:无意义 1:放杯成功 2:执行失败(传感器还有信号) 3:放杯异常</returns>
  741. private int putCup()
  742. {
  743. try
  744. {
  745. if (GetStatus<bool>("RobotValue1")) return 2;
  746. Sence(GVL_MorkTLebaiJC.JUICE_放杯);
  747. Wait();
  748. new LebaiRobot_SetValueEvent() { RobotSetValue = 1 }.Publish();
  749. Sence(GVL_MorkTLebaiJC.JUICE_放杯检测);
  750. Wait();
  751. new LebaiRobot_SetValueEvent() { RobotSetValue = 1 }.Publish();
  752. if (GetStatus<bool>("GetInput2"))
  753. {
  754. return 1;
  755. }
  756. else
  757. {
  758. return 3;
  759. }
  760. }
  761. catch (Exception ex)
  762. {
  763. DeviceProcessLogShow(ex.ToString());
  764. return 0;
  765. }
  766. }
  767. /// <summary>
  768. /// 检测放杯位,是否有杯子
  769. /// </summary>
  770. /// <returns>0:无意义 1:没有杯子 2:有杯子 </returns>
  771. private int checkCup()
  772. {
  773. try
  774. {
  775. while (GetStatus<bool>("RobotValue1"))
  776. {
  777. Thread.Sleep(100);
  778. if (DateTime.Now.Subtract(delayTimeOut).TotalSeconds >= 1) return 2;
  779. }
  780. DeviceProcessLogShow("放杯位有杯子未取走,等待取走,最多等待60s,即跳出流程");
  781. return 1;
  782. }
  783. catch (Exception ex)
  784. {
  785. DeviceProcessLogShow(ex.ToString());
  786. return 0;
  787. }
  788. }
  789. public void SimOrder<T>(T simOrder)
  790. {
  791. if (simOrder != null)
  792. {
  793. if (simOrder is List<ushort> locs)
  794. {
  795. List<OrderLocInfo> orders = new List<OrderLocInfo>();
  796. string subId = Guid.NewGuid().ToString();
  797. foreach (var item in locs)
  798. {
  799. if (true)
  800. {
  801. orders.Add(new OrderLocInfo() { Loc = item, SuborderId = subId });
  802. }
  803. }
  804. }
  805. }
  806. }
  807. public override void Stop()
  808. {
  809. }
  810. public override void ReadData()
  811. {
  812. }
  813. public override void ResetProgram()
  814. {
  815. }
  816. public override void SimOrder()
  817. {
  818. }
  819. }
  820. }