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