终端一体化运控平台
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Control_MorkTHQ.cs 33 KiB

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