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

2047 lines
93 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. namespace BPASmartClient.MorkF
  12. {
  13. public class Control_MorkF : BaseDevice
  14. {
  15. public override DeviceClientType DeviceType => DeviceClientType.MORKSF;
  16. public AutoResetEvent minorReset = new AutoResetEvent(false);
  17. public AutoResetEvent mainReset = new AutoResetEvent(false);
  18. GVL_MorkF morkF = new GVL_MorkF();//全局对象声明
  19. public StirFryBom stirFryBom = new StirFryBom();//创建获取流程的对象
  20. StirFryGoods stirFryGoods = new StirFryGoods();//创建商品对象
  21. List<int> resultorder = new List<int>();//调试变量
  22. /// <summary>
  23. /// 入口
  24. /// </summary>
  25. public override void DoMain()
  26. {
  27. CommandRegist();//调试
  28. ServerInit();
  29. DataParse();//数据解析
  30. DeviceProcessLogShow("MORKF 设备初始化完成");
  31. }
  32. #region 调试代码
  33. public void CommandRegist()
  34. {
  35. ActionManage.GetInstance.Register(PLCInite, "InitCommand");
  36. ActionManage.GetInstance.Register(InitialData, "SimultaorOrder");
  37. ActionManage.GetInstance.Register(MaterialOne, "MaterialOne");
  38. ActionManage.GetInstance.Register(MaterialTwo, "MaterialTwo");
  39. ActionManage.GetInstance.Register(MaterialThree, "MaterialThree");
  40. ActionManage.GetInstance.Register(MaterialFour, "MaterialFour");
  41. ActionManage.GetInstance.Register(MaterialFive, "MaterialFive");
  42. ActionManage.GetInstance.Register(ManualOpenExhaust, "OpenExhaust");
  43. ActionManage.GetInstance.Register(CloseExhaust, "CloaseExhaust");
  44. ActionManage.GetInstance.Register(StartQX, "StartQXOne");
  45. ActionManage.GetInstance.Register(StartQX, "StartQXTwo");
  46. ActionManage.GetInstance.Register(ShreddCabbage, "ShreddCabbage");
  47. ActionManage.GetInstance.Register(FryPork, "FryPork");
  48. ActionManage.GetInstance.Register(XingBaoGu, "XingBaoGu");
  49. ActionManage.GetInstance.Register(TakePot, "TakePot");
  50. ActionManage.GetInstance.Register(TakePotReset, "TakePotReset");
  51. ActionManage.GetInstance.Register(TakeMaterial, "TakeMaterial");
  52. ActionManage.GetInstance.Register(ManualOutMeal, "OutMeal");
  53. ActionManage.GetInstance.Register<Action>(AddOil, "AddOil");
  54. ActionManage.GetInstance.Register(TakeOff, "TakeOff");
  55. ActionManage.GetInstance.Register(OneBlock, "OneBlock");
  56. ActionManage.GetInstance.Register(TwoBlock, "TwoBlock");
  57. ActionManage.GetInstance.Register(ThreeBlock, "ThreeBlock");
  58. ActionManage.GetInstance.Register(OverTurnOff, "OverTurnOff");
  59. ActionManage.GetInstance.Register(OverOneBlock, "OverOneBlock");
  60. ActionManage.GetInstance.Register(OverTwoBlock, "OverTwoBlock");
  61. ActionManage.GetInstance.Register(OverThreeBlock, "OverThreeBlock");
  62. ActionManage.GetInstance.Register(OverGoOn, "OverGoOn");
  63. ActionManage.GetInstance.Register(OverGoDown, "OverGoDown");
  64. ActionManage.GetInstance.Register(AutoModel, "AutoModel");
  65. ActionManage.GetInstance.Register(ManualModel, "ManualModel");
  66. ActionManage.GetInstance.Register<Action>(AddOil, "SecAddOil");
  67. ActionManage.GetInstance.Register(TakeOff, "SecTakeOff");
  68. ActionManage.GetInstance.Register(OneBlock, "SecOneBlock");
  69. ActionManage.GetInstance.Register(TwoBlock, "SecTwoBlock");
  70. ActionManage.GetInstance.Register(ThreeBlock, "SecThreeBlock");
  71. ActionManage.GetInstance.Register(OverTurnOff, "SecOverTurnOff");
  72. ActionManage.GetInstance.Register(OverOneBlock, "SecOverOneBlock");
  73. ActionManage.GetInstance.Register(OverTwoBlock, "SecOverTwoBlock");
  74. ActionManage.GetInstance.Register(OverThreeBlock, "SecOverThreeBlock");
  75. ActionManage.GetInstance.Register(OverGoOn, "SecOverGoOn");
  76. ActionManage.GetInstance.Register(OverGoDown, "SecOverGoDown");
  77. ActionManage.GetInstance.Register(AutoModel, "SecAutoModel");
  78. ActionManage.GetInstance.Register(ManualModel, "SecManualModel");
  79. }
  80. /// <summary>
  81. /// 手撕包菜流程
  82. /// </summary>
  83. public void ShreddCabbage()
  84. {
  85. if (stirFryBom.StirFryActions.Count > 0)
  86. {
  87. stirFryBom.StirFryActions.Clear();
  88. }
  89. //流程
  90. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T1, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.清洗槽取锅 } });
  91. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T2, PotActions = new List<StirFryPotAction>() { StirFryPotAction.大火持续 }, During = 5 });
  92. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T3, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.加入A料 }, PotActions = new List<StirFryPotAction>() { StirFryPotAction.加油, StirFryPotAction.搅拌臂下位, StirFryPotAction.低速旋转 }, During = 6 });
  93. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T4, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止旋转, StirFryPotAction.停止火力, StirFryPotAction.搅拌臂上位 } });//加A料
  94. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T5, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.加入B料 }, PotActions = new List<StirFryPotAction>() { StirFryPotAction.中火持续, StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 6 });
  95. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T6, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止火力, StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });//加B料
  96. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T7, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.加入C料 }, PotActions = new List<StirFryPotAction>() { StirFryPotAction.中火持续, StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 9 });
  97. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T8, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止火力, StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });//加C料
  98. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T9, PotActions = new List<StirFryPotAction>() { StirFryPotAction.中火持续, StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 30 });
  99. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T10, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止火力, StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });
  100. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T11, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.灶取锅 } });
  101. }
  102. /// <summary>
  103. /// 盐煎肉流程
  104. /// </summary>
  105. public void FryPork()
  106. {
  107. if (stirFryBom.StirFryActions.Count > 0)
  108. {
  109. stirFryBom.StirFryActions.Clear();
  110. }
  111. //流程
  112. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T1, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.清洗槽取锅 } });
  113. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T2, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止火力, StirFryPotAction.搅拌臂下位, StirFryPotAction.低速旋转 }, During = 15 });
  114. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T3, PotActions = new List<StirFryPotAction>() { StirFryPotAction.加油, StirFryPotAction.停止火力 }, During = 19 });
  115. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T4, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });
  116. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T5, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.加入A料 } });
  117. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T6, PotActions = new List<StirFryPotAction>() { StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 20 });
  118. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T7, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止火力 }, During = 35 });
  119. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T8, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位, } });
  120. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T9, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.加入B料 } });
  121. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T10, PotActions = new List<StirFryPotAction>() { StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 22 });
  122. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T11, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });
  123. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T12, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.加入C料 } });
  124. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T13, PotActions = new List<StirFryPotAction>() { StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 70 });
  125. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T14, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止火力, StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });
  126. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T15, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.灶取锅 } });
  127. }
  128. /// <summary>
  129. /// 酱烧杏鲍菇流程
  130. /// </summary>
  131. public void XingBaoGu()
  132. {
  133. if (stirFryBom.StirFryActions.Count > 0)
  134. {
  135. stirFryBom.StirFryActions.Clear();
  136. }
  137. //流程
  138. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T1, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.清洗槽取锅 } });
  139. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T2, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.加入A料 }, PotActions = new List<StirFryPotAction>() { StirFryPotAction.中火持续, StirFryPotAction.搅拌臂下位, StirFryPotAction.低速旋转 }, During = 5 });
  140. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T3, PotActions = new List<StirFryPotAction>() { StirFryPotAction.加油 }, During = 12 });
  141. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T4, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });//加A料
  142. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T6, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.加入B料 }, PotActions = new List<StirFryPotAction>() { StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 25 });
  143. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T7, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });//加B料
  144. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T9, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.加入C料 }, PotActions = new List<StirFryPotAction>() { StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 30 });
  145. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T10, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止火力, StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });//加C料
  146. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T6, PotActions = new List<StirFryPotAction>() { StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 55 });
  147. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T11, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.灶取锅 } });
  148. }
  149. public void StartQX(object obj)
  150. {
  151. if ((int)obj == 1)
  152. WriteData("M1.4", true);
  153. if ((int)obj == 2)
  154. WriteData("M1.7", true);
  155. }
  156. public void ManualOpenExhaust()
  157. {
  158. WriteData("M0.7", true);
  159. }
  160. public void CloseExhaust()
  161. {
  162. WriteData("M0.7", false);
  163. }
  164. public void TakeMaterial()
  165. {
  166. WriteData("M14.1", true);
  167. }
  168. public void ManualOutMeal()
  169. {
  170. WriteData("M14.2", true);
  171. }
  172. public void MaterialOne()
  173. {
  174. WriteData("M13.0", true);
  175. }
  176. public void MaterialTwo()
  177. {
  178. WriteData("M13.1", true);
  179. }
  180. public void MaterialThree()
  181. {
  182. WriteData("M13.2", true);
  183. }
  184. public void MaterialFour()
  185. {
  186. WriteData("M13.3", true);
  187. }
  188. public void MaterialFive()
  189. {
  190. WriteData("M13.4", true);
  191. }
  192. public void AutoModel(object obj)
  193. {
  194. WriteData("0.3", true);
  195. }
  196. public void ManualModel()
  197. {
  198. WriteData("0.2", true);
  199. }
  200. public void AddOil(object obj)
  201. {
  202. if ((int)obj == 1)
  203. {
  204. Task.Run(() => { WriteData("M2.7", true); Task.Delay(4000).Wait(); WriteData("M2.7", false); });
  205. }
  206. if ((int)obj == 2)
  207. {
  208. Task.Run(() => { WriteData("M3.1", true); Task.Delay(4000).Wait(); WriteData("M3.1", false); });
  209. }
  210. }
  211. public void TakePot(object obj)
  212. {
  213. WriteData("M14.0", true);
  214. }
  215. public void TakePotReset(object obj)
  216. {
  217. WriteData("M14.0", false);
  218. }
  219. public void TakeOff(object obj)
  220. {
  221. if ((int)obj == 1)
  222. WriteData("M4.0", new bool[] { false, false, false, false, false, false, false, false });//0000 0000
  223. if ((int)obj == 2)
  224. WriteData("M5.0", new bool[] { false, false, false, false, false, false, false, false });//0000 0000
  225. }
  226. public void OneBlock(object obj)
  227. {
  228. if ((int)obj == 1)
  229. WriteData("M4.0", new bool[] { true, false, false, false, false, false, false, false });//0000 0001
  230. if ((int)obj == 2)
  231. WriteData("M5.0", new bool[] { true, false, false, false, false, false, false, false });//0000 0001
  232. }
  233. public void TwoBlock(object obj)
  234. {
  235. if ((int)obj == 1)
  236. WriteData("M4.0", new bool[] { false, true, false, false, false, false, false, false });//0000 0010
  237. if ((int)obj == 2)
  238. WriteData("M5.0", new bool[] { false, true, false, false, false, false, false, false });//0000 0010
  239. }
  240. public void ThreeBlock(object obj)
  241. {
  242. if ((int)obj == 1)
  243. WriteData("M4.0", new bool[] { true, true, false, false, false, false, false, false });//0000 0011
  244. if ((int)obj == 2)
  245. WriteData("M5.0", new bool[] { true, true, false, false, false, false, false, false });//0000 0011
  246. }
  247. public void OverTurnOff(object obj)
  248. {
  249. if ((int)obj == 1)
  250. WriteData("M7.0", true);
  251. if ((int)obj == 2)
  252. WriteData("M7.4", true);
  253. }
  254. public void OverOneBlock(object obj)
  255. {
  256. if ((int)obj == 1)
  257. WriteData("M7.1", true);
  258. if ((int)obj == 2)
  259. WriteData("M7.5", true);
  260. }
  261. public void OverTwoBlock(object obj)
  262. {
  263. if ((int)obj == 1)
  264. WriteData("M7.2", true);
  265. if ((int)obj == 2)
  266. WriteData("M7.6", true);
  267. }
  268. public void OverThreeBlock(object obj)
  269. {
  270. if ((int)obj == 1)
  271. WriteData("M7.3", true);
  272. if ((int)obj == 2)
  273. WriteData("M7.7", true);
  274. }
  275. public void OverGoOn(object obj)
  276. {
  277. if ((int)obj == 1)
  278. WriteData("M8.0", true);
  279. if ((int)obj == 2)
  280. WriteData("M8.4", true);
  281. }
  282. public void OverGoDown(object obj)
  283. {
  284. if ((int)obj == 1)
  285. WriteData("M8.2", true);
  286. if ((int)obj == 2)
  287. WriteData("M8.6", true);
  288. }
  289. public void FlowInite()
  290. {
  291. }
  292. /// <summary>
  293. /// 订单初始化
  294. /// </summary>
  295. private void InitialData()
  296. {
  297. //队列
  298. string subId = Guid.NewGuid().ToString();
  299. morkF.TakeMaterialQueue.Enqueue(new OrderLocInfo() { SuborderId = subId, MaterialLoc = 1 });//A料
  300. morkF.TakeMaterialQueue.Enqueue(new OrderLocInfo() { SuborderId = subId, MaterialLoc = 2 });//B料
  301. morkF.TakeMaterialQueue.Enqueue(new OrderLocInfo() { SuborderId = subId, MaterialLoc = 3 });//C料
  302. morkF.TakePlateQueue.Enqueue(new OrderLocInfo() { SuborderId = subId });
  303. resultorder.AddRange(new int[] { 1, 2, 3 });
  304. morkF.listStirBom.Add(stirFryBom);
  305. }
  306. #endregion
  307. public override void ResetProgram()
  308. {
  309. morkF = null;
  310. morkF = new GVL_MorkF();
  311. }
  312. /// <summary>
  313. /// PLC数据读取
  314. /// </summary>
  315. public override void ReadData()
  316. {
  317. GetStatus("M0.1", new Action<bool[]>((bools) =>
  318. {
  319. Initing = bools[0];
  320. morkF.InitialComplete = Initing;
  321. }));
  322. GetStatus("M1.0", new Action<bool[]>((bools) =>
  323. {
  324. morkF.ProvidePlateModule = bools[0];
  325. morkF.ProvidePlateComplete = bools[2];
  326. morkF.CleanModule = bools[3];
  327. morkF.CleanComplete = bools[5];
  328. }));
  329. GetStatus("M2.0", new Action<bool[]>((bools) =>
  330. {
  331. morkF.KitchenOneStatus = bools[1];
  332. morkF.KitchenSecondStatus = bools[4];
  333. morkF.FallOilComplete = bools[8];
  334. }));
  335. GetStatus("M8.0", new Action<bool[]>((bools) =>
  336. {
  337. morkF.TurnMachineUpComplete = bools[1];
  338. morkF.TurnMachineDownComplete = bools[3];
  339. }));
  340. GetStatus("M13.5", new Action<bool[]>((bools) =>
  341. {
  342. morkF.MaterialArriveComplete = bools[0];
  343. }));
  344. GetStatus("M16.0", new Action<bool[]>((bools) =>
  345. {
  346. morkF.PutPotToKitchenComlete = bools[1];
  347. morkF.TakeMaterialComplete = bools[2];
  348. morkF.FallMaterialComplete = bools[3];
  349. morkF.PlaceRinseTableComplete = bools[5];
  350. morkF.RoobotIdle = bools[6];
  351. }));
  352. }
  353. private void ServerInit()
  354. {
  355. //物料信息
  356. EventBus.EventBus.GetInstance().Subscribe<MaterialDeliveryEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  357. {
  358. if (@event == null) return;
  359. if (@event is MaterialDeliveryEvent material)
  360. {
  361. orderMaterialDelivery = material.orderMaterialDelivery;
  362. }
  363. });
  364. //配方数据信息
  365. EventBus.EventBus.GetInstance().Subscribe<RecipeBomEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  366. {
  367. if (@event == null) return;
  368. if (@event is RecipeBomEvent recipe)
  369. {
  370. recipeBoms = recipe.recipeBoms;
  371. WriteRecipeBoms();
  372. }
  373. });
  374. }
  375. private void OrderChange(string subid, ORDER_STATUS oRDER_STATUS)
  376. {
  377. EventBus.EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { Status = oRDER_STATUS, SubOrderId = subid });
  378. }
  379. /// <summary>
  380. /// 数据解析
  381. /// </summary>
  382. private void DataParse()
  383. {
  384. EventBus.EventBus.GetInstance().Subscribe<DoOrderEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle)
  385. {
  386. if (@event == null) return;
  387. if (@event is DoOrderEvent order)
  388. {
  389. if (order.MorkOrder.GoodBatchings == null) return;
  390. OrderCount++;
  391. DeviceProcessLogShow($"接收到{OrderCount}次订单");
  392. foreach (var item in order.MorkOrder.GoodBatchings)
  393. {
  394. var res = orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId);
  395. if (res != null)
  396. {
  397. if (ushort.TryParse(res.BatchingLoc, out ushort loc))
  398. {
  399. //if (morkF.TakeMaterialQueue.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  400. //将一个商品的ABC料位置存入队列
  401. morkF.TakeMaterialQueue.Enqueue(new OrderLocInfo() { SuborderId = order.MorkOrder.SuborderId, BatchingId = res.BatchingId, MaterialLoc = ushort.Parse(res.BatchingLoc) });
  402. }
  403. //int index = 0;
  404. //if (recipeBoms != null)
  405. //{
  406. // index = Array.FindIndex(recipeBoms.RecipeIds?.ToArray(), p => p.RecipeId == order.MorkOrder.RecipeId);
  407. // index++;
  408. //}
  409. if (morkF.TakePlateQueue.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  410. morkF.TakePlateQueue.Enqueue(new OrderLocInfo()
  411. {
  412. SuborderId = order.MorkOrder.SuborderId,
  413. BatchingId = res.BatchingId
  414. //RecipeNumber = (index >= 1 && index <= 10) ? (ushort)index : (ushort)0
  415. });
  416. }
  417. }
  418. //根据ID 查找对应制作流程,
  419. }
  420. });
  421. }
  422. //}
  423. /// <summary>
  424. /// 主任务
  425. /// </summary>
  426. public override void MainTask()
  427. {
  428. TakePlatelTask();
  429. TurntableControl();
  430. MainProcessExecute();
  431. MinorProcessExcute();
  432. SingleProcess();
  433. }
  434. //辅流程执行
  435. private void MinorProcessExcute()
  436. {
  437. if (!morkF.MinorProcessExcuteLock)
  438. {
  439. morkF.MinorProcessExcuteLock = true;
  440. Task.Run(() =>
  441. {
  442. if (morkF.MinorProcessFlag && !morkF.RoobotIdle && morkF.TakeMaterialQueue.Count > 0)
  443. {
  444. morkF.MinorProessStatus = true;
  445. morkF.MainProcessStatus = false;
  446. StirFryBom bom = morkF.listStirBom.ElementAt(0);
  447. morkF.listStirBom.RemoveAt(0);
  448. foreach (var res in bom.StirFryActions)
  449. {
  450. DeviceProcessLogShow($"执行流程{res.Time}");
  451. //机器人线程
  452. Task taskRobot = Task.Run(new Action(() =>
  453. {
  454. foreach (var temp in res.RobotActions)
  455. {
  456. switch (temp)
  457. {
  458. case StirFryRobotAction.清洗槽取锅:
  459. TakePotTask();//执行取锅操作
  460. break;
  461. case StirFryRobotAction.加入A料:
  462. TakeBurdenATask();//执行取A料操作
  463. break;
  464. case StirFryRobotAction.加入B料:
  465. TakeBurdenATask();//执行取B料操作
  466. break;
  467. case StirFryRobotAction.加入C料:
  468. TakeBurdenCTask();//执行取C料操作
  469. break;
  470. case StirFryRobotAction.灶取锅:
  471. OutDishTask();//执行出餐操作
  472. CleanPotTask();//洗锅操作
  473. break;
  474. }
  475. }
  476. }));
  477. //炒锅线程操作
  478. Task taskPot = Task.Run(new Action(() =>
  479. {
  480. foreach (var temp in res.PotActions)
  481. {
  482. switch (temp)
  483. {
  484. case StirFryPotAction.NONE:
  485. break;
  486. case StirFryPotAction.大火t1s:
  487. KitchenAdjustGears(3);
  488. Task.Delay(1000).Wait(); //大火加热1s//执行大火锅干操作
  489. break;
  490. case StirFryPotAction.加油:
  491. AddOil();//注油//执行加油操作
  492. break;
  493. case StirFryPotAction.中火t2s:
  494. KitchenAdjustGears(2);
  495. Task.Delay(2000).Wait();//执行操作
  496. break;
  497. case StirFryPotAction.小火持续:
  498. KitchenAdjustGears(1);
  499. break;
  500. case StirFryPotAction.中火持续:
  501. KitchenAdjustGears(5);
  502. break;
  503. case StirFryPotAction.大火持续:
  504. KitchenAdjustGears(7);
  505. break;
  506. case StirFryPotAction.停止火力:
  507. KitchenAdjustGears(0);//关闭灶加热
  508. break;
  509. case StirFryPotAction.搅拌臂上位:
  510. TurnUpStatusDetect();//执行搅拌臂上位操作
  511. break;
  512. case StirFryPotAction.搅拌臂下位:
  513. TurnDownStatusDetect();//执行搅拌臂下位操作
  514. break;
  515. case StirFryPotAction.低速旋转:
  516. TurnMachineGearsControl(1);//执行搅拌臂速度1挡操作
  517. break;
  518. case StirFryPotAction.快速旋转:
  519. TurnMachineGearsControl(2);//执行搅拌臂速度3挡操作
  520. break;
  521. case StirFryPotAction.停止旋转:
  522. TurnMachineGearsControl(0);//执行搅拌臂速度0挡操作
  523. break;
  524. }
  525. }
  526. }));
  527. Task.WhenAll(taskRobot, taskPot).Wait();//等待所有线程结束
  528. Task.Delay(res.During * 1000).Wait();//当前流程延迟
  529. if (morkF.MainProcessWait)
  530. {
  531. if (morkF.MinorHasTakeMaterial)
  532. {
  533. }
  534. else
  535. {
  536. KitchenAdjustGears(0);//关闭灶加热
  537. morkF.MinorProessStatus = false;
  538. morkF.MainProcessStatus = true;
  539. //阻塞辅流程
  540. minorReset.WaitOne();
  541. }
  542. }
  543. morkF.MinorProessStatus = true;
  544. morkF.MainProcessStatus = false;
  545. }
  546. morkF.MinorOutMealComplete = true;
  547. }
  548. else
  549. {
  550. morkF.MinorProcessExcuteLock = false;//解除辅流程自锁
  551. }
  552. });
  553. }
  554. }
  555. //机器人,锅灶主流程执行
  556. public void MainProcessExecute()
  557. {
  558. if (!morkF.MainProcessExcuteLock)
  559. {
  560. morkF.MainProcessExcuteLock = true;
  561. Task.Run(new Action(() =>
  562. {
  563. if (!morkF.RoobotIdle && morkF.InitialComplete && morkF.TakeMaterialQueue.Count > 0 && morkF.MainProcessFlag)
  564. {
  565. morkF.MainProcessStatus = true;
  566. morkF.MinorProessStatus = false;
  567. StirFryBom bom = morkF.listStirBom.ElementAt(0);
  568. morkF.listStirBom.RemoveAt(0);
  569. foreach (var res in bom.StirFryActions)//遍历所有流程
  570. {
  571. DeviceProcessLogShow($"执行流程{res.Time}");
  572. //机器人线程
  573. Task taskRobot = Task.Run(new Action(() =>
  574. {
  575. foreach (var temp in res.RobotActions)
  576. {
  577. switch (temp)
  578. {
  579. case StirFryRobotAction.清洗槽取锅:
  580. TakePotTask();//执行取锅操作
  581. break;
  582. case StirFryRobotAction.加入A料:
  583. TakeBurdenATask();//执行取A料操作
  584. break;
  585. case StirFryRobotAction.加入B料:
  586. TakeBurdenATask();//执行取B料操作
  587. break;
  588. case StirFryRobotAction.加入C料:
  589. TakeBurdenCTask();//执行取C料操作
  590. break;
  591. case StirFryRobotAction.灶取锅:
  592. OutDishTask();//执行出餐操作
  593. CleanPotTask();//洗锅操作
  594. break;
  595. }
  596. }
  597. }));
  598. //炒锅线程操作
  599. Task taskPot = Task.Run(new Action(() =>
  600. {
  601. foreach (var temp in res.PotActions)
  602. {
  603. switch (temp)
  604. {
  605. case StirFryPotAction.NONE:
  606. break;
  607. case StirFryPotAction.大火t1s:
  608. KitchenAdjustGears(3);
  609. Task.Delay(1000).Wait(); //大火加热1s//执行大火锅干操作
  610. break;
  611. case StirFryPotAction.加油:
  612. AddOil();//注油//执行加油操作
  613. break;
  614. case StirFryPotAction.中火t2s:
  615. KitchenAdjustGears(2);
  616. Task.Delay(2000).Wait();//执行操作
  617. break;
  618. case StirFryPotAction.小火持续:
  619. KitchenAdjustGears(1);
  620. break;
  621. case StirFryPotAction.中火持续:
  622. KitchenAdjustGears(5);
  623. break;
  624. case StirFryPotAction.大火持续:
  625. KitchenAdjustGears(7);
  626. break;
  627. case StirFryPotAction.停止火力:
  628. KitchenAdjustGears(0);//关闭灶加热
  629. break;
  630. case StirFryPotAction.搅拌臂上位:
  631. TurnUpStatusDetect();//执行搅拌臂上位操作
  632. break;
  633. case StirFryPotAction.搅拌臂下位:
  634. TurnDownStatusDetect();//执行搅拌臂下位操作
  635. break;
  636. case StirFryPotAction.低速旋转:
  637. TurnMachineGearsControl(1);//执行搅拌臂速度1挡操作
  638. break;
  639. case StirFryPotAction.快速旋转:
  640. TurnMachineGearsControl(2);//执行搅拌臂速度3挡操作
  641. break;
  642. case StirFryPotAction.停止旋转:
  643. TurnMachineGearsControl(0);//执行搅拌臂速度0挡操作
  644. break;
  645. }
  646. }
  647. }));
  648. Task.WhenAll(taskRobot, taskPot).Wait();//等待所有线程结束
  649. Task.Delay(res.During * 1000).Wait();//当前流程延迟
  650. if (morkF.MinorProcessWait)
  651. {
  652. if (morkF.MainHasTakeMaterial)//针对主流程准备出餐但辅流程机器人忙碌情况下,辅流程不阻塞
  653. {
  654. }
  655. else
  656. {
  657. KitchenAdjustGears(0);//关闭灶加热
  658. morkF.MinorProessStatus = true;
  659. morkF.MainProcessStatus = false;
  660. //阻塞主流程
  661. mainReset.WaitOne();
  662. }
  663. }
  664. morkF.MinorProessStatus = false;
  665. morkF.MainProcessStatus = true;
  666. }
  667. morkF.MainOutMealComplete = true;
  668. }
  669. else
  670. {
  671. morkF.MainProcessExcuteLock = false;//解除流程自锁
  672. }
  673. }));
  674. }
  675. }
  676. /// <summary>
  677. /// 信号处理
  678. /// </summary>
  679. private void SingleProcess()
  680. {
  681. //主流程出餐完成,相应变量复位
  682. if (morkF.MainOutMealComplete)
  683. {
  684. morkF.TakePlateLock = false;
  685. morkF.MainProcessExcuteLock = false;
  686. morkF.MainOrderMaterialCom = false;
  687. morkF.MinorProcessWait = false;//主流程出餐完成取消辅流程线程阻塞
  688. if (morkF.MainProcessPotLoc == 1)
  689. {
  690. morkF.PotInPlace = false;
  691. }
  692. else if (morkF.MainProcessPotLoc == 2)
  693. {
  694. morkF.SecondPotInPlace = false;
  695. }
  696. }
  697. //辅流程出餐完成,相应变量复位
  698. if (morkF.MinorOutMealComplete)
  699. {
  700. morkF.TakePlateLock = false;
  701. morkF.MinorProcessExcuteLock = false;
  702. morkF.MinorOrderMaterialCom = false;
  703. morkF.MainProcessWait = false;//辅流程出餐完成取消主流程线程阻塞
  704. if (morkF.MinorProcessPotLoc == 1)
  705. {
  706. morkF.PotInPlace = false;
  707. }
  708. else if (morkF.MinorProcessPotLoc == 2)
  709. {
  710. morkF.SecondPotInPlace = false;
  711. }
  712. }
  713. }
  714. /// <summary>
  715. /// 转台控制
  716. /// </summary>
  717. private void TurntableControl()
  718. {
  719. //正常轮询
  720. //if (morkF.TakeMaterialQueue.Count > 0 && !morkF.TurnTableLock)
  721. //{
  722. // var result = orderMaterialDelivery.BatchingInfo.Where(p => p.BatchingId == morkF.TakeMaterialQueue.ElementAt(0).BatchingId).ToList();
  723. // if (result != null)
  724. // {
  725. // if (ushort.TryParse(result[0].BatchingLoc, out ushort loc))
  726. // {
  727. // TurnMaterialStore(loc);
  728. // DeviceProcessLogShow($"转台转到【{loc}】位置");
  729. // morkF.TurnTableLock = true; //取料完成后置false
  730. // }
  731. // }
  732. // elseDeviceProcessLogShow("未找到可用的物料信息");
  733. //}
  734. //调试代码
  735. if (morkF.TakeMaterialQueue.Count > 0 && !morkF.TurnTableLock)
  736. {
  737. // var result = orderMaterialDelivery.BatchingInfo.Where(p => p.BatchingId == morkF.TakeMaterialQueue.ElementAt(0).BatchingId).ToList();
  738. if (resultorder != null)
  739. {
  740. TurnMaterialStore(resultorder[0]);
  741. DeviceProcessLogShow($"转台转到【{resultorder[0]}】位置");
  742. resultorder.RemoveAt(0);
  743. morkF.TurnTableLock = true; //取料完成后置false
  744. }
  745. else
  746. {
  747. DeviceProcessLogShow("未找到可用的物料信息");
  748. }
  749. }
  750. }
  751. /// <summary>
  752. /// 供盘
  753. /// </summary>
  754. /// <exception cref="NotImplementedException"></exception>
  755. private void TakePlatelTask()
  756. {
  757. if (!morkF.RoobotIdle && morkF.InitialComplete && morkF.TakePlateQueue.Count > 0 && !morkF.ProvidePlateModule && !morkF.TakePlateLock)
  758. {
  759. if (morkF.TakePlateQueue.TryDequeue(out OrderLocInfo order))
  760. {
  761. StartTakePlate();
  762. if (morkF.MainProcessStatus)
  763. morkF.MainCurrentOrderId = order.SuborderId;
  764. if (morkF.MinorProessStatus)
  765. morkF.MinorCurrentOrderId = order.SuborderId;
  766. morkF.TakePlateLock = true; //订单完成后置false
  767. morkF.MainOutMealComplete = false;
  768. morkF.MinorOutMealComplete = false;
  769. // OrderChange(morkF.CurrentOrderId, ORDER_STATUS.COOKING);
  770. DeviceProcessLogShow($"订单【{order.SuborderId}】执行取碗控制");
  771. }
  772. }
  773. }
  774. /// <summary>
  775. /// 取锅到灶台
  776. /// </summary>
  777. /// <exception cref="NotImplementedException"></exception>
  778. private void TakePotTask()
  779. {
  780. //while (!((!morkF.CleanModule && !morkF.KitchenOneStatus && morkF.CleanComplete) || (!morkF.SecondCleanModule && !morkF.KitchenSecondStatus && morkF.SecondCleanComplete)))
  781. //{
  782. // Task.Delay(5).Wait();
  783. //}
  784. while (!(!morkF.CleanModule || !morkF.SecondCleanModule) && (!morkF.KitchenOneStatus || !morkF.KitchenSecondStatus) && (morkF.CleanComplete || morkF.SecondCleanComplete))//等待取锅条件满足
  785. {
  786. Task.Delay(5).Wait();
  787. }
  788. while (morkF.RoobotIdle)//等待机器人空闲
  789. {
  790. Task.Delay(5).Wait();
  791. }
  792. if (!morkF.CleanModule && !morkF.KitchenOneStatus && morkF.CleanComplete)
  793. {
  794. //取1号锅到1号灶台
  795. TakePotToKitchen(1);
  796. morkF.CurrentPutPotLoc = 1;
  797. WriteData("M1.5", false);//清洗模组1完成复位
  798. }
  799. else if (!morkF.SecondCleanModule && !morkF.KitchenOneStatus && morkF.SecondCleanComplete)
  800. {
  801. //取2号锅到1号灶台
  802. TakePotToKitchen(1);
  803. morkF.CurrentPutPotLoc = 1;
  804. WriteData("M2.0", false);//清洗模组2完成复位
  805. }
  806. if (!morkF.SecondCleanModule && !morkF.KitchenSecondStatus && morkF.SecondCleanComplete)
  807. {
  808. //取2号锅到2号灶台
  809. TakePotToKitchen(2);
  810. morkF.CurrentPutPotLoc = 2;
  811. WriteData("M2.0", false);//清洗模组2完成复位
  812. }
  813. else if (!morkF.CleanModule && !morkF.KitchenSecondStatus && morkF.CleanComplete)
  814. {
  815. //取1号锅到2号灶台
  816. TakePotToKitchen(2);
  817. morkF.CurrentPutPotLoc = 2;
  818. WriteData("M2.0", false);//清洗模组1完成复位
  819. }
  820. if (morkF.MainProcessStatus)
  821. {
  822. morkF.MainProcessPotLoc = morkF.CurrentPutPotLoc;
  823. DeviceProcessLogShow($"订单【{ morkF.MainCurrentOrderId}】执行取锅到灶台控制");
  824. }
  825. if (morkF.MinorProessStatus)
  826. {
  827. morkF.MinorProcessPotLoc = morkF.CurrentPutPotLoc;
  828. DeviceProcessLogShow($"订单【{ morkF.MinorCurrentOrderId}】执行取锅到灶台控制");
  829. }
  830. if (morkF.CurrentPutPotLoc == 1)
  831. {
  832. while (!morkF.PutPotToKitchenComlete)
  833. {
  834. Task.Delay(5).Wait();
  835. }
  836. morkF.PotInPlace = morkF.PutPotToKitchenComlete;//锅到位
  837. WriteData("M14.0", false);//机器人取锅完成复位
  838. }
  839. if (morkF.CurrentPutPotLoc == 2)
  840. {
  841. while (!morkF.PutPotToSecondKitchenComlete)
  842. {
  843. Task.Delay(5).Wait();
  844. }
  845. morkF.SecondPotInPlace = morkF.PutPotToSecondKitchenComlete;
  846. WriteData("M14.4", false);//机器人取锅完成复位
  847. }
  848. Thread.Sleep(2000);
  849. }
  850. /// <summary>
  851. /// 写入配方数据到 PLC
  852. /// </summary>
  853. private void WriteRecipeBoms()
  854. {
  855. //List<ushort> recipeBoms = new List<ushort>();
  856. //if (this.recipeBoms == null) return;
  857. //foreach (var item in this.recipeBoms.RecipeIds)
  858. //{
  859. // foreach (var rec in item.Recipes)
  860. // {
  861. // recipeBoms.Add((ushort)rec);
  862. // }
  863. //}
  864. //if (recipeBoms.Count > 0)
  865. //{
  866. // //配方数据地址范围:VW2000 - VW2278
  867. // WriteData("VW2000", recipeBoms.ToArray());
  868. //}
  869. //else {DeviceProcessLogShow("配方数据为空"); }
  870. }
  871. /// <summary>
  872. /// 转台复位
  873. /// </summary>
  874. /// <param name="loc"></param>
  875. public void TurnReset(int loc)
  876. {
  877. switch (loc)
  878. {
  879. case 1: WriteData("M13.0", false); break;
  880. case 2: WriteData("M13.1", false); break;
  881. case 3: WriteData("M13.2", false); break;
  882. case 4: WriteData("M13.3", false); break;
  883. case 5: WriteData("M13.4", false); break;
  884. }
  885. }
  886. /// <summary>
  887. /// 取素菜A料
  888. /// </summary>
  889. private void TakeBurdenATask()
  890. {
  891. int loc = 0;
  892. //while (morkF.RoobotIdle || (!morkF.PotInPlace && !morkF.SecondPotInPlace) || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅到位
  893. //{
  894. // Task.Delay(5).Wait();
  895. //}
  896. if (morkF.MainProcessStatus)
  897. {
  898. if (morkF.MainProcessPotLoc == 1)
  899. {
  900. while (morkF.RoobotIdle || !morkF.PotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅1到位
  901. {
  902. Task.Delay(5).Wait();
  903. }
  904. }
  905. else
  906. {
  907. while (morkF.RoobotIdle || !morkF.SecondPotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅2到位
  908. {
  909. Task.Delay(5).Wait();
  910. }
  911. }
  912. if (morkF.TakeMaterialQueue.TryDequeue(out OrderLocInfo order))
  913. {
  914. loc = order.MaterialLoc;
  915. TakeBurden(loc);
  916. TurnReset(loc);//转台复位
  917. DeviceProcessLogShow($"订单【{ order.SuborderId}】,执行到转台{loc}位置取料");
  918. }
  919. //等待取料完成
  920. while (!morkF.TakeMaterialComplete)
  921. {
  922. Task.Delay(5).Wait();
  923. }
  924. morkF.MainOrderMaterialCom = false;
  925. morkF.MainHasTakeMaterial = true;
  926. WriteData("M14.1", false);//机器人取料完成复位
  927. }
  928. if (morkF.MinorProessStatus)
  929. {
  930. if (morkF.MinorProcessPotLoc == 1)
  931. {
  932. while (morkF.RoobotIdle || !morkF.PotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅1到位
  933. {
  934. Task.Delay(5).Wait();
  935. }
  936. }
  937. else
  938. {
  939. while (morkF.RoobotIdle || !morkF.SecondPotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅2到位
  940. {
  941. Task.Delay(5).Wait();
  942. }
  943. }
  944. if (morkF.TakeMaterialQueue.TryDequeue(out OrderLocInfo order))
  945. {
  946. loc = order.MaterialLoc;
  947. TakeBurden(loc);
  948. TurnReset(loc);//转台复位
  949. DeviceProcessLogShow($"订单【{ order.SuborderId}】,执行到转台{loc}位置取料");
  950. }
  951. //等待取料完成
  952. while (!morkF.TakeMaterialComplete)
  953. {
  954. Task.Delay(5).Wait();
  955. }
  956. morkF.MinorOrderMaterialCom = false;
  957. morkF.MinorHasTakeMaterial = true;
  958. WriteData("M14.5", false);//机器人取料完成复位
  959. }
  960. morkF.TurnTableLock = false;//转台互锁解除
  961. }
  962. /// <summary>
  963. /// 取素菜B料
  964. /// </summary>
  965. private void TakeBurdenBTask()
  966. {
  967. int loc = 0;
  968. //while (morkF.RoobotIdle || (!morkF.PotInPlace && !morkF.SecondPotInPlace) || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅到位
  969. //{
  970. // Task.Delay(5).Wait();
  971. //}
  972. if (morkF.MainProcessStatus)
  973. {
  974. if (morkF.MainProcessPotLoc == 1)
  975. {
  976. while (morkF.RoobotIdle || !morkF.PotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅1到位
  977. {
  978. Task.Delay(5).Wait();
  979. }
  980. }
  981. else
  982. {
  983. while (morkF.RoobotIdle || !morkF.SecondPotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅2到位
  984. {
  985. Task.Delay(5).Wait();
  986. }
  987. }
  988. if (morkF.TakeMaterialQueue.TryDequeue(out OrderLocInfo order))
  989. {
  990. loc = order.MaterialLoc;
  991. TakeBurden(loc);
  992. TurnReset(loc);//转台复位
  993. DeviceProcessLogShow($"订单【{ order.SuborderId}】,执行到转台{loc}位置取料");
  994. }
  995. //等待取料完成
  996. while (!morkF.TakeMaterialComplete)
  997. {
  998. Task.Delay(5).Wait();
  999. }
  1000. morkF.MainOrderMaterialCom = false;
  1001. morkF.MainHasTakeMaterial = true;
  1002. WriteData("M14.1", false);//机器人取料完成复位
  1003. }
  1004. if (morkF.MinorProessStatus)
  1005. {
  1006. if (morkF.MinorProcessPotLoc == 1)
  1007. {
  1008. while (morkF.RoobotIdle || !morkF.PotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅1到位
  1009. {
  1010. Task.Delay(5).Wait();
  1011. }
  1012. }
  1013. else
  1014. {
  1015. while (morkF.RoobotIdle || !morkF.SecondPotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅2到位
  1016. {
  1017. Task.Delay(5).Wait();
  1018. }
  1019. }
  1020. if (morkF.TakeMaterialQueue.TryDequeue(out OrderLocInfo order))
  1021. {
  1022. loc = order.MaterialLoc;
  1023. TakeBurden(loc);
  1024. TurnReset(loc);//转台复位
  1025. DeviceProcessLogShow($"订单【{ order.SuborderId}】,执行到转台{loc}位置取料");
  1026. }
  1027. //等待取料完成
  1028. while (!morkF.TakeMaterialComplete)
  1029. {
  1030. Task.Delay(5).Wait();
  1031. }
  1032. morkF.MinorOrderMaterialCom = false;
  1033. morkF.MinorHasTakeMaterial = true;
  1034. WriteData("M14.5", false);//机器人取料完成复位
  1035. }
  1036. morkF.TurnTableLock = false;//转台互锁解除
  1037. }
  1038. /// <summary>
  1039. /// 取调味品C料
  1040. /// </summary>
  1041. /// <exception cref="NotImplementedException"></exception>
  1042. private void TakeBurdenCTask()
  1043. {
  1044. #region 旧代码
  1045. //while (morkF.RoobotIdle || (!morkF.PotInPlace && !morkF.SecondPotInPlace) || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅到位
  1046. //{
  1047. // Task.Delay(5).Wait();
  1048. //}
  1049. //if (morkF.TakeMaterialQueue.TryDequeue(out OrderLocInfo order))
  1050. //{
  1051. // int loc = order.MaterialLoc;
  1052. // TakeBurden(loc);
  1053. // TurnReset(loc);//转台复位
  1054. // DeviceProcessLogShow($"订单【{ order.SuborderId}】,执行取C料");
  1055. //}
  1056. //DeviceProcessLogShow($"剩余配料数量{morkF.TakeMaterialQueue.Count}");
  1057. ////等待取料完成
  1058. //while (!morkF.TakeMaterialComplete)
  1059. //{
  1060. // Task.Delay(5).Wait();
  1061. //}
  1062. //morkF.MainOrderMaterialCom = false;
  1063. //if (morkF.MainProcessStatus)
  1064. //{
  1065. // morkF.MainOrderMaterialCom = false;
  1066. // WriteData("M14.1", false);//机器人取料完成复位
  1067. //}
  1068. //if (morkF.MinorProessStatus)
  1069. //{
  1070. // morkF.MinorOrderMaterialCom = false;
  1071. // WriteData("M14.5", false);//机器人取料完成复位
  1072. //}
  1073. //morkF.TurnTableLock = false;//转台互锁解除
  1074. #endregion
  1075. int loc = 0;
  1076. //while (morkF.RoobotIdle || (!morkF.PotInPlace && !morkF.SecondPotInPlace) || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅到位
  1077. //{
  1078. // Task.Delay(5).Wait();
  1079. //}
  1080. if (morkF.MainProcessStatus)
  1081. {
  1082. if (morkF.MainProcessPotLoc == 1)
  1083. {
  1084. while (morkF.RoobotIdle || !morkF.PotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅1到位
  1085. {
  1086. Task.Delay(5).Wait();
  1087. }
  1088. }
  1089. else
  1090. {
  1091. while (morkF.RoobotIdle || !morkF.SecondPotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅2到位
  1092. {
  1093. Task.Delay(5).Wait();
  1094. }
  1095. }
  1096. if (morkF.TakeMaterialQueue.TryDequeue(out OrderLocInfo order))
  1097. {
  1098. loc = order.MaterialLoc;
  1099. TakeBurden(loc);
  1100. TurnReset(loc);//转台复位
  1101. DeviceProcessLogShow($"订单【{ order.SuborderId}】,执行到转台{loc}位置取料");
  1102. }
  1103. //等待取料完成
  1104. while (!morkF.TakeMaterialComplete)
  1105. {
  1106. Task.Delay(5).Wait();
  1107. }
  1108. morkF.MainOrderMaterialCom = false;
  1109. morkF.MainHasTakeMaterial = true;
  1110. WriteData("M14.1", false);//机器人取料完成复位
  1111. }
  1112. if (morkF.MinorProessStatus)
  1113. {
  1114. if (morkF.MinorProcessPotLoc == 1)
  1115. {
  1116. while (morkF.RoobotIdle || !morkF.PotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅1到位
  1117. {
  1118. Task.Delay(5).Wait();
  1119. }
  1120. }
  1121. else
  1122. {
  1123. while (morkF.RoobotIdle || !morkF.SecondPotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅2到位
  1124. {
  1125. Task.Delay(5).Wait();
  1126. }
  1127. }
  1128. if (morkF.TakeMaterialQueue.TryDequeue(out OrderLocInfo order))
  1129. {
  1130. loc = order.MaterialLoc;
  1131. TakeBurden(loc);
  1132. TurnReset(loc);//转台复位
  1133. DeviceProcessLogShow($"订单【{ order.SuborderId}】,执行到转台{loc}位置取料");
  1134. }
  1135. //等待取料完成
  1136. while (!morkF.TakeMaterialComplete)
  1137. {
  1138. Task.Delay(5).Wait();
  1139. }
  1140. morkF.MinorOrderMaterialCom = false;
  1141. morkF.MinorHasTakeMaterial = true;
  1142. WriteData("M14.5", false);//机器人取料完成复位
  1143. }
  1144. morkF.TurnTableLock = false;//转台互锁解除
  1145. }
  1146. /// <summary>
  1147. /// 出餐
  1148. /// </summary>
  1149. private void OutDishTask()
  1150. {
  1151. //while (morkF.RoobotIdle || morkF.CleanModule || !morkF.ProvidePlateComplete)//等待条件满足
  1152. //{
  1153. // Task.Delay(5).Wait();
  1154. //}
  1155. while (morkF.RoobotIdle || (!morkF.CleanModule && !morkF.SecondCleanModule) || !morkF.ProvidePlateComplete)//等待条件满足
  1156. {
  1157. Task.Delay(5).Wait();
  1158. }
  1159. if (morkF.TakePlateQueue.Count == 0)
  1160. {
  1161. WriteData("M0.7", false);//无订单关闭抽风机
  1162. }
  1163. RobotOutMeal();
  1164. WriteData("M1.2", false);//供盘复位
  1165. if (morkF.MainProcessStatus)
  1166. DeviceProcessLogShow($"订单【{ morkF.MainCurrentOrderId}】执行取锅到清洗台控制");
  1167. if (morkF.MinorProessStatus)
  1168. DeviceProcessLogShow($"订单【{ morkF.MinorCurrentOrderId}】执行取锅到清洗台控制");
  1169. }
  1170. /// <summary>
  1171. /// 洗锅放锅
  1172. /// </summary>
  1173. private void CleanPotTask()
  1174. {
  1175. while ((!morkF.PlaceRinseTableComplete || morkF.CleanModule) && (!morkF.PlaceRinseSecondTableComplete || morkF.SecondCleanModule))
  1176. {
  1177. Task.Delay(5).Wait();
  1178. }
  1179. if (morkF.MainProcessStatus)
  1180. {
  1181. WriteData("M14.2", false);//机器人出餐完成复位
  1182. if (morkF.PlaceRinseTableComplete && morkF.CleanModule)
  1183. {
  1184. CleanModuleControl("Start", 1);
  1185. }
  1186. if (morkF.PlaceRinseSecondTableComplete && morkF.SecondCleanModule)
  1187. {
  1188. CleanModuleControl("Start", 2);
  1189. }
  1190. DeviceProcessLogShow($"订单【{ morkF.MainCurrentOrderId}】执行清洗操作");
  1191. morkF.MainProcessFlag = false;
  1192. minorReset.Set();
  1193. }
  1194. if (morkF.MinorProessStatus)
  1195. {
  1196. WriteData("M14.6", false);//机器人出餐完成复位
  1197. if (morkF.PlaceRinseTableComplete && morkF.CleanModule)
  1198. {
  1199. CleanModuleControl("Start", 1);
  1200. }
  1201. if (morkF.PlaceRinseSecondTableComplete && morkF.SecondCleanModule)
  1202. {
  1203. CleanModuleControl("Start", 2);
  1204. }
  1205. DeviceProcessLogShow($"订单【{ morkF.MinorCurrentOrderId}】执行清洗操作");
  1206. morkF.MinorProcessFlag = false;
  1207. mainReset.Set();
  1208. }
  1209. //OrderChange(morkF.CurrentOrderId, ORDER_STATUS.COMPLETED_COOK);
  1210. }
  1211. /// <summary>
  1212. /// 任务复位重启
  1213. /// </summary>
  1214. //private void ResetProgram()
  1215. //{
  1216. // ThreadManage.GetInstance().StartLong(new Action(() =>
  1217. // {
  1218. // if (RTrig.GetInstance("ResetProgram").Start(morkF.DevicDataInite))
  1219. // {
  1220. // ThreadManage.GetInstance().StopTask("MainTask", new Action(() =>
  1221. // {
  1222. // ThreadManage.GetInstance().StopTask("ReadPLCData", new Action(() =>
  1223. // {
  1224. // morkF = null;
  1225. // morkF = new GVL_MorkF();
  1226. // ActionManage.GetInstance.Send("ResetProgram");
  1227. // ActionManage.GetInstance.Send("ClearOrders");
  1228. // ReadData();
  1229. // Main();
  1230. // }));
  1231. // }));
  1232. // }
  1233. // Thread.Sleep(10);
  1234. // }), "ResetProgram");
  1235. //}
  1236. /// <summary>
  1237. /// 翻转机下降及状态检测
  1238. /// </summary>
  1239. public void TurnDownStatusDetect()
  1240. {
  1241. int potLoc= TurnMachineOrientControl("Down");
  1242. if (potLoc==1)
  1243. {
  1244. while (!morkF.TurnMachineDownComplete)//等待翻转机下降完成
  1245. {
  1246. Task.Delay(5).Wait();
  1247. }
  1248. WriteData("M8.3", false);//下降完成复位
  1249. }
  1250. if (potLoc==2)
  1251. {
  1252. while (!morkF.SecondTurnMachineDownComplete)//等待翻转机下降完成
  1253. {
  1254. Task.Delay(5).Wait();
  1255. }
  1256. WriteData("M8.7", false);//下降完成复位
  1257. }
  1258. DeviceProcessLogShow($"翻转机下降完成");
  1259. //if (morkF.MaterialCount == 3 && morkF.MainProcessStatus)
  1260. //{
  1261. // morkF.MainProcessWait = true;
  1262. //}
  1263. //else if (morkF.MaterialCount == 3 && morkF.MinorProessStatus)
  1264. //{
  1265. // morkF.MinorProcessWait = true;
  1266. //}
  1267. }
  1268. /// <summary>
  1269. /// 翻转机上升及状态检测
  1270. /// </summary>
  1271. public void TurnUpStatusDetect()
  1272. {
  1273. while (morkF.RoobotIdle)//机器人忙碌
  1274. {
  1275. Task.Delay(5).Wait();
  1276. }
  1277. TurnMachineOrientControl("Top");//翻转机上升
  1278. if (morkF.MainProcessStatus)
  1279. {
  1280. if (morkF.MainProcessPotLoc==1)
  1281. {
  1282. while (!morkF.TurnMachineUpComplete)//等待翻转机上升完成以及取料完成
  1283. {
  1284. Task.Delay(5).Wait();
  1285. }
  1286. WriteData("M8.1", false);//上升完成复位
  1287. if (!morkF.MainOrderMaterialCom)
  1288. {
  1289. WriteData("M14.3", true);//倒料
  1290. while (!morkF.FallMaterialComplete)//等待倒料完成
  1291. {
  1292. Task.Delay(5).Wait();
  1293. }
  1294. morkF.MaterialCount++;
  1295. WriteData("M14.3", false);//倒料复位
  1296. if (morkF.MaterialCount == 3)
  1297. {
  1298. //允许执行下一个订单流程
  1299. morkF.MaterialCount = 0;
  1300. morkF.MinorProcessFlag = true;
  1301. }
  1302. morkF.MainOrderMaterialCom = true;
  1303. morkF.MainHasTakeMaterial = false;
  1304. DeviceProcessLogShow($"订单【{ morkF.MainCurrentOrderId}】,配料倒料完成");
  1305. }
  1306. else //辅程准备阻塞
  1307. {
  1308. morkF.MainProcessWait = true;
  1309. }
  1310. }
  1311. if (morkF.MainProcessPotLoc==2)
  1312. {
  1313. while (!morkF.SecondTurnMachineUpComplete)//等待翻转机上升完成以及取料完成
  1314. {
  1315. Task.Delay(5).Wait();
  1316. }
  1317. WriteData("M8.5", false);//上升完成复位
  1318. if (!morkF.MainOrderMaterialCom)
  1319. {
  1320. WriteData("M14.7", true);//倒料
  1321. while (!morkF.SecondFallMaterialComplete)//等待倒料完成
  1322. {
  1323. Task.Delay(5).Wait();
  1324. }
  1325. morkF.MaterialCount++;
  1326. WriteData("M14.7", false);//倒料复位
  1327. if (morkF.MaterialCount == 3)
  1328. {
  1329. //允许执行下一个订单流程
  1330. morkF.MaterialCount = 0;
  1331. morkF.MinorProcessFlag = true;
  1332. }
  1333. morkF.MainOrderMaterialCom = true;
  1334. morkF.MainHasTakeMaterial = false;
  1335. DeviceProcessLogShow($"订单【{ morkF.MinorCurrentOrderId}】,配料倒料完成");
  1336. }
  1337. else //辅流程准备阻塞
  1338. {
  1339. morkF.MainProcessWait = true;
  1340. }
  1341. }
  1342. }
  1343. if (morkF.MinorProessStatus)
  1344. {
  1345. if (morkF.MinorProcessPotLoc == 1)
  1346. {
  1347. while (!morkF.TurnMachineUpComplete)//等待翻转机上升完成以及取料完成
  1348. {
  1349. Task.Delay(5).Wait();
  1350. }
  1351. WriteData("M8.1", false);//上升完成复位
  1352. if (!morkF.MinorOrderMaterialCom)
  1353. {
  1354. WriteData("M14.3", true);//倒料
  1355. while (!morkF.FallMaterialComplete)//等待倒料完成
  1356. {
  1357. Task.Delay(5).Wait();
  1358. }
  1359. morkF.MaterialCount++;
  1360. WriteData("M14.3", false);//倒料复位
  1361. if (morkF.MaterialCount == 3)
  1362. {
  1363. //允许执行下一个订单流程
  1364. morkF.MaterialCount = 0;
  1365. morkF.MainProcessFlag = true;
  1366. }
  1367. morkF.MinorOrderMaterialCom = true;
  1368. morkF.MinorHasTakeMaterial = false;
  1369. DeviceProcessLogShow($"订单【{ morkF.MainCurrentOrderId}】,配料倒料完成");
  1370. }
  1371. else //主程准备阻塞
  1372. {
  1373. morkF.MinorProcessWait = true;
  1374. }
  1375. }
  1376. if (morkF.MinorProcessPotLoc==2)
  1377. {
  1378. while (!morkF.SecondTurnMachineUpComplete)//等待翻转机上升完成以及取料完成
  1379. {
  1380. Task.Delay(5).Wait();
  1381. }
  1382. WriteData("M8.5", false);//上升完成复位
  1383. if (!morkF.MinorOrderMaterialCom)
  1384. {
  1385. WriteData("M14.7", true);//倒料
  1386. while (!morkF.SecondFallMaterialComplete)//等待倒料完成
  1387. {
  1388. Task.Delay(5).Wait();
  1389. }
  1390. morkF.MaterialCount++;
  1391. WriteData("M14.7", false);//倒料复位
  1392. if (morkF.MaterialCount == 3)
  1393. {
  1394. //允许执行下一个订单流程
  1395. morkF.MaterialCount = 0;
  1396. morkF.MainProcessFlag = true;
  1397. }
  1398. morkF.MinorOrderMaterialCom = true;
  1399. morkF.MinorHasTakeMaterial = false;
  1400. DeviceProcessLogShow($"订单【{ morkF.MinorCurrentOrderId}】,配料倒料完成");
  1401. }
  1402. else //主流程准备阻塞
  1403. {
  1404. morkF.MinorProcessWait = true;
  1405. }
  1406. }
  1407. }
  1408. //if (morkF.MainProcessStatus)//代表主流程执行的操作
  1409. //{
  1410. //}
  1411. //else if (morkF.MinorProessStatus)//代表辅流程执行的操作
  1412. //{
  1413. //}
  1414. DeviceProcessLogShow("翻转机上升完成");
  1415. }
  1416. private void GetStatus(string key, Action<bool[]> action)
  1417. {
  1418. if (peripheralStatus.ContainsKey(key))
  1419. {
  1420. action((bool[])peripheralStatus[key]);//获取PLC指定地址的状态值
  1421. }
  1422. }
  1423. /// <summary>
  1424. /// 写数据
  1425. /// </summary>
  1426. /// <param name="address"></param>
  1427. /// <param name="value"></param>
  1428. private void WriteData(string address, object value)
  1429. {
  1430. EventBus.EventBus.GetInstance().Publish(new WriteModel() { DeviceId = DeviceId, Address = address, Value = value });
  1431. }
  1432. public void FirstPotGears(int number)
  1433. {
  1434. switch (number)
  1435. {
  1436. case 0:
  1437. //if (morkF.MainProcessStatus && morkF.PotInPlace)
  1438. WriteData("M4.0", new bool[] { false, false, false, false, false, false, false, false });//0000 0000
  1439. //if (morkF.MinorProessStatus && morkF.SecondPotInPlace)
  1440. // WriteData("M5.0", new bool[] { false, false, false, false, false, false, false, false });//0000 0000
  1441. break;
  1442. case 1:
  1443. // if (morkF.MainProcessStatus)
  1444. WriteData("M4.0", new bool[] { true, false, false, false, false, false, false, false });//0000 0001
  1445. //if (morkF.MinorProessStatus)
  1446. // WriteData("M5.0", new bool[] { true, false, false, false, false, false, false, false });//0000 0001
  1447. break;
  1448. case 2:
  1449. //if (morkF.MainProcessStatus)
  1450. WriteData("M4.0", new bool[] { false, true, false, false, false, false, false, false });//0000 0010
  1451. //if (morkF.MinorProessStatus)
  1452. // WriteData("M5.0", new bool[] { false, true, false, false, false, false, false, false });//0000 0010
  1453. break;
  1454. case 3:
  1455. //if (morkF.MainProcessStatus)
  1456. WriteData("M4.0", new bool[] { true, true, false, false, false, false, false, false });//0000 0011
  1457. //if (morkF.MinorProessStatus)
  1458. // WriteData("M5.0", new bool[] { true, true, false, false, false, false, false, false });//0000 0011
  1459. break;
  1460. case 4:
  1461. // if (morkF.MainProcessStatus)
  1462. WriteData("M4.0", new bool[] { false, false, true, false, false, false, false, false });//0000 0100
  1463. //if (morkF.MinorProessStatus)
  1464. // WriteData("M5.0", new bool[] { false, false, true, false, false, false, false, false });//0000 0100
  1465. break;
  1466. case 5:
  1467. if (morkF.MainProcessStatus)
  1468. WriteData("M4.0", new bool[] { true, false, true, false, false, false, false, false });//0000 0101
  1469. //if (morkF.MinorProessStatus)
  1470. // WriteData("M5.0", new bool[] { true, false, true, false, false, false, false, false });//0000 0101
  1471. break;
  1472. case 6:
  1473. // if (morkF.MainProcessStatus)
  1474. WriteData("M4.0", new bool[] { false, true, true, false, false, false, false, false });//0000 0110
  1475. //if (morkF.MinorProessStatus)
  1476. // WriteData("M5.0", new bool[] { false, true, true, false, false, false, false, false });//0000 0110
  1477. break;
  1478. case 7:
  1479. // if (morkF.MainProcessStatus)
  1480. WriteData("M4.0", new bool[] { true, true, true, false, false, false, false, false });//0000 0111
  1481. //if (morkF.MinorProessStatus)
  1482. // WriteData("M5.0", new bool[] { true, true, true, false, false, false, false, false });//0000 0111
  1483. break;
  1484. case 8:
  1485. //if (morkF.MainProcessStatus)
  1486. WriteData("M4.0", new bool[] { false, false, false, true, false, false, false, false });//0000 1000
  1487. //if (morkF.MinorProessStatus)
  1488. // WriteData("M5.0", new bool[] { false, false, false, true, false, false, false, false });//0000 1000
  1489. break;
  1490. case 9:
  1491. //if (morkF.MainProcessStatus)
  1492. WriteData("M4.0", new bool[] { true, false, false, true, false, false, false, false });//0000 1001
  1493. //if (morkF.MinorProessStatus)
  1494. // WriteData("M5.0", new bool[] { true, false, false, true, false, false, false, false });//0000 1001
  1495. break;
  1496. }
  1497. }
  1498. public void SecondPotGears(int number)
  1499. {
  1500. switch (number)
  1501. {
  1502. case 0:
  1503. //if (morkF.MainProcessStatus && morkF.PotInPlace)
  1504. WriteData("M5.0", new bool[] { false, false, false, false, false, false, false, false });//0000 0000
  1505. //if (morkF.MinorProessStatus && morkF.SecondPotInPlace)
  1506. // WriteData("M5.0", new bool[] { false, false, false, false, false, false, false, false });//0000 0000
  1507. break;
  1508. case 1:
  1509. // if (morkF.MainProcessStatus)
  1510. WriteData("M5.0", new bool[] { true, false, false, false, false, false, false, false });//0000 0001
  1511. //if (morkF.MinorProessStatus)
  1512. // WriteData("M5.0", new bool[] { true, false, false, false, false, false, false, false });//0000 0001
  1513. break;
  1514. case 2:
  1515. //if (morkF.MainProcessStatus)
  1516. WriteData("M5.0", new bool[] { false, true, false, false, false, false, false, false });//0000 0010
  1517. //if (morkF.MinorProessStatus)
  1518. // WriteData("M5.0", new bool[] { false, true, false, false, false, false, false, false });//0000 0010
  1519. break;
  1520. case 3:
  1521. //if (morkF.MainProcessStatus)
  1522. WriteData("M5.0", new bool[] { true, true, false, false, false, false, false, false });//0000 0011
  1523. //if (morkF.MinorProessStatus)
  1524. // WriteData("M5.0", new bool[] { true, true, false, false, false, false, false, false });//0000 0011
  1525. break;
  1526. case 4:
  1527. // if (morkF.MainProcessStatus)
  1528. WriteData("M5.0", new bool[] { false, false, true, false, false, false, false, false });//0000 0100
  1529. //if (morkF.MinorProessStatus)
  1530. // WriteData("M5.0", new bool[] { false, false, true, false, false, false, false, false });//0000 0100
  1531. break;
  1532. case 5:
  1533. if (morkF.MainProcessStatus)
  1534. WriteData("M5.0", new bool[] { true, false, true, false, false, false, false, false });//0000 0101
  1535. //if (morkF.MinorProessStatus)
  1536. // WriteData("M5.0", new bool[] { true, false, true, false, false, false, false, false });//0000 0101
  1537. break;
  1538. case 6:
  1539. // if (morkF.MainProcessStatus)
  1540. WriteData("M5.0", new bool[] { false, true, true, false, false, false, false, false });//0000 0110
  1541. //if (morkF.MinorProessStatus)
  1542. // WriteData("M5.0", new bool[] { false, true, true, false, false, false, false, false });//0000 0110
  1543. break;
  1544. case 7:
  1545. // if (morkF.MainProcessStatus)
  1546. WriteData("M5.0", new bool[] { true, true, true, false, false, false, false, false });//0000 0111
  1547. //if (morkF.MinorProessStatus)
  1548. // WriteData("M5.0", new bool[] { true, true, true, false, false, false, false, false });//0000 0111
  1549. break;
  1550. case 8:
  1551. //if (morkF.MainProcessStatus)
  1552. WriteData("M5.0", new bool[] { false, false, false, true, false, false, false, false });//0000 1000
  1553. //if (morkF.MinorProessStatus)
  1554. // WriteData("M5.0", new bool[] { false, false, false, true, false, false, false, false });//0000 1000
  1555. break;
  1556. case 9:
  1557. //if (morkF.MainProcessStatus)
  1558. WriteData("M5.0", new bool[] { true, false, false, true, false, false, false, false });//0000 1001
  1559. //if (morkF.MinorProessStatus)
  1560. // WriteData("M5.0", new bool[] { true, false, false, true, false, false, false, false });//0000 1001
  1561. break;
  1562. }
  1563. }
  1564. /// <summary>
  1565. /// 灶台档位调节
  1566. /// </summary>
  1567. public void KitchenAdjustGears(int number)
  1568. {
  1569. //while (!morkF.PotInPlace||!morkF.SecondPotInPlace)
  1570. //{
  1571. // Task.Delay(5).Wait();
  1572. //}
  1573. if (morkF.MainProcessStatus)
  1574. {
  1575. if (morkF.MainProcessPotLoc == 1)
  1576. {
  1577. while (!morkF.PotInPlace)
  1578. {
  1579. Task.Delay(5).Wait();
  1580. }
  1581. FirstPotGears(number);
  1582. }
  1583. if (morkF.MainProcessPotLoc == 2)
  1584. {
  1585. while (!morkF.SecondPotInPlace)
  1586. {
  1587. Task.Delay(5).Wait();
  1588. }
  1589. SecondPotGears(number);
  1590. }
  1591. }
  1592. if (morkF.MinorProessStatus)
  1593. {
  1594. if (morkF.MinorProcessPotLoc == 1)
  1595. {
  1596. while (!morkF.PotInPlace)
  1597. {
  1598. Task.Delay(5).Wait();
  1599. }
  1600. FirstPotGears(number);
  1601. }
  1602. if (morkF.MinorProcessPotLoc==2)
  1603. {
  1604. while (!morkF.SecondPotInPlace)
  1605. {
  1606. Task.Delay(5).Wait();
  1607. }
  1608. SecondPotGears(number);
  1609. }
  1610. }
  1611. if (morkF.MainProcessStatus)
  1612. DeviceProcessLogShow($"订单【{ morkF.MainCurrentOrderId}】执行取锅到灶台控制");
  1613. if (morkF.MinorProessStatus)
  1614. DeviceProcessLogShow($"订单【{ morkF.MinorCurrentOrderId}】执行取锅到灶台控制");
  1615. }
  1616. /// <summary>
  1617. /// PLC转台控制
  1618. /// </summary>
  1619. /// <param name="loc"></param>
  1620. public void TurnMaterialStore(int loc)
  1621. {
  1622. switch (loc)
  1623. {
  1624. case 1:
  1625. WriteData("M13.0", true);
  1626. break;
  1627. case 2:
  1628. WriteData("M13.1", true);
  1629. break;
  1630. case 3:
  1631. WriteData("M13.2", true);
  1632. break;
  1633. case 4:
  1634. WriteData("M13.3", true);
  1635. break;
  1636. case 5:
  1637. WriteData("M13.4", true);
  1638. break;
  1639. }
  1640. }
  1641. public void PLCInite()
  1642. {
  1643. WriteData("M0.0", true);
  1644. }
  1645. /// <summary>
  1646. /// 供盘启动
  1647. /// </summary>
  1648. public void StartTakePlate()
  1649. {
  1650. WriteData("M1.1", true);
  1651. }
  1652. /// <summary>
  1653. /// 取锅到灶台
  1654. /// </summary>
  1655. public void TakePotToKitchen(int loc)
  1656. {
  1657. if (loc == 1)
  1658. WriteData("M14.0", true);
  1659. if (loc == 2)
  1660. WriteData("M14.4", true);
  1661. }
  1662. /// <summary>
  1663. /// 机器人出餐并将锅放置清洗台位置
  1664. /// </summary>
  1665. public void RobotOutMeal()
  1666. {
  1667. if (morkF.MainProcessStatus)
  1668. {
  1669. if (morkF.MainProcessPotLoc == 1)
  1670. {
  1671. WriteData("M14.2", true);//1号锅出餐
  1672. }
  1673. else if (morkF.MainProcessPotLoc == 2)
  1674. {
  1675. WriteData("M14.6", true);//2号锅出餐
  1676. }
  1677. }
  1678. if (morkF.MinorProessStatus)
  1679. {
  1680. if (morkF.MinorProcessPotLoc == 1)
  1681. {
  1682. WriteData("M14.2", true);//1号锅出餐
  1683. }
  1684. else if (morkF.MinorProcessPotLoc == 2)
  1685. {
  1686. WriteData("M14.6", true);//2号锅出餐
  1687. }
  1688. }
  1689. }
  1690. public void OpenDraft()
  1691. {
  1692. WriteData("M0.7", true);//打开抽风机
  1693. }
  1694. /// <summary>
  1695. /// 注油
  1696. /// </summary>
  1697. public void AddOil()
  1698. {
  1699. if (morkF.MainProcessStatus)
  1700. {
  1701. if (morkF.MainProcessPotLoc == 1)
  1702. {
  1703. while (!morkF.PotInPlace)
  1704. {
  1705. Task.Delay(5).Wait();
  1706. }
  1707. WriteData("M2.7", true);//加油
  1708. OpenDraft();
  1709. DeviceProcessLogShow("开始注油");
  1710. while (!morkF.FallOilComplete)
  1711. {
  1712. Task.Delay(5).Wait();
  1713. }
  1714. }
  1715. if (morkF.MainProcessPotLoc==2)
  1716. {
  1717. while (!morkF.SecondPotInPlace)
  1718. {
  1719. Task.Delay(5).Wait();
  1720. }
  1721. WriteData("M3.1", true);//加油
  1722. OpenDraft();
  1723. DeviceProcessLogShow("开始注油");
  1724. while (!morkF.SecondOilComplete)
  1725. {
  1726. Task.Delay(5).Wait();
  1727. }
  1728. }
  1729. }
  1730. if (morkF.MinorProessStatus)
  1731. {
  1732. if (morkF.MinorProcessPotLoc == 1)
  1733. {
  1734. while (!morkF.PotInPlace)
  1735. {
  1736. Task.Delay(5).Wait();
  1737. }
  1738. WriteData("M2.7", true);//加油
  1739. OpenDraft();
  1740. DeviceProcessLogShow("开始注油");
  1741. while (!morkF.FallOilComplete)
  1742. {
  1743. Task.Delay(5).Wait();
  1744. }
  1745. }
  1746. if (morkF.MinorProcessPotLoc == 2)
  1747. {
  1748. while (!morkF.SecondPotInPlace)
  1749. {
  1750. Task.Delay(5).Wait();
  1751. }
  1752. WriteData("M3.1", true);//加油
  1753. OpenDraft();
  1754. DeviceProcessLogShow("开始注油");
  1755. while (!morkF.SecondOilComplete)
  1756. {
  1757. Task.Delay(5).Wait();
  1758. }
  1759. }
  1760. }
  1761. //while (!morkF.FallOilComplete || !morkF.SecondOilComplete)
  1762. //{
  1763. // Task.Delay(5).Wait();
  1764. //}
  1765. DeviceProcessLogShow("注油完成");
  1766. }
  1767. public void FirstPotTurnMachine(string orientation)
  1768. {
  1769. switch (orientation)
  1770. {
  1771. case "Top": WriteData("M8.0", true); break;
  1772. case "Down": WriteData("M8.2", true); break;
  1773. }
  1774. }
  1775. public void SecondPotTurnMachine(string orientation)
  1776. {
  1777. switch (orientation)
  1778. {
  1779. case "Top": WriteData("M8.4", true); break;
  1780. case "Down": WriteData("M8.6", true); break;
  1781. }
  1782. }
  1783. /// <summary>
  1784. /// 翻转机方向控制
  1785. /// </summary>
  1786. /// <param name="orientation"></param>
  1787. public int TurnMachineOrientControl(string orientation)
  1788. {
  1789. int potLoc=0; ;
  1790. //switch (orientation)
  1791. //{
  1792. // case "Top": if (morkF.MainProcessStatus) WriteData("M8.0", true); if (morkF.MinorProessStatus) WriteData("M8.4", true); break;
  1793. // case "Down": if (morkF.MainProcessStatus) WriteData("M8.2", true); if (morkF.MinorProessStatus) WriteData("M8.6", true); break;
  1794. //}
  1795. if (morkF.MainProcessStatus)
  1796. {
  1797. if (morkF.MainProcessPotLoc == 1)
  1798. {
  1799. FirstPotTurnMachine(orientation);
  1800. potLoc = 1;
  1801. }
  1802. if (morkF.MainProcessPotLoc == 2)
  1803. {
  1804. SecondPotTurnMachine(orientation);
  1805. potLoc=2;
  1806. }
  1807. }
  1808. if (morkF.MinorProessStatus)
  1809. {
  1810. if (morkF.MinorProcessPotLoc == 1)
  1811. {
  1812. FirstPotTurnMachine(orientation);
  1813. potLoc = 1;
  1814. }
  1815. if (morkF.MinorProcessPotLoc == 2)
  1816. {
  1817. SecondPotTurnMachine(orientation);
  1818. potLoc = 2;
  1819. }
  1820. }
  1821. DeviceProcessLogShow($"翻转机执行{orientation}操作");
  1822. return potLoc;
  1823. }
  1824. public void FirstPotTurnMachine(int gear)
  1825. {
  1826. while (!morkF.PotInPlace)
  1827. {
  1828. Task.Delay(5).Wait();
  1829. }
  1830. switch (gear)
  1831. {
  1832. case 0: WriteData("M7.0", true); Task.Delay(1000).Wait(); break;//关闭翻炒机
  1833. case 1: WriteData("M7.1", true); break;//翻炒机1挡
  1834. case 2: WriteData("M7.2", true); break;//翻炒机2挡
  1835. case 3: WriteData("M7.3", true); break;//翻炒机3挡
  1836. }
  1837. }
  1838. public void SecondPotTurnMachine(int gear)
  1839. {
  1840. while (!morkF.SecondPotInPlace)
  1841. {
  1842. Task.Delay(5).Wait();
  1843. }
  1844. switch (gear)
  1845. {
  1846. case 0: WriteData("M7.4", true); Task.Delay(1000).Wait(); break;//关闭翻炒机
  1847. case 1: WriteData("M7.5", true); break;//翻炒机1挡
  1848. case 2: WriteData("M7.6", true); break;//翻炒机2挡
  1849. case 3: WriteData("M7.7", true); break;//翻炒机3挡
  1850. }
  1851. }
  1852. /// <summary>
  1853. /// 翻转机档位控制
  1854. /// </summary>
  1855. public void TurnMachineGearsControl(int gear)
  1856. {
  1857. //while (!morkF.PotInPlace)
  1858. //{
  1859. // Task.Delay(5).Wait();
  1860. //}
  1861. if (morkF.MainProcessStatus)
  1862. {
  1863. if (morkF.MainProcessPotLoc==1)
  1864. {
  1865. FirstPotTurnMachine(gear);
  1866. }
  1867. if (morkF.MainProcessPotLoc == 2)
  1868. {
  1869. SecondPotTurnMachine(gear);
  1870. }
  1871. }
  1872. if (morkF.MinorProessStatus)
  1873. {
  1874. if (morkF.MinorProcessPotLoc==1)
  1875. {
  1876. FirstPotTurnMachine(gear);
  1877. }
  1878. if (morkF.MinorProcessPotLoc == 2)
  1879. {
  1880. SecondPotTurnMachine(gear);
  1881. }
  1882. }
  1883. DeviceProcessLogShow($"翻转机档位调至{gear}挡");
  1884. }
  1885. /// <summary>
  1886. /// 取A,B,C料
  1887. /// </summary>
  1888. public void TakeBurden(int loc)
  1889. {
  1890. if (morkF.MainProcessStatus && morkF.PotInPlace)
  1891. WriteData("M14.1", true);//机器人倒料至1号锅
  1892. if (morkF.MinorProessStatus && morkF.SecondPotInPlace)
  1893. WriteData("M14.5", true);//机器人倒料至2号锅
  1894. }
  1895. /// <summary>
  1896. /// 清洗模组1启停控制
  1897. /// </summary>
  1898. public void CleanModuleControl(string status, int loc)
  1899. {
  1900. if (loc == 1)
  1901. {
  1902. if (status == "Start")
  1903. {
  1904. WriteData("M1.4", true);
  1905. }
  1906. if (status == "Stop")
  1907. {
  1908. WriteData("M1.4", false);
  1909. }
  1910. DeviceProcessLogShow($"清洗模组1执行【{status}】操作");
  1911. }
  1912. if (loc == 2)
  1913. {
  1914. if (status == "Start")
  1915. {
  1916. WriteData("M1.7", true);
  1917. }
  1918. if (status == "Stop")
  1919. {
  1920. WriteData("M1.7", false);
  1921. }
  1922. DeviceProcessLogShow($"清洗模组2执行【{status}】操作");
  1923. }
  1924. }
  1925. public override void Stop()
  1926. {
  1927. }
  1928. public override void SimOrder()
  1929. {
  1930. }
  1931. }
  1932. }