终端一体化运控平台
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 

865 рядки
34 KiB

  1. using BPA.Message;
  2. using BPA.Message.Enum;
  3. using BPASmartClient.Device;
  4. using BPASmartClient.DRCoffee;
  5. using BPASmartClient.EventBus;
  6. using BPASmartClient.GSIceCream;
  7. using BPASmartClient.Helper;
  8. using BPASmartClient.Lebai;
  9. using BPASmartClient.LebaiRobot;
  10. using BPASmartClient.Message;
  11. using BPASmartClient.Model;
  12. using BPASmartClient.Model.乐白机器人;
  13. using BPASmartClient.Model.冰淇淋.Enum;
  14. using BPASmartClient.Model.单片机;
  15. using BPASmartClient.Model.单片机.Enum;
  16. using BPASmartClient.Peripheral;
  17. using Robotc;
  18. using System;
  19. using System.Collections.Generic;
  20. using System.Linq;
  21. using System.Text;
  22. using System.Threading;
  23. using System.Threading.Tasks;
  24. using static BPASmartClient.EventBus.EventBus;
  25. namespace BPASmartClient.MorkTHQ
  26. {
  27. public class Control_MorkTHQ : BaseDevice
  28. {
  29. public override global::BPA.Message.Enum.DeviceClientType DeviceType { get { return BPA.Message.Enum.DeviceClientType.MORKT; } }
  30. GLV_MorkTHQ morkT = new GLV_MorkTHQ();
  31. int[] devStatusBy = new int[2] { 0, 0 };
  32. public override void DoMain()
  33. {
  34. if(Json<KeepDataBase>.Data.IsVerify)
  35. {
  36. IsHealth = true;
  37. }
  38. IsHealth = true;
  39. ServerInit();
  40. DataParse();
  41. EventBus.EventBus.GetInstance().Subscribe<KLMCoffee_CoffeEndCookEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  42. {
  43. if (morkT.MakeCoffeeOrder != null)
  44. morkT.MakeCoffeeOrder.OrderStatus = 1;
  45. });
  46. int i = 0;
  47. EventBus.EventBus.GetInstance().Publish(new GSIceCream_ModeSetEvent { DeviceId = DeviceId, Mode = MORKI_MODE.制冷模式 });
  48. MessageLog.GetInstance.Show("MORKT 设备初始化完成");
  49. }
  50. public override void ResetProgram()
  51. {
  52. morkT = null;
  53. morkT = new GLV_MorkTHQ();
  54. }
  55. private void GetStatus(string key, Action<object> action)
  56. {
  57. if (peripheralStatus.ContainsKey(key))
  58. {
  59. if (peripheralStatus[key] != null)
  60. {
  61. action?.Invoke(peripheralStatus[key]);
  62. }
  63. }
  64. }
  65. public override void MainTask()
  66. {
  67. //制作咖啡
  68. MakeCoffeeProcess();
  69. //制作果汁
  70. MakeJuiceProcess();
  71. //制作冰淇淋
  72. MakeIceCreamProcess();
  73. //制作完取咖啡
  74. MakeCoffeeComplete();
  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. GetStatus("Coffeeprogress", new Action<object>((o) =>
  191. {
  192. if (o is int coffeeFault)
  193. {
  194. morkT.Coffeeprogress = coffeeFault;
  195. }
  196. }));
  197. GetStatus("SCChipIsConnect", new Action<object>((o) =>
  198. {
  199. if (o is bool b)
  200. {
  201. morkT.SCChipIsConnect = b;
  202. }
  203. }));
  204. GetStatus("JuiceIsConnect", new Action<object>((o) =>
  205. {
  206. if (o is bool b)
  207. {
  208. morkT.JuiceIsConnect = b;
  209. }
  210. }));
  211. }
  212. public override void Stop()
  213. {
  214. }
  215. private void ServerInit()
  216. {
  217. //物料信息
  218. EventBus.EventBus.GetInstance().Subscribe<MaterialDeliveryEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  219. {
  220. if (@event == null) return;
  221. if (@event is MaterialDeliveryEvent material)
  222. {
  223. orderMaterialDelivery = material.orderMaterialDelivery;
  224. }
  225. });
  226. //配方数据信息
  227. EventBus.EventBus.GetInstance().Subscribe<RecipeBomEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  228. {
  229. if (@event == null) return;
  230. if (@event is RecipeBomEvent recipe)
  231. {
  232. recipeBoms = recipe.recipeBoms;
  233. }
  234. });
  235. }
  236. /// <summary>
  237. /// 数据解析
  238. /// </summary>
  239. private void DataParse()
  240. {
  241. EventBus.EventBus.GetInstance().Subscribe<DoOrderEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle)
  242. {
  243. if (@event == null) return;
  244. if (@event is DoOrderEvent order)
  245. {
  246. if (order.MorkOrder.GoodBatchings == null) return;
  247. OrderCount++;
  248. DeviceProcessLogShow($"接收到{OrderCount}次订单");
  249. //构建所有商品物料信息
  250. morkT.batchings = PolymerBatching.BuildAll();
  251. //商品类型
  252. GOODS_TYPE currentGoodsType = GOODS_TYPE.NEITHER;
  253. foreach (var item in order.MorkOrder.GoodBatchings)
  254. {
  255. var res = orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId);
  256. if (res != null)
  257. {
  258. //验证商品是咖啡还是冰淇淋
  259. if (ValidateGoodsByBatching(res.BatchingLoc) != GOODS_TYPE.NEITHER)
  260. {
  261. //获取当前物料所属商品类型
  262. currentGoodsType = ValidateGoodsByBatching(res.BatchingLoc);
  263. }
  264. string loc_Goods = string.Empty;
  265. //获取主料和容器位置
  266. if (morkT.batchings[res.BatchingLoc].BatchingClass == BATCHING_CLASS.MAIN_MATERIAL) loc_Goods = res.BatchingLoc;
  267. if (!string.IsNullOrEmpty(loc_Goods))
  268. {
  269. switch (currentGoodsType)
  270. {
  271. case GOODS_TYPE.COFFEE:
  272. if (morkT.morkOrderPushesCoffee.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  273. {
  274. morkT.morkOrderPushesCoffee.Enqueue(new OrderLocInfo()
  275. {
  276. SuborderId = order.MorkOrder.SuborderId,
  277. BatchingId = res.BatchingId,
  278. Loc = loc_Goods,
  279. GoodsName = order.MorkOrder.GoodsName,
  280. SortNum = order.MorkOrder.SortNum
  281. });
  282. }
  283. break;
  284. case GOODS_TYPE.ICECREAM:
  285. if (morkT.morkOrderPushesIceCream.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  286. {
  287. morkT.morkOrderPushesIceCream.Enqueue(new OrderLocInfo()
  288. {
  289. SuborderId = order.MorkOrder.SuborderId,
  290. BatchingId = res.BatchingId,
  291. Loc = loc_Goods,
  292. GoodsName = order.MorkOrder.GoodsName,
  293. SortNum = order.MorkOrder.SortNum
  294. });
  295. }
  296. break;
  297. case GOODS_TYPE.JUICE:
  298. if(morkT.morkOrderPushesIceCream.FirstOrDefault(p=>p.SuborderId == order?.MorkOrder.SuborderId) == null)
  299. {
  300. morkT.GuMake = order.MorkOrder.MakeID == "2";
  301. morkT.morkOrderPushesJuice.Enqueue(new OrderLocInfo()
  302. {
  303. SuborderId = order.MorkOrder.SuborderId,
  304. BatchingId = res.BatchingId,
  305. Loc = loc_Goods,
  306. GoodsName = order.MorkOrder.GoodsName,
  307. SortNum = order.MorkOrder.SortNum
  308. });
  309. }
  310. break;
  311. case GOODS_TYPE.NEITHER:
  312. DeviceProcessLogShow("未知的商品类型");
  313. break;
  314. }
  315. }
  316. }
  317. }
  318. }
  319. });
  320. }
  321. /// <summary>
  322. /// 验证当前是做咖啡还是做冰淇淋
  323. /// </summary>
  324. /// <param name="batchingLoc">物料位置</param>
  325. private GOODS_TYPE ValidateGoodsByBatching(string batchingLoc)
  326. {
  327. if (morkT.batchings.ContainsKey(batchingLoc))
  328. return morkT.batchings[batchingLoc].GoodsType;
  329. return GOODS_TYPE.NEITHER;
  330. }
  331. private void OrderChange(string subid, ORDER_STATUS oRDER_STATUS)
  332. {
  333. EventBus.EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { Status = oRDER_STATUS, SubOrderId = subid, deviceClientType = DeviceType });
  334. }
  335. private void Wait(int value = 101)
  336. {
  337. while (!((bool)peripheralStatus["RobotOK"] && (int)peripheralStatus["RobotValue"] == value))
  338. {
  339. Thread.Sleep(5);
  340. }
  341. }
  342. #region 咖啡
  343. /// <summary>
  344. /// 是否可以开始制作咖啡
  345. /// </summary>
  346. /// <returns></returns>
  347. private bool CoffeeCanMake()
  348. {
  349. bool canMake = (IsHealth && morkT.morkOrderPushesCoffee.Count > 0 && !morkT.IsCoffeeMake) ? true : false;
  350. return canMake;
  351. }
  352. /// <summary>
  353. /// 制作咖啡流程
  354. /// </summary>
  355. private void MakeCoffeeProcess()
  356. {
  357. if (CoffeeCanMake())
  358. {
  359. if (morkT.morkOrderPushesCoffee.TryDequeue(out OrderLocInfo orderLoc))
  360. {
  361. DeviceProcessLogShow($"开始制作 [咖啡] 订单[{orderLoc.SortNum}]");
  362. GetAndCheeckCoffe(orderLoc);//取咖啡杯
  363. if (!morkT.GetCoffeeCup) return;
  364. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = 10051}); //接咖啡后回原点
  365. Wait();
  366. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
  367. EventBus.EventBus.GetInstance().Publish(new KLMCoffee_MakeCoffeeEvent() {DeviceId = DeviceId, DrinkCode = (Model.咖啡机.Enum.DrinkType)int.Parse(orderLoc.Loc) });//接咖啡控制
  368. DeviceProcessLogShow($"发送咖啡机制作{orderLoc.Loc}!");
  369. morkT.IsCoffeeMake = true; morkT.MakeCoffeeOrder = orderLoc;
  370. }
  371. }
  372. }
  373. /// <summary>
  374. /// 咖啡机制作完咖啡,取走并放到取餐口,最后回原点
  375. /// </summary>
  376. private void MakeCoffeeComplete()
  377. {
  378. if (morkT.IsCoffeeMake && IsHealth)
  379. {
  380. if (morkT.MakeCoffeeOrder != null && morkT.MakeCoffeeOrder.OrderStatus == 1)
  381. {
  382. DeviceProcessLogShow($"将咖啡移动到取餐位 [咖啡] 订单[{morkT.MakeCoffeeOrder.SortNum}]");
  383. DoCoffeeQC(morkT.MakeCoffeeOrder);
  384. morkT.MakeCoffeeOrder = null;
  385. morkT.IsCoffeeMake = false;
  386. }
  387. }
  388. }
  389. /// <summary>
  390. /// 将咖啡杯从咖啡机 取走到 取餐口
  391. /// </summary>
  392. private void DoCoffeeQC(OrderLocInfo order)
  393. {
  394. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = 10052 }); //SENCE_取咖啡出餐
  395. Wait();
  396. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
  397. //订单状态改变:完成
  398. OrderChange(order.SuborderId, ORDER_STATUS.COMPLETED_COOK);
  399. morkT.waitMorkOrder = order;
  400. DeviceProcessLogShow($"{order.GoodsName}等待取餐");
  401. //WaitTakeMealOrder.Enqueue(order);
  402. }
  403. /// <summary>
  404. /// 取咖啡杯&&咖啡杯检测 若检测失败机器人回原点
  405. /// </summary>
  406. /// <param name="order"></param>
  407. private void GetAndCheeckCoffe(OrderLocInfo order)
  408. {
  409. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 },(o)=>{ });
  410. OrderChange(order.SuborderId, ORDER_STATUS.COOKING);
  411. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = 10031 }); //SENCE_取咖啡杯
  412. Wait();
  413. Thread.Sleep(500);
  414. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
  415. morkT.GetCoffeeCup = true;
  416. DeviceProcessLogShow("取咖啡杯完成");
  417. }
  418. #endregion
  419. #region 冰淇淋
  420. /// <summary>
  421. /// 冰淇淋是否可以开始制作
  422. /// </summary>
  423. /// <returns></returns>
  424. private bool IceCreamCanMake()
  425. {
  426. bool canMake = (IsHealth && morkT.morkOrderPushesIceCream.Count > 0) ? true : false;
  427. return canMake;
  428. }
  429. /// <summary>
  430. /// 制作冰淇淋流程
  431. /// </summary>
  432. private void MakeIceCreamProcess()
  433. {
  434. if (IceCreamCanMake())
  435. {
  436. if (peripheralStatus.ContainsKey("IceCreamCurrentMode"))
  437. {
  438. if ((MORKI_MODE)peripheralStatus["IceCreamCurrentMode"] != MORKI_MODE.制冷模式) EventBus.EventBus.GetInstance().Publish(new GSIceCream_ModeSetEvent { DeviceId = DeviceId, Mode = MORKI_MODE.制冷模式 });
  439. }
  440. if (peripheralStatus.ContainsKey("IceCreamCXB"))
  441. {
  442. if ((byte)peripheralStatus["IceCreamCXB"] >= 86 && morkT.morkOrderPushesIceCream.Count > 0)//成型比大于86才可以制作
  443. {
  444. bool result = true;
  445. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetInputEvent { DeviceId = DeviceId, Pin = 3 }, (res) =>
  446. {
  447. if (res[0] is bool resultValue)
  448. {
  449. result = resultValue;
  450. }
  451. });
  452. if (result)
  453. {
  454. if (morkT.IceIsOK) DeviceProcessLogShow("请检查冰淇淋出料口有无遮挡");
  455. morkT.IceIsOK = false;
  456. }
  457. else if (morkT.morkOrderPushesIceCream.TryDequeue(out OrderLocInfo order))
  458. {
  459. morkT.IceIsOK = true;
  460. DeviceProcessLogShow($"开始制作 [冰淇淋] 订单[{order.SortNum}]");
  461. DoIceCream(order);
  462. }
  463. }
  464. }
  465. }
  466. }
  467. /// <summary>
  468. /// 做冰淇淋
  469. /// </summary>
  470. private void DoIceCream(OrderLocInfo order)
  471. {
  472. GetIceCreamCup();
  473. //CheckICeCreaCup();
  474. GetIceCream(order);
  475. PutIceCream(order);
  476. }
  477. /// <summary>
  478. /// 取冰淇淋杯
  479. /// </summary>
  480. private void GetIceCreamCup()
  481. {
  482. MessageLog.GetInstance.Show("准备开始制作冰淇淋");
  483. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }, (o) => { });
  484. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = 10032 }); //SENCE_取冰淇淋杯
  485. Wait();
  486. Thread.Sleep(500);
  487. DeviceProcessLogShow("尝试取冰淇淋杯!");
  488. }
  489. /// <summary>
  490. /// 冰淇淋杯检测,失败后机器人回到原点
  491. /// </summary>
  492. private void CheckICeCreaCup()
  493. {
  494. int count = 2;
  495. bool result = true;
  496. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
  497. p:
  498. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = 10034 }); //SENCE_冰淇淋杯检测
  499. Wait();
  500. Thread.Sleep(500);
  501. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) =>
  502. {
  503. if (o != null && o.Length > 0 && o[0] is SignalResult res)
  504. {
  505. MessageLog.GetInstance.Show(res.ToString());
  506. }
  507. });
  508. while((int)peripheralStatus["RobotValue"] != 0)
  509. {
  510. Thread.Sleep(10);
  511. }
  512. MessageLog.GetInstance.Show($"乐白机器人信号值{peripheralStatus["RobotValue"].ToString()}");
  513. //while ((ELebaiRModel)peripheralStatus["RobotMode"] !=ELebaiRModel.空闲状态)
  514. //{
  515. // EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 });
  516. // Thread.Sleep(500);
  517. //}
  518. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetTCPInputEvent { DeviceId = DeviceId, Pin = 1 }, (o) =>
  519. {
  520. if (o != null && o.Length > 0 && o[0] is bool resultValue)
  521. {
  522. result = resultValue;
  523. }
  524. });
  525. if (!result)
  526. {
  527. if (count >= 3)
  528. {
  529. //退出循环回到初始位置
  530. DeviceProcessLogShow($"执行{count}次取冰淇淋杯,仍未成功,订单默认废弃,机器人回到初始位置!");
  531. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = 10049 }); //SENCE_冰淇淋杯回原点
  532. Wait();
  533. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 },(o) => { });
  534. morkT.GetIceCreamCup = false;
  535. return;
  536. }
  537. DeviceProcessLogShow($"执行{count}次取冰淇淋杯!");
  538. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = 10036 }); //SENCE_二次取冰淇淋杯
  539. EventBus.EventBus.GetInstance().Equals(new SCChip_TakeCupEvent { DeviceId = DeviceId, Cup = IC_CUP.CUP_ICECREAM });//落碗控制
  540. Wait();
  541. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
  542. count++;
  543. goto p;
  544. }
  545. morkT.GetIceCreamCup = true;
  546. DeviceProcessLogShow("冰淇淋杯检测完成");
  547. }
  548. /// <summary>
  549. /// 机器人取接冰淇淋
  550. /// </summary>
  551. /// <param name="order"></param>
  552. private void GetIceCream(OrderLocInfo order)
  553. {
  554. //制冷模式
  555. //EventBus.EventBus.GetInstance().Publish(new GSIceCream_ModeSetEvent {DeviceId = DeviceId, Mode = MORKI_MODE.制冷模式 });
  556. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }, (o) => { });
  557. OrderChange(order.SuborderId, ORDER_STATUS.COOKING);
  558. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = 10055 }); //SENCE_接1号冰淇淋
  559. Wait();
  560. bool doItResult = true;
  561. ////出料
  562. //EventBus.EventBus.GetInstance().Publish(new SCChip_RotorSwitchEvent { DeviceId = DeviceId, TurnOn = true });
  563. //Thread.Sleep(500);
  564. //EventBus.EventBus.GetInstance().Publish(new SCChip_RotorSwitchEvent { DeviceId = DeviceId, TurnOn = false });
  565. //Thread.Sleep(500);
  566. //EventBus.EventBus.GetInstance().Publish(new SCChip_MakeIceCreamEvent { DeviceId = DeviceId, SteeringEngine = IC_SE.SE_2 });//冰淇淋出料
  567. //DeviceProcessLogShow("开始等待6s");
  568. //Thread.Sleep(5000);
  569. // 出料
  570. EventBus.EventBus.GetInstance().Publish(new GSIceCream_DischargeEvent { DeviceId = DeviceId }, (o) =>
  571. {
  572. doItResult = (bool)o[0];
  573. });
  574. if (doItResult)
  575. {
  576. IceCreamCookCheck();
  577. }
  578. else
  579. {
  580. int count_1 = 0;
  581. while ((byte)peripheralStatus["IceCreamCXB"] <= 86)
  582. {
  583. Thread.Sleep(5);
  584. count_1++;
  585. if (count_1 >= 2000)
  586. break;
  587. }
  588. IceCreamCookCheck();
  589. }
  590. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
  591. }
  592. /// <summary>
  593. /// 把冰淇淋放到取餐位后回原点
  594. /// </summary>
  595. /// <param name="order"></param>
  596. private void PutIceCream(OrderLocInfo order)
  597. {
  598. bool resultValue = true;
  599. while (resultValue)
  600. {
  601. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetInputEvent { DeviceId = DeviceId, Pin = 0 }, (res) =>
  602. {
  603. if (res[0] is bool b)
  604. {
  605. resultValue = b;
  606. }
  607. });
  608. Thread.Sleep(500);
  609. }
  610. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = 10056 }); //SENCE_放冰淇淋位置
  611. Wait();
  612. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
  613. //订单状态改变:完成
  614. OrderChange(order.SuborderId, ORDER_STATUS.COMPLETED_COOK);
  615. morkT.waitMorkOrder = order;
  616. DeviceProcessLogShow($"{order.GoodsName}等待取餐");
  617. //WaitTakeMealOrder.Enqueue(order);
  618. }
  619. /// <summary>
  620. /// 冰淇淋机器制作冰淇淋
  621. /// </summary>
  622. public void IceCreamCookCheck()
  623. {
  624. bool result = false;
  625. int retry = 3;
  626. DateTime beginTime = DateTime.Now;
  627. while (!result)
  628. {
  629. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetInputEvent { DeviceId = DeviceId, Pin = 3 }, (res) =>
  630. {
  631. if (res[0] is bool resultValue)
  632. {
  633. result = resultValue;
  634. }
  635. });
  636. if (retry <= 0 || DateTime.Now.Subtract(beginTime).TotalSeconds >= 10)
  637. {
  638. DeviceProcessLogShow("超时未出料,重试次数用尽");
  639. break;
  640. }
  641. if (DateTime.Now.Subtract(beginTime).TotalSeconds > 5)
  642. {
  643. DeviceProcessLogShow("超时未出料,重新发送打料指令");
  644. EventBus.EventBus.GetInstance().Publish( new GSIceCream_ModeSetEvent() { DeviceId =DeviceId, Mode = MORKI_MODE.打料 });
  645. beginTime = DateTime.Now;
  646. retry--;
  647. }
  648. Thread.Sleep(10);
  649. }
  650. DeviceProcessLogShow("开始等待6s");
  651. Thread.Sleep(5000);
  652. }
  653. #endregion
  654. #region 果汁
  655. /// <summary>
  656. /// 制作果汁流程
  657. /// </summary>
  658. private void MakeJuiceProcess()
  659. {
  660. if(morkT.morkOrderPushesJuice.TryDequeue(out OrderLocInfo order))
  661. {
  662. OrderChange(order.SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
  663. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = 11111 });//SENCE_取果汁杯位置
  664. int JuicerNum1 = int.Parse(order.Loc);
  665. switch (JuicerNum1)
  666. {
  667. case 52:
  668. if (morkT.GuMake)
  669. {
  670. morkT.JuicerNum = 0x00;
  671. }
  672. else
  673. {
  674. morkT.JuicerNum = 0x01;
  675. }
  676. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_HQ.SENCE_接果汁公共位置 });
  677. Wait();
  678. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_HQ.SENCE_接1号果汁位置 });
  679. Wait();
  680. break;
  681. case 53:
  682. if (morkT.GuMake)
  683. {
  684. morkT.JuicerNum = 0x02;
  685. }
  686. else
  687. {
  688. morkT.JuicerNum = 0x03;
  689. }
  690. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_HQ.SENCE_接果汁公共位置 });
  691. Wait();
  692. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_HQ.SENCE_接2号果汁位置 });
  693. Wait();
  694. break;
  695. case 54:
  696. if (morkT.GuMake)
  697. {
  698. morkT.JuicerNum = 0x04;
  699. }
  700. else
  701. {
  702. morkT.JuicerNum = 0x05;
  703. }
  704. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_HQ.SENCE_接果汁公共位置 });
  705. Wait();
  706. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_HQ.SENCE_接3号果汁位置 });
  707. Wait();
  708. break;
  709. case 55:
  710. if (morkT.GuMake)
  711. {
  712. morkT.JuicerNum = 0x06;
  713. }
  714. else
  715. {
  716. morkT.JuicerNum = 0x07;
  717. }
  718. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_HQ.SENCE_接果汁公共位置 });
  719. Wait();
  720. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_HQ.SENCE_接4号果汁位置 });
  721. Wait();
  722. break;
  723. default:
  724. morkT.JuicerNum = 0x00;
  725. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_HQ.SENCE_接果汁公共位置 });
  726. Wait();
  727. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_HQ.SENCE_接1号果汁位置 });
  728. Wait();
  729. break;
  730. }
  731. var devStatus = GetDeviceStatus<int[]>("GetDeviceStatus");
  732. var devStatus1 = Convert.ToString(devStatus[0], 2);
  733. var devStatus2 = devStatus[1];
  734. if (devStatus1.IndexOf("0") == 1 && devStatus2 == 0)
  735. {
  736. EventBus.EventBus.GetInstance().Publish(new WriteJuicer() { Value = morkT.JuicerNum });
  737. Thread.Sleep(100);
  738. devStatusBy = GetDeviceStatus<int[]>("GetDeviceStatus");
  739. while (!(devStatusBy[1] == 0))
  740. {
  741. Thread.Sleep(100);
  742. devStatusBy = GetDeviceStatus<int[]>("GetDeviceStatus");
  743. while (devStatusBy.Length != 2)
  744. {
  745. Thread.Sleep(100);
  746. devStatusBy = GetDeviceStatus<int[]>("GetDeviceStatus");
  747. }
  748. }
  749. devStatusBy = GetDeviceStatus<int[]>("GetDeviceStatus");
  750. Thread.Sleep(5000);
  751. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_HQ.SENCE_放果汁杯位置后回原点 });
  752. Wait();
  753. OrderChange(order.SuborderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE);
  754. MessageLog.GetInstance.Show("果汁制作完成");
  755. }
  756. }
  757. }
  758. private T GetDeviceStatus<T>(string key)
  759. {
  760. if (peripheralStatus.ContainsKey(key))
  761. {
  762. if (peripheralStatus[key] != null)
  763. {
  764. return (T)(peripheralStatus[key]);
  765. }
  766. }
  767. return default;
  768. }
  769. #endregion
  770. public override void SimOrder()
  771. {
  772. }
  773. }
  774. }