终端一体化运控平台
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

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