终端一体化运控平台
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Control_MorkT.cs 32 KiB

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