终端一体化运控平台
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

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