终端一体化运控平台
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.
 
 
 

2382 lines
88 KiB

  1. using BPA.Message;
  2. using BPA.Message.Enum;
  3. using BPASmartClient.Device;
  4. using BPASmartClient.EventBus;
  5. using BPASmartClient.Helper;
  6. using BPASmartClient.Message;
  7. using BPASmartClient.Model;
  8. using BPASmartClient.Model.PLC;
  9. using BPA.Models;
  10. using static BPASmartClient.EventBus.EventBus;
  11. using BPASmartClient.Model.小炒机;
  12. using BPASmartClient.MorkF.Model;
  13. using System.Text;
  14. using System.Collections.Concurrent;
  15. using System.Windows.Documents;
  16. using BPASmartClient.Business;
  17. namespace BPASmartClient.MorkF
  18. {
  19. public class Control_MorkF : BaseDevice
  20. {
  21. /// <summary>
  22. /// while循环最大sleep次数
  23. /// </summary>
  24. private const int sleepCount = 20;
  25. /// <summary>
  26. /// while循环每次sleep时间
  27. /// </summary>
  28. private const int sleepTime = 500;
  29. /// <summary>
  30. /// 菜品库while循环最大sleep次数
  31. /// </summary>
  32. private const int materialSleepCount = 600;
  33. /// <summary>
  34. /// 菜品库while循环每次sleep时间
  35. /// </summary>
  36. private const int materialSleepTime = 100;
  37. /// <summary>
  38. /// 初始化炒锅数量
  39. /// </summary>
  40. private int count = 2;
  41. /// <summary>
  42. /// 菜品盒下移高度,相对于坐标系
  43. /// </summary>
  44. private const int materialBoxHigh = 4080;
  45. //菜品库一层的高度
  46. private const int materialHigh = 34500;
  47. /// <summary>
  48. /// 菜品库第一层的起始基点,为最下层盒子的中间点
  49. /// </summary>
  50. private const int materialOne = 34500;
  51. /// <summary>
  52. /// 菜品库第二层的起始基点,为最下层盒子的中间点
  53. /// </summary>
  54. private const int materialTwo = 34500;
  55. /// <summary>
  56. /// 菜品库第三层的起始基点,为最下层盒子的中间点
  57. /// </summary>
  58. private const int materialThree = 34500;
  59. //传感器到菜品库的高度(坐标系)
  60. private const int materialLaserHigh = 34500;
  61. //传感器到菜品库的高度(厘米)
  62. private const int materialLaserHighCM = 29;
  63. /// <summary>
  64. /// 传感器到隔板的距离(坐标系)
  65. /// </summary>
  66. private const int clapboardLaserHigh = 10000;
  67. //炒锅1倒菜的xy坐标
  68. private const int materialPutPositionXFry1 = 70000;
  69. private const int materialPutPositionYFry1 = 40000;
  70. //炒锅2倒菜的xy坐标
  71. private const int materialPutPositionXFry2 = 70000;
  72. private const int materialPutPositionYFry2 = 40000;
  73. //菜品库机械爪放置菜品距离
  74. private const int materialToFryDistance = 10000;
  75. //当前炒锅,默认为1号炒锅
  76. private int fryIndex = 0;
  77. public override DeviceClientType DeviceType => DeviceClientType.MORKCS;
  78. public AutoResetEvent minorReset = new AutoResetEvent(false);
  79. public AutoResetEvent mainReset = new AutoResetEvent(false);
  80. /// <summary>
  81. /// 炒锅编号与炒锅实例
  82. /// </summary>
  83. Dictionary<int, GVL_MorkF> morkFs = new Dictionary<int, GVL_MorkF>();//全局对象声明
  84. /// <summary>
  85. /// 菜品库对象
  86. /// </summary>
  87. ML_MorkF ml_morkf = new ML_MorkF();
  88. /// <summary>
  89. /// 小炒菜单集合
  90. /// </summary>
  91. public static List<StirFryGoods> LocalstirFryGoods = new List<StirFryGoods>();
  92. /// <summary>
  93. /// 待炒小炒队列
  94. /// </summary>
  95. private ConcurrentQueue<OrderLocInfo> StirFryGoodsQuenes = new ConcurrentQueue<OrderLocInfo>();
  96. /// <summary>
  97. /// 炒锅炒制线程名称
  98. /// </summary>
  99. private const String striConst = "炒锅{0}炒制{1}线程";
  100. /// <summary>
  101. /// 当前炒制菜品
  102. /// </summary>
  103. private OrderLocInfo[] nowStirFryGood = new OrderLocInfo[2];
  104. /// <summary>
  105. /// 待取菜队列
  106. /// </summary>
  107. private ConcurrentQueue<MaterialOperation> materialOperationQuenes = new ConcurrentQueue<MaterialOperation>();
  108. List<int> resultorder = new List<int>();//调试变量
  109. /// <summary>
  110. /// 入口
  111. /// </summary>
  112. public override void DoMain()
  113. {
  114. IsHealth = true;
  115. for (int i = 0; i < count; i++)
  116. {
  117. morkFs.Add(i, new GVL_MorkF());
  118. }
  119. DataParse();//数据解析
  120. CommandRegist();//调试
  121. ServerInit();
  122. DeviceProcessLogShow("MORKF 设备初始化完成");
  123. ///初始化菜品库
  124. //FoodLibInit();
  125. Task2ReadMaterialData();
  126. //Json<MaterialSurplus>.Read();
  127. }
  128. /// <summary>
  129. /// 主任务
  130. /// </summary>
  131. public override void MainTask()
  132. {
  133. //炒锅炒制线程
  134. MainProcessExcute();
  135. //菜品库操作线程
  136. MainProcessMaterial();
  137. //MinorProcessExcute();
  138. //SingleProcess();
  139. }
  140. private void Task2ReadMaterialData()
  141. {
  142. ThreadManage.GetInstance().StartLong(new Action(() => {
  143. //获取定位到达状态
  144. GetStatus("M10.0", new Action<object>((objects) =>
  145. {
  146. if (objects is bool[] bools)
  147. {
  148. //ml_morkf.ArriveComplete = bools[i];
  149. //小炒定点到达上升沿信号捕获
  150. if (RTrig.GetInstance("SmartArriveComplete").Start(bools[0]))
  151. {
  152. if (isInitialArrive == false)
  153. {
  154. MessageLog.GetInstance.Show("到达上升沿为true,isInitialArrive is false");
  155. isInitialArrive = true;
  156. }
  157. else
  158. {
  159. MessageLog.GetInstance.Show("到达上升沿为true");
  160. ml_morkf.ArriveComplete = true;
  161. isInitialArrive = true;
  162. }
  163. }
  164. }
  165. }), 2);
  166. }), "ReadMaterialSmartArriveCompleteData", true);
  167. ThreadManage.GetInstance().StartLong(new Action(() => {
  168. ReadMaterialData();
  169. Thread.Sleep(10);
  170. }), "ReadMaterialData", true);
  171. }
  172. private void ReadMaterialData()
  173. {
  174. //获取激光距离
  175. GetStatus("VW270", new Action<object>((objects) =>
  176. {
  177. if (objects is ushort[] bools)
  178. {
  179. for (int i = 0; i < 1; i++)
  180. {
  181. ml_morkf.LaserDistance = bools[i];
  182. }
  183. }
  184. }), 2);
  185. //获取坐标X
  186. GetStatus("VD828", new Action<object>((objects) =>
  187. {
  188. if (objects is int bools)
  189. {
  190. ml_morkf.ArmPositionX = bools;
  191. }
  192. }), 2);
  193. //获取坐标Y
  194. GetStatus("VD832", new Action<object>((objects) =>
  195. {
  196. if (objects is int bools)
  197. {
  198. ml_morkf.ArmPositionY = bools;
  199. }
  200. }), 2);
  201. //获取爪子到达位置
  202. GetStatus("M11.0", new Action<object>((objects) =>
  203. {
  204. if (objects is bool[] bools && bools.Length > 3)
  205. {
  206. ml_morkf.PawArrivePortOne = bools[0];
  207. ml_morkf.PawArrivePortTwo = bools[1];
  208. ml_morkf.PawArrivePortThree = bools[2];
  209. }
  210. }), 2);
  211. //获取总初始化完成
  212. GetStatus("M10.2", new Action<object>((objects) =>
  213. {
  214. if (objects is bool[] bools)
  215. {
  216. for (int i = 0; i < 1; i++)
  217. {
  218. ml_morkf.InitialComplete = bools[i];
  219. }
  220. }
  221. }), 2);
  222. //抓手初始化完成
  223. GetStatus("M10.3", new Action<object>((objects) =>
  224. {
  225. if (objects is bool[] bools)
  226. {
  227. for (int i = 0; i < 1; i++)
  228. {
  229. ml_morkf.PawInitialComplete = bools[i];
  230. }
  231. }
  232. }), 2);
  233. }
  234. public override void Stop()
  235. {
  236. IsHealth = false;
  237. }
  238. #region 调试代码
  239. public void CommandRegist()
  240. {
  241. #region 设备控制
  242. ActionManage.GetInstance.Register(PLCInite, "InitCommand");
  243. ActionManage.GetInstance.Register(StartOrder, "StartOrder");
  244. ActionManage.GetInstance.Register(StartOrderMain, "开始下单");
  245. ActionManage.GetInstance.Register(StartLocalOrder, "StartLocalOrder");
  246. ActionManage.GetInstance.Register(StopLocalOrder, "StopLocalOrder");
  247. #endregion
  248. #region 菜品库
  249. ActionManage.GetInstance.Register(new Action(() =>
  250. {
  251. ThreadManage.GetInstance().Start(new Action(() =>
  252. {
  253. FoodLibInit();
  254. }), "FoodLibInit");
  255. }), "FoodLibInit");
  256. ActionManage.GetInstance.Register(new Action<object>((o) =>
  257. {
  258. ThreadManage.GetInstance().Start(new Action(() =>
  259. {
  260. Electromagnetism(o);
  261. }), "Electromagnetism");
  262. }), "Electromagnetism");
  263. ActionManage.GetInstance.Register(new Action(() =>
  264. {
  265. ThreadManage.GetInstance().Start(new Action(() =>
  266. {
  267. PawToPoint1();
  268. }), "PawToPoint1");
  269. }), "PawToPoint1");
  270. ActionManage.GetInstance.Register(new Action(() =>
  271. {
  272. ThreadManage.GetInstance().Start(new Action(() =>
  273. {
  274. PawToPoint2();
  275. }), "PawToPoint2");
  276. }), "PawToPoint2");
  277. ActionManage.GetInstance.Register(new Action(() =>
  278. {
  279. ThreadManage.GetInstance().Start(new Action(() =>
  280. {
  281. PawToPoint3();
  282. }), "PawToPoint3");
  283. }), "PawToPoint3");
  284. ActionManage.GetInstance.Register(new Action(() =>
  285. {
  286. ThreadManage.GetInstance().Start(new Action(() =>
  287. {
  288. GetDistance_1();
  289. }), "GetDistance_1");
  290. }), "GetDistance_1");
  291. ActionManage.GetInstance.Register(new Action(() =>
  292. {
  293. ThreadManage.GetInstance().Start(new Action(() =>
  294. {
  295. GetDistance_2();
  296. }), "GetDistance_2");
  297. }), "GetDistance_2");
  298. ActionManage.GetInstance.Register(new Action(() =>
  299. {
  300. ThreadManage.GetInstance().Start(new Action(() =>
  301. {
  302. GetDistance_3();
  303. }), "GetDistance_3");
  304. }), "GetDistance_3");
  305. ActionManage.GetInstance.Register(PawTurnFront, "PawTurnFront");
  306. ActionManage.GetInstance.Register(PawTurnBack, "PawTurnBack");
  307. ActionManage.GetInstance.Register(new Action<object>((list) =>
  308. {
  309. ThreadManage.GetInstance().Start(new Action(() =>
  310. {
  311. if (list is List<int> list_int)
  312. {
  313. if (list_int.Count == 2)
  314. {
  315. SetArmPosition(list_int[0], list_int[1]);
  316. }
  317. }
  318. }), "SetArmPosition");
  319. }), "SetArmPosition");
  320. ActionManage.GetInstance.Register(new Action<object>((list) =>
  321. {
  322. if (list is bool startOrStop)
  323. {
  324. ArmRunUp(startOrStop);
  325. }
  326. }), "ArmRunUp");
  327. ActionManage.GetInstance.Register(new Action<object>((list) =>
  328. {
  329. if (list is bool startOrStop)
  330. {
  331. ArmRunDown(startOrStop);
  332. }
  333. }), "ArmRunDown");
  334. ActionManage.GetInstance.Register(new Action<object>((list) =>
  335. {
  336. if (list is bool startOrStop)
  337. {
  338. ArmRunLeft(startOrStop);
  339. }
  340. }), "ArmRunLeft");
  341. ActionManage.GetInstance.Register(new Action<object>((list) =>
  342. {
  343. if (list is bool startOrStop)
  344. {
  345. ArmRunRight(startOrStop);
  346. }
  347. }), "ArmRunRight");
  348. ActionManage.GetInstance.Register(new Action<object>((list) =>
  349. {
  350. ThreadManage.GetInstance().Start(new Action(() =>
  351. {
  352. if (list is List<int> list_int)
  353. {
  354. if (list_int.Count == 2)
  355. {
  356. SetNowPosition(list_int[0], list_int[1]);
  357. }
  358. }
  359. }), "SetNowPosition");
  360. }), "SetNowPosition");
  361. #endregion
  362. //ActionManage.GetInstance.Register(PLCInite, "InitCommand");
  363. #region 配料控制
  364. ActionManage.GetInstance.Register(new Action<object>((o) =>
  365. {
  366. ThreadManage.GetInstance().Start(new Action(() =>
  367. {
  368. OutSeasoning(o, fryIndex);
  369. }), "OutMaterials");
  370. }), "OutMaterials");
  371. //ActionManage.GetInstance.Register(OutSeasoning, "OutMaterials");
  372. #endregion
  373. #region 炒锅
  374. ActionManage.GetInstance.Register(new Action(() =>
  375. {
  376. ThreadManage.GetInstance().Start(new Action(() =>
  377. {
  378. Plc1Reset(fryIndex);
  379. }), "Plc1Reset");
  380. }), "Plc1Reset");
  381. ActionManage.GetInstance.Register(new Action(() =>
  382. {
  383. ThreadManage.GetInstance().Start(new Action(() =>
  384. {
  385. AddOil();
  386. }), "AddOil");
  387. }), "AddOil");
  388. ActionManage.GetInstance.Register(new Action(() =>
  389. {
  390. ThreadManage.GetInstance().Start(new Action(() =>
  391. {
  392. StartFire(fryIndex);
  393. }), "StartFire");
  394. }), "StartFire");
  395. ActionManage.GetInstance.Register(new Action(() =>
  396. {
  397. ThreadManage.GetInstance().Start(new Action(() =>
  398. {
  399. StopFire(fryIndex);
  400. }), "StopFire");
  401. }), "StopFire");
  402. ActionManage.GetInstance.Register(new Action(() =>
  403. {
  404. ThreadManage.GetInstance().Start(new Action(() =>
  405. {
  406. StartStir(fryIndex);
  407. }), "StartStir");
  408. }), "StartStir");
  409. ActionManage.GetInstance.Register(new Action(() =>
  410. {
  411. ThreadManage.GetInstance().Start(new Action(() =>
  412. {
  413. StopStir(fryIndex);
  414. }), "StopStir");
  415. }), "StopStir");
  416. ActionManage.GetInstance.Register(new Action(() =>
  417. {
  418. ThreadManage.GetInstance().Start(new Action(() =>
  419. {
  420. OutFood(fryIndex);
  421. }), "OutFood");
  422. }), "OutFood");
  423. ActionManage.GetInstance.Register(new Action(() =>
  424. {
  425. ThreadManage.GetInstance().Start(new Action(() =>
  426. {
  427. StirArmGoOrigin(fryIndex);
  428. }), "StirArmGoOrigin");
  429. }), "StirArmGoOrigin");
  430. ActionManage.GetInstance.Register(new Action(() =>
  431. {
  432. ThreadManage.GetInstance().Start(new Action(() =>
  433. {
  434. StirArmGoWork(fryIndex);
  435. }), "StirArmGoWork");
  436. }), "StirArmGoWork");
  437. ActionManage.GetInstance.Register(new Action(() =>
  438. {
  439. ThreadManage.GetInstance().Start(new Action(() =>
  440. {
  441. HBOTGoWork(fryIndex);
  442. }), "HBOTGoWork");
  443. }), "HBOTGoWork");
  444. ActionManage.GetInstance.Register(new Action(() =>
  445. {
  446. ThreadManage.GetInstance().Start(new Action(() =>
  447. {
  448. OutMeal(fryIndex);
  449. }), "OutMeal");
  450. }), "OutMeal");
  451. ActionManage.GetInstance.Register(new Action<object>((o) =>
  452. {
  453. ThreadManage.GetInstance().Start(new Action(() =>
  454. {
  455. SetFire(o, fryIndex);
  456. }), "SetFire");
  457. }), "SetFire");
  458. ActionManage.GetInstance.Register(new Action<object>((o) =>
  459. {
  460. ThreadManage.GetInstance().Start(new Action(() =>
  461. {
  462. SetFry(o);
  463. }), "SetFry");
  464. }), "SetFry");
  465. ActionManage.GetInstance.Register(new Action<object>((o) =>
  466. {
  467. ThreadManage.GetInstance().Start(new Action(() =>
  468. {
  469. SetStir(o, fryIndex);
  470. }), "SetStir");
  471. }), "SetStir");
  472. #endregion
  473. }
  474. /// <summary>
  475. /// 本地菜单下单
  476. /// </summary>
  477. private void StartOrder(object o)
  478. {
  479. if (o == null) return;
  480. if (o is int goodId)
  481. {
  482. var res = LocalstirFryGoods?.FirstOrDefault(p => p.GoodsKey == goodId);//匹配订单对应制作流程
  483. if (res != null)
  484. {
  485. /* morkF.listStirBom.Add(res.StirFryBomInfo);*///添加订单制作流程
  486. if (StirFryGoodsQuenes.Count > 0) return;
  487. StirFryGoodsQuenes.Enqueue(new OrderLocInfo()
  488. {
  489. SuborderId = Guid.NewGuid().ToString(),
  490. StirPotActions = res.StirPotActions,
  491. GoodName = "本地菜品"
  492. });
  493. MessageLog.GetInstance.Show($"添加本地订单{res.GoodsKey}");
  494. }
  495. }
  496. }
  497. /// <summary>
  498. /// 本地菜单下单
  499. /// </summary>
  500. private void StartOrderMain(object o)
  501. {
  502. if (o == null) return;
  503. if (o is string goodId)
  504. {
  505. var res = LocalstirFryGoods?.FirstOrDefault(p => p.GoodsKey.ToString() == goodId);//匹配订单对应制作流程
  506. if (res != null)
  507. {
  508. /* morkF.listStirBom.Add(res.StirFryBomInfo);*///添加订单制作流程
  509. if (StirFryGoodsQuenes.Count > 0) return;
  510. StirFryGoodsQuenes.Enqueue(new OrderLocInfo()
  511. {
  512. SuborderId = Guid.NewGuid().ToString(),
  513. StirPotActions = res.StirPotActions,
  514. GoodName = "本地菜品"
  515. });
  516. MessageLog.GetInstance.Show($"添加本地订单{res.GoodsKey}");
  517. }
  518. }
  519. }
  520. private void StartLocalOrder()
  521. {
  522. if (StirFryGoodsQuenes.Count > 0) return;//只能一个一个做
  523. if (Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions.Count > 0)
  524. {
  525. StirFryGoodsQuenes.Enqueue(new OrderLocInfo()
  526. {
  527. SuborderId = Guid.NewGuid().ToString(),
  528. StirPotActions = Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions,
  529. GoodName = "本地菜品"
  530. });
  531. MessageLog.GetInstance.Show($"添加本地模拟的订单{Json<LocalPotStep>.Data.LocalstirFryGoods.GoodsKey}");
  532. }
  533. }
  534. /// <summary>
  535. /// 停止本地菜单炒制
  536. /// </summary>
  537. private void StopLocalOrder(int num = -1)
  538. {
  539. //判断当前是否有炒制菜品
  540. if (nowStirFryGood == null) return;
  541. //根据morkFs中是否有num执行不同的停止操作
  542. if (!morkFs.ContainsKey(num))
  543. {
  544. //根据调试界面的当前炒锅编号停止炒制线程
  545. ThreadManage.GetInstance().StopTask(String.Format(striConst, fryIndex.ToString(), nowStirFryGood[fryIndex].GoodName), new Action(() => { Plc1Reset(fryIndex); }));
  546. }
  547. else
  548. {
  549. //根据炒锅编号停止炒制线程
  550. ThreadManage.GetInstance().StopTask(String.Format(striConst, fryIndex.ToString(), nowStirFryGood[num].GoodName), new Action(() => { Plc1Reset(num); }));
  551. }
  552. }
  553. /// <summary>
  554. /// 重置程序
  555. /// </summary>
  556. public override void ResetProgram()
  557. {
  558. IsHealth = true;
  559. morkFs.Clear();
  560. morkFs = new Dictionary<int, GVL_MorkF>();
  561. ml_morkf = new ML_MorkF();
  562. //根据编号new炒锅实例对象
  563. for (int i = 0; i < count; i++)
  564. {
  565. morkFs.Add(i, new GVL_MorkF());
  566. }
  567. }
  568. #endregion
  569. #region 公用PLC方法
  570. /// <summary>
  571. /// 获取设备PLC的所有状态
  572. /// </summary>
  573. /// <param name="key"></param>
  574. /// <param name="action"></param>
  575. /// <param name="num">炒锅编号</param>
  576. private void GetStatus(string key, Action<object> action, int num)
  577. {
  578. if (dicPort2peripheralStatus.ContainsKey(num))
  579. {
  580. if (dicPort2peripheralStatus[num].ContainsKey(key))
  581. {
  582. action((object)dicPort2peripheralStatus[num][key]);//获取PLC指定地址的状态值
  583. }
  584. }
  585. }
  586. /// <summary>
  587. /// PLC数据读取
  588. /// </summary>
  589. public override void ReadData()
  590. {
  591. for (int i = 0; i < morkFs.Count; i++)
  592. {
  593. GetStatus("LB50", new Action<object>((objects) =>
  594. {
  595. if (!morkFs.ContainsKey(i))
  596. {
  597. return;
  598. }
  599. if (objects is bool[] bools)
  600. {
  601. morkFs[i].FryPot1_InitialComplete = bools[0];
  602. morkFs[i].FryPot1_HOBTPut = bools[1];
  603. morkFs[i].FryPot1_HOBTGet = bools[2];
  604. morkFs[i].FryPot1_MaterialIntoPot = bools[3];
  605. morkFs[i].OutFoodCompelete = bools[4];
  606. morkFs[i].CanOutFood = bools[5];
  607. morkFs[i].GetFoodCompelete = bools[6];
  608. morkFs[i].CanOutPotWashingWater = bools[7];
  609. morkFs[i].ArmOnOrigin = bools[8];
  610. morkFs[i].ArmOnWorking = bools[9];
  611. morkFs[i].PotOnOrigin = bools[10];
  612. }
  613. }), i);
  614. }
  615. for (int j = 0; j < morkFs.Count; j++)
  616. {
  617. GetStatus("LB74", new Action<object>((objects) =>
  618. {
  619. if (!morkFs.ContainsKey(j))
  620. {
  621. return;
  622. }
  623. if (objects is bool[] bools)
  624. {
  625. for (int i = 0; i < 14; i++)
  626. {
  627. morkFs[j].PassWay1_Compelete[i] = bools[i];
  628. }
  629. }
  630. }), j);
  631. }
  632. for (int i = 0; i < morkFs.Count; i++)
  633. {
  634. if (!morkFs.ContainsKey(i))
  635. {
  636. return;
  637. }
  638. GetStatus("LB90", new Action<object>((objects) =>
  639. {
  640. if (objects is bool[] bools)
  641. {
  642. morkFs[i].AutoMode = bools[0];
  643. }
  644. }), i);
  645. }
  646. }
  647. #endregion
  648. #region 菜品库PLC操作方法
  649. /// <summary>
  650. /// 菜品库数据写入
  651. /// </summary>
  652. /// <param name="address"></param>
  653. /// <param name="value"></param>
  654. private void MaterailLibrary_Write(string address, object value, int num = 2)
  655. {
  656. WriteControlExact(address, value, num);
  657. }
  658. /// <summary>
  659. /// 菜品库初始化
  660. /// </summary>
  661. public bool FoodLibInit()
  662. {
  663. MaterailLibrary_Write("M0.2", true);
  664. Thread.Sleep(500);
  665. for (int i = 0; i < materialSleepCount && !ml_morkf.InitialComplete; i++)
  666. {
  667. Thread.Sleep(materialSleepTime);
  668. if (i >= materialSleepCount - 1)
  669. {
  670. MessageLog.GetInstance.Show("菜品库初始化超时");
  671. return false;
  672. }
  673. }
  674. return true;
  675. }
  676. /// <summary>
  677. /// 电磁阀启停
  678. /// </summary>
  679. /// <param name="o">电磁阀启停:true:启动。false:停止。</param>
  680. public void Electromagnetism(object o)
  681. {
  682. if (!ml_morkf.InitialComplete)
  683. {
  684. return;
  685. }
  686. if (o == null) return;
  687. if (o is List<bool> bs && bs.Count == 1)
  688. {
  689. MaterailLibrary_Write("M1.3", bs[0]);
  690. }
  691. }
  692. public bool PawToPoint1()
  693. {
  694. if (!ml_morkf.InitialComplete)
  695. {
  696. return false;
  697. }
  698. MessageLog.GetInstance.Show("爪子去到1号位");
  699. MaterailLibrary_Write("M1.0", true);
  700. for (int i = 0; i < materialSleepCount && !ml_morkf.PawArrivePortOne; i++)
  701. {
  702. Thread.Sleep(materialSleepTime);
  703. if (i >= materialSleepCount - 1)
  704. {
  705. MessageLog.GetInstance.Show("爪子去到1号位超时");
  706. return false;
  707. }
  708. }
  709. Thread.Sleep(300);
  710. MessageLog.GetInstance.Show("爪子去到1号位完成");
  711. return true;
  712. }
  713. public bool PawToPoint2()
  714. {
  715. if (!ml_morkf.InitialComplete)
  716. {
  717. return false;
  718. }
  719. MessageLog.GetInstance.Show("爪子去到2号位");
  720. MaterailLibrary_Write("M1.1", true);
  721. for (int i = 0; i < materialSleepCount && !ml_morkf.PawArrivePortTwo; i++)
  722. {
  723. Thread.Sleep(materialSleepTime);
  724. if (i >= materialSleepCount - 1)
  725. {
  726. MessageLog.GetInstance.Show("爪子去到2号位超时");
  727. return false;
  728. }
  729. }
  730. Thread.Sleep(300);
  731. MessageLog.GetInstance.Show("爪子去到2号位完成");
  732. return true;
  733. }
  734. public bool PawToPoint3()
  735. {
  736. if (!ml_morkf.InitialComplete)
  737. {
  738. return false;
  739. }
  740. MessageLog.GetInstance.Show("爪子去到3号位");
  741. MaterailLibrary_Write("M1.2", true);
  742. for (int i = 0; i < materialSleepCount && !ml_morkf.PawArrivePortThree; i++)
  743. {
  744. Thread.Sleep(materialSleepTime);
  745. if (i >= materialSleepCount - 1)
  746. {
  747. MessageLog.GetInstance.Show("爪子去到3号位超时");
  748. return false;
  749. }
  750. }
  751. Thread.Sleep(300);
  752. MessageLog.GetInstance.Show("爪子去到3号位完成");
  753. return true;
  754. }
  755. public bool GetDistance_1()
  756. {
  757. if (!ml_morkf.InitialComplete)
  758. {
  759. return false;
  760. }
  761. MaterailLibrary_Write("M0.3", true);
  762. MaterailLibrary_Write("M0.3", false);
  763. Thread.Sleep(300);
  764. MessageLog.GetInstance.Show("1号测距开启完成");
  765. return true;
  766. }
  767. public bool GetDistance_2()
  768. {
  769. if (!ml_morkf.InitialComplete)
  770. {
  771. return false;
  772. }
  773. MaterailLibrary_Write("M0.4", true);
  774. MaterailLibrary_Write("M0.4", false);
  775. Thread.Sleep(300);
  776. MessageLog.GetInstance.Show("2号测距开启完成");
  777. return true;
  778. }
  779. public bool GetDistance_3()
  780. {
  781. if (!ml_morkf.InitialComplete)
  782. {
  783. return false;
  784. }
  785. MaterailLibrary_Write("M0.5", true);
  786. MaterailLibrary_Write("M0.5", false);
  787. Thread.Sleep(300);
  788. MessageLog.GetInstance.Show("3号测距开启完成");
  789. return true;
  790. }
  791. /// <summary>
  792. /// 根据x坐标获取传感器距离
  793. /// </summary>
  794. /// <param name="x"></param>
  795. /// <returns></returns>
  796. public bool GetDistance(int x)
  797. {
  798. bool ret = true;
  799. //是否在第一层菜品库
  800. if (x > 0 && x <= materialLaserHigh)
  801. {
  802. //获取传感器1的距离
  803. ret &= GetDistance_1();
  804. Thread.Sleep(400);
  805. //获取传感器1的距离
  806. ret &= GetDistance_1();
  807. }
  808. //是否在第二层菜品库
  809. else if (x > materialLaserHigh && x <= (2 * materialLaserHigh + clapboardLaserHigh))
  810. {
  811. //获取传感器2的距离
  812. ret &= GetDistance_2();
  813. Thread.Sleep(400);
  814. ret &= GetDistance_2();
  815. }
  816. //是否在第三层菜品库
  817. else if (x > (2 * materialLaserHigh + clapboardLaserHigh) && x <= (3 * materialLaserHigh + 2 * clapboardLaserHigh))
  818. {
  819. //获取传感器3的距离
  820. ret &= GetDistance_3();
  821. Thread.Sleep(400);
  822. ret &= GetDistance_3();
  823. }
  824. if (!ret)
  825. {
  826. MessageLog.GetInstance.Show($"错误:X轴:{x}获取传感器数据出错");
  827. }
  828. return ret;
  829. }
  830. public void PawTurnFront()
  831. {
  832. MaterailLibrary_Write("", true);
  833. }
  834. public void PawTurnBack()
  835. {
  836. MaterailLibrary_Write("", true);
  837. }
  838. /// <summary>
  839. /// 设定机械臂的位置
  840. /// </summary>
  841. /// <param name="x"></param>
  842. /// <param name="y"></param>
  843. public bool SetArmPosition(int x, int y)
  844. {
  845. if (!ml_morkf.InitialComplete)
  846. {
  847. return false;
  848. }
  849. //取反
  850. x -= 2 * x;
  851. y -= 2 * y;
  852. if (x > 0 || y > 0)
  853. {
  854. MessageLog.GetInstance.Show($"机械臂移动到[{x},{y}]非法");
  855. return false;
  856. }
  857. MaterailLibrary_Write("VD836", x);
  858. Thread.Sleep(100);
  859. MaterailLibrary_Write("VD840", y);
  860. Thread.Sleep(200);
  861. MessageLog.GetInstance.Show($"机械臂移动到[{x},{y}]");
  862. //到达置为false
  863. ml_morkf.ArriveComplete = false;
  864. //定位启动
  865. MaterailLibrary_Write("M0.0", true);
  866. Thread.Sleep(400);
  867. for (int i = 0; i < materialSleepCount && (!ml_morkf.ArriveComplete); i++)
  868. {
  869. Thread.Sleep(materialSleepTime);
  870. //若是目标点与当前坐标一致,跳出循环
  871. if((ml_morkf.ArmPositionX == x && ml_morkf.ArmPositionY == y))
  872. {
  873. MessageLog.GetInstance.Show($"机械臂已移动到[{ml_morkf.ArmPositionX},{ml_morkf.ArmPositionY}]");
  874. break;
  875. }
  876. if (i >= materialSleepCount - 1)
  877. {
  878. MessageLog.GetInstance.Show("机械臂移动操作超时");
  879. return false;
  880. }
  881. }
  882. MessageLog.GetInstance.Show("机械臂移动操作完成");
  883. Thread.Sleep(500);
  884. return true;
  885. }
  886. /// <summary>
  887. /// 设定机械臂的当前坐标
  888. /// </summary>
  889. /// <param name="x"></param>
  890. /// <param name="y"></param>
  891. public void SetNowPosition(int x, int y)
  892. {
  893. //取反
  894. x -= 2 * x;
  895. y -= 2 * y;
  896. MessageLog.GetInstance.Show($"设置机械臂当前坐标为[{x},{y}]");
  897. MaterailLibrary_Write("VD828", x);
  898. Thread.Sleep(200);
  899. MaterailLibrary_Write("VD832", y);
  900. Thread.Sleep(200);
  901. }
  902. /// <summary>
  903. /// 机械臂向上移动开关
  904. /// </summary>
  905. /// <param name="startOrStop">true:开启,false:关闭</param>
  906. public void ArmRunUp(bool startOrStop)
  907. {
  908. MaterailLibrary_Write("M5.3", startOrStop);
  909. Thread.Sleep(200);
  910. }
  911. /// <summary>
  912. /// 机械臂向下移动开关
  913. /// </summary>
  914. /// <param name="startOrStop">true:开启,false:关闭</param>
  915. public void ArmRunDown(bool startOrStop)
  916. {
  917. MaterailLibrary_Write("M5.4", startOrStop);
  918. Thread.Sleep(200);
  919. }
  920. /// <summary>
  921. /// 机械臂向左移动开关
  922. /// </summary>
  923. /// <param name="startOrStop">true:开启,false:关闭</param>
  924. public void ArmRunLeft(bool startOrStop)
  925. {
  926. MaterailLibrary_Write("M5.5", startOrStop);
  927. Thread.Sleep(200);
  928. }
  929. /// <summary>
  930. /// 机械臂向右移动开关
  931. /// </summary>
  932. /// <param name="startOrStop">true:开启,false:关闭</param>
  933. public void ArmRunRight(bool startOrStop)
  934. {
  935. MaterailLibrary_Write("M5.6", startOrStop);
  936. Thread.Sleep(200);
  937. }
  938. //菜品库锁
  939. object lock_Materail = new object();
  940. /// <summary>
  941. /// 取菜操作
  942. /// </summary>
  943. /// <param name="x">取菜x轴坐标</param>
  944. /// <param name="y">取菜y轴坐标</param>
  945. /// <param name="fryNum">炒锅编号</param>
  946. public bool GetMaterail(int x, int y, int fryNum)
  947. {
  948. //设置到抓菜处
  949. if (!SetArmPosition(x, y))
  950. {
  951. return false;
  952. }
  953. if (!GetDistance(x))
  954. {
  955. MessageLog.GetInstance.Show("错误:获取传感器数据出错");
  956. return false;
  957. }
  958. Thread.Sleep(1000);
  959. //获取传感器的距离,转换成坐标系的点
  960. int laserHigh = ml_morkf.LaserDistance;
  961. MessageLog.GetInstance.Show($"传感器的距离{laserHigh}");
  962. if (laserHigh > 29)
  963. {
  964. MessageLog.GetInstance.Show("错误:传感器获取数据大于隔板与传感器之间的距离");
  965. return false;
  966. }
  967. int moveX = 0;
  968. if (LaserDistance2Coordinate(laserHigh, out moveX) != Laser2CoordinateState.MaterialNormal)
  969. {
  970. MessageLog.GetInstance.Show("错误:传感器距离转坐标值失败");
  971. return false;
  972. }
  973. if(x < moveX)
  974. {
  975. MessageLog.GetInstance.Show("错误:传感器距离转坐标值大于当前x轴坐标");
  976. return false;
  977. }
  978. //设置到传感器感应的距离处
  979. if (!SetArmPosition(x - moveX, y))
  980. {
  981. return false;
  982. }
  983. ////关闭电磁阀
  984. //Electromagnetism(new List<bool> { true });
  985. //Thread.Sleep(500);
  986. #if true
  987. //爪子去1号位抓菜
  988. if (!PawToPoint1())
  989. {
  990. return false;
  991. }
  992. #endif
  993. //设置到该层菜品库最高处
  994. if (!SetArmPosition(x - materialHigh, y))
  995. {
  996. return false;
  997. }
  998. ////移动前开启电磁阀
  999. //Electromagnetism(new List<bool> { false });
  1000. //Thread.Sleep(500);
  1001. #if true
  1002. //爪子去2号位放菜
  1003. if (!PawToPoint2())
  1004. {
  1005. return false;
  1006. }
  1007. #endif
  1008. ////判断炒锅是否可以放盒
  1009. //for (int i = 0; materialSleepCount > i && !morkFs[fryIndex].FryPot1_HOBTPut; i++)
  1010. //{
  1011. // Thread.Sleep(materialSleepTime);
  1012. // if (i >= materialSleepCount - 1)
  1013. // {
  1014. // MessageLog.GetInstance.Show("等待炒锅允许放盒超时");
  1015. // return;
  1016. // }
  1017. //}
  1018. //关闭启磁吸
  1019. MagnetOff(fryNum);
  1020. Thread.Sleep(200);
  1021. //根据炒锅不同设置不同的出菜处
  1022. if (fryNum % 2 == 0)
  1023. {
  1024. x = materialPutPositionXFry1;
  1025. y = materialPutPositionYFry1;
  1026. }
  1027. else
  1028. {
  1029. x = materialPutPositionXFry2;
  1030. y = materialPutPositionYFry2;
  1031. }
  1032. //设置到炒锅1出菜处
  1033. if (!SetArmPosition(x, y))
  1034. {
  1035. return false;
  1036. }
  1037. #if true
  1038. //爪子去3号位放菜
  1039. if (!PawToPoint3())
  1040. {
  1041. return false;
  1042. }
  1043. #endif
  1044. //开启磁吸
  1045. MagnetOn(fryNum);
  1046. Thread.Sleep(200);
  1047. //设置到炒锅1出菜处
  1048. if (!SetArmPosition(x + materialToFryDistance, y))
  1049. {
  1050. return false;
  1051. }
  1052. #if true
  1053. //爪子回到2号位
  1054. if (!PawToPoint2())
  1055. {
  1056. return false;
  1057. }
  1058. #endif
  1059. ////关闭电磁阀
  1060. //Electromagnetism(new List<bool> { false });
  1061. //Thread.Sleep(300);
  1062. if (morkFs.ContainsKey(fryNum))
  1063. {
  1064. morkFs[fryNum].GetMaterialComplete = true;
  1065. }
  1066. return true;
  1067. }
  1068. /// <summary>
  1069. /// 更新菜品库存量
  1070. /// </summary>
  1071. /// <returns></returns>
  1072. public bool UpdateMaterialLibraryStock()
  1073. {
  1074. try
  1075. {
  1076. //判断是否初始化
  1077. if(!ml_morkf.InitialComplete)
  1078. {
  1079. return false;
  1080. }
  1081. foreach(var item in MaterialCoordinate.dicNoMaterialCoordinate)
  1082. {
  1083. //设置到抓菜处
  1084. if (!SetArmPosition(item.Value.X, item.Value.Y))
  1085. {
  1086. return false;
  1087. }
  1088. //获取该处的距离
  1089. if (!GetDistance(item.Value.X))
  1090. {
  1091. MessageLog.GetInstance.Show("错误:获取传感器数据出错");
  1092. return false;
  1093. }
  1094. Thread.Sleep(1000);
  1095. //获取传感器的距离
  1096. int laserHigh = ml_morkf.LaserDistance;
  1097. int surplus = 0;
  1098. //根据距离算出菜品余量
  1099. Laser2CoordinateState state = LaserDistance2MaterialCount(laserHigh, out surplus);
  1100. if (state != Laser2CoordinateState.MaterialNormal || state != Laser2CoordinateState.MaterialEmpty)
  1101. {
  1102. return false;
  1103. }
  1104. //更新菜品余量
  1105. if (!MaterialSurplusOperation.GetInstance().UpdateSurplus(item.Key, surplus))
  1106. {
  1107. return false;
  1108. }
  1109. }
  1110. return true;
  1111. }
  1112. catch(Exception ex)
  1113. {
  1114. return false;
  1115. }
  1116. }
  1117. /// <summary>
  1118. /// 传感器距离转为x轴坐标系
  1119. /// </summary>
  1120. /// <param name="distance"></param>
  1121. /// <param name="x"></param>
  1122. /// <returns></returns>
  1123. public Laser2CoordinateState LaserDistance2Coordinate(int distance,out int x)
  1124. {
  1125. x = 0;
  1126. try
  1127. {
  1128. //菜盒放多了
  1129. if (distance<6)
  1130. {
  1131. return Laser2CoordinateState.MaterialOverdo;
  1132. }
  1133. else if (distance >= 6 && distance < 10)
  1134. {
  1135. x = 24882;
  1136. return Laser2CoordinateState.MaterialNormal;
  1137. }
  1138. else if(distance>=10 && distance < 14)
  1139. {
  1140. x = 18661;
  1141. return Laser2CoordinateState.MaterialNormal;
  1142. }
  1143. else if(distance >= 14 && distance < 19)
  1144. {
  1145. x = 12441;
  1146. return Laser2CoordinateState.MaterialNormal;
  1147. }
  1148. else if (distance >= 19 && distance < 23)
  1149. {
  1150. x = 6220;
  1151. return Laser2CoordinateState.MaterialNormal;
  1152. }
  1153. else if (distance >= 23 && distance < 28)
  1154. {
  1155. x = 0;
  1156. return Laser2CoordinateState.MaterialNormal;
  1157. }
  1158. else
  1159. {
  1160. return Laser2CoordinateState.MaterialEmpty;
  1161. }
  1162. }
  1163. catch(Exception ex)
  1164. {
  1165. return Laser2CoordinateState.MaterialUnkown;
  1166. }
  1167. }
  1168. /// <summary>
  1169. /// 传感器距离转为菜品数量
  1170. /// </summary>
  1171. /// <param name="distance"></param>
  1172. /// <param name="x"></param>
  1173. /// <returns></returns>
  1174. public Laser2CoordinateState LaserDistance2MaterialCount(int distance, out int count)
  1175. {
  1176. count = 0;
  1177. try
  1178. {
  1179. //菜盒放多了
  1180. if (distance < 6)
  1181. {
  1182. return Laser2CoordinateState.MaterialOverdo;
  1183. }
  1184. else if (distance >= 6 && distance < 10)
  1185. {
  1186. count = 5;
  1187. return Laser2CoordinateState.MaterialNormal;
  1188. }
  1189. else if (distance >= 10 && distance < 14)
  1190. {
  1191. count = 4;
  1192. return Laser2CoordinateState.MaterialNormal;
  1193. }
  1194. else if (distance >= 14 && distance < 19)
  1195. {
  1196. count = 3;
  1197. return Laser2CoordinateState.MaterialNormal;
  1198. }
  1199. else if (distance >= 19 && distance < 23)
  1200. {
  1201. count = 2;
  1202. return Laser2CoordinateState.MaterialNormal;
  1203. }
  1204. else if (distance >= 23 && distance < 28)
  1205. {
  1206. count = 1;
  1207. return Laser2CoordinateState.MaterialNormal;
  1208. }
  1209. else
  1210. {
  1211. count = 0;
  1212. return Laser2CoordinateState.MaterialEmpty;
  1213. }
  1214. }
  1215. catch (Exception ex)
  1216. {
  1217. return Laser2CoordinateState.MaterialUnkown;
  1218. }
  1219. }
  1220. /// <summary>
  1221. /// 获取菜品测试
  1222. /// </summary>
  1223. /// <param name="isGet"></param>
  1224. private void GetMaterailTest(MaterialOperation materialOperation)
  1225. {
  1226. ThreadManage.GetInstance().Start(new Action(() => {
  1227. bool ret = false;
  1228. try
  1229. {
  1230. Coordinate myCoordinate = new Coordinate();
  1231. //获取坐标,根据菜品的位置信息
  1232. if (!NoMaterial2Coordinate(materialOperation.materialInfo.Loc, out myCoordinate))
  1233. {
  1234. MessageLog.GetInstance.Show($"炒锅{materialOperation.fryNum}获取菜品[{materialOperation.materialInfo.Name}]失败,找不到对应位置");
  1235. return;
  1236. }
  1237. lock (lock_Materail)
  1238. {
  1239. ml_morkf.MaterailIsWorking = true;
  1240. }
  1241. //取菜操作
  1242. ret =GetMaterail(myCoordinate.X, myCoordinate.Y, materialOperation.fryNum);
  1243. }
  1244. catch (Exception ex)
  1245. {
  1246. ret = false;
  1247. }
  1248. finally
  1249. {
  1250. lock (lock_Materail)
  1251. {
  1252. ml_morkf.MaterailIsWorking = false;
  1253. }
  1254. if (ret == true)
  1255. {
  1256. //指定位置菜品减一
  1257. MaterialSurplusOperation.GetInstance().ReduceSurplus(materialOperation.materialInfo.Loc);
  1258. }
  1259. }
  1260. }), $"菜品库操作");
  1261. }
  1262. #endregion
  1263. #region 炒锅PLC基本操作方法
  1264. /// <summary>
  1265. /// 炒锅写寄存器方法,num为炒锅对应编号,从0开始
  1266. /// </summary>
  1267. /// <param name="address">寄存器地址</param>
  1268. /// <param name="value">值</param>
  1269. /// <param name="num">炒锅编号</param>
  1270. private void FirePot_Write(string address, object value, int num)
  1271. {
  1272. WriteControlExact(address, value, num);
  1273. }
  1274. /// <summary>
  1275. /// 出调料
  1276. /// </summary>
  1277. /// <param name="o"></param>
  1278. public void OutSeasoning(object o, int num)
  1279. {
  1280. if (o == null) return;
  1281. if (o is List<int> ints && ints.Count == 2 && morkFs.ContainsKey(num))
  1282. {
  1283. FirePot_Write(morkFs[num].PassWayValue[ints[0]], (ushort)ints[1], num);//写入通道值
  1284. Thread.Sleep(400);
  1285. FirePot_Write(morkFs[num].StartPassWay[ints[0]], true, num);//开启通道
  1286. Thread.Sleep(400);
  1287. FirePot_Write(morkFs[num].StartPassWay[ints[0]], false, num);//开启通道
  1288. }
  1289. }
  1290. /// <summary>
  1291. /// 出多个调料
  1292. /// </summary>
  1293. public void OutSeasonings(List<SeasoningList> seasoningLists, int num)
  1294. {
  1295. //防止越界
  1296. if (!morkFs.ContainsKey(num))
  1297. {
  1298. return;
  1299. }
  1300. foreach (SeasoningList seasoning in seasoningLists)
  1301. {
  1302. FirePot_Write(morkFs[num].PassWayValue[seasoning.Loc], (ushort)seasoning.Qty, num);
  1303. Thread.Sleep(300);
  1304. }
  1305. foreach (SeasoningList seasoning in seasoningLists)
  1306. {
  1307. FirePot_Write(morkFs[num].StartPassWay[seasoning.Loc], true, num);
  1308. Thread.Sleep(300);
  1309. }
  1310. foreach (SeasoningList seasoning in seasoningLists)
  1311. {
  1312. FirePot_Write(morkFs[num].StartPassWay[seasoning.Loc], false, num);
  1313. Thread.Sleep(300);
  1314. }
  1315. foreach (SeasoningList seasoning in seasoningLists)
  1316. {
  1317. FirePot_Write(morkFs[num].StartPassWay[seasoning.Loc], false, num);
  1318. Thread.Sleep(300);
  1319. }
  1320. }
  1321. /// <summary>
  1322. /// 复位
  1323. /// </summary>
  1324. public void Plc1Reset(int num)
  1325. {
  1326. ThreadManage.GetInstance().Start(new Action(() =>
  1327. {
  1328. StopFire(num);
  1329. Thread.Sleep(200);
  1330. StopStir(num);
  1331. Thread.Sleep(200);
  1332. FirePot_Write("LB5", false, num);
  1333. Thread.Sleep(200);
  1334. FirePot_Write("LB3", false, num);
  1335. Thread.Sleep(200);
  1336. FirePot_Write("LB6", false, num);
  1337. Thread.Sleep(200);
  1338. FirePot_Write("LB7", false, num);
  1339. Thread.Sleep(200);
  1340. FirePot_Write("LB4", false, num);
  1341. Thread.Sleep(200);
  1342. FirePot_Write("LB53", false, num);
  1343. if (morkFs.ContainsKey(num))
  1344. {
  1345. foreach (var item in morkFs[num].StartPassWay.Values)
  1346. {
  1347. Thread.Sleep(200);
  1348. FirePot_Write(item, false, num);
  1349. }
  1350. }
  1351. }), "炒锅1初始化");
  1352. }
  1353. /// <summary>
  1354. /// 炒锅初始化
  1355. /// </summary>
  1356. public void PLCInite()
  1357. {
  1358. for (int i = 0; i < morkFs.Count; i++)
  1359. {
  1360. FirePot_Write("LB0", true, i);
  1361. for (int j = 0; j < sleepCount && !morkFs[i].FryPot1_InitialComplete; j++)
  1362. {
  1363. Thread.Sleep(sleepTime);
  1364. if (j >= sleepCount - 1)
  1365. {
  1366. MessageLog.GetInstance.Show($"炒锅{j}初始化超时");
  1367. }
  1368. }
  1369. //while (!morkFs[i].FryPot1_InitialComplete)
  1370. //{
  1371. // Thread.Sleep(500);
  1372. //}
  1373. FirePot_Write("LB0", false, i);
  1374. }
  1375. }
  1376. //加油
  1377. public void AddOil()
  1378. {
  1379. }
  1380. //加热启动
  1381. public void StartFire(int num)
  1382. {
  1383. FirePot_Write("LB1", true, num);
  1384. Thread.Sleep(200);
  1385. }
  1386. //加热停止
  1387. public void StopFire(int num)
  1388. {
  1389. FirePot_Write("LB1", false, num);
  1390. Thread.Sleep(200);
  1391. }
  1392. //搅拌启动
  1393. public void StartStir(int num)
  1394. {
  1395. FirePot_Write("LB2", true, num);
  1396. Thread.Sleep(200);
  1397. }
  1398. //搅拌启停止
  1399. public void StopStir(int num)
  1400. {
  1401. FirePot_Write("LB2", false, num);
  1402. Thread.Sleep(200);
  1403. }
  1404. //倒菜
  1405. public void OutFood(int num,bool isMaterial = false)
  1406. {
  1407. if (!morkFs.ContainsKey(num))
  1408. {
  1409. return;
  1410. }
  1411. int i = 0;
  1412. if(isMaterial)
  1413. {
  1414. //判断是否完成取菜
  1415. for (i = 0; i < materialSleepCount && !morkFs[num].GetMaterialComplete; i++)
  1416. {
  1417. if (i == 10)
  1418. {
  1419. //停止搅拌
  1420. StopStir(num);
  1421. //火力设置为2档
  1422. SetFire(new List<int> { 2 }, num);
  1423. }
  1424. Thread.Sleep(materialSleepTime);
  1425. if (i >= materialSleepCount - 1)
  1426. {
  1427. MessageLog.GetInstance.Show($"炒锅{num}倒菜超时:未能等到取菜完成");
  1428. return;
  1429. }
  1430. }
  1431. if (i > 9)
  1432. {
  1433. //开启搅拌
  1434. StartStir(num);
  1435. //火力设置回原本火力
  1436. SetFire(new List<int> { morkFs[num].Fire }, num);
  1437. }
  1438. }
  1439. FirePot_Write("LB3", true, num);
  1440. MessageLog.GetInstance.Show("倒菜启动");
  1441. Thread.Sleep(500);
  1442. for (i = 0; i < materialSleepCount && !morkFs[num].FryPot1_MaterialIntoPot; i++)
  1443. {
  1444. Thread.Sleep(materialSleepTime);
  1445. if (i >= materialSleepCount - 1)
  1446. {
  1447. MessageLog.GetInstance.Show($"炒锅{num}倒菜超时");
  1448. }
  1449. }
  1450. FirePot_Write("LB3", false, num);
  1451. Thread.Sleep(200);
  1452. MessageLog.GetInstance.Show("倒菜完成");
  1453. morkFs[num].GetMaterialComplete = false;
  1454. }
  1455. //搅拌臂去原点位
  1456. public void StirArmGoOrigin(int num)
  1457. {
  1458. if (!morkFs.ContainsKey(num))
  1459. {
  1460. return;
  1461. }
  1462. FirePot_Write("LB5", true, num);
  1463. MessageLog.GetInstance.Show("搅拌臂去原点位");
  1464. for (int i = 0; i < sleepCount && !morkFs[num].ArmOnOrigin; i++)
  1465. {
  1466. Thread.Sleep(sleepTime);
  1467. if (i >= sleepCount - 1)
  1468. {
  1469. MessageLog.GetInstance.Show($"炒锅{num}搅拌臂去原点位超时");
  1470. }
  1471. }
  1472. FirePot_Write("LB5", false, num);
  1473. Thread.Sleep(200);
  1474. MessageLog.GetInstance.Show("搅拌臂到达原点位");
  1475. }
  1476. //搅拌臂去炒制位
  1477. public void StirArmGoWork(int num)
  1478. {
  1479. if (!morkFs.ContainsKey(num))
  1480. {
  1481. return;
  1482. }
  1483. if (!morkFs[num].ArmOnWorking/* && morkFs[num].PotOnOrigin*/)
  1484. {
  1485. FirePot_Write("LB6", true, num);
  1486. MessageLog.GetInstance.Show("搅拌臂去工作位");
  1487. for (int i = 0; i < sleepCount && !morkFs[num].ArmOnWorking; i++)
  1488. {
  1489. Thread.Sleep(sleepTime);
  1490. if (i >= sleepCount - 1)
  1491. {
  1492. MessageLog.GetInstance.Show($"炒锅{num}搅拌臂去炒制位超时");
  1493. }
  1494. }
  1495. //while (!morkFs[num].ArmOnWorking)
  1496. //{
  1497. // Thread.Sleep(200);
  1498. //}
  1499. FirePot_Write("LB6", false, num);
  1500. Thread.Sleep(200);
  1501. MessageLog.GetInstance.Show("搅拌臂到达工作位");
  1502. }
  1503. }
  1504. //HBOT放盒子到位
  1505. public void HBOTGoWork(int num)
  1506. {
  1507. FirePot_Write("LB7", true, num);
  1508. Thread.Sleep(400);
  1509. FirePot_Write("LB7", false, num);
  1510. }
  1511. //出餐启动
  1512. public void OutMeal(int num)
  1513. {
  1514. if (!morkFs[num].ArmOnOrigin /*&& morkFs[num].PotOnOrigin*/)
  1515. {
  1516. MessageLog.GetInstance.Show("搅拌臂不在原点位,无法完成出餐");
  1517. return;
  1518. }
  1519. FirePot_Write("LB4", true, num);
  1520. Thread.Sleep(200);
  1521. FirePot_Write("LB4", false, num);
  1522. }
  1523. //加热挡位设定
  1524. public void SetFire(object o, int num)
  1525. {
  1526. if (o == null) return;
  1527. if (o is List<int> ints && ints.Count == 1)
  1528. {
  1529. FirePot_Write("LW14", (ushort)ints[0], num);
  1530. Thread.Sleep(200);
  1531. }
  1532. }
  1533. public void SetFry(object o)
  1534. {
  1535. if (o == null) return;
  1536. if (o is List<int> ints && ints.Count == 1)
  1537. {
  1538. fryIndex = ints[0] - 1;
  1539. }
  1540. }
  1541. /// <summary>
  1542. /// 搅拌挡位设定
  1543. /// </summary>
  1544. /// <param name="o"></param>
  1545. public void SetStir(object o, int num)
  1546. {
  1547. if (o == null) return;
  1548. if (o is List<int> ints && ints.Count == 1)
  1549. {
  1550. FirePot_Write("LW15", (ushort)ints[0], num);
  1551. Thread.Sleep(200);
  1552. }
  1553. }
  1554. public void MagnetOn(int num)
  1555. {
  1556. FirePot_Write("LB8", false, num);
  1557. Thread.Sleep(200);
  1558. }
  1559. public void MagnetOff(int num)
  1560. {
  1561. FirePot_Write("LB8", true, num);
  1562. Thread.Sleep(200);
  1563. }
  1564. #endregion
  1565. private static object saveMaterialLock = new object();
  1566. private void SaveMaterialData()
  1567. {
  1568. lock(saveMaterialLock)
  1569. {
  1570. Json<MaterialSurplus>.Data = MaterialSurplusOperation.GetInstance().materialSurplus;
  1571. Json<MaterialSurplus>.Save();
  1572. }
  1573. }
  1574. bool isInitialArrive = false;
  1575. bool isInitialPaw = false;
  1576. #region 联网交互
  1577. private void ServerInit()
  1578. {
  1579. //物料信息
  1580. EventBus.EventBus.GetInstance().Subscribe<MaterialDeliveryEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  1581. {
  1582. if (@event == null) return;
  1583. if (@event is MaterialDeliveryEvent material)
  1584. {
  1585. orderMaterialDelivery = material.orderMaterialDelivery;
  1586. }
  1587. });
  1588. //配方数据信息
  1589. EventBus.EventBus.GetInstance().Subscribe<RecipeBomEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  1590. {
  1591. if (@event == null) return;
  1592. if (@event is RecipeBomEvent recipe)
  1593. {
  1594. recipeBoms = recipe.recipeBoms;
  1595. }
  1596. });
  1597. //小炒流程信息
  1598. EventBus.EventBus.GetInstance().Subscribe<StirFryGoodsEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callback)
  1599. {
  1600. if (@event == null) return;
  1601. if (@event is StirFryGoodsEvent stirFry)
  1602. {
  1603. if(stirFry.stirFrymessage != null)
  1604. {
  1605. if (stirFry.stirFrymessage.stirFryGoods.Count > 0)
  1606. {
  1607. foreach (var item in stirFry.stirFrymessage.stirFryGoods)
  1608. {
  1609. LocalstirFryGoods.Add(new StirFryGoods
  1610. {
  1611. GoodsKey = item.GoodsKey,
  1612. StirPotActions = OrderSort(item.StirPotActions),
  1613. });
  1614. GlobalFoodMenu.LocalFoodMenus.Add(new FoodMenuModel
  1615. {
  1616. GoodKey = item.GoodsKey.ToString(),
  1617. GoodName = "",
  1618. });
  1619. }
  1620. }
  1621. if(stirFry.stirFrymessage.materials.Count > 0)
  1622. {
  1623. MaterialSurplusOperation.GetInstance().UpdateSurplusAll(stirFry.stirFrymessage.materials);
  1624. //foreach (var item in stirFry.stirFrymessage.materials)
  1625. //{
  1626. // MaterialSurplusOperation.GetInstance().materialSurplus.dicSurplus.Add(new MaterialInfo
  1627. // {
  1628. // Id = item.Id,
  1629. // Key = item.Key,
  1630. // Name = item.Name,
  1631. // Loc = item.Loc,
  1632. // Qty = item.Qty,
  1633. // });
  1634. //}
  1635. SaveMaterialData();
  1636. }
  1637. }
  1638. MessageLog.GetInstance.Show("接收到小炒流程信息");
  1639. //流程解析
  1640. foreach (var item in LocalstirFryGoods)
  1641. {
  1642. MessageLog.GetInstance.Show($"添加菜谱{item.GoodsKey}");
  1643. // morkF.listStirBom.Add(item.StirFryBomInfo);//添加订单制作流程
  1644. string MenuStep = "菜单步骤:";
  1645. foreach (var items in item.StirPotActions)
  1646. {
  1647. switch (items.Actions)
  1648. {
  1649. case nameof(StirFryPotActionEnum.加热开启):
  1650. MenuStep += items.Actions + ",";
  1651. break;
  1652. case nameof(StirFryPotActionEnum.设置加热挡位1):
  1653. MenuStep += items.Actions + ",";
  1654. break;
  1655. case nameof(StirFryPotActionEnum.设置加热挡位2):
  1656. MenuStep += items.Actions + ",";
  1657. break;
  1658. case nameof(StirFryPotActionEnum.设置加热挡位3):
  1659. MenuStep += items.Actions + ",";
  1660. break;
  1661. case nameof(StirFryPotActionEnum.设置加热挡位4):
  1662. MenuStep += items.Actions + ",";
  1663. break;
  1664. case nameof(StirFryPotActionEnum.设置加热挡位5):
  1665. MenuStep += items.Actions + ",";
  1666. break;
  1667. case nameof(StirFryPotActionEnum.设置加热挡位6):
  1668. MenuStep += items.Actions + ",";
  1669. break;
  1670. case nameof(StirFryPotActionEnum.设置加热挡位7):
  1671. MenuStep += items.Actions + ",";
  1672. break;
  1673. case nameof(StirFryPotActionEnum.设置加热挡位8):
  1674. MenuStep += items.Actions + ",";
  1675. break;
  1676. case nameof(StirFryPotActionEnum.设置加热挡位9):
  1677. MenuStep += items.Actions + ",";
  1678. break;
  1679. case nameof(StirFryPotActionEnum.设置加热挡位10):
  1680. MenuStep += items.Actions + ",";
  1681. break;
  1682. case nameof(StirFryPotActionEnum.停止加热):
  1683. MenuStep += items.Actions + ",";
  1684. break;
  1685. case nameof(StirFryPotActionEnum.加调料):
  1686. MenuStep += items.Actions + ",";
  1687. break;
  1688. case nameof(StirFryPotActionEnum.取原料):
  1689. MenuStep += items.Actions + ",";
  1690. break;
  1691. case nameof(StirFryPotActionEnum.开启搅拌):
  1692. MenuStep += items.Actions + ",";
  1693. break;
  1694. case nameof(StirFryPotActionEnum.设置搅拌挡位1):
  1695. MenuStep += items.Actions + ",";
  1696. break;
  1697. case nameof(StirFryPotActionEnum.设置搅拌挡位2):
  1698. MenuStep += items.Actions + ",";
  1699. break;
  1700. case nameof(StirFryPotActionEnum.设置搅拌挡位3):
  1701. MenuStep += items.Actions + ",";
  1702. break;
  1703. case nameof(StirFryPotActionEnum.关闭搅拌):
  1704. MenuStep += items.Actions + ",";
  1705. break;
  1706. case nameof(StirFryPotActionEnum.出餐启动):
  1707. MenuStep += items.Actions + ",";
  1708. break;
  1709. case nameof(StirFryPotActionEnum.道菜启动):
  1710. MenuStep += items.Actions + ",";
  1711. break;
  1712. case nameof(StirFryPotActionEnum.炒制菜品):
  1713. MenuStep += items.Actions + ",";
  1714. break;
  1715. case nameof(StirFryPotActionEnum.搅拌臂原点位):
  1716. MenuStep += items.Actions + ",";
  1717. break;
  1718. case nameof(StirFryPotActionEnum.搅拌臂炒制位):
  1719. MenuStep += items.Actions + ",";
  1720. break;
  1721. case nameof(StirFryPotActionEnum.洗锅):
  1722. MenuStep += items.Actions + ",";
  1723. break;
  1724. default:
  1725. break;
  1726. }
  1727. }
  1728. MessageLog.GetInstance.Show(MenuStep);
  1729. }
  1730. }
  1731. });
  1732. }
  1733. /// <summary>
  1734. /// 订单排序
  1735. /// </summary>
  1736. /// <param name="potActions"></param>
  1737. /// <returns></returns>
  1738. private List<PotActions> OrderSort(List<PotActions> potActions)
  1739. {
  1740. if (potActions.Count > 1)
  1741. {
  1742. potActions.Sort(
  1743. delegate (PotActions st1, PotActions st2)
  1744. {
  1745. //降序排列
  1746. //return st2.FryTime.CompareTo(st1.FryTime);
  1747. //升序版(颠倒 st1 和 st2 即可)
  1748. return st1.FryTime.CompareTo(st2.FryTime);
  1749. });
  1750. }
  1751. return potActions;
  1752. }
  1753. /// <summary>
  1754. /// 订单状态发布
  1755. /// </summary>
  1756. /// <param name="subid"></param>
  1757. /// <param name="oRDER_STATUS"></param>
  1758. private void OrderChange(string subid, ORDER_STATUS oRDER_STATUS)
  1759. {
  1760. EventBus.EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { Status = oRDER_STATUS, SubOrderId = subid });
  1761. }
  1762. /// <summary>
  1763. /// 数据解析
  1764. /// </summary>
  1765. private void DataParse()
  1766. {
  1767. //if (!morkFs.ContainsKey(num))
  1768. //{
  1769. // return;
  1770. //}
  1771. EventBus.EventBus.GetInstance().Subscribe<DoOrderEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle)
  1772. {
  1773. if (@event == null) return;
  1774. if (@event is DoOrderEvent order)
  1775. {
  1776. if (order.MorkOrder.GoodBatchings == null) return;
  1777. OrderCount++;
  1778. DeviceProcessLogShow($"接收到{OrderCount}次订单");
  1779. Enum.GetNames(typeof(StirFryPotActionEnum));
  1780. //var res = LocalstirFryGoods?.FirstOrDefault(p => p.GoodsKey == order.MorkOrder.RecipeId);//匹配订单对应制作流程
  1781. if(order.MorkOrder.GoodBatchings.Count <= 0)
  1782. {
  1783. return;
  1784. }
  1785. if(order.MorkOrder.DeviceId != DeviceId)
  1786. {
  1787. return;
  1788. }
  1789. //var res = LocalstirFryGoods[0];
  1790. //if (res != null)
  1791. //{
  1792. // /* morkF.listStirBom.Add(res.StirFryBomInfo);*///添加订单制作流程
  1793. // //添加到带炒小炒队列
  1794. // if (StirFryGoodsQuenes.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  1795. // {
  1796. // lock (lock_MainProcessExcute)
  1797. // {
  1798. // StirFryGoodsQuenes.Enqueue(new OrderLocInfo()
  1799. // {
  1800. // SuborderId = order.MorkOrder.SuborderId,
  1801. // StirPotActions = res.StirPotActions,
  1802. // GoodName = order.MorkOrder.GoodsName
  1803. // });
  1804. // }
  1805. // }
  1806. //}
  1807. //暂时使用本地菜单
  1808. StartLocalOrder();
  1809. }
  1810. });
  1811. }
  1812. #endregion
  1813. private object lock_MainProcessExcute = new object();
  1814. /// <summary>
  1815. /// 炒锅主流程
  1816. /// </summary>
  1817. private void MainProcessExcute()
  1818. {
  1819. //判断是否有订单信息
  1820. if(StirFryGoodsQuenes.Count > 0)
  1821. {
  1822. //遍历炒锅,找到合适、空闲的炒锅
  1823. for(int i = 0;i<morkFs.Count;i++)
  1824. {
  1825. if (/*morkFs[i].AutoMode && morkFs[i].FryPot1_InitialComplete &&*/
  1826. !morkFs[i].FryWorking)//炒锅在自动状态&&初始化完成&&是否在炒菜中
  1827. {
  1828. lock(lock_MainProcessExcute)
  1829. {
  1830. //待炒小炒队列出队列
  1831. if (StirFryGoodsQuenes.TryDequeue(out var res))
  1832. {
  1833. //设置当前炒制菜品
  1834. nowStirFryGood[i] = res;
  1835. //炒锅工作状态置为正在工作中
  1836. morkFs[i].FryWorking = true;
  1837. //空闲炒锅入队列
  1838. morkFs[i].StirFryGoodsQuenes.Enqueue(res);
  1839. //炒锅取菜状态置为未取到
  1840. morkFs[i].GetMaterialComplete = false;
  1841. //开启线程进行炒制
  1842. ThreadManage.GetInstance().Start(new Action(() =>
  1843. {
  1844. try
  1845. {
  1846. MessageLog.GetInstance.Show($"炒锅{i}开始炒制菜品{res.GoodName}");
  1847. Coordinate myCoordinate = new Coordinate();
  1848. int getMaterailNum = 0;
  1849. foreach (var potActions in res.StirPotActions)
  1850. {
  1851. if (ThreadManage.GetInstance().IsCanncel(String.Format(striConst, i.ToString(), nowStirFryGood[i].GoodName)))
  1852. {
  1853. return;
  1854. }
  1855. switch (potActions.Actions)
  1856. {
  1857. case nameof(StirFryPotActionEnum.加热开启):
  1858. StartFire(i);
  1859. MessageLog.GetInstance.Show(potActions.Actions);
  1860. break;
  1861. case nameof(StirFryPotActionEnum.设置加热挡位1):
  1862. morkFs[i].Fire = 1;
  1863. SetFire(new List<int> { 1 }, i);
  1864. MessageLog.GetInstance.Show(potActions.Actions);
  1865. break;
  1866. case nameof(StirFryPotActionEnum.设置加热挡位2):
  1867. morkFs[i].Fire = 2;
  1868. SetFire(new List<int> { 2 }, i);
  1869. MessageLog.GetInstance.Show(potActions.Actions);
  1870. break;
  1871. case nameof(StirFryPotActionEnum.设置加热挡位3):
  1872. morkFs[i].Fire = 3;
  1873. SetFire(new List<int> { 3 }, i);
  1874. MessageLog.GetInstance.Show(potActions.Actions);
  1875. break;
  1876. case nameof(StirFryPotActionEnum.设置加热挡位4):
  1877. morkFs[i].Fire = 4;
  1878. SetFire(new List<int> { 4 }, i);
  1879. MessageLog.GetInstance.Show(potActions.Actions);
  1880. break;
  1881. case nameof(StirFryPotActionEnum.设置加热挡位5):
  1882. morkFs[i].Fire = 5;
  1883. SetFire(new List<int> { 5 }, i);
  1884. MessageLog.GetInstance.Show(potActions.Actions);
  1885. break;
  1886. case nameof(StirFryPotActionEnum.设置加热挡位6):
  1887. morkFs[i].Fire = 6;
  1888. SetFire(new List<int> { 6 }, i);
  1889. MessageLog.GetInstance.Show(potActions.Actions);
  1890. break;
  1891. case nameof(StirFryPotActionEnum.设置加热挡位7):
  1892. morkFs[i].Fire = 7;
  1893. SetFire(new List<int> { 7 }, i);
  1894. MessageLog.GetInstance.Show(potActions.Actions);
  1895. break;
  1896. case nameof(StirFryPotActionEnum.设置加热挡位8):
  1897. morkFs[i].Fire = 8;
  1898. SetFire(new List<int> { 8 }, i);
  1899. MessageLog.GetInstance.Show(potActions.Actions);
  1900. break;
  1901. case nameof(StirFryPotActionEnum.设置加热挡位9):
  1902. morkFs[i].Fire = 9;
  1903. SetFire(new List<int> { 9 }, i);
  1904. MessageLog.GetInstance.Show(potActions.Actions);
  1905. break;
  1906. case nameof(StirFryPotActionEnum.设置加热挡位10):
  1907. morkFs[i].Fire = 10;
  1908. SetFire(new List<int> { 10 }, i);
  1909. MessageLog.GetInstance.Show(potActions.Actions);
  1910. break;
  1911. case nameof(StirFryPotActionEnum.停止加热):
  1912. StopFire(i);
  1913. MessageLog.GetInstance.Show(potActions.Actions);
  1914. break;
  1915. case nameof(StirFryPotActionEnum.加调料):
  1916. OutSeasonings(potActions.SeasoningLists, i);
  1917. MessageLog.GetInstance.Show(potActions.Actions);
  1918. break;
  1919. case nameof(StirFryPotActionEnum.取原料):
  1920. //炒锅取菜状态置为未取到
  1921. morkFs[i].GetMaterialComplete = false;
  1922. if(potActions.MaterialLists != null)
  1923. {
  1924. foreach (var item in potActions.MaterialLists)
  1925. {
  1926. //通过ID获取有效的菜品对象
  1927. MaterialInfo materialInfo = MaterialSurplusOperation.GetInstance().GetVailedMaterial(item.MaterialId);
  1928. if (materialInfo == null)
  1929. {
  1930. MessageLog.GetInstance.Show($"炒锅{i}获取菜品[{materialInfo.Name}]失败,库存不足");
  1931. continue;
  1932. }
  1933. materialOperationQuenes.Enqueue(new MaterialOperation { materialInfo = materialInfo, fryNum = i });
  1934. }
  1935. }
  1936. else
  1937. {
  1938. MessageLog.GetInstance.Show($"炒锅{i}获取菜品失败,菜品列表为空");
  1939. }
  1940. //if(getMaterailNum == 0)
  1941. //{
  1942. // if (NoMaterial2Coordinate(MaterialCoordinate.MLNumberList[1], out myCoordinate))
  1943. // {
  1944. // materialOperationQuenes.Enqueue(new MaterialOperation() { fryNum = i, coordinate = myCoordinate });
  1945. // getMaterailNum++;
  1946. // }
  1947. //}
  1948. //else if(getMaterailNum == 1)
  1949. //{
  1950. // if (NoMaterial2Coordinate(MaterialCoordinate.MLNumberList[4], out myCoordinate))
  1951. // {
  1952. // materialOperationQuenes.Enqueue(new MaterialOperation() { fryNum = i, coordinate = myCoordinate });
  1953. // getMaterailNum++;
  1954. // }
  1955. //}
  1956. MessageLog.GetInstance.Show(potActions.Actions);
  1957. break;
  1958. case nameof(StirFryPotActionEnum.开启搅拌):
  1959. StartStir(i);
  1960. MessageLog.GetInstance.Show(potActions.Actions);
  1961. break;
  1962. case nameof(StirFryPotActionEnum.设置搅拌挡位1):
  1963. SetStir(new List<int> { 1 }, i);
  1964. MessageLog.GetInstance.Show(potActions.Actions);
  1965. break;
  1966. case nameof(StirFryPotActionEnum.设置搅拌挡位2):
  1967. SetStir(new List<int> { 2 }, i);
  1968. MessageLog.GetInstance.Show(potActions.Actions);
  1969. break;
  1970. case nameof(StirFryPotActionEnum.设置搅拌挡位3):
  1971. SetStir(new List<int> { 3 }, i);
  1972. MessageLog.GetInstance.Show(potActions.Actions);
  1973. break;
  1974. case nameof(StirFryPotActionEnum.关闭搅拌):
  1975. StopStir(i);
  1976. MessageLog.GetInstance.Show(potActions.Actions);
  1977. break;
  1978. case nameof(StirFryPotActionEnum.出餐启动):
  1979. MessageLog.GetInstance.Show(potActions.Actions);
  1980. break;
  1981. case nameof(StirFryPotActionEnum.道菜启动):
  1982. OutFood(i, true);
  1983. break;
  1984. case nameof(StirFryPotActionEnum.炒制菜品):
  1985. Thread.Sleep(potActions.During * 1000);
  1986. break;
  1987. case nameof(StirFryPotActionEnum.搅拌臂原点位):
  1988. StirArmGoOrigin(i);
  1989. MessageLog.GetInstance.Show(potActions.Actions);
  1990. break;
  1991. case nameof(StirFryPotActionEnum.搅拌臂炒制位):
  1992. StirArmGoWork(i);
  1993. MessageLog.GetInstance.Show(potActions.Actions);
  1994. break;
  1995. case nameof(StirFryPotActionEnum.洗锅):
  1996. MessageLog.GetInstance.Show(potActions.Actions);
  1997. break;
  1998. default:
  1999. break;
  2000. }
  2001. }
  2002. Plc1Reset(i);//复位
  2003. Thread.Sleep(3000);
  2004. //回原点位
  2005. StirArmGoOrigin(i);
  2006. MessageLog.GetInstance.Show($"菜品{res.GoodName}完成");
  2007. }
  2008. catch (Exception ex)
  2009. {
  2010. ThreadManage.GetInstance().StopTask($"炒锅{i}{res.GoodName}炒制线程");
  2011. MessageLog.GetInstance.Show($"炒锅{i}炒制菜品{res.GoodName}出错,错误信息:" + ex.Message);
  2012. }
  2013. finally
  2014. {
  2015. nowStirFryGood[i] = null;
  2016. //炒完后出队列
  2017. morkFs[i].StirFryGoodsQuenes.TryDequeue(out var orderQueue);
  2018. morkFs[i].FryWorking = false;
  2019. }
  2020. }), String.Format(striConst, i.ToString(), nowStirFryGood[i].GoodName)/*$"炒锅{i}炒制{res.GoodName}线程"*/);
  2021. }
  2022. }
  2023. break;
  2024. }
  2025. }
  2026. }
  2027. }
  2028. /// <summary>
  2029. /// 菜品库主流程
  2030. /// </summary>
  2031. private void MainProcessMaterial()
  2032. {
  2033. if(materialOperationQuenes.Count > 0)
  2034. {
  2035. //判断是否初始化与是否在工作中
  2036. if (ml_morkf.InitialComplete && !ml_morkf.MaterailIsWorking)
  2037. {
  2038. //待菜品库操作列出队列
  2039. if (materialOperationQuenes.TryDequeue(out var res))
  2040. {
  2041. ml_morkf.MaterailIsWorking = true;
  2042. MessageLog.GetInstance.Show("开始操作菜品库");
  2043. //ThreadManage.GetInstance().Start(new Action(()=>{
  2044. // GetMaterail(res.x, res.y, res.fryNum);
  2045. //}),"菜品库操作");
  2046. GetMaterailTest(res);
  2047. }
  2048. }
  2049. }
  2050. }
  2051. /// <summary>
  2052. /// 信号处理
  2053. /// </summary>
  2054. private void SingleProcess()
  2055. {
  2056. }
  2057. private void ScreenDataServer()
  2058. {
  2059. LocalMqtt.GetInstance.Init(ScreenDeviceType.大炒);
  2060. ThreadManage.GetInstance().StartLong(new Action(() =>
  2061. {
  2062. List<StatsModel> statsModels = new List<StatsModel>();
  2063. statsModels.Add(new StatsModel() { Name = "帝王蟹", Count = 666 });
  2064. ScreenModelMinWok maxWok = new ScreenModelMinWok
  2065. {
  2066. IsRun = new Random().Next(0, 2) == 0 ? IsRun.运行 : IsRun.停止, //设备是否运行
  2067. WorkStatus_1 = (WorkStatus)new Random().Next(0, 3), //设备运行状态
  2068. WorkStatus_2 = (WorkStatus)new Random().Next(0, 3), //设备运行状态
  2069. RobotStatu = (WorkStatus)new Random().Next(0, 3), //机器人状态 待机 1 正常
  2070. Alarm = new List<AlarmModel>(), //告警集合
  2071. FailuresCount = 0, //故障数
  2072. StatsCount = statsModels, //统计菜品数量
  2073. MinWok_Dishes_1 = "满汉全席",//当前炒制菜品名
  2074. MinWok_Dishes_2 = "海鲜大餐",
  2075. MinWok_Task_1 = "炒制菜品",//当前任务
  2076. MinWok_Task_2 = "热油", //当前任务
  2077. MinWok_Process_1 = new List<ProcessModel>(), //炒锅当前任务流程
  2078. MinWok_Process_2 = new List<ProcessModel>(), //炒锅当前任务流程
  2079. MinWok_HeatGear_1 = new Random().Next(0, 5).ToString(), //炒锅加热档位
  2080. MinWok_HeatGear_2 = new Random().Next(0, 5).ToString(), //炒锅加热档位
  2081. MinWok_StirGear_1 = new Random().Next(0, 5).ToString(), //炒锅搅拌档位
  2082. MinWok_StirGear_2 = new Random().Next(0, 5).ToString(), //炒锅搅拌档位
  2083. MinWok_OrderCount_1 = 2, //订单数量
  2084. MinWok_OrderCount_2 = 2, //订单数量
  2085. MinWok_ErrorOrderCount_1 = 0, //异常订单数量
  2086. MinWok_ErrorOrderCount_2 = 0, //异常订单数量
  2087. };
  2088. LocalMqtt.GetInstance.Publish(maxWok);
  2089. Thread.Sleep(1000);
  2090. }), "大屏数据上报");
  2091. }
  2092. public override void SimOrder()
  2093. {
  2094. }
  2095. /// <summary>
  2096. /// 菜品编号转换为坐标
  2097. /// </summary>
  2098. /// <param name="no"></param>
  2099. /// <param name="coordinate"></param>
  2100. /// <returns></returns>
  2101. public bool NoMaterial2Coordinate(string no,out Coordinate coordinate)
  2102. {
  2103. //默认返回0,0
  2104. coordinate = new Coordinate();
  2105. coordinate.X = 0;
  2106. coordinate.Y = 0;
  2107. try
  2108. {
  2109. if(MaterialCoordinate.dicNoMaterialCoordinate.ContainsKey(no))
  2110. {
  2111. coordinate = MaterialCoordinate.dicNoMaterialCoordinate[no];
  2112. return true;
  2113. }
  2114. else
  2115. {
  2116. return false;
  2117. }
  2118. }
  2119. catch (Exception ex)
  2120. {
  2121. return false;
  2122. }
  2123. finally
  2124. {
  2125. }
  2126. }
  2127. public enum Laser2CoordinateState
  2128. {
  2129. MaterialOverdo = 0,//菜品过量
  2130. MaterialNormal = 1,//菜品正常
  2131. MaterialEmpty = 2,//菜品为空
  2132. MaterialUnkown = 999,//菜品未知错误
  2133. }
  2134. }
  2135. }