终端一体化运控平台
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

919 linhas
40 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.Message;
  18. using BPASmartClient.Model.乐白机器人;
  19. using BPASmartClient.Model.单片机;
  20. using BPASmartClient.Model.PLC;
  21. using BPASmartClient.DRCoffee;
  22. using BPASmartClient.LebaiRobot;
  23. using BPASmartClient.RobotGripper;
  24. using BPASmartClient.Model.电夹爪;
  25. using BPASmartClient.Model.奶茶味魔方;
  26. namespace BPASmartClient.MorkT_BarCounter
  27. {
  28. /*
  29. * 冰淇淋咖啡机组合套装
  30. * 物料位置:
  31. * 1:冰淇料
  32. * 2:冰淇淋杯
  33. * 5:咖啡
  34. * 6:咖啡杯
  35. * 9: 茶
  36. * 10: 茶杯
  37. */
  38. public class Control_MorkT_BarCounter : BaseDevice
  39. {
  40. private Dictionary<string, PolymerBatching> batchings = new Dictionary<string, PolymerBatching>();
  41. //容器位置
  42. private string holderLoc;
  43. //主料位置
  44. private string mainMaterialLoc;
  45. public override global::BPA.Message.Enum.DeviceClientType DeviceType { get { return BPA.Message.Enum.DeviceClientType.MORKT; } }
  46. GVL_MorkT morkT =new GVL_MorkT();
  47. /// <summary>
  48. /// 果汁机做法,true:热饮,false:冷饮
  49. /// </summary>
  50. private bool GuMake = false;
  51. /// <summary>
  52. /// 订单是否加冰
  53. /// </summary>
  54. private bool IsAddIce = false;
  55. public override void DoMain()
  56. {
  57. if (Json<KeepDataBase>.Data.IsVerify)
  58. {
  59. IsHealth = true;
  60. }
  61. Json<SaveParModel>.Read();
  62. GVL_MorkT.MilkTeaCHValue = Json<SaveParModel>.Data.parData;
  63. IsHealth = true;
  64. serverInit();
  65. DataParse();
  66. ActionManage.GetInstance.Register(new Action<object>((o) => { SimOrder(o); }), "SimOrder");//模拟订单委托注册
  67. }
  68. private void serverInit()
  69. {
  70. EventBus.EventBus.GetInstance().Subscribe<MaterialDeliveryEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  71. {
  72. if (@event == null) return;
  73. if (@event is MaterialDeliveryEvent material)
  74. {
  75. orderMaterialDelivery = material.orderMaterialDelivery;
  76. }
  77. });
  78. }
  79. private void DataParse()
  80. {
  81. EventBus.EventBus.GetInstance().Subscribe<DoOrderEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle)
  82. {
  83. if (@event == null) return;
  84. if (@event is DoOrderEvent order)
  85. {
  86. if (order.MorkOrder.GoodBatchings == null) return;
  87. OrderCount++;
  88. DeviceProcessLogShow($"接收到{OrderCount}次订单");
  89. batchings = PolymerBatching.BuildAll();
  90. //商品类型
  91. GOODS_TYPE currentGoodsType = GOODS_TYPE.NEITHER;
  92. foreach (var item in order.MorkOrder.GoodBatchings)
  93. {
  94. var res = orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId);
  95. if (res != null)
  96. {
  97. //验证商品是做的某种饮料
  98. if (ValidateGoodsByBatching(res.BatchingLoc) != GOODS_TYPE.NEITHER)
  99. {
  100. //获取当前物料所属商品类型
  101. currentGoodsType = ValidateGoodsByBatching(res.BatchingLoc);
  102. }
  103. switch (batchings[res.BatchingLoc].BatchingClass)
  104. {
  105. case BATCHING_CLASS.HOLDER:
  106. holderLoc = res.BatchingLoc;
  107. break;
  108. case BATCHING_CLASS.MAIN_MATERIAL:
  109. mainMaterialLoc = res.BatchingLoc;
  110. break;
  111. }
  112. //根据商品类型执行具体制作流程
  113. switch (currentGoodsType)
  114. {
  115. case GOODS_TYPE.COFFEE:
  116. if (morkT.morkOrderPushesCoffee.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  117. {
  118. morkT.morkOrderPushesCoffee.Enqueue(new OrderLocInfo()
  119. {
  120. SuborderId = order.MorkOrder.SuborderId,
  121. BatchingId = res.BatchingId,
  122. Loc = ushort.Parse( mainMaterialLoc),
  123. GoodName = order.MorkOrder.GoodsName,
  124. });
  125. morkT.morkOrderPushesAll.Enqueue(new OrderLocInfo()
  126. {
  127. SuborderId = order.MorkOrder.SuborderId,
  128. BatchingId = res.BatchingId,
  129. Loc = ushort.Parse(mainMaterialLoc),
  130. GoodName = order.MorkOrder.GoodsName,
  131. });
  132. }
  133. break;
  134. //case GOODS_TYPE.JUICE:
  135. // if (morkTLebaiJC.morkOrderPushesJuicer.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  136. // {
  137. // morkTLebaiJC.morkOrderPushesJuicer.Enqueue(new OrderLocInfo()
  138. // {
  139. // SuborderId = order.MorkOrder.SuborderId,
  140. // BatchingId = res.BatchingId,
  141. // Loc = ushort.Parse(mainMaterialLoc),
  142. // GoodName = order.MorkOrder.GoodsName,
  143. // makeID = order.MorkOrder.MakeID,
  144. // });
  145. // }
  146. // break;
  147. case GOODS_TYPE.MilkTea:
  148. if (morkT.morkOrderPushesMilkTea.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  149. {
  150. morkT.morkOrderPushesMilkTea.Enqueue(new OrderLocInfo()
  151. {
  152. SuborderId = order.MorkOrder.SuborderId,
  153. BatchingId = res.BatchingId,
  154. Loc = ushort.Parse(mainMaterialLoc),
  155. GoodName = order.MorkOrder.GoodsName,
  156. });
  157. morkT.morkOrderPushesAll.Enqueue(new OrderLocInfo()
  158. {
  159. SuborderId = order.MorkOrder.SuborderId,
  160. BatchingId = res.BatchingId,
  161. Loc = ushort.Parse(mainMaterialLoc),
  162. GoodName = order.MorkOrder.GoodsName,
  163. });
  164. }
  165. break;
  166. //case GOODS_TYPE.WATER:
  167. // if (morkTLebaiJC.morkOrderPushesWater.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  168. // {
  169. // morkTLebaiJC.morkOrderPushesWater.Enqueue(new OrderLocInfo()
  170. // {
  171. // SuborderId = order.MorkOrder.SuborderId,
  172. // BatchingId = res.BatchingId,
  173. // Loc = ushort.Parse(mainMaterialLoc),
  174. // GoodName = order.MorkOrder.GoodsName,
  175. // });
  176. // }
  177. // break;
  178. case GOODS_TYPE.NEITHER:
  179. DeviceProcessLogShow("未知的商品类型");
  180. break;
  181. }
  182. }
  183. }
  184. }
  185. });
  186. }
  187. /// <summary>
  188. /// 将空杯放好到接饮料的地方的标志位
  189. /// </summary>
  190. private bool bFirstTrig_MilkTea = false;
  191. private bool bFirstTrig_Coffee = false;
  192. /// <summary>
  193. /// 延迟的超时时间
  194. /// </summary>
  195. DateTime delayTimeOut_Coffee;
  196. DateTime delayTimeOut_MilkTea;
  197. public override void MainTask()
  198. {
  199. EventBus.EventBus.GetInstance().Subscribe<DRCoffee_CoffeEndCookEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  200. {
  201. if (morkT.IsHaveCoffeeCup && morkT.MakeCoffeeEnd != true)
  202. morkT.MakeCoffeeEnd = true;
  203. bFirstTrig_Coffee = false;
  204. });
  205. if (morkT.IsHaveCoffeeCup && morkT.MakeCoffeeEnd != true)
  206. {
  207. if (!bFirstTrig_Coffee)
  208. {
  209. bFirstTrig_Coffee = true;
  210. delayTimeOut_Coffee = DateTime.Now;
  211. }
  212. else if (DateTime.Now.Subtract(delayTimeOut_Coffee).TotalSeconds > 180 && bFirstTrig_Coffee == true)
  213. {
  214. DeviceProcessLogShow("接咖啡超时,接咖啡结束,等待取咖啡");
  215. bFirstTrig_Coffee = false;
  216. if (morkT.IsHaveCoffeeCup)
  217. morkT.MakeCoffeeEnd = true;
  218. }
  219. }
  220. if (morkT.IsHaveTeaMilkTeaCup && morkT.MakeMilkTeaEnd != true)
  221. {
  222. if (!bFirstTrig_MilkTea)
  223. {
  224. bFirstTrig_MilkTea = true;
  225. delayTimeOut_MilkTea = DateTime.Now;//开启接水信号后,记录当前时间
  226. }
  227. else if (DateTime.Now.Subtract(delayTimeOut_MilkTea).TotalSeconds >= 180 && bFirstTrig_MilkTea == true)//接水超过50s后,启动接水完成标志,开启接水程序
  228. {
  229. DeviceProcessLogShow("接茶或水延迟时间结束");
  230. morkT.MakeMilkTeaEnd = true;
  231. }
  232. if ( GetStatus<bool>("Get_MilkTeaCubeStatus") == true)
  233. {
  234. while(GetStatus<bool>("Get_MilkTeaCubeDosingStatus") == true)
  235. {
  236. if (morkT.IsHaveTeaMilkTeaCup && morkT.MakeMilkTeaEnd != true)
  237. {
  238. morkT.MakeMilkTeaEnd = true;
  239. bFirstTrig_MilkTea = false;
  240. new MilkTea_MakeMilkTeaEvent() { DeviceId = DeviceId, TagName = "StartSignReset" }.Publish();
  241. }
  242. }
  243. }
  244. }
  245. DoCoffee();
  246. DoMilkTea();
  247. }
  248. /// <summary>
  249. /// 订单状态改变
  250. /// </summary>
  251. /// <param name="subid"></param>
  252. /// <param name="oRDER_STATUS"></param>
  253. private void OrderChange(string subid, ORDER_STATUS oRDER_STATUS)
  254. {
  255. EventBus.EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { Status = oRDER_STATUS, SubOrderId = subid, deviceClientType = DeviceType });
  256. }
  257. /// <summary>
  258. /// 验证商品是做的某种饮料
  259. /// </summary>
  260. /// <param name="batchingLoc">物料位置</param>
  261. private GOODS_TYPE ValidateGoodsByBatching(string batchingLoc)
  262. {
  263. if (batchings.ContainsKey(batchingLoc))
  264. return batchings[batchingLoc].GoodsType;
  265. return GOODS_TYPE.NEITHER;
  266. }
  267. /// <summary>
  268. /// 乐白的场景
  269. /// </summary>
  270. /// <param name="sen"></param>
  271. private void Sence(int sen)
  272. {
  273. new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = sen }.Publish();
  274. }
  275. /// <summary>
  276. /// 乐白的数字量输出
  277. /// </summary>
  278. /// <param name="value"></param>
  279. /// <param name="pin"></param>
  280. private void Output(bool value,int pin)
  281. {
  282. new LebaiRobot_SetOutPutEvent { DeviceId = DeviceId, Pin = pin,Value=value }.Publish();
  283. }
  284. private T GetStatus<T>(string key)
  285. {
  286. if (peripheralStatus.ContainsKey(key))
  287. {
  288. if (peripheralStatus[key] != null)
  289. {
  290. return (T)(peripheralStatus[key]);
  291. }
  292. }
  293. return default;
  294. }
  295. int[] devStatusBy = new int[2] { 0, 0 };
  296. /// <summary>
  297. /// 传感器的输入信号 0:无意义 1:有信号 2:无信号 3:信号不正确
  298. /// </summary>
  299. int bSensorInput;
  300. /// <summary>
  301. /// 判断是否有咖啡订单
  302. /// </summary>
  303. /// <returns></returns>
  304. private bool IsMakeCoffee()
  305. {
  306. bool bMake = (IsHealth && morkT.morkOrderPushesCoffee.Count > 0 && !morkT.IsHaveCoffeeCup && morkT.morkOrderPushesAll.ElementAt(0).SuborderId == morkT.morkOrderPushesCoffee.ElementAt(0).SuborderId) ? true : false;
  307. return bMake;
  308. }
  309. /// <summary>
  310. /// 判断是否有果汁订单
  311. /// </summary>
  312. /// <returns></returns>
  313. private bool IsMakeJuice()
  314. {
  315. bool bMake = (IsHealth && morkT.morkOrderPushesJuicer.Count > 0 && !morkT.IsHaveJuiceCup && morkT.morkOrderPushesAll.ElementAt(0).SuborderId == morkT.morkOrderPushesCoffee.ElementAt(0).SuborderId) ? true : false;
  316. return bMake;
  317. }
  318. /// <summary>
  319. /// 判断是否有茶订单
  320. /// </summary>
  321. /// <returns></returns>
  322. private bool IsMakeMilkTea()
  323. {
  324. bool bMake = (IsHealth && morkT.morkOrderPushesMilkTea.Count > 0 && !morkT.IsHaveTeaMilkTeaCup && morkT.morkOrderPushesAll.ElementAt(0).SuborderId == morkT.morkOrderPushesMilkTea.ElementAt(0).SuborderId) ? true : false;
  325. return bMake;
  326. }
  327. /// <summary>
  328. /// 判断是否有开水订单
  329. /// </summary>
  330. /// <returns></returns>
  331. private bool IsMakeWater()
  332. {
  333. bool bMake = (IsHealth && morkT.morkOrderPushesWater.Count > 0 && !morkT.IsHaveTeaMilkTeaCup) ? true : false;
  334. return bMake;
  335. }
  336. /// <summary>
  337. /// 做咖啡流程
  338. /// </summary>
  339. private void DoCoffee()
  340. {
  341. if (IsMakeCoffee())
  342. {
  343. Discharge_Control(Kind.咖啡);//接咖啡
  344. morkT.IsHaveCoffeeCup = true;
  345. }
  346. else if(morkT.MakeCoffeeEnd)
  347. {
  348. try
  349. {
  350. PutCup(Kind.咖啡);
  351. DeviceProcessLogShow("-------------咖啡制作完成------------");
  352. morkT.MakeCoffeeEnd = false;
  353. morkT.IsHaveCoffeeCup = false;
  354. morkT.morkOrderPushesCoffee.TryDequeue(out OrderLocInfo orderLoc);
  355. morkT.morkOrderPushesAll.TryDequeue(out OrderLocInfo orderLoc1);
  356. }
  357. catch (Exception ex)
  358. {
  359. MessageLog.GetInstance.ShowEx(ex.ToString());
  360. }
  361. }
  362. }
  363. private void DoMilkTea()
  364. {
  365. if (IsMakeMilkTea())
  366. {
  367. Discharge_Control(Kind.奶茶);//接咖啡
  368. morkT.IsHaveTeaMilkTeaCup = true;
  369. }
  370. else if (morkT.MakeMilkTeaEnd && morkT.morkOrderPushesMilkTea.Count > 0)
  371. {
  372. try
  373. {
  374. PutCup(Kind.奶茶);
  375. DeviceProcessLogShow("-------------奶茶制作完成------------");
  376. morkT.IsHaveTeaMilkTeaCup = false;
  377. morkT.MakeMilkTeaEnd = false;
  378. morkT.morkOrderPushesMilkTea.TryDequeue(out OrderLocInfo orderLoc);
  379. morkT.morkOrderPushesAll.TryDequeue(out OrderLocInfo orderLoc1);
  380. }
  381. catch (Exception ex)
  382. {
  383. MessageLog.GetInstance.ShowEx(ex.ToString());
  384. }
  385. }
  386. }
  387. #region 做咖啡流程
  388. /// <summary>
  389. /// 出料控制
  390. /// </summary>
  391. private void Discharge_Control(Kind kind)
  392. {
  393. if (!morkT.IsHaveCoffeeCup)
  394. {
  395. if (kind == Kind.咖啡)
  396. {
  397. OrderChange(morkT.morkOrderPushesCoffee.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
  398. }
  399. else
  400. {
  401. OrderChange(morkT.morkOrderPushesMilkTea.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
  402. }
  403. int resultTakeCup = takeCup();
  404. if (resultTakeCup == 1)
  405. {
  406. if (kind == Kind.咖啡)
  407. {
  408. new WriteJaka() { DeviceId =DeviceId, TagName = "JaKaProgramName", Value = JakaModel.SENCE_取杯位_接咖啡位 }.Publish();
  409. JakaWait(int.Parse(JakaModel.SENCE_取杯位_接咖啡位));
  410. new DRCoffee_MakeCoffeeEvent() { DeviceId = DeviceId, DrinkCode = (DrCoffeeDrinksCode)(morkT.morkOrderPushesCoffee.ElementAt(0).Loc) }.Publish(); //控制咖啡出料
  411. //new WriteGripper() { TagName = "PWMControl", CH_Number = "0", PWMOutput = "500" }.Publish();//夹爪的幅度控制
  412. //new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接咖啡_初始位 }.Publish();
  413. //Wait(int.Parse(JakaModel.SENCE_接咖啡_初始位));
  414. //DeviceProcessLogShow("接咖啡杯动作完成");
  415. }
  416. else
  417. {
  418. new WriteJaka() { DeviceId = DeviceId, TagName = "JaKaProgramName", Value = JakaModel.SENCE_取杯位_接奶茶位 }.Publish();
  419. JakaWait(int.Parse(JakaModel.SENCE_取杯位_接奶茶位));
  420. while (GetStatus<bool>("Get_MilkTeaCubeStatus") == false)
  421. {
  422. new MilkTea_MakeMilkTeaEvent() { DeviceId = DeviceId, TagName = "ParameterSet", MilkTeaKind = GVL_MorkT.MilkTeaCHValue }.Publish(); //写入奶茶参数
  423. new MilkTea_MakeMilkTeaEvent() { DeviceId = DeviceId, TagName = "Start" }.Publish();
  424. break;
  425. }
  426. //new WriteGripper() { TagName = "PWMControl", CH_Number = "0", PWMOutput = "500" }.Publish();//夹爪的幅度控制
  427. //new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_接奶茶_初始位 }.Publish();
  428. //Wait(int.Parse(JakaModel.SENCE_接奶茶_初始位));
  429. //DeviceProcessLogShow("接奶茶杯动作完成");
  430. }
  431. }
  432. else
  433. {
  434. DeviceProcessLogShow("取杯失败 回到初始位,请及时处理!!");
  435. new WriteJaka() { DeviceId = DeviceId, TagName = "JaKaProgramName", Value = JakaModel.SENCE_异常回初始位 }.Publish();
  436. JakaWait(int.Parse(JakaModel.SENCE_异常回初始位));
  437. }
  438. }
  439. }
  440. public bool outCupCheck;
  441. private void PutCup(Kind res)
  442. {
  443. //new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish();
  444. //Wait(int.Parse(JakaModel.SENCE_初始位));
  445. //new WriteGripper() { TagName = "PWMControl", CH_Number = "0", PWMOutput = "500" }.Publish();//夹爪的幅度控制
  446. //new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish();
  447. //Wait(int.Parse(JakaModel.SENCE_初始位_放杯位检测));
  448. //while (GetStatus<bool>("Get_JakaRobotDI0"))//判断放杯位置是否有物品
  449. //{
  450. // if (!outCupCheck)
  451. // DeviceProcessLogShow("成品处有纸杯存在,请取走!!");
  452. // outCupCheck = true;
  453. //}
  454. //outCupCheck = false;
  455. if (res == Kind.咖啡)
  456. {
  457. //new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放杯位检测_接咖啡 }.Publish();
  458. //Wait(int.Parse(JakaModel.SENCE_放杯位检测_接咖啡));
  459. //new WriteGripper() { TagName = "PWMControl", CH_Number = "0", PWMOutput = "1300" }.Publish();//夹爪的幅度控制
  460. //new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放杯位检测_接咖啡 }.Publish();
  461. //Wait(int.Parse(JakaModel.SENCE_接咖啡_放杯位));
  462. //new WriteGripper() { TagName = "PWMControl", CH_Number = "0", PWMOutput = "500" }.Publish();//夹爪的幅度控制
  463. new WriteJaka() { DeviceId = DeviceId, TagName = "JaKaProgramName", Value = JakaModel.SENCE_接咖啡位_放咖啡位 }.Publish();
  464. JakaWait(int.Parse(JakaModel.SENCE_接咖啡位_放咖啡位));
  465. //new WriteGripper() { DeviceId = DeviceId, TagName = "PWMControl", CH_Number = "0", PWMOutput = "0500" }.Publish();//夹爪的幅度控制
  466. //new WriteJaka() { DeviceId = DeviceId, TagName = "JakaDOutput", Value = true, DO_Index = 1 }.Publish();
  467. }
  468. else
  469. {
  470. //new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放杯位检测_接咖啡 }.Publish();
  471. //Wait(int.Parse(JakaModel.SENCE_放杯位检测_接奶茶));
  472. //new WriteGripper() { TagName = "PWMControl", CH_Number = "0", PWMOutput = "1300" }.Publish();//夹爪的幅度控制
  473. //new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_放杯位检测_接咖啡 }.Publish();
  474. //Wait(int.Parse(JakaModel.SENCE_接奶茶_放杯位));
  475. //new WriteGripper() { TagName = "PWMControl", CH_Number = "0", PWMOutput = "500" }.Publish();//夹爪的幅度控制
  476. new WriteJaka() { DeviceId = DeviceId, TagName = "JaKaProgramName", Value = JakaModel.SENCE_等奶茶_接奶茶位 }.Publish();
  477. JakaWait(int.Parse(JakaModel.SENCE_等奶茶_接奶茶位));
  478. new WriteJaka() { DeviceId = DeviceId, TagName = "JaKaProgramName", Value = JakaModel.SENCE_接奶茶位_放奶茶位 }.Publish();
  479. JakaWait(int.Parse(JakaModel.SENCE_接奶茶位_放奶茶位));
  480. //new WriteGripper() { DeviceId = DeviceId, TagName = "PWMControl", CH_Number = "0", PWMOutput = "500" }.Publish();//夹爪的幅度控制
  481. //new WriteJaka() { DeviceId = DeviceId, TagName = "JakaDOutput", Value = true, DO_Index = 1 }.Publish();
  482. }
  483. new WriteJaka() { DeviceId = DeviceId, TagName = "JaKaProgramName", Value = JakaModel.SENCE_放杯位_初始位 }.Publish();
  484. JakaWait(int.Parse(JakaModel.SENCE_放杯位_初始位));
  485. if (GetStatus<bool>("Get_JakaRobotDI5"))
  486. {
  487. DeviceProcessLogShow("放杯完成,杯子感应器但仍有信号");
  488. }
  489. if (res == Kind.咖啡)
  490. {
  491. OrderChange(morkT.morkOrderPushesCoffee.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE);
  492. DeviceProcessLogShow($"-------------{morkT.morkOrderPushesCoffee.ElementAt(0).GoodName}制作完成------------");
  493. }
  494. else
  495. {
  496. OrderChange(morkT.morkOrderPushesMilkTea.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE);
  497. DeviceProcessLogShow($"-------------{morkT.morkOrderPushesMilkTea.ElementAt(0).GoodName}制作完成------------");
  498. }
  499. }
  500. #endregion
  501. /// <summary>
  502. /// 取杯的次数
  503. /// </summary>
  504. private int nCnt;
  505. /// <summary>
  506. /// 取杯流程
  507. /// </summary>
  508. /// <returns>0:无意义,1:取杯成功 2:取杯失败</returns>
  509. private int takeCup()
  510. {
  511. try
  512. {
  513. // new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish();
  514. // Wait(int.Parse(JakaModel.SENCE_初始位));
  515. // new WriteGripper() { TagName = "PWMControl", CH_Number = "0", PWMOutput = "500" }.Publish();//夹爪的幅度控制
  516. //p: new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_落杯 }.Publish();
  517. // Wait(int.Parse(JakaModel.SENCE_落杯));
  518. // new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_取杯位检测_取杯位 }.Publish();
  519. // Wait(int.Parse(JakaModel.SENCE_初始位_取杯位检测));
  520. // if (!GetStatus<bool>("Get_JakaRobotDI0"))
  521. // goto p;
  522. // new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_取杯位检测_取杯位 }.Publish();
  523. // Wait(int.Parse(JakaModel.SENCE_取杯位检测_取杯位));
  524. // new WriteGripper() { TagName = "PWMControl", CH_Number = "0", PWMOutput = "1300" }.Publish();//夹爪的幅度控制
  525. // Thread.Sleep(2000);
  526. // while (!GetStatus<bool>("Get_JakaRobotDI0")) //读取传感器的值
  527. // {
  528. // new WriteJaka() { TagName = "JaKaProgramName", Value = JakaModel.SENCE_异常回初始位 }.Publish();
  529. // Wait(int.Parse(JakaModel.SENCE_异常回初始位));
  530. // return 2;
  531. // }
  532. bool test1 = false;
  533. if (test1)
  534. {
  535. #region 第一种取杯方式
  536. new WriteJaka() { DeviceId = DeviceId, TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish();
  537. JakaWait(int.Parse(JakaModel.SENCE_初始位));
  538. new WriteGripper() { DeviceId = DeviceId, TagName = "PWMControl", CH_Number = "0", PWMOutput = "1350" }.Publish();//夹爪的幅度控制
  539. new WriteJaka() { DeviceId = DeviceId, TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位_取杯位 }.Publish();
  540. JakaWait(int.Parse(JakaModel.SENCE_初始位_取杯位));
  541. int cnt = 0;
  542. new WriteGripper() { DeviceId = DeviceId, TagName = "PWMControl", CH_Number = "0", PWMOutput = "1350" }.Publish();//夹爪的幅度控制
  543. p: new WriteJaka() { DeviceId = DeviceId, TagName = "JaKaProgramName", Value = JakaModel.SENCE_落杯 }.Publish();
  544. JakaWait(int.Parse(JakaModel.SENCE_落杯));
  545. cnt = cnt + 1;
  546. if (!GetStatus<bool>("Get_JakaRobotDI6"))
  547. {
  548. if (cnt < 3)
  549. goto p;
  550. else
  551. {
  552. return 2;
  553. }
  554. }
  555. return 1;
  556. #endregion
  557. }
  558. else
  559. {
  560. #region 第二种取杯方式
  561. new WriteJaka() { DeviceId = DeviceId, TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位 }.Publish();
  562. JakaWait(int.Parse(JakaModel.SENCE_初始位));
  563. //new WriteJaka() { DeviceId = DeviceId, TagName = "JakaDOutput", Value = false, DO_Index = 1 }.Publish();
  564. //new WriteGripper() { DeviceId = DeviceId, TagName = "PWMControl", CH_Number = "0", PWMOutput = "1350" }.Publish();//夹爪的幅度控制
  565. new WriteJaka() { DeviceId = DeviceId, TagName = "JaKaProgramName", Value = JakaModel.SENCE_初始位_取杯位 }.Publish();
  566. JakaWait(int.Parse(JakaModel.SENCE_初始位_取杯位));
  567. int cnt = 0;
  568. p: new WriteJaka() { DeviceId = DeviceId, TagName = "JaKaProgramName", Value = JakaModel.SENCE_落杯 }.Publish();
  569. JakaWait(int.Parse(JakaModel.SENCE_落杯));
  570. cnt = cnt + 1;
  571. if (!GetStatus<bool>("Get_JakaRobotDI5"))
  572. {
  573. if (cnt < 3)
  574. goto p;
  575. else
  576. {
  577. return 2;
  578. }
  579. }
  580. Thread.Sleep(2000);
  581. new WriteJaka() { DeviceId = DeviceId, TagName = "JaKaProgramName", Value = JakaModel.SENCE_取杯位_取杯放杯检测位 }.Publish();
  582. JakaWait(int.Parse(JakaModel.SENCE_取杯位_取杯放杯检测位));
  583. //new WriteJaka() { DeviceId = DeviceId, TagName = "JakaDOutput", Value = true, DO_Index = 1 }.Publish();
  584. //Thread.Sleep(2000);
  585. //new WriteJaka() { DeviceId = DeviceId, TagName = "JakaDOutput", Value = false, DO_Index = 1 }.Publish();
  586. //new WriteGripper() { DeviceId = DeviceId, TagName = "PWMControl", CH_Number = "0", PWMOutput = "1200" }.Publish();//夹爪的幅度控制
  587. //Thread.Sleep(2000);
  588. //new WriteGripper() { DeviceId = DeviceId, TagName = "PWMControl", CH_Number = "0", PWMOutput = "1350" }.Publish();//夹爪的幅度控制
  589. new WriteJaka() { DeviceId = DeviceId, TagName = "JaKaProgramName", Value = JakaModel.SENCE_取杯放杯检测位_取杯位 }.Publish();
  590. JakaWait(int.Parse(JakaModel.SENCE_取杯放杯检测位_取杯位));
  591. return 1;
  592. #endregion
  593. }
  594. }
  595. catch (Exception ex)
  596. {
  597. DeviceProcessLogShow(ex.ToString());
  598. }
  599. return 2;
  600. }
  601. public void SimOrder<T>(T simOrder)
  602. {
  603. }
  604. private void JakaWait(int value)
  605. {
  606. while (!((GetStatus<int>("Get_JakaRobotAO1") == value) && GetStatus<int>("Get_JakaRobotProgramStatus") == 0))//判断文件是否已经执行结束 且 文件末端变量值==文件名
  607. {
  608. int a = GetStatus<int>("Get_JakaRobotAO1");
  609. int b = GetStatus<int>("Get_JakaRobotProgramStatus");
  610. Thread.Sleep(5);
  611. }
  612. }
  613. #region PLC 控制函数
  614. private void WritePLCData(string address, object value)
  615. {
  616. EventBus.EventBus.GetInstance().Publish(new WriteModel() { DeviceId = DeviceId, Address = address, Value = value });
  617. }
  618. private void GetStatus(string key, Action<object> action)
  619. {
  620. if (peripheralStatus.ContainsKey(key))
  621. {
  622. if (peripheralStatus[key] != null)
  623. {
  624. action?.Invoke(peripheralStatus[key]);
  625. }
  626. }
  627. }
  628. public override void ReadData()
  629. {
  630. #region 乐白机器人状态
  631. GetStatus("RobotIsConnected", new Action<object>((o) =>
  632. {
  633. if (o is bool b)
  634. {
  635. morkT.RobotIsConnected = b;
  636. }
  637. }));
  638. GetStatus("RobotMode", new Action<object>((o) =>
  639. {
  640. if (o is ELebaiRModel eLebaiRModel)
  641. {
  642. morkT.RobotMode = eLebaiRModel;
  643. }
  644. }));
  645. GetStatus("LeibaiGetTcpInput", new Action<object>((o) =>
  646. {
  647. if (o is bool b)
  648. {
  649. morkT.RobotGetTcpInput = b;
  650. }
  651. }));
  652. GetStatus("LeibaiGetInput1", new Action<object>((o) =>
  653. {
  654. if (o is bool b)
  655. {
  656. morkT.RobotGetInput0 = b;
  657. }
  658. }));
  659. GetStatus("LeibaiGetInput2", new Action<object>((o) =>
  660. {
  661. if (o is bool b)
  662. {
  663. morkT.RobotGetInput1 = b;
  664. }
  665. }));
  666. GetStatus("LeibaiGetInput3", new Action<object>((o) =>
  667. {
  668. if (o is bool b)
  669. {
  670. morkT.RobotGetInput2 = b;
  671. }
  672. }));
  673. GetStatus("LeibaiGetInput4", new Action<object>((o) =>
  674. {
  675. if (o is bool b)
  676. {
  677. morkT.RobotGetInput3 = b;
  678. }
  679. }));
  680. #endregion
  681. #region 制冰机状态
  682. GetStatus("MakeIceConnected", new Action<object>((o) =>
  683. {
  684. if (o is bool bt)
  685. {
  686. morkT.IceMakerConnect = bt;
  687. }
  688. }));
  689. GetStatus("MakeIceDeviceStatus", new Action<object>((o) =>
  690. {
  691. if (o is byte bt)
  692. {
  693. morkT.IceMakerState = bt;
  694. }
  695. }));
  696. #endregion
  697. #region 咖啡机状态
  698. GetStatus("CoffeeIsConnected", new Action<object>((o) =>
  699. {
  700. if (o is bool b)
  701. {
  702. morkT.CoffeeIsConnected = b;
  703. }
  704. }));
  705. GetStatus("CoffeeStatus", new Action<object>((o) =>
  706. {
  707. if (o is DrCoffeeStatus coffeeStatus)
  708. {
  709. morkT.DrCoffeeStatus = coffeeStatus;
  710. }
  711. }));
  712. GetStatus("CoffeeAppStatus", new Action<object>((o) =>
  713. {
  714. if (o is DrCoffeeAppStatus appStatus)
  715. {
  716. morkT.CoffeeAppStatus = appStatus;
  717. }
  718. }));
  719. GetStatus("CoffeeWarning", new Action<object>((o) =>
  720. {
  721. if (o is DrCoffeeWarning coffeeWarning)
  722. {
  723. morkT.CoffeeWarning = coffeeWarning;
  724. }
  725. }));
  726. GetStatus("CoffeeFault", new Action<object>((o) =>
  727. {
  728. if (o is DrCoffeeFault coffeeFault)
  729. {
  730. morkT.CaffeeFault = coffeeFault;
  731. }
  732. }));
  733. #endregion
  734. #region 单片机状态
  735. EventBus.EventBus.GetInstance().Publish(new ReadMcu() { DeviceId = DeviceId, ReadPar = 0, TagName = "SCChipGetInput0" });
  736. EventBus.EventBus.GetInstance().Publish(new ReadMcu() { DeviceId = DeviceId, ReadPar = 0, TagName = "SCChipGetInput1" });
  737. EventBus.EventBus.GetInstance().Publish(new ReadMcu() { DeviceId = DeviceId, ReadPar = 0, TagName = "SCChipGetInput2" });
  738. EventBus.EventBus.GetInstance().Publish(new ReadMcu() { DeviceId = DeviceId, ReadPar = 0, TagName = "SCChipGetInput3" });
  739. EventBus.EventBus.GetInstance().Publish(new ReadMcu() { DeviceId = DeviceId, ReadPar = 0, TagName = "SCChipGetInput4" });
  740. EventBus.EventBus.GetInstance().Publish(new ReadMcu() { DeviceId = DeviceId, ReadPar = 0, TagName = "SCChipGetInput5" });
  741. EventBus.EventBus.GetInstance().Publish(new ReadMcu() { DeviceId = DeviceId, ReadPar = 0, TagName = "SCChipGetInput6" });
  742. EventBus.EventBus.GetInstance().Publish(new ReadMcu() { DeviceId = DeviceId, ReadPar = 0, TagName = "SCChipGetInput7" });
  743. GetStatus("SCChipIsConnect", new Action<object>((o) =>
  744. {
  745. if (o is bool b)
  746. {
  747. morkT.SCChipIsConnect = b;
  748. }
  749. }));
  750. GetStatus("SCChipGetInput0", new Action<object>((o) =>
  751. {
  752. if (o is bool b)
  753. {
  754. morkT.SCChipInput0 = b;
  755. }
  756. }));
  757. GetStatus("SCChipGetInput1", new Action<object>((o) =>
  758. {
  759. if (o is bool b)
  760. {
  761. morkT.SCChipInput1 = b;
  762. }
  763. }));
  764. GetStatus("SCChipGetInput2", new Action<object>((o) =>
  765. {
  766. if (o is bool b)
  767. {
  768. morkT.SCChipInput2 = b;
  769. }
  770. }));
  771. GetStatus("SCChipGetInput3", new Action<object>((o) =>
  772. {
  773. if (o is bool b)
  774. {
  775. morkT.SCChipInput3 = b;
  776. }
  777. }));
  778. GetStatus("SCChipGetInput4", new Action<object>((o) =>
  779. {
  780. if (o is bool b)
  781. {
  782. morkT.SCChipInput4 = b;
  783. }
  784. }));
  785. GetStatus("SCChipGetInput5", new Action<object>((o) =>
  786. {
  787. if (o is bool b)
  788. {
  789. morkT.SCChipInput5 = b;
  790. }
  791. }));
  792. GetStatus("SCChipGetInput6", new Action<object>((o) =>
  793. {
  794. if (o is bool b)
  795. {
  796. morkT.SCChipInput6 = b;
  797. }
  798. }));
  799. GetStatus("SCChipGetInput7", new Action<object>((o) =>
  800. {
  801. if (o is bool b)
  802. {
  803. morkT.SCChipInput7 = b;
  804. }
  805. }));
  806. #endregion
  807. #region 果汁机
  808. GetStatus("GetJuicerConnected", new Action<object>((o) =>
  809. {
  810. if (o is bool b)
  811. {
  812. morkT.JuicerConnected = b;
  813. }
  814. }));
  815. GetStatus("GetJuicerDeviceStatus", new Action<object>((o) =>
  816. {
  817. if (o is int[] b)
  818. {
  819. morkT.JuicerState = b;
  820. }
  821. }));
  822. #endregion
  823. }
  824. #endregion
  825. public override void Stop()
  826. {
  827. }
  828. public override void ResetProgram()
  829. {
  830. }
  831. public override void SimOrder()
  832. {
  833. EventBus.EventBus.GetInstance().Subscribe<MorkTSimOrder>(0, delegate (IEvent @event, EventCallBackHandle callBackHandle)
  834. {
  835. string guid = Guid.NewGuid().ToString();
  836. if (@event != null && @event is MorkTSimOrder msm)
  837. {
  838. DeviceProcessLogShow("----开始模拟订单----");
  839. if (msm.OrderNum == 1)
  840. {
  841. morkT.morkOrderPushesCoffee.Enqueue(new OrderLocInfo() { Loc =(ushort)msm.DrinkCode, SuborderId = guid, GoodName="模拟咖啡订单" });
  842. }
  843. else if (msm.OrderNum == 2)
  844. {
  845. morkT.morkOrderPushesJuicer.Enqueue(new OrderLocInfo() { Loc = (ushort) (msm.JuiceList + 51), makeID = msm.JuiceMakeID, SuborderId = guid, GoodName = "模拟果汁订单" });
  846. }
  847. else if (msm.OrderNum == 3)
  848. {
  849. morkT.morkOrderPushesMilkTea.Enqueue(new OrderLocInfo() { SuborderId = guid, GoodName = "模拟茶水订单" });
  850. }
  851. else if (msm.OrderNum == 4)
  852. {
  853. morkT.morkOrderPushesWater.Enqueue(new OrderLocInfo() { SuborderId = guid, GoodName = "模拟开水订单" });
  854. }
  855. }
  856. });
  857. }
  858. }
  859. }