终端一体化运控平台
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

738 řádky
29 KiB

  1. using BPA.Message.Enum;
  2. using BPASmartClient.Device;
  3. using BPASmartClient.DRCoffee;
  4. using BPASmartClient.EventBus;
  5. using BPASmartClient.GSIceCream;
  6. using BPASmartClient.Helper;
  7. using BPASmartClient.Lebai;
  8. using BPASmartClient.LebaiRobot;
  9. using BPASmartClient.Message;
  10. using BPASmartClient.Model;
  11. using BPASmartClient.Model.乐白机器人;
  12. using BPASmartClient.Model.冰淇淋.Enum;
  13. using BPASmartClient.Model.单片机;
  14. using BPASmartClient.Model.单片机.Enum;
  15. using BPASmartClient.Peripheral;
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Linq;
  19. using System.Text;
  20. using System.Threading;
  21. using System.Threading.Tasks;
  22. using static BPASmartClient.EventBus.EventBus;
  23. namespace BPASmartClient.MorkT
  24. {
  25. public class Control_MorkT : BaseDevice
  26. {
  27. public override global::BPA.Message.Enum.DeviceClientType DeviceType { get { return BPA.Message.Enum.DeviceClientType.MORKT; } }
  28. GLV_MorkT morkT = new GLV_MorkT();
  29. public override void DoMain()
  30. {
  31. if (Json<KeepDataBase>.Data.IsVerify)
  32. {
  33. IsHealth = true;
  34. }
  35. IsHealth = true;
  36. ServerInit();
  37. DataParse();
  38. EventBus.EventBus.GetInstance().Subscribe<DRCoffee_CoffeEndCookEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  39. {
  40. if (morkT.MakeCoffeeOrder != null)
  41. morkT.MakeCoffeeOrder.OrderStatus = 1;
  42. });
  43. int i = 0;
  44. EventBus.EventBus.GetInstance().Publish(new GSIceCream_ModeSetEvent { DeviceId = DeviceId, Mode = MORKI_MODE.制冷模式 });
  45. MessageLog.GetInstance.Show("MORKT 设备初始化完成");
  46. }
  47. public override void ResetProgram()
  48. {
  49. morkT = null;
  50. morkT = new GLV_MorkT();
  51. }
  52. private void GetStatus(string key, Action<object> action)
  53. {
  54. if (peripheralStatus.ContainsKey(key))
  55. {
  56. if (peripheralStatus[key] != null)
  57. {
  58. action?.Invoke(peripheralStatus[key]);
  59. }
  60. }
  61. }
  62. public override void MainTask()
  63. {
  64. if (morkT.waitMorkOrder != null)//更新订单取走状态
  65. {
  66. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetInputEvent() { DeviceId = DeviceId, Pin = 0 }, (o) =>
  67. {
  68. if (o != null && o.Length > 0 && o[0] is bool res)
  69. {
  70. if (!res)
  71. {
  72. OrderChange(morkT.waitMorkOrder.SuborderId, ORDER_STATUS.COMPLETED_TAKE);
  73. DeviceProcessLogShow("订单取餐完成");
  74. morkT.waitMorkOrder = null;
  75. }
  76. }
  77. });
  78. }
  79. MakeCoffeeProcess();
  80. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetInputEvent { DeviceId = DeviceId, Pin = 0 }, (o) =>
  81. {
  82. if (o != null && o.Length > 0 && o[0] is bool resultValue)
  83. {
  84. if (!resultValue)//取餐口有空余位置
  85. {
  86. MakeIceCreamProcess();
  87. MakeCoffeeComplete();
  88. }
  89. }
  90. });
  91. }
  92. public override void ReadData()
  93. {
  94. GetStatus("RobotIsConnected", new Action<object>((o) =>
  95. {
  96. if (o is bool b)
  97. {
  98. morkT.RobotIsConnected = b;
  99. }
  100. }));
  101. GetStatus("RobotMode", new Action<object>((o) =>
  102. {
  103. if (o is ELebaiRModel eLebaiRModel)
  104. {
  105. morkT.RobotMode = eLebaiRModel;
  106. }
  107. }));
  108. GetStatus("IceCreamIsConnected", new Action<object>((o) =>
  109. {
  110. if (o is bool b)
  111. {
  112. morkT.IceCreamIsConnected = b;
  113. }
  114. }));
  115. GetStatus("IceCreamYLWD", new Action<object>((o) =>
  116. {
  117. if (o is short s)
  118. {
  119. morkT.YLWD = s;
  120. }
  121. }));
  122. GetStatus("IceCreamHQWD", new Action<object>((o) =>
  123. {
  124. if (o is short s)
  125. {
  126. morkT.HQWD = s;
  127. }
  128. }));
  129. GetStatus("IceCreamDL", new Action<object>((o) =>
  130. {
  131. if (o is short s)
  132. {
  133. morkT.DL = s;
  134. }
  135. }));
  136. GetStatus("IceCreamDY", new Action<object>((o) =>
  137. {
  138. if (o is short s)
  139. {
  140. morkT.DY = s;
  141. }
  142. }));
  143. GetStatus("IceCreamCXB", new Action<object>((o) =>
  144. {
  145. if (o is byte bt)
  146. {
  147. morkT.CBX = bt;
  148. }
  149. }));
  150. GetStatus("IceCreamCurrentMode", new Action<object>((o) =>
  151. {
  152. if (o is MORKI_MODE mORKI_MODE)
  153. {
  154. morkT.IceCreamMode = mORKI_MODE;
  155. }
  156. }));
  157. GetStatus("IceCreamFault", new Action<object>((o) =>
  158. {
  159. if (o is MORKI_FAULT mORKI_FAULT)
  160. {
  161. morkT.IceCreamFault = mORKI_FAULT;
  162. }
  163. }));
  164. GetStatus("IceCreamDLCompleted", new Action<object>((o) =>
  165. {
  166. if (o is bool b)
  167. {
  168. morkT.DLCompleted = b;
  169. }
  170. }));
  171. GetStatus("CoffeeIsConnected", new Action<object>((o) =>
  172. {
  173. if (o is bool b)
  174. {
  175. morkT.CoffeeIsConnected = b;
  176. }
  177. }));
  178. GetStatus("CoffeeStatus", new Action<object>((o) =>
  179. {
  180. if (o is DrCoffeeStatus coffeeStatus)
  181. {
  182. morkT.DrCoffeeStatus = coffeeStatus;
  183. }
  184. }));
  185. GetStatus("CoffeeAppStatus", new Action<object>((o) =>
  186. {
  187. if (o is DrCoffeeAppStatus appStatus)
  188. {
  189. morkT.CoffeeAppStatus = appStatus;
  190. }
  191. }));
  192. GetStatus("CoffeeWarning", new Action<object>((o) =>
  193. {
  194. if (o is DrCoffeeWarning coffeeWarning)
  195. {
  196. morkT.CoffeeWarning = coffeeWarning;
  197. }
  198. }));
  199. GetStatus("CoffeeFault", new Action<object>((o) =>
  200. {
  201. if (o is DrCoffeeFault coffeeFault)
  202. {
  203. morkT.CaffeeFault = coffeeFault;
  204. }
  205. }));
  206. }
  207. public override void Stop()
  208. {
  209. }
  210. private void ServerInit()
  211. {
  212. //物料信息
  213. EventBus.EventBus.GetInstance().Subscribe<MaterialDeliveryEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  214. {
  215. if (@event == null) return;
  216. if (@event is MaterialDeliveryEvent material)
  217. {
  218. orderMaterialDelivery = material.orderMaterialDelivery;
  219. }
  220. });
  221. //配方数据信息
  222. EventBus.EventBus.GetInstance().Subscribe<RecipeBomEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  223. {
  224. if (@event == null) return;
  225. if (@event is RecipeBomEvent recipe)
  226. {
  227. recipeBoms = recipe.recipeBoms;
  228. }
  229. });
  230. }
  231. /// <summary>
  232. /// 数据解析
  233. /// </summary>
  234. private void DataParse()
  235. {
  236. EventBus.EventBus.GetInstance().Subscribe<DoOrderEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle)
  237. {
  238. if (@event == null) return;
  239. if (@event is DoOrderEvent order)
  240. {
  241. if (order.MorkOrder.GoodBatchings == null) return;
  242. OrderCount++;
  243. DeviceProcessLogShow($"接收到{OrderCount}次订单");
  244. //构建所有商品物料信息
  245. morkT.batchings = PolymerBatching.BuildAll();
  246. //商品类型
  247. GOODS_TYPE currentGoodsType = GOODS_TYPE.NEITHER;
  248. foreach (var item in order.MorkOrder.GoodBatchings)
  249. {
  250. var res = orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId);
  251. if (res != null)
  252. {
  253. //验证商品是咖啡还是冰淇淋
  254. if (ValidateGoodsByBatching(res.BatchingLoc) != GOODS_TYPE.NEITHER)
  255. {
  256. //获取当前物料所属商品类型
  257. currentGoodsType = ValidateGoodsByBatching(res.BatchingLoc);
  258. }
  259. string loc_Goods = string.Empty;
  260. //获取主料和容器位置
  261. if (morkT.batchings[res.BatchingLoc].BatchingClass == BATCHING_CLASS.MAIN_MATERIAL) loc_Goods = res.BatchingLoc;
  262. if (!string.IsNullOrEmpty(loc_Goods))
  263. {
  264. switch (currentGoodsType)
  265. {
  266. case GOODS_TYPE.COFFEE:
  267. if (morkT.morkOrderPushesCoffee.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  268. {
  269. morkT.morkOrderPushesCoffee.Enqueue(new OrderLocInfo()
  270. {
  271. SuborderId = order.MorkOrder.SuborderId,
  272. BatchingId = res.BatchingId,
  273. Loc = loc_Goods,
  274. GoodsName = order.MorkOrder.GoodsName,
  275. SortNum = order.MorkOrder.SortNum
  276. });
  277. }
  278. break;
  279. case GOODS_TYPE.ICECREAM:
  280. if (morkT.morkOrderPushesIceCream.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  281. {
  282. morkT.morkOrderPushesIceCream.Enqueue(new OrderLocInfo()
  283. {
  284. SuborderId = order.MorkOrder.SuborderId,
  285. BatchingId = res.BatchingId,
  286. Loc = loc_Goods,
  287. GoodsName = order.MorkOrder.GoodsName,
  288. SortNum = order.MorkOrder.SortNum
  289. });
  290. }
  291. break;
  292. case GOODS_TYPE.NEITHER:
  293. DeviceProcessLogShow("未知的商品类型");
  294. break;
  295. }
  296. }
  297. }
  298. }
  299. }
  300. });
  301. }
  302. /// <summary>
  303. /// 验证当前是做咖啡还是做冰淇淋
  304. /// </summary>
  305. /// <param name="batchingLoc">物料位置</param>
  306. private GOODS_TYPE ValidateGoodsByBatching(string batchingLoc)
  307. {
  308. if (morkT.batchings.ContainsKey(batchingLoc))
  309. return morkT.batchings[batchingLoc].GoodsType;
  310. return GOODS_TYPE.NEITHER;
  311. }
  312. private void OrderChange(string subid, ORDER_STATUS oRDER_STATUS)
  313. {
  314. EventBus.EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { Status = oRDER_STATUS, SubOrderId = subid, deviceClientType = DeviceType });
  315. }
  316. private void Wait(int value = 101)
  317. {
  318. while (!((bool)peripheralStatus["RobotOK"] && (int)peripheralStatus["RobotValue"] == value))
  319. {
  320. Thread.Sleep(5);
  321. }
  322. }
  323. /// <summary>
  324. /// 是否可以开始制作咖啡
  325. /// </summary>
  326. /// <returns></returns>
  327. private bool CoffeeCanMake()
  328. {
  329. bool canMake = (IsHealth && morkT.morkOrderPushesCoffee.Count > 0 && !morkT.IsCoffeeMake) ? true : false;
  330. return canMake;
  331. }
  332. /// <summary>
  333. /// 制作咖啡流程
  334. /// </summary>
  335. private void MakeCoffeeProcess()
  336. {
  337. if (CoffeeCanMake())
  338. {
  339. if (morkT.morkOrderPushesCoffee.TryDequeue(out OrderLocInfo orderLoc))
  340. {
  341. DeviceProcessLogShow($"开始制作 [咖啡] 订单[{orderLoc.SortNum}]");
  342. GetAndCheeckCoffe(orderLoc);//取咖啡杯
  343. if (!morkT.GetCoffeeCup) return;
  344. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = 10051 }); //接咖啡后回原点
  345. Wait();
  346. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 });
  347. EventBus.EventBus.GetInstance().Publish(new DRCoffee_MakeCoffeeEvent() { DeviceId = DeviceId, DrinkCode = (Model.咖啡机.Enum.DrCoffeeDrinksCode)int.Parse(orderLoc.Loc) });//接咖啡控制
  348. DeviceProcessLogShow($"发送咖啡机制作{orderLoc.Loc}!");
  349. morkT.IsCoffeeMake = true; morkT.MakeCoffeeOrder = orderLoc;
  350. }
  351. }
  352. }
  353. /// <summary>
  354. /// 咖啡机制作完咖啡,取走并放到取餐口,最后回原点
  355. /// </summary>
  356. private void MakeCoffeeComplete()
  357. {
  358. if (morkT.IsCoffeeMake && IsHealth)
  359. {
  360. if (morkT.MakeCoffeeOrder != null && morkT.MakeCoffeeOrder.OrderStatus == 1)
  361. {
  362. DeviceProcessLogShow($"将咖啡移动到取餐位 [咖啡] 订单[{morkT.MakeCoffeeOrder.SortNum}]");
  363. DoCoffeeQC(morkT.MakeCoffeeOrder);
  364. morkT.MakeCoffeeOrder = null;
  365. morkT.IsCoffeeMake = false;
  366. }
  367. }
  368. }
  369. /// <summary>
  370. /// 将咖啡杯从咖啡机 取走到 取餐口
  371. /// </summary>
  372. private void DoCoffeeQC(OrderLocInfo order)
  373. {
  374. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = 10052 }); //SENCE_取咖啡出餐
  375. Wait();
  376. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 });
  377. //订单状态改变:完成
  378. OrderChange(order.SuborderId, ORDER_STATUS.COMPLETED_COOK);
  379. morkT.waitMorkOrder = order;
  380. DeviceProcessLogShow($"{order.GoodsName}等待取餐");
  381. //WaitTakeMealOrder.Enqueue(order);
  382. }
  383. /// <summary>
  384. /// 取咖啡杯&&咖啡杯检测 若检测失败机器人回原点
  385. /// </summary>
  386. /// <param name="order"></param>
  387. private void GetAndCheeckCoffe(OrderLocInfo order)
  388. {
  389. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 });
  390. OrderChange(order.SuborderId, ORDER_STATUS.COOKING);
  391. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = 10031 }); //SENCE_取咖啡杯
  392. Wait();
  393. EventBus.EventBus.GetInstance().Publish(new SCChip_TakeCupEvent { DeviceId = DeviceId, Cup = IC_CUP.CUP_COFFEE });//落碗控制
  394. Thread.Sleep(500);
  395. DeviceProcessLogShow("尝试取咖啡杯!");
  396. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 });
  397. int count = 1;
  398. bool result = true;
  399. p:
  400. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = 10033 }); //SENCE_咖啡杯检测
  401. Wait();
  402. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 });
  403. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetTCPInputEvent { DeviceId = DeviceId, Pin = 1 }, (o) =>
  404. {
  405. if (o != null && o.Length > 0 && o[0] is bool resultValue)
  406. {
  407. result = resultValue;
  408. }
  409. });
  410. if (!result)
  411. {
  412. if (count >= 3)
  413. {
  414. //退出循环回到初始位置
  415. DeviceProcessLogShow($"执行{count}次取咖啡杯,仍为成功,订单默认废弃,机器人回到初始位置!");
  416. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = 10050 }); //SENCE_咖啡杯回原点
  417. Wait();
  418. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 });
  419. morkT.GetCoffeeCup = false;
  420. return;
  421. }
  422. DeviceProcessLogShow("执行二次取咖啡杯");
  423. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = 10035 }); //SENCE_二次取咖啡杯
  424. Wait();
  425. EventBus.EventBus.GetInstance().Equals(new SCChip_TakeCupEvent { DeviceId = DeviceId, Cup = IC_CUP.CUP_COFFEE });//落碗控制
  426. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 });
  427. count++;
  428. goto p;
  429. }
  430. morkT.GetCoffeeCup = true;
  431. DeviceProcessLogShow("取咖啡杯完成");
  432. }
  433. /// <summary>
  434. /// 冰淇淋是否可以开始制作
  435. /// </summary>
  436. /// <returns></returns>
  437. private bool IceCreamCanMake()
  438. {
  439. bool canMake = (IsHealth && morkT.morkOrderPushesIceCream.Count > 0) ? true : false;
  440. return canMake;
  441. }
  442. /// <summary>
  443. /// 制作冰淇淋流程
  444. /// </summary>
  445. private void MakeIceCreamProcess()
  446. {
  447. //if (IceCreamCanMake())
  448. //{
  449. if (morkT.morkOrderPushesIceCream.TryDequeue(out OrderLocInfo order))
  450. {
  451. DoIceCream(order);
  452. }
  453. //if(peripheralStatus.ContainsKey("IceCreamCurrentMode"))
  454. //{
  455. // if ((MORKI_MODE)peripheralStatus["IceCreamCurrentMode"] != MORKI_MODE.制冷模式) EventBus.EventBus.GetInstance().Publish(new GSIceCream_ModeSetEvent { DeviceId = DeviceId, Mode = MORKI_MODE.制冷模式 });
  456. //}
  457. //if(peripheralStatus.ContainsKey("IceCreamCXB"))
  458. //{
  459. // if ((byte)peripheralStatus["IceCreamCXB"] >= 86 && morkT.morkOrderPushesIceCream.Count > 0)//成型比大于86才可以制作
  460. // {
  461. // bool result = true;
  462. // EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetInputEvent { DeviceId = DeviceId, Pin = 3 }, (res) =>
  463. // {
  464. // if (res[0] is bool resultValue)
  465. // {
  466. // result = resultValue;
  467. // }
  468. // });
  469. // if (result)
  470. // {
  471. // if (morkT.IceIsOK) DeviceProcessLogShow("请检查冰淇淋出料口有无遮挡");
  472. // morkT.IceIsOK = false;
  473. // }
  474. // else if (morkT.morkOrderPushesIceCream.TryDequeue(out OrderLocInfo order))
  475. // {
  476. // morkT.IceIsOK = true;
  477. // DeviceProcessLogShow($"开始制作 [冰淇淋] 订单[{order.SortNum}]");
  478. // DoIceCream(order);
  479. // }
  480. // }
  481. //}
  482. //}
  483. }
  484. /// <summary>
  485. /// 做冰淇淋
  486. /// </summary>
  487. private void DoIceCream(OrderLocInfo order)
  488. {
  489. GetIceCreamCup();
  490. CheckICeCreaCup();
  491. if (morkT.GetIceCreamCup)
  492. {
  493. GetIceCream(order);
  494. PutIceCream(order);
  495. }
  496. }
  497. /// <summary>
  498. /// 取冰淇淋杯
  499. /// </summary>
  500. private void GetIceCreamCup()
  501. {
  502. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 });
  503. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = 10032 }); //SENCE_取冰淇淋杯
  504. Wait();
  505. EventBus.EventBus.GetInstance().Publish(new SCChip_TakeCupEvent { DeviceId = DeviceId, Cup = IC_CUP.CUP_ICECREAM });//落碗控制
  506. Thread.Sleep(500);
  507. DeviceProcessLogShow("尝试取冰淇淋杯!");
  508. }
  509. /// <summary>
  510. /// 冰淇淋杯检测,失败后机器人回到原点
  511. /// </summary>
  512. private void CheckICeCreaCup()
  513. {
  514. int count = 2;
  515. bool result = true;
  516. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 });
  517. p:
  518. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = 10034 }); //SENCE_冰淇淋杯检测
  519. Wait();
  520. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 });
  521. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetTCPInputEvent { DeviceId = DeviceId, Pin = 1 }, (o) =>
  522. {
  523. if (o != null && o.Length > 0 && o[0] is bool resultValue)
  524. {
  525. result = resultValue;
  526. }
  527. });
  528. if (!result)
  529. {
  530. if (count >= 3)
  531. {
  532. //退出循环回到初始位置
  533. DeviceProcessLogShow($"执行{count}次取冰淇淋杯,仍未成功,订单默认废弃,机器人回到初始位置!");
  534. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = 10049 }); //SENCE_冰淇淋杯回原点
  535. Wait();
  536. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 });
  537. morkT.GetIceCreamCup = false;
  538. return;
  539. }
  540. DeviceProcessLogShow($"执行{count}次取冰淇淋杯!");
  541. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = 10036 }); //SENCE_二次取冰淇淋杯
  542. EventBus.EventBus.GetInstance().Equals(new SCChip_TakeCupEvent { DeviceId = DeviceId, Cup = IC_CUP.CUP_ICECREAM });//落碗控制
  543. Wait();
  544. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 });
  545. count++;
  546. goto p;
  547. }
  548. morkT.GetIceCreamCup = true;
  549. DeviceProcessLogShow("冰淇淋杯检测完成");
  550. }
  551. /// <summary>
  552. /// 机器人取接冰淇淋
  553. /// </summary>
  554. /// <param name="order"></param>
  555. private void GetIceCream(OrderLocInfo order)
  556. {
  557. //制冷模式
  558. //EventBus.EventBus.GetInstance().Publish(new GSIceCream_ModeSetEvent {DeviceId = DeviceId, Mode = MORKI_MODE.制冷模式 });
  559. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 });
  560. OrderChange(order.SuborderId, ORDER_STATUS.COOKING);
  561. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = 10039 }); //SENCE_接1号冰淇淋
  562. Wait();
  563. bool doItResult = true;
  564. //出料
  565. EventBus.EventBus.GetInstance().Publish(new SCChip_RotorSwitchEvent { DeviceId = DeviceId, TurnOn = true });
  566. Thread.Sleep(500);
  567. EventBus.EventBus.GetInstance().Publish(new SCChip_RotorSwitchEvent { DeviceId = DeviceId, TurnOn = false });
  568. EventBus.EventBus.GetInstance().Publish(new SCChip_MakeIceCreamEvent { DeviceId = DeviceId, SteeringEngine = IC_SE.SE_2 });//冰淇淋出料
  569. DeviceProcessLogShow("开始等待6s");
  570. Thread.Sleep(6000);
  571. //出料
  572. //EventBus.EventBus.GetInstance().Publish(new GSIceCream_DischargeEvent { DeviceId = DeviceId },(o)=>
  573. //{
  574. // doItResult = (bool)o[0];
  575. //});
  576. //if (doItResult)
  577. //{
  578. // IceCreamCookCheck();
  579. //}
  580. //else
  581. //{
  582. // int count_1 = 0;
  583. // while ((byte)peripheralStatus["IceCreamCXB"] <= 86)
  584. // {
  585. // Thread.Sleep(5);
  586. // count_1++;
  587. // if (count_1 >= 2000)
  588. // break;
  589. // }
  590. // IceCreamCookCheck();
  591. //}
  592. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 });
  593. }
  594. /// <summary>
  595. /// 把冰淇淋放到取餐位后回原点
  596. /// </summary>
  597. /// <param name="order"></param>
  598. private void PutIceCream(OrderLocInfo order)
  599. {
  600. bool resultValue = true;
  601. while (resultValue)
  602. {
  603. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetInputEvent { DeviceId = DeviceId, Pin = 0 }, (res) =>
  604. {
  605. if (res[0] is bool b)
  606. {
  607. resultValue = b;
  608. }
  609. });
  610. Thread.Sleep(500);
  611. }
  612. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = 10043 }); //SENCE_放冰淇淋位置
  613. Wait();
  614. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 });
  615. //订单状态改变:完成
  616. OrderChange(order.SuborderId, ORDER_STATUS.COMPLETED_COOK);
  617. morkT.waitMorkOrder = order;
  618. DeviceProcessLogShow($"{order.GoodsName}等待取餐");
  619. //WaitTakeMealOrder.Enqueue(order);
  620. }
  621. /// <summary>
  622. /// 冰淇淋机器制作冰淇淋
  623. /// </summary>
  624. public void IceCreamCookCheck()
  625. {
  626. bool result = false;
  627. int retry = 3;
  628. DateTime beginTime = DateTime.Now;
  629. while (!result)
  630. {
  631. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetInputEvent { DeviceId = DeviceId, Pin = 3 }, (res) =>
  632. {
  633. if (res[0] is bool resultValue)
  634. {
  635. result = resultValue;
  636. }
  637. });
  638. if (retry <= 0 || DateTime.Now.Subtract(beginTime).TotalSeconds >= 10)
  639. {
  640. DeviceProcessLogShow("超时未出料,重试次数用尽");
  641. break;
  642. }
  643. if (DateTime.Now.Subtract(beginTime).TotalSeconds > 5)
  644. {
  645. DeviceProcessLogShow("超时未出料,重新发送打料指令");
  646. EventBus.EventBus.GetInstance().Publish(new GSIceCream_ModeSetEvent() { DeviceId = DeviceId, Mode = MORKI_MODE.打料 });
  647. beginTime = DateTime.Now;
  648. retry--;
  649. }
  650. Thread.Sleep(10);
  651. }
  652. DeviceProcessLogShow("开始等待6s");
  653. Thread.Sleep(5000);
  654. }
  655. public override void SimOrder()
  656. {
  657. }
  658. }
  659. }