终端一体化运控平台
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

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