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

1736 lignes
67 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. namespace BPASmartClient.MorkF
  16. {
  17. public class Control_MorkF : BaseDevice
  18. {
  19. /// <summary>
  20. /// while循环最大sleep次数
  21. /// </summary>
  22. private const int sleepCount = 20;
  23. /// <summary>
  24. /// while循环每次sleep时间
  25. /// </summary>
  26. private const int sleepTime = 500;
  27. /// <summary>
  28. /// 初始化炒锅数量
  29. /// </summary>
  30. private int count = 2;
  31. //当前炒锅,默认为1号炒锅
  32. private int fryIndex = 0;
  33. public override DeviceClientType DeviceType => DeviceClientType.MORKCS;
  34. public AutoResetEvent minorReset = new AutoResetEvent(false);
  35. public AutoResetEvent mainReset = new AutoResetEvent(false);
  36. /// <summary>
  37. /// 炒锅编号与炒锅实例
  38. /// </summary>
  39. Dictionary<int,GVL_MorkF> morkFs = new Dictionary<int, GVL_MorkF>();//全局对象声明
  40. /// <summary>
  41. /// 菜品库对象
  42. /// </summary>
  43. ML_MorkF ml_morkf = new ML_MorkF();
  44. /// <summary>
  45. /// 小炒菜单集合
  46. /// </summary>
  47. public static List<StirFryGoods> LocalstirFryGoods = new List<StirFryGoods>();
  48. /// <summary>
  49. /// 待炒小炒队列
  50. /// </summary>
  51. private ConcurrentQueue<OrderLocInfo> StirFryGoodsQuenes = new ConcurrentQueue<OrderLocInfo>();
  52. /// <summary>
  53. /// 炒锅炒制线程名称
  54. /// </summary>
  55. private const String striConst = "炒锅{0}炒制{1}线程";
  56. /// <summary>
  57. /// 当前炒制菜品
  58. /// </summary>
  59. private OrderLocInfo nowStirFryGood = null;
  60. List<int> resultorder = new List<int>();//调试变量
  61. /// <summary>
  62. /// 入口
  63. /// </summary>
  64. public override void DoMain()
  65. {
  66. IsHealth = true;
  67. //WriteControl("VD836", 0);
  68. //WriteControl("VD840", 0);
  69. //Thread.Sleep(400);
  70. //WriteControl("M0.0", true);
  71. for (int i = 0;i< count;i++)
  72. {
  73. morkFs.Add(i, new GVL_MorkF());
  74. }
  75. DataParse();//数据解析
  76. CommandRegist();//调试
  77. ServerInit();
  78. DeviceProcessLogShow("MORKF 设备初始化完成");
  79. }
  80. /// <summary>
  81. /// 主任务
  82. /// </summary>
  83. public override void MainTask()
  84. {
  85. MainProcessExcute();
  86. //MinorProcessExcute();
  87. //SingleProcess();
  88. }
  89. public override void Stop()
  90. {
  91. IsHealth = false;
  92. }
  93. #region 调试代码
  94. public void CommandRegist()
  95. {
  96. #region 设备控制
  97. ActionManage.GetInstance.Register(PLCInite, "InitCommand");
  98. ActionManage.GetInstance.Register(StartOrder, "StartOrder");
  99. ActionManage.GetInstance.Register(StartOrderMain, "开始下单");
  100. ActionManage.GetInstance.Register(StartLocalOrder, "StartLocalOrder");
  101. ActionManage.GetInstance.Register(StopLocalOrder, "StopLocalOrder");
  102. #endregion
  103. #region 菜品库
  104. ActionManage.GetInstance.Register(new Action(() =>
  105. {
  106. ThreadManage.GetInstance().Start(new Action(() =>
  107. {
  108. FoodLibInit();
  109. }), "FoodLibInit");
  110. }), "FoodLibInit");
  111. ActionManage.GetInstance.Register(new Action<object>((o) =>
  112. {
  113. ThreadManage.GetInstance().Start(new Action(() =>
  114. {
  115. Electromagnetism(o);
  116. }), "Electromagnetism");
  117. }), "Electromagnetism");
  118. ActionManage.GetInstance.Register(new Action(() =>
  119. {
  120. ThreadManage.GetInstance().Start(new Action(() =>
  121. {
  122. GetDistance_1();
  123. }), "GetDistance_1");
  124. }), "GetDistance_1");
  125. ActionManage.GetInstance.Register(new Action(() =>
  126. {
  127. ThreadManage.GetInstance().Start(new Action(() =>
  128. {
  129. GetDistance_2();
  130. }), "GetDistance_2");
  131. }), "GetDistance_2");
  132. ActionManage.GetInstance.Register(new Action(() =>
  133. {
  134. ThreadManage.GetInstance().Start(new Action(() =>
  135. {
  136. GetDistance_3();
  137. }), "GetDistance_3");
  138. }), "GetDistance_3");
  139. ActionManage.GetInstance.Register(PawTurnFront, "PawTurnFront");
  140. ActionManage.GetInstance.Register(PawTurnBack, "PawTurnBack");
  141. ActionManage.GetInstance.Register(new Action<object>((list) =>
  142. {
  143. ThreadManage.GetInstance().Start(new Action(() =>
  144. {
  145. if(list is List<int> list_int)
  146. {
  147. if (list_int.Count == 2)
  148. {
  149. SetArmPosition(list_int[0], list_int[1]);
  150. }
  151. }
  152. }), "SetArmPosition");
  153. }), "SetArmPosition");
  154. #endregion
  155. //ActionManage.GetInstance.Register(PLCInite, "InitCommand");
  156. #region 配料控制
  157. ActionManage.GetInstance.Register(new Action<object>((o) =>
  158. {
  159. ThreadManage.GetInstance().Start(new Action(() =>
  160. {
  161. OutSeasoning(o, fryIndex);
  162. }), "OutMaterials");
  163. }), "OutMaterials");
  164. //ActionManage.GetInstance.Register(OutSeasoning, "OutMaterials");
  165. #endregion
  166. #region 炒锅
  167. ActionManage.GetInstance.Register(new Action(() =>
  168. {
  169. ThreadManage.GetInstance().Start(new Action(() =>
  170. {
  171. Plc1Reset(fryIndex);
  172. }), "Plc1Reset");
  173. }) , "Plc1Reset");
  174. ActionManage.GetInstance.Register(new Action(() =>
  175. {
  176. ThreadManage.GetInstance().Start(new Action(() =>
  177. {
  178. AddOil();
  179. }), "AddOil");
  180. }), "AddOil");
  181. ActionManage.GetInstance.Register(new Action(() =>
  182. {
  183. ThreadManage.GetInstance().Start(new Action(() =>
  184. {
  185. StartFire(fryIndex);
  186. }), "StartFire");
  187. }), "StartFire");
  188. ActionManage.GetInstance.Register(new Action(() =>
  189. {
  190. ThreadManage.GetInstance().Start(new Action(() =>
  191. {
  192. StopFire(fryIndex);
  193. }), "StopFire");
  194. }), "StopFire");
  195. ActionManage.GetInstance.Register(new Action(() =>
  196. {
  197. ThreadManage.GetInstance().Start(new Action(() =>
  198. {
  199. StartStir(fryIndex);
  200. }), "StartStir");
  201. }), "StartStir");
  202. ActionManage.GetInstance.Register(new Action(() =>
  203. {
  204. ThreadManage.GetInstance().Start(new Action(() =>
  205. {
  206. StopStir(fryIndex);
  207. }), "StopStir");
  208. }), "StopStir");
  209. ActionManage.GetInstance.Register(new Action(() =>
  210. {
  211. ThreadManage.GetInstance().Start(new Action(() =>
  212. {
  213. OutFood(fryIndex);
  214. }), "OutFood");
  215. }), "OutFood");
  216. ActionManage.GetInstance.Register(new Action(() =>
  217. {
  218. ThreadManage.GetInstance().Start(new Action(() =>
  219. {
  220. StirArmGoOrigin(fryIndex);
  221. }), "StirArmGoOrigin");
  222. }), "StirArmGoOrigin");
  223. ActionManage.GetInstance.Register(new Action(() =>
  224. {
  225. ThreadManage.GetInstance().Start(new Action(() =>
  226. {
  227. StirArmGoWork(fryIndex);
  228. }), "StirArmGoWork");
  229. }), "StirArmGoWork");
  230. ActionManage.GetInstance.Register(new Action(() =>
  231. {
  232. ThreadManage.GetInstance().Start(new Action(() =>
  233. {
  234. HBOTGoWork(fryIndex);
  235. }), "HBOTGoWork");
  236. }), "HBOTGoWork");
  237. ActionManage.GetInstance.Register(new Action(() =>
  238. {
  239. ThreadManage.GetInstance().Start(new Action(() =>
  240. {
  241. OutMeal(fryIndex);
  242. }), "OutMeal");
  243. }), "OutMeal");
  244. ActionManage.GetInstance.Register(new Action<object>((o) =>
  245. {
  246. ThreadManage.GetInstance().Start(new Action(() =>
  247. {
  248. SetFire(o,fryIndex);
  249. }), "SetFire");
  250. }), "SetFire");
  251. ActionManage.GetInstance.Register(new Action<object>((o) =>
  252. {
  253. ThreadManage.GetInstance().Start(new Action(() =>
  254. {
  255. SetFry(o);
  256. }), "SetFry");
  257. }), "SetFry");
  258. ActionManage.GetInstance.Register(new Action<object>((o) =>
  259. {
  260. ThreadManage.GetInstance().Start(new Action(() =>
  261. {
  262. SetStir(o,fryIndex);
  263. }), "SetStir");
  264. }), "SetStir");
  265. #endregion
  266. }
  267. /// <summary>
  268. /// 本地菜单下单
  269. /// </summary>
  270. private void StartOrder(object o)
  271. {
  272. if(o==null) return;
  273. if(o is int goodId)
  274. {
  275. var res = LocalstirFryGoods?.FirstOrDefault(p => p.GoodsKey == goodId);//匹配订单对应制作流程
  276. if (res != null)
  277. {
  278. /* morkF.listStirBom.Add(res.StirFryBomInfo);*///添加订单制作流程
  279. if (StirFryGoodsQuenes.Count > 0) return;
  280. StirFryGoodsQuenes.Enqueue(new OrderLocInfo()
  281. {
  282. SuborderId = Guid.NewGuid().ToString(),
  283. StirPotActions = res.StirPotActions,
  284. GoodName = "本地菜品"
  285. });
  286. MessageLog.GetInstance.Show($"添加本地订单{res.GoodsKey}");
  287. }
  288. }
  289. }
  290. /// <summary>
  291. /// 本地菜单下单
  292. /// </summary>
  293. private void StartOrderMain(object o)
  294. {
  295. if (o == null) return;
  296. if (o is string goodId)
  297. {
  298. var res = LocalstirFryGoods?.FirstOrDefault(p => p.GoodsKey.ToString() == goodId);//匹配订单对应制作流程
  299. if (res != null)
  300. {
  301. /* morkF.listStirBom.Add(res.StirFryBomInfo);*///添加订单制作流程
  302. if (StirFryGoodsQuenes.Count > 0) return;
  303. StirFryGoodsQuenes.Enqueue(new OrderLocInfo()
  304. {
  305. SuborderId = Guid.NewGuid().ToString(),
  306. StirPotActions = res.StirPotActions,
  307. GoodName = "本地菜品"
  308. });
  309. MessageLog.GetInstance.Show($"添加本地订单{res.GoodsKey}");
  310. }
  311. }
  312. }
  313. private void StartLocalOrder()
  314. {
  315. if (StirFryGoodsQuenes.Count > 0) return;//只能一个一个做
  316. if (Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions.Count>0)
  317. {
  318. StirFryGoodsQuenes.Enqueue(new OrderLocInfo()
  319. {
  320. SuborderId = Guid.NewGuid().ToString(),
  321. StirPotActions = Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions,
  322. GoodName = "本地菜品"
  323. });
  324. MessageLog.GetInstance.Show($"添加本地模拟的订单{Json<LocalPotStep>.Data.LocalstirFryGoods.GoodsKey}");
  325. }
  326. }
  327. /// <summary>
  328. /// 停止本地菜单炒制
  329. /// </summary>
  330. private void StopLocalOrder(int num = -1)
  331. {
  332. //判断当前是否有炒制菜品
  333. if (nowStirFryGood == null) return;
  334. //根据morkFs中是否有num执行不同的停止操作
  335. if (!morkFs.ContainsKey(num))
  336. {
  337. //根据调试界面的当前炒锅编号停止炒制线程
  338. ThreadManage.GetInstance().StopTask(String.Format(striConst, fryIndex.ToString(), nowStirFryGood.GoodName), new Action(() => { Plc1Reset(fryIndex); }));
  339. }
  340. else
  341. {
  342. //根据炒锅编号停止炒制线程
  343. ThreadManage.GetInstance().StopTask(String.Format(striConst, fryIndex.ToString(), nowStirFryGood.GoodName), new Action(() => { Plc1Reset(num); }));
  344. }
  345. }
  346. /// <summary>
  347. /// 重置程序
  348. /// </summary>
  349. public override void ResetProgram()
  350. {
  351. IsHealth = true;
  352. morkFs.Clear();
  353. morkFs = new Dictionary<int, GVL_MorkF>();
  354. ml_morkf = new ML_MorkF();
  355. //根据编号new炒锅实例对象
  356. for (int i = 0; i < count; i++)
  357. {
  358. morkFs.Add(i, new GVL_MorkF());
  359. }
  360. }
  361. #endregion
  362. #region 公用PLC方法
  363. /// <summary>
  364. /// 获取设备PLC的所有状态
  365. /// </summary>
  366. /// <param name="key"></param>
  367. /// <param name="action"></param>
  368. /// <param name="num">炒锅编号</param>
  369. private void GetStatus(string key, Action<object> action, int num)
  370. {
  371. if (dicPort2peripheralStatus.ContainsKey(num))
  372. {
  373. if (dicPort2peripheralStatus[num].ContainsKey(key))
  374. {
  375. action((object)dicPort2peripheralStatus[num][key]);//获取PLC指定地址的状态值
  376. }
  377. }
  378. }
  379. /// <summary>
  380. /// PLC数据读取
  381. /// </summary>
  382. public override void ReadData()
  383. {
  384. for (int i = 0; i < morkFs.Count; i++)
  385. {
  386. GetStatus("LB50", new Action<object>((objects) =>
  387. {
  388. if (!morkFs.ContainsKey(i))
  389. {
  390. return;
  391. }
  392. if (objects is bool[] bools)
  393. {
  394. morkFs[i].FryPot1_InitialComplete = bools[0];
  395. morkFs[i].FryPot1_HOBTPut = bools[1];
  396. morkFs[i].FryPot1_HOBTGet = bools[2];
  397. morkFs[i].FryPot1_MaterialIntoPot = bools[3];
  398. morkFs[i].OutFoodCompelete = bools[4];
  399. morkFs[i].CanOutFood = bools[5];
  400. morkFs[i].GetFoodCompelete = bools[6];
  401. morkFs[i].CanOutPotWashingWater = bools[7];
  402. morkFs[i].ArmOnOrigin = bools[8];
  403. morkFs[i].ArmOnWorking = bools[9];
  404. morkFs[i].PotOnOrigin = bools[10];
  405. }
  406. }), i);
  407. }
  408. for (int j = 0; j < morkFs.Count; j++)
  409. {
  410. GetStatus("LB74", new Action<object>((objects) =>
  411. {
  412. if (!morkFs.ContainsKey(j))
  413. {
  414. return;
  415. }
  416. if (objects is bool[] bools)
  417. {
  418. for (int i = 0; i < 14; i++)
  419. {
  420. morkFs[j].PassWay1_Compelete[i] = bools[i];
  421. }
  422. }
  423. }), j);
  424. }
  425. for (int i = 0; i < morkFs.Count; i++)
  426. {
  427. if (!morkFs.ContainsKey(i))
  428. {
  429. return;
  430. }
  431. GetStatus("LB90", new Action<object>((objects) =>
  432. {
  433. if (objects is bool[] bools)
  434. {
  435. morkFs[i].AutoMode = bools[0];
  436. }
  437. }), i);
  438. }
  439. //获取激光距离
  440. GetStatus("VW270", new Action<object>((objects) =>
  441. {
  442. if (objects is int[] bools)
  443. {
  444. for (int i = 0; i < 1; i++)
  445. {
  446. ml_morkf.LaserDistance = bools[i];
  447. }
  448. }
  449. }), 2);
  450. //获取坐标X
  451. GetStatus("VD828", new Action<object>((objects) =>
  452. {
  453. if (objects is int[] bools)
  454. {
  455. for (int i = 0; i < 1; i++)
  456. {
  457. ml_morkf.ArmPositionX = bools[i];
  458. }
  459. }
  460. }), 2);
  461. //获取坐标Y
  462. GetStatus("VD832", new Action<object>((objects) =>
  463. {
  464. if (objects is int[] bools)
  465. {
  466. for (int i = 0; i < 1; i++)
  467. {
  468. ml_morkf.ArmPositionY = bools[i];
  469. }
  470. }
  471. }), 2);
  472. //获取爪子到达位置
  473. GetStatus("M11.0", new Action<object>((objects) =>
  474. {
  475. if (objects is bool[] bools && bools.Length > 3)
  476. {
  477. //ml_morkf.PawArrivePortOne = bools[0];
  478. //ml_morkf.PawArrivePortTwo = bools[1];
  479. //ml_morkf.PawArrivePortThree = bools[2];
  480. if (isInitialPaw == false)
  481. {
  482. isInitialArrive = true;
  483. }
  484. else
  485. {
  486. //小炒爪子到达1号位上升沿信号捕获
  487. if (RTrig.GetInstance("SmartGitdistance1Complete").Start(bools[0]))
  488. {
  489. ml_morkf.PawArrivePortOne = true;
  490. }
  491. //小炒爪子到达3号位上升沿信号捕获
  492. if (RTrig.GetInstance("SmartGitdistance2Complete").Start(bools[1]))
  493. {
  494. ml_morkf.PawArrivePortTwo = true;
  495. }
  496. //小炒爪子到达3号位上升沿信号捕获
  497. if (RTrig.GetInstance("SmartGitdistance3Complete").Start(bools[2]))
  498. {
  499. ml_morkf.PawArrivePortThree = true;
  500. }
  501. isInitialArrive = true;
  502. }
  503. }
  504. }), 2);
  505. //获取定位到达状态
  506. GetStatus("M10.0", new Action<object>((objects) =>
  507. {
  508. if (objects is bool[] bools)
  509. {
  510. for (int i = 0; i < 1; i++)
  511. {
  512. //ml_morkf.ArriveComplete = bools[i];
  513. //小炒定点到达上升沿信号捕获
  514. if (RTrig.GetInstance("SmartArriveComplete").Start(bools[i]))
  515. {
  516. if (isInitialArrive == false)
  517. {
  518. MessageLog.GetInstance.Show("到达上升沿为true,isInitialArrive is false");
  519. isInitialArrive = true;
  520. }
  521. else
  522. {
  523. MessageLog.GetInstance.Show("到达上升沿为true");
  524. ml_morkf.ArriveComplete = true;
  525. isInitialArrive = true;
  526. }
  527. }
  528. }
  529. }
  530. }), 2);
  531. //获取总初始化完成
  532. GetStatus("M10.2", new Action<object>((objects) =>
  533. {
  534. if (objects is bool[] bools)
  535. {
  536. for (int i = 0; i < 1; i++)
  537. {
  538. ml_morkf.InitialComplete = bools[i];
  539. }
  540. }
  541. }), 2);
  542. //抓手初始化完成
  543. GetStatus("M10.3", new Action<object>((objects) =>
  544. {
  545. if (objects is bool[] bools)
  546. {
  547. for (int i = 0; i < 1; i++)
  548. {
  549. ml_morkf.PawInitialComplete = bools[i];
  550. }
  551. }
  552. }), 2);
  553. }
  554. #endregion
  555. #region 菜品库PLC操作方法
  556. /// <summary>
  557. /// 菜品库数据写入
  558. /// </summary>
  559. /// <param name="address"></param>
  560. /// <param name="value"></param>
  561. private void MaterailLibrary_Write(string address, object value,int num)
  562. {
  563. WriteControlExact(address, value, num);
  564. }
  565. /// <summary>
  566. /// 菜品库初始化
  567. /// </summary>
  568. public void FoodLibInit(int num = 2)
  569. {
  570. MaterailLibrary_Write("M0.2", true, num);
  571. }
  572. /// <summary>
  573. /// 电磁阀启停
  574. /// </summary>
  575. /// <param name="o">电磁阀启停:true:启动。false:停止。</param>
  576. public void Electromagnetism(object o,int num = 2)
  577. {
  578. if (o == null) return;
  579. if (o is List<bool> bs && bs.Count == 1)
  580. {
  581. MaterailLibrary_Write("M1.3", bs[0],num);
  582. }
  583. }
  584. public bool GetDistance_1(int num = 2)
  585. {
  586. MessageLog.GetInstance.Show("爪子去到1号位");
  587. MaterailLibrary_Write("M1.0", true, num);
  588. for (int i = 0; i < sleepCount && !ml_morkf.PawArrivePortOne; i++)
  589. {
  590. Thread.Sleep(sleepTime);
  591. if (i >= sleepCount - 1)
  592. {
  593. MessageLog.GetInstance.Show("爪子去到1号位超时");
  594. return false;
  595. }
  596. }
  597. MessageLog.GetInstance.Show("爪子去到1号位完成");
  598. return true;
  599. }
  600. public bool GetDistance_2(int num = 2)
  601. {
  602. MessageLog.GetInstance.Show("爪子去到2号位");
  603. MaterailLibrary_Write("M1.1", true, num);
  604. for (int i = 0; i < sleepCount && !ml_morkf.PawArrivePortTwo; i++)
  605. {
  606. Thread.Sleep(sleepTime);
  607. if (i >= sleepCount - 1)
  608. {
  609. MessageLog.GetInstance.Show("爪子去到2号位超时");
  610. return false;
  611. }
  612. }
  613. MessageLog.GetInstance.Show("爪子去到2号位完成");
  614. return true;
  615. }
  616. public bool GetDistance_3(int num = 2)
  617. {
  618. MessageLog.GetInstance.Show("爪子去到3号位");
  619. MaterailLibrary_Write("M1.2", true,num);
  620. for (int i = 0; i < sleepCount && !ml_morkf.PawArrivePortThree; i++)
  621. {
  622. Thread.Sleep(sleepTime);
  623. if (i >= sleepCount - 1)
  624. {
  625. MessageLog.GetInstance.Show("爪子去到3号位超时");
  626. return false;
  627. }
  628. }
  629. MessageLog.GetInstance.Show("爪子去到3号位完成");
  630. return true;
  631. }
  632. public void PawTurnFront(int num = 2)
  633. {
  634. MaterailLibrary_Write("", true, num);
  635. }
  636. public void PawTurnBack(int num = 2)
  637. {
  638. MaterailLibrary_Write("", true, num);
  639. }
  640. /// <summary>
  641. /// 设定机械臂的位置
  642. /// </summary>
  643. /// <param name="x"></param>
  644. /// <param name="y"></param>
  645. public bool SetArmPosition(int x, int y, int num = 2)
  646. {
  647. //取反
  648. x -= 2 * x;
  649. y -= 2 * y;
  650. MaterailLibrary_Write("VD836", x, num);
  651. Thread.Sleep(100);
  652. MaterailLibrary_Write("VD840", y, num);
  653. Thread.Sleep(200);
  654. MessageLog.GetInstance.Show($"机械臂移动到[{x},{y}]");
  655. //定位启动
  656. MaterailLibrary_Write("M0.0", true, num);
  657. for (int i = 0; i < sleepCount && !ml_morkf.ArriveComplete; i++)
  658. {
  659. Thread.Sleep(sleepTime);
  660. if (i >= sleepCount - 1)
  661. {
  662. MessageLog.GetInstance.Show("机械臂移动操作超时");
  663. return false;
  664. }
  665. }
  666. MessageLog.GetInstance.Show("机械臂移动操作完成");
  667. Thread.Sleep(500);
  668. return true;
  669. }
  670. //菜品库锁
  671. object lock_Materail = new object();
  672. private const int up = 10000;
  673. /// <summary>
  674. /// 获取菜品
  675. /// </summary>
  676. public void GetMaterail(int x,int y)
  677. {
  678. //设置到抓菜处
  679. if(!SetArmPosition(x, y))
  680. {
  681. return;
  682. }
  683. //Thread.Sleep(2000);
  684. //关闭电磁阀
  685. Electromagnetism(new List<bool> { true });
  686. Thread.Sleep(500);
  687. //爪子去1号位抓菜
  688. if (!GetDistance_1())
  689. {
  690. return;
  691. }
  692. Thread.Sleep(500);
  693. //移动前开启电磁阀
  694. Electromagnetism(new List<bool> { false });
  695. Thread.Sleep(500);
  696. //设置到出菜处,都在x轴-40000处出菜
  697. if (!SetArmPosition(-40000, y))
  698. {
  699. return;
  700. }
  701. Thread.Sleep(500);
  702. //爪子去3号位放菜
  703. if (!GetDistance_3())
  704. {
  705. return;
  706. }
  707. Thread.Sleep(500);
  708. ////关闭电磁阀
  709. //Electromagnetism(new List<bool> { false });
  710. //Thread.Sleep(300);
  711. }
  712. /// <summary>
  713. /// 获取菜品测试
  714. /// </summary>
  715. /// <param name="isGet"></param>
  716. private void GetMaterailTest(int getNum)
  717. {
  718. ThreadManage.GetInstance().Start(new Action(()=>{
  719. int x1 = 0, x2 = 0, y= 0;
  720. for (int i = 0; i < sleepCount * 2 && ml_morkf.MaterailIsWorking; i++)
  721. {
  722. Thread.Sleep(sleepTime);
  723. if (i >= sleepCount * 2 - 1)
  724. {
  725. MessageLog.GetInstance.Show("菜品库正在工作中.....");
  726. return;
  727. }
  728. }
  729. //if (!ml_morkf.InitialComplete)
  730. //{
  731. // MessageLog.GetInstance.Show("菜品库未初始化");
  732. // return;
  733. //}
  734. if (getNum == 0)
  735. {
  736. x2 = -20000;
  737. y = 40000;
  738. }
  739. else if (getNum == 1)
  740. {
  741. x2 = -15000;
  742. y = -52500;
  743. }
  744. else
  745. {
  746. MessageLog.GetInstance.Show("菜品库无效操作");
  747. return;
  748. }
  749. try
  750. {
  751. lock (lock_Materail)
  752. {
  753. ml_morkf.MaterailIsWorking = true;
  754. }
  755. //菜品库去指定位置
  756. if (!SetArmPosition(x1, y))
  757. {
  758. MessageLog.GetInstance.Show("菜品库[机械臂操作失败]");
  759. return;
  760. }
  761. //取菜操作
  762. GetMaterail(x2,y);
  763. //机械臂去取菜放位
  764. if (!SetArmPosition(-30000, -20000))
  765. {
  766. MessageLog.GetInstance.Show("菜品库[机械臂操作失败]");
  767. return;
  768. }
  769. //机械臂回原点
  770. if (!SetArmPosition(0, 0))
  771. {
  772. MessageLog.GetInstance.Show("菜品库[机械臂操作失败]");
  773. return;
  774. }
  775. }
  776. catch (Exception ex)
  777. {
  778. }
  779. finally
  780. {
  781. lock (lock_Materail)
  782. {
  783. ml_morkf.MaterailIsWorking = false;
  784. }
  785. }
  786. }),$"菜品库操作{getNum}");
  787. }
  788. #endregion
  789. #region 炒锅PLC基本操作方法
  790. /// <summary>
  791. /// 炒锅写寄存器方法,num为炒锅对应编号,从0开始
  792. /// </summary>
  793. /// <param name="address">寄存器地址</param>
  794. /// <param name="value">值</param>
  795. /// <param name="num">炒锅编号</param>
  796. private void FirePot_Write(string address, object value, int num)
  797. {
  798. WriteControlExact(address, value, num);
  799. }
  800. /// <summary>
  801. /// 出调料
  802. /// </summary>
  803. /// <param name="o"></param>
  804. public void OutSeasoning(object o, int num)
  805. {
  806. if (o == null) return;
  807. if (o is List<int> ints && ints.Count == 2 && morkFs.ContainsKey(num))
  808. {
  809. FirePot_Write(morkFs[num].PassWayValue[ints[0]], (ushort)ints[1], num);//写入通道值
  810. Thread.Sleep(400);
  811. FirePot_Write(morkFs[num].StartPassWay[ints[0]], true, num);//开启通道
  812. Thread.Sleep(400);
  813. FirePot_Write(morkFs[num].StartPassWay[ints[0]], false, num);//开启通道
  814. }
  815. }
  816. /// <summary>
  817. /// 出多个调料
  818. /// </summary>
  819. public void OutSeasonings(List<SeasoningList> seasoningLists, int num)
  820. {
  821. //防止越界
  822. if (!morkFs.ContainsKey(num))
  823. {
  824. return;
  825. }
  826. foreach (SeasoningList seasoning in seasoningLists)
  827. {
  828. FirePot_Write(morkFs[num].PassWayValue[seasoning.Loc], (ushort)seasoning.Qty, num);
  829. Thread.Sleep(300);
  830. }
  831. foreach (SeasoningList seasoning in seasoningLists)
  832. {
  833. FirePot_Write(morkFs[num].StartPassWay[seasoning.Loc], true, num);
  834. Thread.Sleep(300);
  835. }
  836. foreach (SeasoningList seasoning in seasoningLists)
  837. {
  838. FirePot_Write(morkFs[num].StartPassWay[seasoning.Loc], false, num);
  839. Thread.Sleep(300);
  840. }
  841. foreach (SeasoningList seasoning in seasoningLists)
  842. {
  843. FirePot_Write(morkFs[num].StartPassWay[seasoning.Loc], false, num);
  844. Thread.Sleep(300);
  845. }
  846. }
  847. /// <summary>
  848. /// 复位
  849. /// </summary>
  850. public void Plc1Reset(int num)
  851. {
  852. ThreadManage.GetInstance().Start(new Action(() =>
  853. {
  854. StopFire(num);
  855. Thread.Sleep(200);
  856. StopStir(num);
  857. Thread.Sleep(200);
  858. FirePot_Write("LB5", false, num);
  859. Thread.Sleep(200);
  860. FirePot_Write("LB3", false, num);
  861. Thread.Sleep(200);
  862. FirePot_Write("LB6", false, num);
  863. Thread.Sleep(200);
  864. FirePot_Write("LB7", false, num);
  865. Thread.Sleep(200);
  866. FirePot_Write("LB4", false, num);
  867. Thread.Sleep(200);
  868. FirePot_Write("LB53", false, num);
  869. if (morkFs.ContainsKey(num))
  870. {
  871. foreach (var item in morkFs[num].StartPassWay.Values)
  872. {
  873. Thread.Sleep(200);
  874. FirePot_Write(item, false, num);
  875. }
  876. }
  877. }), "炒锅1初始化");
  878. }
  879. /// <summary>
  880. /// 炒锅初始化
  881. /// </summary>
  882. public void PLCInite()
  883. {
  884. for (int i = 0; i < morkFs.Count; i++)
  885. {
  886. FirePot_Write("LB0", true, i);
  887. for (int j = 0; j < sleepCount && !morkFs[i].FryPot1_InitialComplete; j++)
  888. {
  889. Thread.Sleep(sleepTime);
  890. if (j >= sleepCount - 1)
  891. {
  892. MessageLog.GetInstance.Show($"炒锅{j}初始化超时");
  893. }
  894. }
  895. //while (!morkFs[i].FryPot1_InitialComplete)
  896. //{
  897. // Thread.Sleep(500);
  898. //}
  899. FirePot_Write("LB0", false, i);
  900. }
  901. }
  902. //加油
  903. public void AddOil()
  904. {
  905. }
  906. //加热启动
  907. public void StartFire(int num)
  908. {
  909. FirePot_Write("LB1", true, num);
  910. Thread.Sleep(200);
  911. }
  912. //加热停止
  913. public void StopFire(int num)
  914. {
  915. FirePot_Write("LB1", false, num);
  916. Thread.Sleep(200);
  917. }
  918. //搅拌启动
  919. public void StartStir(int num)
  920. {
  921. FirePot_Write("LB2", true, num);
  922. Thread.Sleep(200);
  923. }
  924. //搅拌启停止
  925. public void StopStir(int num)
  926. {
  927. FirePot_Write("LB2", false, num);
  928. Thread.Sleep(200);
  929. }
  930. //倒菜
  931. public void OutFood(int num)
  932. {
  933. if (!morkFs.ContainsKey(num))
  934. {
  935. return;
  936. }
  937. FirePot_Write("LB3", true, num);
  938. MessageLog.GetInstance.Show("倒菜启动");
  939. Thread.Sleep(400);
  940. for (int i = 0; i < sleepCount && !morkFs[num].FryPot1_MaterialIntoPot; i++)
  941. {
  942. Thread.Sleep(sleepTime);
  943. if (i >= sleepCount - 1)
  944. {
  945. MessageLog.GetInstance.Show($"炒锅{num}倒菜超时");
  946. }
  947. }
  948. FirePot_Write("LB3", false, num);
  949. Thread.Sleep(200);
  950. MessageLog.GetInstance.Show("倒菜完成");
  951. }
  952. //搅拌臂去原点位
  953. public void StirArmGoOrigin(int num)
  954. {
  955. if (!morkFs.ContainsKey(num))
  956. {
  957. return;
  958. }
  959. FirePot_Write("LB5", true, num);
  960. MessageLog.GetInstance.Show("搅拌臂去原点位");
  961. for (int i = 0; i < sleepCount && !morkFs[num].ArmOnOrigin; i++)
  962. {
  963. Thread.Sleep(sleepTime);
  964. if (i >= sleepCount - 1)
  965. {
  966. MessageLog.GetInstance.Show($"炒锅{num}搅拌臂去原点位超时");
  967. }
  968. }
  969. //while (!morkFs[num].ArmOnOrigin)
  970. //{
  971. // Thread.Sleep(200);
  972. //}
  973. FirePot_Write("LB5", false, num);
  974. Thread.Sleep(200);
  975. MessageLog.GetInstance.Show("搅拌臂到达原点位");
  976. }
  977. //搅拌臂去炒制位
  978. public void StirArmGoWork(int num)
  979. {
  980. if (!morkFs.ContainsKey(num))
  981. {
  982. return;
  983. }
  984. if (!morkFs[num].ArmOnWorking/* && morkFs[num].PotOnOrigin*/)
  985. {
  986. FirePot_Write("LB6", true, num);
  987. MessageLog.GetInstance.Show("搅拌臂去工作位");
  988. for (int i = 0; i < sleepCount && !morkFs[num].ArmOnWorking; i++)
  989. {
  990. Thread.Sleep(sleepTime);
  991. if (i >= sleepCount - 1)
  992. {
  993. MessageLog.GetInstance.Show($"炒锅{num}搅拌臂去炒制位超时");
  994. }
  995. }
  996. //while (!morkFs[num].ArmOnWorking)
  997. //{
  998. // Thread.Sleep(200);
  999. //}
  1000. FirePot_Write("LB6", false, num);
  1001. Thread.Sleep(200);
  1002. MessageLog.GetInstance.Show("搅拌臂到达工作位");
  1003. }
  1004. }
  1005. //HBOT放盒子到位
  1006. public void HBOTGoWork(int num)
  1007. {
  1008. FirePot_Write("LB7", true, num);
  1009. Thread.Sleep(400);
  1010. FirePot_Write("LB7", false, num);
  1011. }
  1012. //出餐启动
  1013. public void OutMeal(int num)
  1014. {
  1015. if (!morkFs[num].ArmOnOrigin /*&& morkFs[num].PotOnOrigin*/)
  1016. {
  1017. MessageLog.GetInstance.Show("搅拌臂不在原点位,无法完成出餐");
  1018. return;
  1019. }
  1020. FirePot_Write("LB4", true, num);
  1021. Thread.Sleep(200);
  1022. FirePot_Write("LB4", false, num);
  1023. }
  1024. //加热挡位设定
  1025. public void SetFire(object o, int num)
  1026. {
  1027. if (o == null) return;
  1028. if (o is List<int> ints && ints.Count == 1)
  1029. {
  1030. FirePot_Write("LW14", (ushort)ints[0], num);
  1031. Thread.Sleep(200);
  1032. }
  1033. }
  1034. public void SetFry(object o)
  1035. {
  1036. if (o == null) return;
  1037. if (o is List<int> ints && ints.Count == 1)
  1038. {
  1039. fryIndex = ints[0] - 1;
  1040. }
  1041. }
  1042. /// <summary>
  1043. /// 搅拌挡位设定
  1044. /// </summary>
  1045. /// <param name="o"></param>
  1046. public void SetStir(object o, int num)
  1047. {
  1048. if (o == null) return;
  1049. if (o is List<int> ints && ints.Count == 1)
  1050. {
  1051. FirePot_Write("LW15", (ushort)ints[0], num);
  1052. Thread.Sleep(200);
  1053. }
  1054. }
  1055. #endregion
  1056. bool isInitialArrive = false;
  1057. bool isInitialPaw = false;
  1058. #region 联网交互
  1059. private void ServerInit()
  1060. {
  1061. //物料信息
  1062. EventBus.EventBus.GetInstance().Subscribe<MaterialDeliveryEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  1063. {
  1064. if (@event == null) return;
  1065. if (@event is MaterialDeliveryEvent material)
  1066. {
  1067. orderMaterialDelivery = material.orderMaterialDelivery;
  1068. }
  1069. });
  1070. //配方数据信息
  1071. EventBus.EventBus.GetInstance().Subscribe<RecipeBomEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  1072. {
  1073. if (@event == null) return;
  1074. if (@event is RecipeBomEvent recipe)
  1075. {
  1076. recipeBoms = recipe.recipeBoms;
  1077. }
  1078. });
  1079. //小炒流程信息
  1080. EventBus.EventBus.GetInstance().Subscribe<StirFryGoodsEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callback)
  1081. {
  1082. if (@event == null) return;
  1083. if (@event is StirFryGoodsEvent stirFry)
  1084. {
  1085. if(stirFry.stirFrymessage != null)
  1086. {
  1087. if (stirFry.stirFrymessage.stirFryGoods.Count > 0)
  1088. {
  1089. foreach (var item in stirFry.stirFrymessage.stirFryGoods)
  1090. {
  1091. LocalstirFryGoods.Add(new StirFryGoods
  1092. {
  1093. GoodsKey = item.GoodsKey,
  1094. StirPotActions = OrderSort(item.StirPotActions),
  1095. });
  1096. GlobalFoodMenu.LocalFoodMenus.Add(new FoodMenuModel
  1097. {
  1098. GoodKey = item.GoodsKey.ToString(),
  1099. GoodName = "",
  1100. });
  1101. }
  1102. }
  1103. }
  1104. MessageLog.GetInstance.Show("接收到小炒流程信息");
  1105. //流程解析
  1106. foreach (var item in LocalstirFryGoods)
  1107. {
  1108. MessageLog.GetInstance.Show($"添加菜谱{item.GoodsKey}");
  1109. // morkF.listStirBom.Add(item.StirFryBomInfo);//添加订单制作流程
  1110. string MenuStep = "菜单步骤:";
  1111. foreach (var items in item.StirPotActions)
  1112. {
  1113. switch (items.Actions)
  1114. {
  1115. case nameof(StirFryPotActionEnum.加热开启):
  1116. MenuStep += items.Actions + ",";
  1117. break;
  1118. case nameof(StirFryPotActionEnum.设置加热挡位1):
  1119. MenuStep += items.Actions + ",";
  1120. break;
  1121. case nameof(StirFryPotActionEnum.设置加热挡位2):
  1122. MenuStep += items.Actions + ",";
  1123. break;
  1124. case nameof(StirFryPotActionEnum.设置加热挡位3):
  1125. MenuStep += items.Actions + ",";
  1126. break;
  1127. case nameof(StirFryPotActionEnum.设置加热挡位4):
  1128. MenuStep += items.Actions + ",";
  1129. break;
  1130. case nameof(StirFryPotActionEnum.设置加热挡位5):
  1131. MenuStep += items.Actions + ",";
  1132. break;
  1133. case nameof(StirFryPotActionEnum.设置加热挡位6):
  1134. MenuStep += items.Actions + ",";
  1135. break;
  1136. case nameof(StirFryPotActionEnum.设置加热挡位7):
  1137. MenuStep += items.Actions + ",";
  1138. break;
  1139. case nameof(StirFryPotActionEnum.设置加热挡位8):
  1140. MenuStep += items.Actions + ",";
  1141. break;
  1142. case nameof(StirFryPotActionEnum.设置加热挡位9):
  1143. MenuStep += items.Actions + ",";
  1144. break;
  1145. case nameof(StirFryPotActionEnum.设置加热挡位10):
  1146. MenuStep += items.Actions + ",";
  1147. break;
  1148. case nameof(StirFryPotActionEnum.停止加热):
  1149. MenuStep += items.Actions + ",";
  1150. break;
  1151. case nameof(StirFryPotActionEnum.加调料):
  1152. MenuStep += items.Actions + ",";
  1153. break;
  1154. case nameof(StirFryPotActionEnum.取原料):
  1155. MenuStep += items.Actions + ",";
  1156. break;
  1157. case nameof(StirFryPotActionEnum.开启搅拌):
  1158. MenuStep += items.Actions + ",";
  1159. break;
  1160. case nameof(StirFryPotActionEnum.设置搅拌挡位1):
  1161. MenuStep += items.Actions + ",";
  1162. break;
  1163. case nameof(StirFryPotActionEnum.设置搅拌挡位2):
  1164. MenuStep += items.Actions + ",";
  1165. break;
  1166. case nameof(StirFryPotActionEnum.设置搅拌挡位3):
  1167. MenuStep += items.Actions + ",";
  1168. break;
  1169. case nameof(StirFryPotActionEnum.关闭搅拌):
  1170. MenuStep += items.Actions + ",";
  1171. break;
  1172. case nameof(StirFryPotActionEnum.出餐启动):
  1173. MenuStep += items.Actions + ",";
  1174. break;
  1175. case nameof(StirFryPotActionEnum.道菜启动):
  1176. MenuStep += items.Actions + ",";
  1177. break;
  1178. case nameof(StirFryPotActionEnum.炒制菜品):
  1179. MenuStep += items.Actions + ",";
  1180. break;
  1181. case nameof(StirFryPotActionEnum.搅拌臂原点位):
  1182. MenuStep += items.Actions + ",";
  1183. break;
  1184. case nameof(StirFryPotActionEnum.搅拌臂炒制位):
  1185. MenuStep += items.Actions + ",";
  1186. break;
  1187. case nameof(StirFryPotActionEnum.洗锅):
  1188. MenuStep += items.Actions + ",";
  1189. break;
  1190. default:
  1191. break;
  1192. }
  1193. }
  1194. MessageLog.GetInstance.Show(MenuStep);
  1195. }
  1196. }
  1197. });
  1198. }
  1199. /// <summary>
  1200. /// 订单排序
  1201. /// </summary>
  1202. /// <param name="potActions"></param>
  1203. /// <returns></returns>
  1204. private List<PotActions> OrderSort(List<PotActions> potActions)
  1205. {
  1206. if (potActions.Count > 1)
  1207. {
  1208. potActions.Sort(
  1209. delegate (PotActions st1, PotActions st2)
  1210. {
  1211. //降序排列
  1212. //return st2.FryTime.CompareTo(st1.FryTime);
  1213. //升序版(颠倒 st1 和 st2 即可)
  1214. return st1.FryTime.CompareTo(st2.FryTime);
  1215. });
  1216. }
  1217. return potActions;
  1218. }
  1219. /// <summary>
  1220. /// 订单状态发布
  1221. /// </summary>
  1222. /// <param name="subid"></param>
  1223. /// <param name="oRDER_STATUS"></param>
  1224. private void OrderChange(string subid, ORDER_STATUS oRDER_STATUS)
  1225. {
  1226. EventBus.EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { Status = oRDER_STATUS, SubOrderId = subid });
  1227. }
  1228. /// <summary>
  1229. /// 数据解析
  1230. /// </summary>
  1231. private void DataParse()
  1232. {
  1233. //if (!morkFs.ContainsKey(num))
  1234. //{
  1235. // return;
  1236. //}
  1237. EventBus.EventBus.GetInstance().Subscribe<DoOrderEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle)
  1238. {
  1239. if (@event == null) return;
  1240. if (@event is DoOrderEvent order)
  1241. {
  1242. if (order.MorkOrder.GoodBatchings == null) return;
  1243. OrderCount++;
  1244. DeviceProcessLogShow($"接收到{OrderCount}次订单");
  1245. Enum.GetNames(typeof(StirFryPotActionEnum));
  1246. //var res = LocalstirFryGoods?.FirstOrDefault(p => p.GoodsKey == order.MorkOrder.RecipeId);//匹配订单对应制作流程
  1247. if(order.MorkOrder.GoodBatchings.Count <= 0)
  1248. {
  1249. return;
  1250. }
  1251. if(order.MorkOrder.DeviceId != DeviceId)
  1252. {
  1253. return;
  1254. }
  1255. //var res = LocalstirFryGoods[0];
  1256. //if (res != null)
  1257. //{
  1258. // /* morkF.listStirBom.Add(res.StirFryBomInfo);*///添加订单制作流程
  1259. // //添加到带炒小炒队列
  1260. // if (StirFryGoodsQuenes.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  1261. // {
  1262. // lock (lock_MainProcessExcute)
  1263. // {
  1264. // StirFryGoodsQuenes.Enqueue(new OrderLocInfo()
  1265. // {
  1266. // SuborderId = order.MorkOrder.SuborderId,
  1267. // StirPotActions = res.StirPotActions,
  1268. // GoodName = order.MorkOrder.GoodsName
  1269. // });
  1270. // }
  1271. // }
  1272. //}
  1273. //暂时使用本地菜单
  1274. StartLocalOrder();
  1275. }
  1276. });
  1277. }
  1278. #endregion
  1279. private object lock_MainProcessExcute = new object();
  1280. /// <summary>
  1281. /// 炒锅主流程
  1282. /// </summary>
  1283. private void MainProcessExcute()
  1284. {
  1285. //判断是否有订单信息
  1286. if(StirFryGoodsQuenes.Count > 0)
  1287. {
  1288. //遍历炒锅,找到合适、空闲的炒锅
  1289. for(int i = 0;i<morkFs.Count;i++)
  1290. {
  1291. if (/*morkFs[i].AutoMode && morkFs[i].FryPot1_InitialComplete &&*/
  1292. !morkFs[i].FryWorking)//炒锅在自动状态&&初始化完成&&是否在炒菜中
  1293. {
  1294. lock(lock_MainProcessExcute)
  1295. {
  1296. //待炒小炒队列出队列
  1297. if (StirFryGoodsQuenes.TryDequeue(out var res))
  1298. {
  1299. //设置当前炒制菜品
  1300. nowStirFryGood = res;
  1301. //炒锅工作状态置为正在工作中
  1302. morkFs[i].FryWorking = true;
  1303. //空闲炒锅入队列
  1304. morkFs[i].StirFryGoodsQuenes.Enqueue(res);
  1305. MessageLog.GetInstance.Show($"炒锅{i}开始炒制菜品{res.GoodName}");
  1306. //开启线程进行炒制
  1307. ThreadManage.GetInstance().Start(new Action(() =>
  1308. {
  1309. try
  1310. {
  1311. int getMaterailNum = 0;
  1312. foreach (var potActions in res.StirPotActions)
  1313. {
  1314. if (ThreadManage.GetInstance().IsCanncel(String.Format(striConst, i.ToString(), nowStirFryGood.GoodName)))
  1315. {
  1316. return;
  1317. }
  1318. switch (potActions.Actions)
  1319. {
  1320. case nameof(StirFryPotActionEnum.加热开启):
  1321. StartFire(i);
  1322. MessageLog.GetInstance.Show(potActions.Actions);
  1323. break;
  1324. case nameof(StirFryPotActionEnum.设置加热挡位1):
  1325. SetFire(new List<int> { 1 }, i);
  1326. MessageLog.GetInstance.Show(potActions.Actions);
  1327. break;
  1328. case nameof(StirFryPotActionEnum.设置加热挡位2):
  1329. SetFire(new List<int> { 2 }, i);
  1330. MessageLog.GetInstance.Show(potActions.Actions);
  1331. break;
  1332. case nameof(StirFryPotActionEnum.设置加热挡位3):
  1333. SetFire(new List<int> { 3 }, i);
  1334. MessageLog.GetInstance.Show(potActions.Actions);
  1335. break;
  1336. case nameof(StirFryPotActionEnum.设置加热挡位4):
  1337. SetFire(new List<int> { 4 }, i);
  1338. MessageLog.GetInstance.Show(potActions.Actions);
  1339. break;
  1340. case nameof(StirFryPotActionEnum.设置加热挡位5):
  1341. SetFire(new List<int> { 5 }, i);
  1342. MessageLog.GetInstance.Show(potActions.Actions);
  1343. break;
  1344. case nameof(StirFryPotActionEnum.设置加热挡位6):
  1345. SetFire(new List<int> { 6 }, i);
  1346. MessageLog.GetInstance.Show(potActions.Actions);
  1347. break;
  1348. case nameof(StirFryPotActionEnum.设置加热挡位7):
  1349. SetFire(new List<int> { 7 }, i);
  1350. MessageLog.GetInstance.Show(potActions.Actions);
  1351. break;
  1352. case nameof(StirFryPotActionEnum.设置加热挡位8):
  1353. SetFire(new List<int> { 8 }, i);
  1354. MessageLog.GetInstance.Show(potActions.Actions);
  1355. break;
  1356. case nameof(StirFryPotActionEnum.设置加热挡位9):
  1357. SetFire(new List<int> { 9 }, i);
  1358. MessageLog.GetInstance.Show(potActions.Actions);
  1359. break;
  1360. case nameof(StirFryPotActionEnum.设置加热挡位10):
  1361. SetFire(new List<int> { 10 }, i);
  1362. MessageLog.GetInstance.Show(potActions.Actions);
  1363. break;
  1364. case nameof(StirFryPotActionEnum.停止加热):
  1365. StopFire(i);
  1366. MessageLog.GetInstance.Show(potActions.Actions);
  1367. break;
  1368. case nameof(StirFryPotActionEnum.加调料):
  1369. OutSeasonings(potActions.SeasoningLists, i);
  1370. MessageLog.GetInstance.Show(potActions.Actions);
  1371. break;
  1372. case nameof(StirFryPotActionEnum.取原料):
  1373. GetMaterailTest(getMaterailNum);
  1374. getMaterailNum++;
  1375. MessageLog.GetInstance.Show(potActions.Actions);
  1376. break;
  1377. case nameof(StirFryPotActionEnum.开启搅拌):
  1378. StartStir(i);
  1379. MessageLog.GetInstance.Show(potActions.Actions);
  1380. break;
  1381. case nameof(StirFryPotActionEnum.设置搅拌挡位1):
  1382. SetStir(new List<int> { 1 }, i);
  1383. MessageLog.GetInstance.Show(potActions.Actions);
  1384. break;
  1385. case nameof(StirFryPotActionEnum.设置搅拌挡位2):
  1386. SetStir(new List<int> { 2 }, i);
  1387. MessageLog.GetInstance.Show(potActions.Actions);
  1388. break;
  1389. case nameof(StirFryPotActionEnum.设置搅拌挡位3):
  1390. SetStir(new List<int> { 3 }, i);
  1391. MessageLog.GetInstance.Show(potActions.Actions);
  1392. break;
  1393. case nameof(StirFryPotActionEnum.关闭搅拌):
  1394. StopStir(i);
  1395. MessageLog.GetInstance.Show(potActions.Actions);
  1396. break;
  1397. case nameof(StirFryPotActionEnum.出餐启动):
  1398. MessageLog.GetInstance.Show(potActions.Actions);
  1399. break;
  1400. case nameof(StirFryPotActionEnum.道菜启动):
  1401. OutFood(i);
  1402. break;
  1403. case nameof(StirFryPotActionEnum.炒制菜品):
  1404. Thread.Sleep(potActions.During * 1000);
  1405. break;
  1406. case nameof(StirFryPotActionEnum.搅拌臂原点位):
  1407. StirArmGoOrigin(i);
  1408. MessageLog.GetInstance.Show(potActions.Actions);
  1409. break;
  1410. case nameof(StirFryPotActionEnum.搅拌臂炒制位):
  1411. StirArmGoWork(i);
  1412. MessageLog.GetInstance.Show(potActions.Actions);
  1413. break;
  1414. case nameof(StirFryPotActionEnum.洗锅):
  1415. MessageLog.GetInstance.Show(potActions.Actions);
  1416. break;
  1417. default:
  1418. break;
  1419. }
  1420. }
  1421. Plc1Reset(i);//复位
  1422. Thread.Sleep(3000);
  1423. //回原点位
  1424. StirArmGoOrigin(i);
  1425. //while (!morkFs[i].ArmOnOrigin)
  1426. //{
  1427. // Thread.Sleep(100);
  1428. //}
  1429. //出餐
  1430. //OutMeal(i);
  1431. MessageLog.GetInstance.Show($"菜品{res.GoodName}完成");
  1432. }
  1433. catch (Exception ex)
  1434. {
  1435. ThreadManage.GetInstance().StopTask($"炒锅{i}{res.GoodName}炒制线程");
  1436. MessageLog.GetInstance.Show($"炒锅{i}炒制菜品{res.GoodName}出错,错误信息:" + ex.Message);
  1437. }
  1438. finally
  1439. {
  1440. nowStirFryGood = null;
  1441. //炒完后出队列
  1442. morkFs[i].StirFryGoodsQuenes.TryDequeue(out var orderQueue);
  1443. morkFs[i].FryWorking = false;
  1444. }
  1445. }), String.Format(striConst, i.ToString(), nowStirFryGood.GoodName)/*$"炒锅{i}炒制{res.GoodName}线程"*/);
  1446. }
  1447. }
  1448. break;
  1449. }
  1450. }
  1451. }
  1452. }
  1453. /// <summary>
  1454. /// 信号处理
  1455. /// </summary>
  1456. private void SingleProcess()
  1457. {
  1458. //if (!morkF.AutoMode)
  1459. //{
  1460. // if (morkF.IsAuto)
  1461. // {
  1462. // Plc1Reset();
  1463. // morkF.IsAuto = false;
  1464. // }
  1465. //}
  1466. //else morkF.IsAuto = true;
  1467. }
  1468. public override void SimOrder()
  1469. {
  1470. ActionManage.GetInstance.Register(morkSim, "模拟小炒锅1订单");
  1471. }
  1472. private void morkSim(object o)
  1473. {
  1474. //if (o == null) return;
  1475. //if(o is List<int> ins)
  1476. //{
  1477. // ThreadManage.GetInstance().Start(new Action(() =>
  1478. // {
  1479. // if (morkF.FryPot1_InitialComplete && morkF.AutoMode)//初始化完成&&自动模式&& 锅在原点位置
  1480. // {
  1481. // if (!morkF.ArmOnWorking)//搅拌臂是否在工作位
  1482. // {
  1483. // StirArmGoWork();
  1484. // while (!morkF.ArmOnWorking)
  1485. // {
  1486. // Thread.Sleep(500);
  1487. // }
  1488. // OutSeasoning(new List<int> { 1, 100 });//加油500g
  1489. // while (!morkF.PassWay1_1Compelete)
  1490. // {
  1491. // Thread.Sleep(1000);
  1492. // }
  1493. // WriteControlExact(morkF.StartPassWay[ 1], false);//开启通道关闭
  1494. // Thread.Sleep(500);
  1495. // SetFire(new List<int> { ins[1] });//加热三档
  1496. // StartFire();//开始加热
  1497. // Thread.Sleep(500);
  1498. // SetStir(new List<int> { ins[2] });//搅拌二挡
  1499. // Thread.Sleep(500);
  1500. // StartStir();//开始搅拌
  1501. // Thread.Sleep(ins[0]*1000);//加热10s
  1502. // OutSeasoning(new List<int> { 11, 30 });//加调料1 50g
  1503. // Thread.Sleep(400);
  1504. // OutSeasoning(new List<int> { 12, 30 });//加调料2 30g
  1505. // while (!morkF.PassWay1_11Compelete&& !morkF.PassWay1_12Compelete)
  1506. // {
  1507. // Thread.Sleep(1000);
  1508. // }
  1509. // WriteControlExact(morkF.StartPassWay[11], false);//开启通道关闭
  1510. // Thread.Sleep(500);
  1511. // WriteControlExact(morkF.StartPassWay[12], false);//开启通道信号关闭
  1512. // Thread.Sleep(500);
  1513. // OutFood();//倒菜品1
  1514. // while (!morkF.FryPot1_MaterialIntoPot)//菜品1倒菜完成
  1515. // {
  1516. // Thread.Sleep(500);
  1517. // }
  1518. // WriteControlExact("LB53", false);
  1519. // Thread.Sleep(500);
  1520. // SetFire(new List<int> { ins[4] });//菜品1加热档
  1521. // Thread.Sleep(500);
  1522. // SetStir(new List<int>() { ins[5] });//菜品1搅拌挡
  1523. // Thread.Sleep(ins[3]*1000);//菜品1炒制时间
  1524. // OutSeasoning(new List<int> {3, 8 });//加调料3 20g
  1525. // while (!morkF.PassWay1_3Compelete)
  1526. // {
  1527. // Thread.Sleep(1000);
  1528. // }
  1529. // WriteControlExact(morkF.StartPassWay[3], false);//开启通道信号关闭
  1530. // Thread.Sleep(500);
  1531. // OutFood();//倒菜菜品2
  1532. // while (!morkF.FryPot1_MaterialIntoPot)//菜品2倒菜完成
  1533. // {
  1534. // Thread.Sleep(500);
  1535. // }
  1536. // WriteControlExact("LB53", false);
  1537. // Thread.Sleep(500);
  1538. // SetFire(new List<int> { ins[7] });//菜品2加热档
  1539. // Thread.Sleep(500);
  1540. // SetStir(new List<int>() { ins[8] });//菜品2搅拌挡
  1541. // Thread.Sleep(ins[6] * 1000);//菜品2炒制时间
  1542. // StopStir();//停止搅拌
  1543. // Thread.Sleep(500);
  1544. // StopFire();//停止加热
  1545. // Thread.Sleep(2000);
  1546. // StirArmGoOrigin();//搅拌臂回原点位
  1547. // }
  1548. // }
  1549. // }), "模拟炒锅1订单");
  1550. //}
  1551. }
  1552. }
  1553. }