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

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