终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Control_MORKJC2.cs 33 KiB

2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Linq;
  5. using System.Threading;
  6. using System.Collections.Concurrent;
  7. using System.Diagnostics;
  8. using System.Threading.Tasks;
  9. using BPASmartClient.Device;
  10. using BPA.Message.Enum;
  11. using BPA.Message;
  12. using BPASmartClient.Helper;
  13. using BPASmartClient.Model.咖啡机.Enum;
  14. using BPASmartClient.Model;
  15. using BPASmartClient.EventBus;
  16. using static BPASmartClient.EventBus.EventBus;
  17. using BPASmartClient.Message;
  18. using BPASmartClient.Model.乐白机器人;
  19. using BPASmartClient.Model.单片机;
  20. namespace BPASmartClient.MorkTLebaiJC
  21. {
  22. /*
  23. * 冰淇淋咖啡机组合套装
  24. * 物料位置:
  25. * 1:冰淇料
  26. * 2:冰淇淋杯
  27. * 5:咖啡
  28. * 6:咖啡杯
  29. * 9: 茶
  30. * 10: 茶杯
  31. */
  32. public class Control_MORKJC2 : BaseDevice
  33. {
  34. private Dictionary<string, PolymerBatching> batchings = new Dictionary<string, PolymerBatching>();
  35. //容器位置
  36. private string holderLoc;
  37. //主料位置
  38. private string mainMaterialLoc;
  39. public override global::BPA.Message.Enum.DeviceClientType DeviceType { get { return BPA.Message.Enum.DeviceClientType.MORKT; } }
  40. GVL_MorkTLebaiJC morkTLebaiJC =new GVL_MorkTLebaiJC();
  41. /// <summary>
  42. /// 果汁机做法,true:热饮,false:冷饮
  43. /// </summary>
  44. private bool GuMake = false;
  45. public override void DoMain()
  46. {
  47. if (Json<KeepDataBase>.Data.IsVerify)
  48. {
  49. IsHealth = true;
  50. }
  51. IsHealth = true;
  52. serverInit();
  53. DataParse();
  54. ActionManage.GetInstance.Register(new Action<object>((o) => { SimOrder(o); }), "SimOrder");//模拟订单委托注册
  55. }
  56. private void serverInit()
  57. {
  58. EventBus.EventBus.GetInstance().Subscribe<MaterialDeliveryEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  59. {
  60. if (@event == null) return;
  61. if (@event is MaterialDeliveryEvent material)
  62. {
  63. orderMaterialDelivery = material.orderMaterialDelivery;
  64. }
  65. });
  66. }
  67. private void DataParse()
  68. {
  69. EventBus.EventBus.GetInstance().Subscribe<DoOrderEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle)
  70. {
  71. if (@event == null) return;
  72. if (@event is DoOrderEvent order)
  73. {
  74. if (order.MorkOrder.GoodBatchings == null) return;
  75. OrderCount++;
  76. DeviceProcessLogShow($"接收到{OrderCount}次订单");
  77. batchings = PolymerBatching.BuildAll();
  78. //商品类型
  79. GOODS_TYPE currentGoodsType = GOODS_TYPE.NEITHER;
  80. foreach (var item in order.MorkOrder.GoodBatchings)
  81. {
  82. var res = orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId);
  83. if (res != null)
  84. {
  85. //验证商品是做的某种饮料
  86. if (ValidateGoodsByBatching(res.BatchingLoc) != GOODS_TYPE.NEITHER)
  87. {
  88. //获取当前物料所属商品类型
  89. currentGoodsType = ValidateGoodsByBatching(res.BatchingLoc);
  90. }
  91. //
  92. switch (batchings[res.BatchingLoc].BatchingClass)
  93. {
  94. case BATCHING_CLASS.HOLDER:
  95. holderLoc = res.BatchingLoc;
  96. break;
  97. case BATCHING_CLASS.MAIN_MATERIAL:
  98. mainMaterialLoc = res.BatchingLoc;
  99. break;
  100. }
  101. //根据商品类型执行具体制作流程
  102. switch (currentGoodsType)
  103. {
  104. case GOODS_TYPE.COFFEE:
  105. if (morkTLebaiJC.morkOrderPushesCoffee.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  106. {
  107. morkTLebaiJC.morkOrderPushesCoffee.Enqueue(new OrderLocInfo()
  108. {
  109. SuborderId = order.MorkOrder.SuborderId,
  110. BatchingId = res.BatchingId,
  111. Loc = ushort.Parse( mainMaterialLoc),
  112. GoodName = order.MorkOrder.GoodsName,
  113. });
  114. }
  115. break;
  116. case GOODS_TYPE.JUICE:
  117. GuMake = order.MorkOrder.MakeID == "2";//判断果汁的冷热
  118. if (morkTLebaiJC.morkOrderPushesJuicer.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  119. {
  120. morkTLebaiJC.morkOrderPushesJuicer.Enqueue(new OrderLocInfo()
  121. {
  122. SuborderId = order.MorkOrder.SuborderId,
  123. BatchingId = res.BatchingId,
  124. Loc = ushort.Parse(mainMaterialLoc),
  125. GoodName = order.MorkOrder.GoodsName,
  126. });
  127. }
  128. break;
  129. case GOODS_TYPE.TEA:
  130. if (morkTLebaiJC.morkOrderPushesTea.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  131. {
  132. morkTLebaiJC.morkOrderPushesTea.Enqueue(new OrderLocInfo()
  133. {
  134. SuborderId = order.MorkOrder.SuborderId,
  135. BatchingId = res.BatchingId,
  136. Loc = ushort.Parse(mainMaterialLoc),
  137. GoodName = order.MorkOrder.GoodsName,
  138. });
  139. }
  140. break;
  141. case GOODS_TYPE.WATER:
  142. if (morkTLebaiJC.morkOrderPushesWater.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  143. {
  144. morkTLebaiJC.morkOrderPushesWater.Enqueue(new OrderLocInfo()
  145. {
  146. SuborderId = order.MorkOrder.SuborderId,
  147. BatchingId = res.BatchingId,
  148. Loc = ushort.Parse(mainMaterialLoc),
  149. GoodName = order.MorkOrder.GoodsName,
  150. });
  151. }
  152. break;
  153. case GOODS_TYPE.NEITHER:
  154. DeviceProcessLogShow("未知的商品类型");
  155. break;
  156. }
  157. }
  158. }
  159. }
  160. });
  161. }
  162. private bool bFirstTrig_TeaWater = false;
  163. /// <summary>
  164. /// 延迟的超时时间
  165. /// </summary>
  166. DateTime delayTimeOut;
  167. private bool bFirstTrig_Coffee = false;
  168. DateTime delayTimeOut_Coffee;
  169. private bool bFirstTrig_Juice = false;
  170. DateTime delayTimeOut_Juice;
  171. public override void MainTask()
  172. {
  173. EventBus.EventBus.GetInstance().Subscribe<DRCoffee_CoffeEndCookEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  174. {
  175. if (morkTLebaiJC.IsHaveCoffeeCup)
  176. morkTLebaiJC.MakeCoffeeEnd = true;
  177. });
  178. if (pickUpCoffeeHaveCup)
  179. {
  180. if (!bFirstTrig_Coffee)
  181. {
  182. bFirstTrig_Coffee = true;
  183. delayTimeOut_Coffee = DateTime.Now;
  184. }
  185. else if (DateTime.Now.Subtract(delayTimeOut_Coffee).TotalSeconds > 180 && bFirstTrig_Coffee == true)
  186. {
  187. bFirstTrig_Coffee = false;
  188. if (morkTLebaiJC.IsHaveCoffeeCup)
  189. morkTLebaiJC.MakeCoffeeEnd = true;
  190. }
  191. }
  192. if (morkTLebaiJC.IsHaveJuiceCup)
  193. {
  194. var Juicestate = GetStatus<int[]>("GetDeviceStatus");
  195. if (Juicestate != null)
  196. {
  197. if (Juicestate.Length > 0)
  198. {
  199. var Juicestate1 = Convert.ToString(Juicestate[0], 2);
  200. var Juicestate2 = Juicestate[1];
  201. if (Juicestate1.IndexOf("0") == 1 && Juicestate2 == 0)
  202. {
  203. morkTLebaiJC.MakeJuiceEnd = true;
  204. }
  205. }
  206. }
  207. //若无状态返回 则加延迟
  208. if (!bFirstTrig_Juice)
  209. {
  210. bFirstTrig_Juice = true;
  211. delayTimeOut_Juice = DateTime.Now;
  212. }
  213. else if (DateTime.Now.Subtract(delayTimeOut_Juice).TotalSeconds > 30 && bFirstTrig_Juice == true)
  214. {
  215. bFirstTrig_Juice = false;
  216. morkTLebaiJC.MakeJuiceEnd = true;
  217. }
  218. }
  219. if (morkTLebaiJC.IsHaveTeaWaterCup)
  220. {
  221. if (!bFirstTrig_TeaWater)
  222. {
  223. bFirstTrig_TeaWater = true;
  224. delayTimeOut = DateTime.Now;
  225. }
  226. else if (DateTime.Now.Subtract(delayTimeOut).TotalSeconds >= 50 && bFirstTrig_TeaWater == true)
  227. {
  228. bFirstTrig_TeaWater = false;
  229. morkTLebaiJC.MakeTeaEnd = true;
  230. }
  231. }
  232. DoCoffee();
  233. DoJuice();
  234. DoBoiledTea();
  235. DoBoiledWater();
  236. }
  237. /// <summary>
  238. /// 订单状态改变
  239. /// </summary>
  240. /// <param name="subid"></param>
  241. /// <param name="oRDER_STATUS"></param>
  242. private void OrderChange(string subid, ORDER_STATUS oRDER_STATUS)
  243. {
  244. EventBus.EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { Status = oRDER_STATUS, SubOrderId = subid, deviceClientType = DeviceType });
  245. }
  246. /// <summary>
  247. /// 验证商品是做的某种饮料
  248. /// </summary>
  249. /// <param name="batchingLoc">物料位置</param>
  250. private GOODS_TYPE ValidateGoodsByBatching(string batchingLoc)
  251. {
  252. if (batchings.ContainsKey(batchingLoc))
  253. return batchings[batchingLoc].GoodsType;
  254. return GOODS_TYPE.NEITHER;
  255. }
  256. /// <summary>
  257. /// 乐白的场景结束等待
  258. /// </summary>
  259. /// <param name="value"></param>
  260. private void Wait(int value = 101)
  261. {
  262. while (!((bool)peripheralStatus["RobotOK"] && (int)peripheralStatus["RobotValue"] == value))
  263. {
  264. Thread.Sleep(5);
  265. }
  266. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  267. }
  268. /// <summary>
  269. /// 乐白的场景
  270. /// </summary>
  271. /// <param name="sen"></param>
  272. private void Sence(int sen)
  273. {
  274. new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = sen }.Publish();
  275. }
  276. /// <summary>
  277. /// 乐白的数字量输出
  278. /// </summary>
  279. /// <param name="value"></param>
  280. /// <param name="pin"></param>
  281. private void Output(bool value,int pin)
  282. {
  283. new LebaiRobot_SetOutPutEvent { DeviceId = DeviceId, Pin = pin,Value=value }.Publish();
  284. }
  285. private T GetStatus<T>(string key)
  286. {
  287. if (peripheralStatus.ContainsKey(key))
  288. {
  289. if (peripheralStatus[key] != null)
  290. {
  291. return (T)(peripheralStatus[key]);
  292. }
  293. }
  294. return default;
  295. }
  296. int[] devStatusBy = new int[2] { 0, 0 };
  297. bool outCupCheck = false;//放纸杯位置有无判断
  298. /// <summary>
  299. /// 判断接咖啡的位置是否有杯子
  300. /// </summary>
  301. bool pickUpCoffeeHaveCup = false;
  302. /// <summary>
  303. /// 判断接果汁的位置是否有杯子
  304. /// </summary>
  305. bool pickUpJuiceHaveCup = false;
  306. /// <summary>
  307. /// 判断接开水的位置是否有杯子
  308. /// </summary>
  309. bool pickUpHotWaterHaveCup = false;
  310. /// <summary>
  311. /// 传感器的输入信号 0:无意义 1:有信号 2:无信号 3:信号不正确
  312. /// </summary>
  313. int bSensorInput;
  314. private bool IsMakeCoffee()
  315. {
  316. bool bMake = (IsHealth && morkTLebaiJC.morkOrderPushesCoffee.Count > 0 && !morkTLebaiJC.IsHaveCoffeeCup) ? true : false;
  317. return bMake;
  318. }
  319. private bool IsMakeJuice()
  320. {
  321. bool bMake = (IsHealth && morkTLebaiJC.morkOrderPushesJuicer.Count > 0 && !morkTLebaiJC.IsHaveJuiceCup) ? true : false;
  322. return bMake;
  323. }
  324. private bool IsMakeTeaWater()
  325. {
  326. bool bMake = (IsHealth && morkTLebaiJC.morkOrderPushesTea.Count > 0 && !morkTLebaiJC.IsHaveTeaWaterCup) ? true : false;
  327. return bMake;
  328. }
  329. private bool IsMakeWater()
  330. {
  331. bool bMake = (IsHealth && morkTLebaiJC.morkOrderPushesWater.Count > 0 && !morkTLebaiJC.IsHaveTeaWaterCup) ? true : false;
  332. return bMake;
  333. }
  334. /// <summary>
  335. /// 做咖啡流程
  336. /// </summary>
  337. private void DoCoffee()
  338. {
  339. if (IsMakeCoffee())
  340. {
  341. if (morkTLebaiJC.morkOrderPushesCoffee.TryDequeue(out OrderLocInfo orderLoc))
  342. {
  343. PickUpCoffee();//接咖啡
  344. morkTLebaiJC.IsHaveCoffeeCup = true;
  345. }
  346. }
  347. else if(morkTLebaiJC.MakeCoffeeEnd)
  348. {
  349. PutCoffeeCup();
  350. pickUpCoffeeHaveCup = false;
  351. morkTLebaiJC.IsHaveCoffeeCup = false;
  352. }
  353. }
  354. private void DoJuice()
  355. {
  356. if (IsMakeJuice())
  357. {
  358. if (morkTLebaiJC.morkOrderPushesJuicer.TryDequeue(out OrderLocInfo orderLoc))
  359. {
  360. PickUpJuicer();
  361. morkTLebaiJC.IsHaveJuiceCup = true;
  362. }
  363. }
  364. else if (morkTLebaiJC.MakeJuiceEnd)
  365. {
  366. Thread.Sleep(5000);//延迟五秒,防止接饮料口滴饮料
  367. putJuice();
  368. pickUpJuiceHaveCup = false;
  369. morkTLebaiJC.IsHaveJuiceCup = false;
  370. morkTLebaiJC.MakeJuiceEnd = false;
  371. }
  372. }
  373. private void DoBoiledTea()
  374. {
  375. if (IsMakeTeaWater())
  376. {
  377. if (morkTLebaiJC.morkOrderPushesTea.TryDequeue(out OrderLocInfo orderLoc))
  378. {
  379. PickUpTea();
  380. morkTLebaiJC.IsHaveTeaWaterCup = true;
  381. }
  382. }
  383. else if(morkTLebaiJC.MakeTeaEnd)
  384. {
  385. PutWaterCup();
  386. pickUpHotWaterHaveCup = false;
  387. morkTLebaiJC.IsHaveTeaWaterCup = false ;
  388. morkTLebaiJC.MakeTeaEnd = false;
  389. }
  390. }
  391. private void DoBoiledWater()
  392. {
  393. if (IsMakeWater())
  394. {
  395. if (morkTLebaiJC.morkOrderPushesWater.TryDequeue(out OrderLocInfo orderLoc))
  396. {
  397. PickUpWater();
  398. }
  399. }
  400. else if (morkTLebaiJC.MakeTeaEnd)
  401. {
  402. PutWaterCup();
  403. pickUpHotWaterHaveCup = false;
  404. morkTLebaiJC.IsHaveTeaWaterCup = false;
  405. morkTLebaiJC.MakeTeaEnd = false;
  406. }
  407. }
  408. #region 做咖啡流程
  409. /// <summary>
  410. /// 接咖啡
  411. /// </summary>
  412. private void PickUpCoffee()
  413. {
  414. //while (GetStatus<bool>("RobotValue1"))//判断放杯位置是否有物品
  415. //{
  416. // if (!outCupCheck)
  417. // DeviceProcessLogShow("成品处有纸杯存在,请取走!!");
  418. // outCupCheck = true;
  419. //}
  420. if (!pickUpCoffeeHaveCup)
  421. {
  422. outCupCheck = false;
  423. OrderChange(morkTLebaiJC.morkOrderPushesCoffee.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
  424. int resultTakeCup = takeCup();
  425. if (resultTakeCup == 1)
  426. {
  427. DeviceProcessLogShow("咖啡杯取杯完成");
  428. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  429. Sence(GVL_MorkTLebaiJC.接咖啡);
  430. Wait();
  431. pickUpCoffeeHaveCup = true;
  432. new DRCoffee_MakeCoffeeEvent() { DrinkCode = (DrCoffeeDrinksCode)int.Parse(mainMaterialLoc) }.Publish(); //接咖啡控制 //DrCoffeeDrinksCode.热水
  433. }
  434. else
  435. {
  436. DeviceProcessLogShow("取杯失败 回到初始位,请及时处理!!");
  437. Sence(GVL_MorkTLebaiJC.机器人初始位);
  438. }
  439. }
  440. }
  441. /// <summary>
  442. /// 咖啡杯接好,放咖啡杯
  443. /// </summary>
  444. private void PutCoffeeCup()
  445. {
  446. while (GetStatus<bool>("RobotValue1"))//判断放杯位置是否有物品
  447. {
  448. if (!outCupCheck)
  449. DeviceProcessLogShow("成品处有纸杯存在,请取走!!");
  450. outCupCheck = true;
  451. }
  452. outCupCheck = false;
  453. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  454. Sence(GVL_MorkTLebaiJC.放咖啡杯);
  455. Wait();
  456. OrderChange(morkTLebaiJC.morkOrderPushesCoffee.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE);
  457. DeviceProcessLogShow("咖啡制作完成");
  458. }
  459. #endregion
  460. #region 做开水流程
  461. /// <summary>
  462. /// 接开水
  463. /// </summary>
  464. private void PickUpWater()
  465. {
  466. #region 接水流程
  467. if (!pickUpHotWaterHaveCup)
  468. {
  469. OrderChange(morkTLebaiJC.morkOrderPushesWater.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
  470. int resultTakeCup = takeCup();
  471. if (resultTakeCup == 1)
  472. {
  473. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  474. Sence(GVL_MorkTLebaiJC.接开水);
  475. Wait();
  476. Output(false, 1);
  477. Output(false, 0);
  478. Thread.Sleep(100);
  479. Output(true, 0);
  480. Thread.Sleep(3000);
  481. Output(false, 0);
  482. Thread.Sleep(100);
  483. Output(false, 1);
  484. Thread.Sleep(100);
  485. Output(true, 1);
  486. Thread.Sleep(500);
  487. Output(false, 1);
  488. }
  489. else
  490. {
  491. return;
  492. }
  493. }
  494. #endregion
  495. }
  496. #endregion
  497. #region 做茶流程
  498. /// <summary>
  499. /// 做茶
  500. /// </summary>
  501. private void PickUpTea()
  502. {
  503. #region 接茶流程
  504. if (!pickUpHotWaterHaveCup)
  505. {
  506. OrderChange(morkTLebaiJC.morkOrderPushesTea.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
  507. int resultTakeCup = takeCup();
  508. if (resultTakeCup == 1)
  509. {
  510. DeviceProcessLogShow("取茶杯完成");
  511. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  512. Sence(GVL_MorkTLebaiJC.接茶叶);
  513. Wait();
  514. new WriteMcu() { TagName = "ServoControl", Address = "1", Value = 90 }.Publish();
  515. Thread.Sleep(1000);
  516. new WriteMcu() { TagName = "ServoControl", Address = "1", Value = 150 }.Publish();
  517. Thread.Sleep(1000);
  518. new WriteMcu() { TagName = "ServoControl", Address = "1", Value = 90 }.Publish();
  519. Thread.Sleep(3000);
  520. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  521. Sence(GVL_MorkTLebaiJC.接茶水);
  522. Wait();
  523. Output(false, 1);
  524. Output(false, 0);
  525. Thread.Sleep(100);
  526. Output(true, 0);
  527. Thread.Sleep(3000);
  528. Output(false, 0);
  529. Thread.Sleep(100);
  530. Output(false, 1);
  531. Thread.Sleep(100);
  532. Output(true, 1);
  533. Thread.Sleep(500);
  534. Output(false, 1);
  535. pickUpHotWaterHaveCup = true;
  536. }
  537. else
  538. {
  539. return;
  540. }
  541. }
  542. #endregion
  543. }
  544. /// <summary>
  545. /// 放水杯流程
  546. /// </summary>
  547. private void PutWaterCup()
  548. {
  549. while (GetStatus<bool>("RobotValue1"))//判断放杯位置是否有物品
  550. {
  551. if (!outCupCheck)
  552. DeviceProcessLogShow("成品处有纸杯存在,请取走!!");
  553. outCupCheck = true;
  554. }
  555. outCupCheck = false;
  556. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  557. Sence(GVL_MorkTLebaiJC.放水杯);
  558. Wait();
  559. OrderChange(morkTLebaiJC.morkOrderPushesWater.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE);
  560. DeviceProcessLogShow("茶水制作完成");
  561. }
  562. #endregion
  563. #region 做果汁流程
  564. /// <summary>
  565. /// 果汁机控制信号
  566. /// </summary>
  567. private byte JuicerNum;
  568. private int JuiceCH;
  569. /// <summary>
  570. /// 接果汁
  571. /// </summary>
  572. private void PickUpJuicer()
  573. {
  574. #region 接果汁流程
  575. if (!pickUpJuiceHaveCup)
  576. {
  577. OrderChange(morkTLebaiJC.morkOrderPushesJuicer.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
  578. int resultTakeCup = takeCup();
  579. JuiceCH = int.Parse(mainMaterialLoc);
  580. if (resultTakeCup == 1)
  581. {
  582. switch (JuiceCH)
  583. {
  584. case 52:
  585. if (GuMake)
  586. JuicerNum = 0x00;
  587. else
  588. JuicerNum = 0x01;
  589. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  590. Sence(GVL_MorkTLebaiJC.接果汁1);
  591. Wait();
  592. break;
  593. case 53:
  594. if (GuMake)
  595. JuicerNum = 0x02;
  596. else
  597. JuicerNum = 0x03;
  598. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  599. Sence(GVL_MorkTLebaiJC.接果汁2);
  600. Wait();
  601. break;
  602. case 54:
  603. if (GuMake)
  604. JuicerNum = 0x04;
  605. else
  606. JuicerNum = 0x05;
  607. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  608. Sence(GVL_MorkTLebaiJC.接果汁3);
  609. Wait();
  610. break;
  611. case 55:
  612. if (GuMake)
  613. JuicerNum = 0x06;
  614. else
  615. JuicerNum = 0x07;
  616. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  617. Sence(GVL_MorkTLebaiJC.接果汁4);
  618. Wait();
  619. break;
  620. default:
  621. JuicerNum = 0x00;
  622. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  623. Sence(GVL_MorkTLebaiJC.接果汁1);
  624. Wait();
  625. break;
  626. }
  627. new WriteJuicer() { Value = JuicerNum }.Publish();
  628. pickUpJuiceHaveCup = true;
  629. }
  630. else
  631. {
  632. return;
  633. }
  634. }
  635. #endregion
  636. }
  637. /// <summary>
  638. /// 取接好果汁杯
  639. /// </summary>
  640. private void putJuice()
  641. {
  642. while (GetStatus<bool>("RobotValue1"))//判断放杯位置是否有物品
  643. {
  644. if (!outCupCheck)
  645. DeviceProcessLogShow("成品处有纸杯存在,请取走!!");
  646. outCupCheck = true;
  647. }
  648. outCupCheck = false;
  649. switch (JuiceCH)
  650. {
  651. case 52:
  652. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  653. Sence(GVL_MorkTLebaiJC.放果汁杯1);
  654. Wait();
  655. break;
  656. case 53:
  657. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  658. Sence(GVL_MorkTLebaiJC.放果汁杯2);
  659. Wait();
  660. break;
  661. case 54:
  662. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  663. Sence(GVL_MorkTLebaiJC.放果汁杯3);
  664. Wait();
  665. break;
  666. case 55:
  667. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  668. Sence(GVL_MorkTLebaiJC.放果汁杯4);
  669. Wait();
  670. break;
  671. default:
  672. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  673. Sence(GVL_MorkTLebaiJC.放果汁杯1);
  674. Wait();
  675. break;
  676. }
  677. OrderChange(morkTLebaiJC.morkOrderPushesJuicer.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE);
  678. DeviceProcessLogShow("果汁制作完成");
  679. }
  680. #endregion
  681. /// <summary>
  682. /// 取杯的次数
  683. /// </summary>
  684. private int nCnt;
  685. /// <summary>
  686. /// 传感器的检测次数
  687. /// </summary>
  688. private int checkCnt;
  689. /// <summary>
  690. /// 取杯流程
  691. /// </summary>
  692. /// <returns>0:无意义,1:取杯成功 2:取杯失败</returns>
  693. private int takeCup()
  694. {
  695. try
  696. {
  697. nCnt = 0;
  698. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  699. Sence(GVL_MorkTLebaiJC.机器人初始位);
  700. Wait();
  701. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  702. Sence(GVL_MorkTLebaiJC.取纸杯);
  703. Wait();
  704. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  705. Sence(GVL_MorkTLebaiJC.取纸杯检测);
  706. Wait();
  707. nCnt++;
  708. Thread.Sleep(2000);
  709. while (!GetStatus<bool>("GetInput")) //读取传感器的值
  710. {
  711. if (nCnt > 3)
  712. {
  713. nCnt = 0;
  714. DeviceProcessLogShow("三次取杯失败,回原点");
  715. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  716. Sence(GVL_MorkTLebaiJC.机器人初始位);
  717. Wait();
  718. return 2;
  719. }
  720. else
  721. {
  722. nCnt++;
  723. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  724. Sence(GVL_MorkTLebaiJC.二次取杯);
  725. Wait();
  726. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  727. Sence(GVL_MorkTLebaiJC.取纸杯检测);
  728. Wait();
  729. }
  730. Thread.Sleep(1000);
  731. }
  732. }
  733. catch (Exception ex)
  734. {
  735. DeviceProcessLogShow(ex.ToString());
  736. }
  737. return 2;
  738. }
  739. /// <summary>
  740. /// 放杯
  741. /// </summary>
  742. /// <returns>0:无意义 1:放杯成功 2:执行失败(传感器还有信号) 3:放杯异常</returns>
  743. private int putCup()
  744. {
  745. try
  746. {
  747. if (GetStatus<bool>("RobotValue1")) return 2;
  748. Sence(GVL_MorkTLebaiJC.JUICE_放杯);
  749. Wait();
  750. new LebaiRobot_SetValueEvent() { RobotSetValue = 1 }.Publish();
  751. Sence(GVL_MorkTLebaiJC.JUICE_放杯检测);
  752. Wait();
  753. new LebaiRobot_SetValueEvent() { RobotSetValue = 1 }.Publish();
  754. if (GetStatus<bool>("GetInput2"))
  755. {
  756. return 1;
  757. }
  758. else
  759. {
  760. return 3;
  761. }
  762. }
  763. catch (Exception ex)
  764. {
  765. DeviceProcessLogShow(ex.ToString());
  766. return 0;
  767. }
  768. }
  769. /// <summary>
  770. /// 检测放杯位,是否有杯子
  771. /// </summary>
  772. /// <returns>0:无意义 1:没有杯子 2:有杯子 </returns>
  773. private int checkCup()
  774. {
  775. try
  776. {
  777. while (GetStatus<bool>("RobotValue1"))
  778. {
  779. Thread.Sleep(100);
  780. if (DateTime.Now.Subtract(delayTimeOut).TotalSeconds >= 1) return 2;
  781. }
  782. DeviceProcessLogShow("放杯位有杯子未取走,等待取走,最多等待60s,即跳出流程");
  783. return 1;
  784. }
  785. catch (Exception ex)
  786. {
  787. DeviceProcessLogShow(ex.ToString());
  788. return 0;
  789. }
  790. }
  791. public void SimOrder<T>(T simOrder)
  792. {
  793. if (simOrder != null)
  794. {
  795. if (simOrder is List<ushort> locs)
  796. {
  797. List<OrderLocInfo> orders = new List<OrderLocInfo>();
  798. string subId = Guid.NewGuid().ToString();
  799. foreach (var item in locs)
  800. {
  801. if (true)
  802. {
  803. orders.Add(new OrderLocInfo() { Loc = item, SuborderId = subId });
  804. }
  805. }
  806. }
  807. }
  808. }
  809. public override void Stop()
  810. {
  811. }
  812. public override void ReadData()
  813. {
  814. }
  815. public override void ResetProgram()
  816. {
  817. }
  818. public override void SimOrder()
  819. {
  820. }
  821. }
  822. }