终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

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