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

Control_MorkTHQ.cs 34 KiB

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