终端一体化运控平台
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

1496 rader
69 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. List<int> resultorder = new List<int>();//调试变量
  21. /// <summary>
  22. /// 入口
  23. /// </summary>
  24. public override void DoMain()
  25. {
  26. CommandRegist();//调试
  27. ServerInit();
  28. DataParse();//数据解析
  29. DeviceProcessLogShow("MORKF 设备初始化完成");
  30. }
  31. #region 调试代码
  32. public void CommandRegist()
  33. {
  34. ActionManage.GetInstance.Register(PLCInite, "InitCommand");
  35. ActionManage.GetInstance.Register(InitialData, "SimultaorOrder");
  36. ActionManage.GetInstance.Register(MaterialOne, "MaterialOne");
  37. ActionManage.GetInstance.Register(MaterialTwo, "MaterialTwo");
  38. ActionManage.GetInstance.Register(MaterialThree, "MaterialThree");
  39. ActionManage.GetInstance.Register(MaterialFour, "MaterialFour");
  40. ActionManage.GetInstance.Register(MaterialFive, "MaterialFive");
  41. ActionManage.GetInstance.Register(ManualOpenExhaust, "OpenExhaust");
  42. ActionManage.GetInstance.Register(CloseExhaust, "CloaseExhaust");
  43. ActionManage.GetInstance.Register(StartQX,"StartQXOne");
  44. ActionManage.GetInstance.Register(StartQX, "StartQXTwo");
  45. ActionManage.GetInstance.Register(ShreddCabbage, "ShreddCabbage");
  46. ActionManage.GetInstance.Register(FryPork, "FryPork");
  47. ActionManage.GetInstance.Register(XingBaoGu, "XingBaoGu");
  48. ActionManage.GetInstance.Register(TakePot, "TakePot");
  49. ActionManage.GetInstance.Register(TakePotReset, "TakePotReset");
  50. ActionManage.GetInstance.Register(TakeMaterial, "TakeMaterial");
  51. ActionManage.GetInstance.Register(ManualOutMeal, "OutMeal");
  52. ActionManage.GetInstance.Register<Action>(AddOil,"AddOil");
  53. ActionManage.GetInstance.Register(TakeOff, "TakeOff");
  54. ActionManage.GetInstance.Register(OneBlock, "OneBlock");
  55. ActionManage.GetInstance.Register(TwoBlock, "TwoBlock");
  56. ActionManage.GetInstance.Register(ThreeBlock, "ThreeBlock");
  57. ActionManage.GetInstance.Register(OverTurnOff, "OverTurnOff");
  58. ActionManage.GetInstance.Register(OverOneBlock, "OverOneBlock");
  59. ActionManage.GetInstance.Register(OverTwoBlock, "OverTwoBlock");
  60. ActionManage.GetInstance.Register(OverThreeBlock, "OverThreeBlock");
  61. ActionManage.GetInstance.Register(OverGoOn, "OverGoOn");
  62. ActionManage.GetInstance.Register(OverGoDown, "OverGoDown");
  63. ActionManage.GetInstance.Register(AutoModel, "AutoModel");
  64. ActionManage.GetInstance.Register(ManualModel, "ManualModel");
  65. ActionManage.GetInstance.Register<Action>(AddOil, "SecAddOil");
  66. ActionManage.GetInstance.Register(TakeOff, "SecTakeOff");
  67. ActionManage.GetInstance.Register(OneBlock, "SecOneBlock");
  68. ActionManage.GetInstance.Register(TwoBlock, "SecTwoBlock");
  69. ActionManage.GetInstance.Register(ThreeBlock, "SecThreeBlock");
  70. ActionManage.GetInstance.Register(OverTurnOff, "SecOverTurnOff");
  71. ActionManage.GetInstance.Register(OverOneBlock, "SecOverOneBlock");
  72. ActionManage.GetInstance.Register(OverTwoBlock, "SecOverTwoBlock");
  73. ActionManage.GetInstance.Register(OverThreeBlock, "SecOverThreeBlock");
  74. ActionManage.GetInstance.Register(OverGoOn, "SecOverGoOn");
  75. ActionManage.GetInstance.Register(OverGoDown, "SecOverGoDown");
  76. ActionManage.GetInstance.Register(AutoModel, "SecAutoModel");
  77. ActionManage.GetInstance.Register(ManualModel, "SecManualModel");
  78. }
  79. /// <summary>
  80. /// 手撕包菜流程
  81. /// </summary>
  82. public void ShreddCabbage()
  83. {
  84. if (stirFryBom.StirFryActions.Count > 0)
  85. {
  86. stirFryBom.StirFryActions.Clear();
  87. }
  88. //流程
  89. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T1, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.清洗槽取锅 } });
  90. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T2, PotActions = new List<StirFryPotAction>() { StirFryPotAction.大火持续 }, During = 5 });
  91. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T3, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.加入A料 }, PotActions = new List<StirFryPotAction>() { StirFryPotAction.加油, StirFryPotAction.搅拌臂下位, StirFryPotAction.低速旋转 }, During = 6 });
  92. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T4, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止旋转, StirFryPotAction.停止火力, StirFryPotAction.搅拌臂上位 } });//加A料
  93. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T5, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.加入B料 }, PotActions = new List<StirFryPotAction>() { StirFryPotAction.中火持续, StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 6 });
  94. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T6, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止火力, StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });//加B料
  95. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T7, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.加入C料 }, PotActions = new List<StirFryPotAction>() { StirFryPotAction.中火持续, StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 9 });
  96. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T8, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止火力, StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });//加C料
  97. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T9, PotActions = new List<StirFryPotAction>() { StirFryPotAction.中火持续, StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 30 });
  98. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T10, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止火力, StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });
  99. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T11, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.灶取锅 } });
  100. }
  101. /// <summary>
  102. /// 盐煎肉流程
  103. /// </summary>
  104. public void FryPork()
  105. {
  106. if (stirFryBom.StirFryActions.Count > 0)
  107. {
  108. stirFryBom.StirFryActions.Clear();
  109. }
  110. //流程
  111. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T1, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.清洗槽取锅 } });
  112. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T2, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止火力, StirFryPotAction.搅拌臂下位, StirFryPotAction.低速旋转 }, During = 15 });
  113. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T3, PotActions = new List<StirFryPotAction>() { StirFryPotAction.加油, StirFryPotAction.停止火力 }, During = 19 });
  114. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T4, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });
  115. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T5, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.加入A料 } });
  116. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T6, PotActions = new List<StirFryPotAction>() { StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 20 });
  117. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T7, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止火力 }, During = 35 });
  118. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T8, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位, } });
  119. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T9, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.加入B料 } });
  120. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T10, PotActions = new List<StirFryPotAction>() { StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 22 });
  121. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T11, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });
  122. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T12, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.加入C料 } });
  123. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T13, PotActions = new List<StirFryPotAction>() { StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 70 });
  124. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T14, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止火力, StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });
  125. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T15, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.灶取锅 } });
  126. }
  127. /// <summary>
  128. /// 酱烧杏鲍菇流程
  129. /// </summary>
  130. public void XingBaoGu()
  131. {
  132. if (stirFryBom.StirFryActions.Count > 0)
  133. {
  134. stirFryBom.StirFryActions.Clear();
  135. }
  136. //流程
  137. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T1, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.清洗槽取锅 } });
  138. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T2, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.加入A料 }, PotActions = new List<StirFryPotAction>() { StirFryPotAction.中火持续, StirFryPotAction.搅拌臂下位, StirFryPotAction.低速旋转 }, During = 5 });
  139. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T3, PotActions = new List<StirFryPotAction>() { StirFryPotAction.加油 }, During = 12 });
  140. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T4, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });//加A料
  141. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T6, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.加入B料 }, PotActions = new List<StirFryPotAction>() { StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 25 });
  142. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T7, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });//加B料
  143. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T9, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.加入C料 }, PotActions = new List<StirFryPotAction>() { StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 30 });
  144. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T10, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止火力, StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });//加C料
  145. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T6, PotActions = new List<StirFryPotAction>() { StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 55 });
  146. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T11, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.灶取锅 } });
  147. }
  148. public void StartQX(object obj)
  149. {
  150. if ((int)obj == 1)
  151. WriteData("M1.4", true);
  152. if ((int)obj == 2)
  153. WriteData("M1.7", true);
  154. }
  155. public void ManualOpenExhaust()
  156. {
  157. WriteData("M0.7",true);
  158. }
  159. public void CloseExhaust()
  160. {
  161. WriteData("M0.7",false);
  162. }
  163. public void TakeMaterial()
  164. {
  165. WriteData("M14.1",true);
  166. }
  167. public void ManualOutMeal()
  168. {
  169. WriteData("M14.2",true);
  170. }
  171. public void MaterialOne()
  172. {
  173. WriteData("M13.0",true);
  174. }
  175. public void MaterialTwo()
  176. {
  177. WriteData("M13.1", true);
  178. }
  179. public void MaterialThree()
  180. {
  181. WriteData("M13.2", true);
  182. }
  183. public void MaterialFour()
  184. {
  185. WriteData("M13.3", true);
  186. }
  187. public void MaterialFive()
  188. {
  189. WriteData("M13.4", true);
  190. }
  191. public void AutoModel(object obj)
  192. {
  193. WriteData("0.3", true);
  194. }
  195. public void ManualModel()
  196. {
  197. WriteData("0.2", true);
  198. }
  199. public void AddOil(object obj)
  200. {
  201. if ((int)obj == 1)
  202. {
  203. Task.Run(() => { WriteData("M2.7", true); Task.Delay(4000).Wait(); WriteData("M2.7", false); });
  204. }
  205. if ((int)obj == 2)
  206. {
  207. Task.Run(() => { WriteData("M3.1", true); Task.Delay(4000).Wait(); WriteData("M3.1", false); });
  208. }
  209. }
  210. public void TakePot(object obj)
  211. {
  212. WriteData("M14.0", true);
  213. }
  214. public void TakePotReset(object obj)
  215. {
  216. WriteData("M14.0", false);
  217. }
  218. public void TakeOff(object obj)
  219. {
  220. if ((int)obj == 1)
  221. WriteData("M4.0", new bool[] { false, false, false, false, false, false, false, false });//0000 0000
  222. if ((int)obj == 2)
  223. WriteData("M5.0", new bool[] { false, false, false, false, false, false, false, false });//0000 0000
  224. }
  225. public void OneBlock(object obj)
  226. {
  227. if ((int)obj == 1)
  228. WriteData("M4.0", new bool[] { true, false, false, false, false, false, false, false });//0000 0001
  229. if ((int)obj == 2)
  230. WriteData("M5.0", new bool[] { true, false, false, false, false, false, false, false });//0000 0001
  231. }
  232. public void TwoBlock(object obj)
  233. {
  234. if ((int)obj == 1)
  235. WriteData("M4.0", new bool[] { false, true, false, false, false, false, false, false });//0000 0010
  236. if ((int)obj == 2)
  237. WriteData("M5.0", new bool[] { false, true, false, false, false, false, false, false });//0000 0010
  238. }
  239. public void ThreeBlock(object obj)
  240. {
  241. if ((int)obj == 1)
  242. WriteData("M4.0", new bool[] { true, true, false, false, false, false, false, false });//0000 0011
  243. if ((int)obj == 2)
  244. WriteData("M5.0", new bool[] { true, true, false, false, false, false, false, false });//0000 0011
  245. }
  246. public void OverTurnOff(object obj)
  247. {
  248. if ((int)obj == 1)
  249. WriteData("M7.0", true);
  250. if ((int)obj == 2)
  251. WriteData("M7.4", true);
  252. }
  253. public void OverOneBlock(object obj)
  254. {
  255. if ((int)obj == 1)
  256. WriteData("M7.1", true);
  257. if ((int)obj == 2)
  258. WriteData("M7.5", true);
  259. }
  260. public void OverTwoBlock(object obj)
  261. {
  262. if ((int)obj == 1)
  263. WriteData("M7.2", true);
  264. if ((int)obj == 2)
  265. WriteData("M7.6",true);
  266. }
  267. public void OverThreeBlock(object obj)
  268. {
  269. if ((int)obj == 1)
  270. WriteData("M7.3", true);
  271. if ((int)obj == 2)
  272. WriteData("M7.7",true);
  273. }
  274. public void OverGoOn(object obj)
  275. {
  276. if ((int)obj == 1)
  277. WriteData("M8.0", true);
  278. if ((int)obj == 2)
  279. WriteData("M8.4",true);
  280. }
  281. public void OverGoDown(object obj)
  282. {
  283. if ((int)obj == 1)
  284. WriteData("M8.2", true);
  285. if ((int)obj == 2)
  286. WriteData("M8.6", true);
  287. }
  288. public void FlowInite()
  289. {
  290. }
  291. /// <summary>
  292. /// 订单初始化
  293. /// </summary>
  294. private void InitialData()
  295. {
  296. ////模拟流程
  297. //if (stirFryBom.StirFryActions.Count > 0)
  298. //{
  299. // stirFryBom.StirFryActions.Clear();
  300. //}
  301. ////流程
  302. //stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T1, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.清洗槽取锅 } });
  303. //stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T2, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止火力 }, During = 3 });
  304. //stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T3, PotActions = new List<StirFryPotAction>() { StirFryPotAction.加油, StirFryPotAction.停止火力 }, During = 3 });
  305. //stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T4, PotActions = new List<StirFryPotAction>() { StirFryPotAction.搅拌臂下位, StirFryPotAction.停止火力, StirFryPotAction.低速旋转 }, During = 15 });
  306. //stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T5, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.加入A料, }, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止旋转 } });
  307. //stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T6, PotActions = new List<StirFryPotAction>() { StirFryPotAction.快速旋转, StirFryPotAction.停止火力 }, During = 5 });
  308. //stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T7, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.加入B料, }, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止火力, StirFryPotAction.停止旋转 } });
  309. //stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T8, PotActions = new List<StirFryPotAction>() { StirFryPotAction.快速旋转, StirFryPotAction.停止火力 }, During = 5 });
  310. //stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T9, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.加入C料, }, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止火力, StirFryPotAction.停止旋转 } });
  311. //stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T10, PotActions = new List<StirFryPotAction>() { StirFryPotAction.快速旋转, StirFryPotAction.停止火力 }, During = 3 });
  312. //stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T11, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止火力, StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });
  313. //stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T12, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.灶取锅 } });
  314. //队列
  315. string subId = Guid.NewGuid().ToString();
  316. morkF.TakeMaterialQueue.Enqueue(new OrderLocInfo() { SuborderId = subId, MaterialLoc = 1 });//A料
  317. morkF.TakeMaterialQueue.Enqueue(new OrderLocInfo() { SuborderId = subId, MaterialLoc = 2 });//B料
  318. morkF.TakeMaterialQueue.Enqueue(new OrderLocInfo() { SuborderId = subId, MaterialLoc = 3 });//C料
  319. morkF.TakePlateQueue.Enqueue(new OrderLocInfo() { SuborderId = subId });
  320. resultorder.AddRange(new int[] { 1, 2, 3 });
  321. morkF.listStirBom.Add(stirFryBom);
  322. }
  323. #endregion
  324. public override void ResetProgram()
  325. {
  326. morkF = null;
  327. morkF = new GVL_MorkF();
  328. }
  329. /// <summary>
  330. /// PLC数据读取
  331. /// </summary>
  332. public override void ReadData()
  333. {
  334. GetStatus("M0.1", new Action<bool[]>((bools) =>
  335. {
  336. Initing = bools[0];
  337. morkF.InitialComplete = Initing;
  338. }));
  339. GetStatus("M1.0", new Action<bool[]>((bools) =>
  340. {
  341. morkF.ProvidePlateModule = bools[0];
  342. morkF.ProvidePlateComplete = bools[2];
  343. morkF.CleanModule = bools[3];
  344. morkF.CleanComplete = bools[5];
  345. }));
  346. GetStatus("M2.0", new Action<bool[]>((bools) =>
  347. {
  348. morkF.KitchenOneStatus = bools[1];
  349. morkF.KitchenSecondStatus = bools[4];
  350. morkF.FallOilComplete = bools[8];
  351. }));
  352. GetStatus("M8.0", new Action<bool[]>((bools) =>
  353. {
  354. morkF.TurnMachineUpComplete = bools[1];
  355. morkF.TurnMachineDownComplete = bools[3];
  356. }));
  357. GetStatus("M13.5", new Action<bool[]>((bools) =>
  358. {
  359. morkF.MaterialArriveComplete = bools[0];
  360. }));
  361. GetStatus("M16.0", new Action<bool[]>((bools) =>
  362. {
  363. morkF.PutPotToKitchenComlete = bools[1];
  364. morkF.TakeMaterialComplete = bools[2];
  365. morkF.FallMaterialComplete = bools[3];
  366. morkF.PlaceRinseTableComplete = bools[5];
  367. morkF.RoobotIdle = bools[6];
  368. }));
  369. }
  370. private void ServerInit()
  371. {
  372. //物料信息
  373. EventBus.EventBus.GetInstance().Subscribe<MaterialDeliveryEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  374. {
  375. if (@event == null) return;
  376. if (@event is MaterialDeliveryEvent material)
  377. {
  378. orderMaterialDelivery = material.orderMaterialDelivery;
  379. }
  380. });
  381. //配方数据信息
  382. EventBus.EventBus.GetInstance().Subscribe<RecipeBomEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  383. {
  384. if (@event == null) return;
  385. if (@event is RecipeBomEvent recipe)
  386. {
  387. recipeBoms = recipe.recipeBoms;
  388. WriteRecipeBoms();
  389. }
  390. });
  391. }
  392. private void OrderChange(string subid, ORDER_STATUS oRDER_STATUS)
  393. {
  394. EventBus.EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { Status = oRDER_STATUS, SubOrderId = subid });
  395. }
  396. /// <summary>
  397. /// 写入配方数据到 PLC
  398. /// </summary>
  399. private void WriteRecipeBoms()
  400. {
  401. //List<ushort> recipeBoms = new List<ushort>();
  402. //if (this.recipeBoms == null) return;
  403. //foreach (var item in this.recipeBoms.RecipeIds)
  404. //{
  405. // foreach (var rec in item.Recipes)
  406. // {
  407. // recipeBoms.Add((ushort)rec);
  408. // }
  409. //}
  410. //if (recipeBoms.Count > 0)
  411. //{
  412. // //配方数据地址范围:VW2000 - VW2278
  413. // WriteData("VW2000", recipeBoms.ToArray());
  414. //}
  415. //else {DeviceProcessLogShow("配方数据为空"); }
  416. }
  417. /// <summary>
  418. /// 数据解析
  419. /// </summary>
  420. private void DataParse()
  421. {
  422. EventBus.EventBus.GetInstance().Subscribe<DoOrderEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle)
  423. {
  424. if (@event == null) return;
  425. if (@event is DoOrderEvent order)
  426. {
  427. if (order.MorkOrder.GoodBatchings == null) return;
  428. OrderCount++;
  429. DeviceProcessLogShow($"接收到{OrderCount}次订单");
  430. foreach (var item in order.MorkOrder.GoodBatchings)
  431. {
  432. var res = orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId);
  433. if (res != null)
  434. {
  435. if (ushort.TryParse(res.BatchingLoc, out ushort loc))
  436. {
  437. //if (morkF.TakeMaterialQueue.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  438. //将一个商品的ABC料位置存入队列
  439. morkF.TakeMaterialQueue.Enqueue(new OrderLocInfo() { SuborderId = order.MorkOrder.SuborderId, BatchingId = res.BatchingId, MaterialLoc = ushort.Parse(res.BatchingLoc) });
  440. }
  441. //int index = 0;
  442. //if (recipeBoms != null)
  443. //{
  444. // index = Array.FindIndex(recipeBoms.RecipeIds?.ToArray(), p => p.RecipeId == order.MorkOrder.RecipeId);
  445. // index++;
  446. //}
  447. if (morkF.TakePlateQueue.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  448. morkF.TakePlateQueue.Enqueue(new OrderLocInfo()
  449. {
  450. SuborderId = order.MorkOrder.SuborderId,
  451. BatchingId = res.BatchingId
  452. //RecipeNumber = (index >= 1 && index <= 10) ? (ushort)index : (ushort)0
  453. });
  454. }
  455. }
  456. //根据ID 查找对应制作流程,
  457. }
  458. });
  459. }
  460. //}
  461. /// <summary>
  462. /// 主任务
  463. /// </summary>
  464. public override void MainTask()
  465. {
  466. TakePlatelTask();
  467. TurntableControl();
  468. MainProcessExecute();
  469. MinorProcessExcute();
  470. SingleProcess();
  471. }
  472. //辅流程执行
  473. private void MinorProcessExcute()
  474. {
  475. if (!morkF.MinorProcessExcuteLock)
  476. {
  477. morkF.MinorProcessExcuteLock = true;
  478. Task.Run(() =>
  479. {
  480. if (morkF.MinorProcessFlag && !morkF.RoobotIdle && morkF.TakeMaterialQueue.Count > 0)
  481. {
  482. morkF.MinorProessStatus = true;
  483. morkF.MainProcessStatus = false;
  484. StirFryBom bom = morkF.listStirBom.ElementAt(0);
  485. morkF.listStirBom.RemoveAt(0);
  486. foreach (var res in bom.StirFryActions)
  487. {
  488. DeviceProcessLogShow($"执行流程{res.Time}");
  489. //机器人线程
  490. Task taskRobot = Task.Run(new Action(() =>
  491. {
  492. foreach (var temp in res.RobotActions)
  493. {
  494. switch (temp)
  495. {
  496. case StirFryRobotAction.清洗槽取锅:
  497. TakePotTask();//执行取锅操作
  498. break;
  499. case StirFryRobotAction.加入A料:
  500. TakeBurdenATask();//执行取A料操作
  501. break;
  502. case StirFryRobotAction.加入B料:
  503. TakeBurdenATask();//执行取B料操作
  504. break;
  505. case StirFryRobotAction.加入C料:
  506. TakeBurdenCTask();//执行取C料操作
  507. break;
  508. case StirFryRobotAction.灶取锅:
  509. OutDishTask();//执行出餐操作
  510. CleanPotTask();//洗锅操作
  511. break;
  512. }
  513. }
  514. }));
  515. //炒锅线程操作
  516. Task taskPot = Task.Run(new Action(() =>
  517. {
  518. foreach (var temp in res.PotActions)
  519. {
  520. switch (temp)
  521. {
  522. case StirFryPotAction.NONE:
  523. break;
  524. case StirFryPotAction.大火t1s:
  525. KitchenAdjustGears(3);
  526. Task.Delay(1000).Wait(); //大火加热1s//执行大火锅干操作
  527. break;
  528. case StirFryPotAction.加油:
  529. AddOil();//注油//执行加油操作
  530. break;
  531. case StirFryPotAction.中火t2s:
  532. KitchenAdjustGears(2);
  533. Task.Delay(2000).Wait();//执行操作
  534. break;
  535. case StirFryPotAction.小火持续:
  536. KitchenAdjustGears(1);
  537. break;
  538. case StirFryPotAction.中火持续:
  539. KitchenAdjustGears(5);
  540. break;
  541. case StirFryPotAction.大火持续:
  542. KitchenAdjustGears(7);
  543. break;
  544. case StirFryPotAction.停止火力:
  545. KitchenAdjustGears(0);//关闭灶加热
  546. break;
  547. case StirFryPotAction.搅拌臂上位:
  548. TurnUpStatusDetect();//执行搅拌臂上位操作
  549. break;
  550. case StirFryPotAction.搅拌臂下位:
  551. TurnDownStatusDetect();//执行搅拌臂下位操作
  552. break;
  553. case StirFryPotAction.低速旋转:
  554. TurnMachineGearsControl(1);//执行搅拌臂速度1挡操作
  555. break;
  556. case StirFryPotAction.快速旋转:
  557. TurnMachineGearsControl(2);//执行搅拌臂速度3挡操作
  558. break;
  559. case StirFryPotAction.停止旋转:
  560. TurnMachineGearsControl(0);//执行搅拌臂速度0挡操作
  561. break;
  562. }
  563. }
  564. }));
  565. Task.WhenAll(taskRobot, taskPot).Wait();//等待所有线程结束
  566. Task.Delay(res.During * 1000).Wait();//当前流程延迟
  567. if (morkF.MainProcessWait)
  568. {
  569. KitchenAdjustGears(0);//关闭灶加热
  570. morkF.MinorProessStatus = false;
  571. morkF.MainProcessStatus = true;
  572. //阻塞辅流程
  573. minorReset.WaitOne();
  574. }
  575. morkF.MinorProessStatus = true;
  576. morkF.MainProcessStatus = false;
  577. }
  578. morkF.MinorOutMealComplete = true;
  579. }
  580. else
  581. {
  582. morkF.MinorProcessExcuteLock = false;//解除辅流程自锁
  583. }
  584. });
  585. }
  586. }
  587. //机器人,锅灶主流程执行
  588. public void MainProcessExecute()
  589. {
  590. if (!morkF.MainProcessExcuteLock)
  591. {
  592. morkF.MainProcessExcuteLock = true;
  593. Task.Run(new Action(() =>
  594. {
  595. if (!morkF.RoobotIdle && morkF.InitialComplete && morkF.TakeMaterialQueue.Count > 0 && morkF.MainProcessFlag)
  596. {
  597. morkF.MainProcessStatus = true;
  598. morkF.MinorProessStatus = false;
  599. StirFryBom bom = morkF.listStirBom.ElementAt(0);
  600. morkF.listStirBom.RemoveAt(0);
  601. foreach (var res in bom.StirFryActions)//遍历所有流程
  602. {
  603. DeviceProcessLogShow($"执行流程{res.Time}");
  604. //机器人线程
  605. Task taskRobot = Task.Run(new Action(() =>
  606. {
  607. foreach (var temp in res.RobotActions)
  608. {
  609. switch (temp)
  610. {
  611. case StirFryRobotAction.清洗槽取锅:
  612. TakePotTask();//执行取锅操作
  613. break;
  614. case StirFryRobotAction.加入A料:
  615. TakeBurdenATask();//执行取A料操作
  616. break;
  617. case StirFryRobotAction.加入B料:
  618. TakeBurdenATask();//执行取B料操作
  619. break;
  620. case StirFryRobotAction.加入C料:
  621. TakeBurdenCTask();//执行取C料操作
  622. break;
  623. case StirFryRobotAction.灶取锅:
  624. OutDishTask();//执行出餐操作
  625. CleanPotTask();//洗锅操作
  626. break;
  627. }
  628. }
  629. }));
  630. //炒锅线程操作
  631. Task taskPot = Task.Run(new Action(() =>
  632. {
  633. foreach (var temp in res.PotActions)
  634. {
  635. switch (temp)
  636. {
  637. case StirFryPotAction.NONE:
  638. break;
  639. case StirFryPotAction.大火t1s:
  640. KitchenAdjustGears(3);
  641. Task.Delay(1000).Wait(); //大火加热1s//执行大火锅干操作
  642. break;
  643. case StirFryPotAction.加油:
  644. AddOil();//注油//执行加油操作
  645. break;
  646. case StirFryPotAction.中火t2s:
  647. KitchenAdjustGears(2);
  648. Task.Delay(2000).Wait();//执行操作
  649. break;
  650. case StirFryPotAction.小火持续:
  651. KitchenAdjustGears(1);
  652. break;
  653. case StirFryPotAction.中火持续:
  654. KitchenAdjustGears(5);
  655. break;
  656. case StirFryPotAction.大火持续:
  657. KitchenAdjustGears(7);
  658. break;
  659. case StirFryPotAction.停止火力:
  660. KitchenAdjustGears(0);//关闭灶加热
  661. break;
  662. case StirFryPotAction.搅拌臂上位:
  663. TurnUpStatusDetect();//执行搅拌臂上位操作
  664. break;
  665. case StirFryPotAction.搅拌臂下位:
  666. TurnDownStatusDetect();//执行搅拌臂下位操作
  667. break;
  668. case StirFryPotAction.低速旋转:
  669. TurnMachineGearsControl(1);//执行搅拌臂速度1挡操作
  670. break;
  671. case StirFryPotAction.快速旋转:
  672. TurnMachineGearsControl(2);//执行搅拌臂速度3挡操作
  673. break;
  674. case StirFryPotAction.停止旋转:
  675. TurnMachineGearsControl(0);//执行搅拌臂速度0挡操作
  676. break;
  677. }
  678. }
  679. }));
  680. Task.WhenAll(taskRobot, taskPot).Wait();//等待所有线程结束
  681. Task.Delay(res.During * 1000).Wait();//当前流程延迟
  682. if (morkF.MinorProcessWait)
  683. {
  684. KitchenAdjustGears(0);//关闭灶加热
  685. morkF.MinorProessStatus = true;
  686. morkF.MainProcessStatus = false;
  687. //阻塞主流程
  688. mainReset.WaitOne();
  689. }
  690. morkF.MinorProessStatus = false;
  691. morkF.MainProcessStatus = true;
  692. }
  693. morkF.MainOutMealComplete = true;
  694. }
  695. else
  696. {
  697. morkF.MainProcessExcuteLock = false;//解除流程自锁
  698. }
  699. }));
  700. }
  701. }
  702. /// <summary>
  703. /// 信号处理
  704. /// </summary>
  705. private void SingleProcess()
  706. {
  707. //主流程出餐完成,相应变量复位
  708. if (morkF.MainOutMealComplete)
  709. {
  710. morkF.TakePlateLock = false;
  711. morkF.PotInPlace = false;
  712. morkF.MainProcessExcuteLock = false;
  713. morkF.MainOrderMaterialCom = false;
  714. }
  715. //辅流程出餐完成,相应变量复位
  716. if (morkF.MinorOutMealComplete)
  717. {
  718. morkF.TakePlateLock = false;
  719. morkF.SecondPotInPlace = false;
  720. morkF.MinorProcessExcuteLock = false;
  721. morkF.MinorOrderMaterialCom = false;
  722. }
  723. }
  724. /// <summary>
  725. /// 转台控制
  726. /// </summary>
  727. private void TurntableControl()
  728. {
  729. //正常轮询
  730. //if (morkF.TakeMaterialQueue.Count > 0 && !morkF.TurnTableLock)
  731. //{
  732. // var result = orderMaterialDelivery.BatchingInfo.Where(p => p.BatchingId == morkF.TakeMaterialQueue.ElementAt(0).BatchingId).ToList();
  733. // if (result != null)
  734. // {
  735. // if (ushort.TryParse(result[0].BatchingLoc, out ushort loc))
  736. // {
  737. // TurnMaterialStore(loc);
  738. // DeviceProcessLogShow($"转台转到【{loc}】位置");
  739. // morkF.TurnTableLock = true; //取料完成后置false
  740. // }
  741. // }
  742. // elseDeviceProcessLogShow("未找到可用的物料信息");
  743. //}
  744. //调试代码
  745. if (morkF.TakeMaterialQueue.Count > 0 && !morkF.TurnTableLock)
  746. {
  747. // var result = orderMaterialDelivery.BatchingInfo.Where(p => p.BatchingId == morkF.TakeMaterialQueue.ElementAt(0).BatchingId).ToList();
  748. if (resultorder != null)
  749. {
  750. TurnMaterialStore(resultorder[0]);
  751. DeviceProcessLogShow($"转台转到【{resultorder[0]}】位置");
  752. resultorder.RemoveAt(0);
  753. morkF.TurnTableLock = true; //取料完成后置false
  754. }
  755. else
  756. {
  757. DeviceProcessLogShow("未找到可用的物料信息");
  758. }
  759. }
  760. }
  761. /// <summary>
  762. /// 供盘
  763. /// </summary>
  764. /// <exception cref="NotImplementedException"></exception>
  765. private void TakePlatelTask()
  766. {
  767. if (!morkF.RoobotIdle && morkF.InitialComplete && morkF.TakePlateQueue.Count > 0 && !morkF.ProvidePlateModule && !morkF.TakePlateLock)
  768. {
  769. if (morkF.TakePlateQueue.TryDequeue(out OrderLocInfo order))
  770. {
  771. StartTakePlate();
  772. if (morkF.MainProcessStatus)
  773. morkF.MainCurrentOrderId = order.SuborderId;
  774. if (morkF.MinorProessStatus)
  775. morkF.MinorCurrentOrderId = order.SuborderId;
  776. morkF.TakePlateLock = true; //订单完成后置false
  777. morkF.MainOutMealComplete = false;
  778. morkF.MinorOutMealComplete = false;
  779. // OrderChange(morkF.CurrentOrderId, ORDER_STATUS.COOKING);
  780. DeviceProcessLogShow($"订单【{order.SuborderId}】执行取碗控制");
  781. }
  782. }
  783. }
  784. /// <summary>
  785. /// 取锅到灶台
  786. /// </summary>
  787. /// <exception cref="NotImplementedException"></exception>
  788. private void TakePotTask()
  789. {
  790. //while (!((!morkF.CleanModule && !morkF.KitchenOneStatus && morkF.CleanComplete) || (!morkF.SecondCleanModule && !morkF.KitchenSecondStatus && morkF.SecondCleanComplete)))
  791. //{
  792. // Task.Delay(5).Wait();
  793. //}
  794. while (!(!morkF.CleanModule || !morkF.SecondCleanModule) && (!morkF.KitchenOneStatus || !morkF.KitchenSecondStatus) && (morkF.CleanComplete || morkF.SecondCleanComplete))//等待取锅条件满足
  795. {
  796. Task.Delay(5).Wait();
  797. }
  798. while (morkF.RoobotIdle)//等待机器人空闲
  799. {
  800. Task.Delay(5).Wait();
  801. }
  802. if (!morkF.CleanModule && !morkF.KitchenOneStatus && morkF.CleanComplete)
  803. {
  804. //取1号锅到1号灶台
  805. TakePotToKitchen(1);
  806. morkF.CurrentPutPotLoc = 1;
  807. WriteData("M1.5", false);//清洗模组1完成复位
  808. }
  809. if (!morkF.SecondCleanModule && !morkF.KitchenSecondStatus && morkF.SecondCleanComplete)
  810. {
  811. //取2号锅到2号灶台
  812. TakePotToKitchen(2);
  813. morkF.CurrentPutPotLoc = 2;
  814. WriteData("M2.0", false);//清洗模组2完成复位
  815. }
  816. if (morkF.MainProcessStatus)
  817. DeviceProcessLogShow($"订单【{ morkF.MainCurrentOrderId}】执行取锅到灶台控制");
  818. if (morkF.MinorProessStatus)
  819. DeviceProcessLogShow($"订单【{ morkF.MinorCurrentOrderId}】执行取锅到灶台控制");
  820. if (morkF.CurrentPutPotLoc == 1)
  821. {
  822. while (!morkF.PutPotToKitchenComlete)
  823. {
  824. Task.Delay(5).Wait();
  825. }
  826. morkF.PotInPlace = morkF.PutPotToKitchenComlete;//锅到位
  827. WriteData("M14.0", false);//机器人取锅完成复位
  828. }
  829. if (morkF.CurrentPutPotLoc == 2)
  830. {
  831. while (!morkF.PutPotToSecondKitchenComlete)
  832. {
  833. Task.Delay(5).Wait();
  834. }
  835. morkF.SecondPotInPlace = morkF.PutPotToSecondKitchenComlete;
  836. WriteData("M14.4", false);//机器人取锅完成复位
  837. }
  838. Thread.Sleep(2000);
  839. }
  840. /// <summary>
  841. /// 转台复位
  842. /// </summary>
  843. /// <param name="loc"></param>
  844. public void TurnReset(int loc)
  845. {
  846. switch (loc)
  847. {
  848. case 1: WriteData("M13.0", false); break;
  849. case 2: WriteData("M13.1", false); break;
  850. case 3: WriteData("M13.2", false); break;
  851. case 4: WriteData("M13.3", false); break;
  852. case 5: WriteData("M13.4", false); break;
  853. }
  854. }
  855. /// <summary>
  856. /// 取素菜A料
  857. /// </summary>
  858. private void TakeBurdenATask()
  859. {
  860. int loc = 0;
  861. while (morkF.RoobotIdle || (!morkF.PotInPlace && !morkF.SecondPotInPlace) || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅到位
  862. {
  863. Task.Delay(5).Wait();
  864. }
  865. if (morkF.TakeMaterialQueue.TryDequeue(out OrderLocInfo order))
  866. {
  867. loc = order.MaterialLoc;
  868. TakeBurden(loc);
  869. TurnReset(loc);//转台复位
  870. DeviceProcessLogShow($"订单【{ order.SuborderId}】,执行到转台{loc}位置取料");
  871. }
  872. //等待取料完成
  873. while (!morkF.TakeMaterialComplete)
  874. {
  875. Task.Delay(5).Wait();
  876. }
  877. if (morkF.MainProcessStatus)
  878. {
  879. morkF.MainOrderMaterialCom = false;
  880. WriteData("M14.1", false);//机器人取料完成复位
  881. }
  882. if (morkF.MinorProessStatus)
  883. {
  884. morkF.MinorOrderMaterialCom = false;
  885. WriteData("M14.5", false);//机器人取料完成复位
  886. }
  887. morkF.TurnTableLock = false;//转台互锁解除
  888. }
  889. /// <summary>
  890. /// 取素菜B料
  891. /// </summary>
  892. private void TakeBurdenBTask()
  893. {
  894. while (morkF.RoobotIdle || (!morkF.PotInPlace && !morkF.SecondPotInPlace) || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅到位
  895. {
  896. Task.Delay(5).Wait();
  897. }
  898. if (morkF.TakeMaterialQueue.TryDequeue(out OrderLocInfo order))
  899. {
  900. int loc = order.MaterialLoc;
  901. TakeBurden(loc);
  902. TurnReset(loc);//转台复位
  903. DeviceProcessLogShow($"订单【{ order.SuborderId}】,执行取B料");
  904. }
  905. //等待取料完成
  906. while (!morkF.TakeMaterialComplete)
  907. {
  908. Task.Delay(5).Wait();
  909. }
  910. morkF.MainOrderMaterialCom = false;
  911. if (morkF.MainProcessStatus)
  912. {
  913. morkF.MainOrderMaterialCom = false;
  914. WriteData("M14.1", false);//机器人取料完成复位
  915. }
  916. if (morkF.MinorProessStatus)
  917. {
  918. morkF.MinorOrderMaterialCom = false;
  919. WriteData("M14.5", false);//机器人取料完成复位
  920. }
  921. morkF.TurnTableLock = false;//转台互锁解除
  922. //while (!morkF.FallMaterialComplete)//等待倒料完成
  923. //{
  924. // Task.Delay(5).Wait();
  925. //}
  926. //MessageLog.GetInstance.Show($"订单【{ order.SuborderId}】,B料倒料完成");
  927. }
  928. /// <summary>
  929. /// 取调味品C料
  930. /// </summary>
  931. /// <exception cref="NotImplementedException"></exception>
  932. private void TakeBurdenCTask()
  933. {
  934. while (morkF.RoobotIdle || (!morkF.PotInPlace && !morkF.SecondPotInPlace) || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅到位
  935. {
  936. Task.Delay(5).Wait();
  937. }
  938. if (morkF.TakeMaterialQueue.TryDequeue(out OrderLocInfo order))
  939. {
  940. int loc = order.MaterialLoc;
  941. TakeBurden(loc);
  942. TurnReset(loc);//转台复位
  943. DeviceProcessLogShow($"订单【{ order.SuborderId}】,执行取C料");
  944. }
  945. DeviceProcessLogShow($"剩余配料数量{morkF.TakeMaterialQueue.Count}");
  946. //等待取料完成
  947. while (!morkF.TakeMaterialComplete)
  948. {
  949. Task.Delay(5).Wait();
  950. }
  951. morkF.MainOrderMaterialCom = false;
  952. if (morkF.MainProcessStatus)
  953. {
  954. morkF.MainOrderMaterialCom = false;
  955. WriteData("M14.1", false);//机器人取料完成复位
  956. }
  957. if (morkF.MinorProessStatus)
  958. {
  959. morkF.MinorOrderMaterialCom = false;
  960. WriteData("M14.5", false);//机器人取料完成复位
  961. }
  962. morkF.TurnTableLock = false;//转台互锁解除
  963. //while (!morkF.FallMaterialComplete)
  964. //{
  965. // Task.Delay(5).Wait();
  966. //}
  967. //morkF.SingelOrderMaterialCom = true;
  968. //MessageLog.GetInstance.Show($"订单【{ order.SuborderId}】,C料倒料完成");
  969. //}
  970. }
  971. /// <summary>
  972. /// 出餐
  973. /// </summary>
  974. private void OutDishTask()
  975. {
  976. //while (morkF.RoobotIdle || morkF.CleanModule || !morkF.ProvidePlateComplete)//等待条件满足
  977. //{
  978. // Task.Delay(5).Wait();
  979. //}
  980. while (morkF.RoobotIdle || (!morkF.CleanComplete && !morkF.SecondCleanComplete) || !morkF.ProvidePlateComplete)//等待条件满足
  981. {
  982. Task.Delay(5).Wait();
  983. }
  984. if (morkF.TakePlateQueue.Count == 0)
  985. {
  986. WriteData("M0.7", false);//无订单关闭抽风机
  987. }
  988. RobotOutMeal();
  989. WriteData("M1.2", false);//供盘复位
  990. if (morkF.MainProcessStatus)
  991. DeviceProcessLogShow($"订单【{ morkF.MainCurrentOrderId}】执行取锅到清洗台控制");
  992. if (morkF.MinorProessStatus)
  993. DeviceProcessLogShow($"订单【{ morkF.MinorCurrentOrderId}】执行取锅到清洗台控制");
  994. }
  995. /// <summary>
  996. /// 洗锅放锅
  997. /// </summary>
  998. private void CleanPotTask()
  999. {
  1000. while (!morkF.PlaceRinseTableComplete || ((morkF.CleanModule && !morkF.MainProcessStatus) && (morkF.SecondCleanModule && !morkF.MinorProessStatus)))
  1001. {
  1002. Task.Delay(5).Wait();
  1003. }
  1004. if (morkF.MainProcessStatus)
  1005. {
  1006. WriteData("M14.2", false);//机器人2号锅出餐完成复位
  1007. CleanModuleControl("Start");
  1008. DeviceProcessLogShow($"订单【{ morkF.MainCurrentOrderId}】执行清洗操作");
  1009. morkF.MainProcessFlag = false;
  1010. minorReset.Set();
  1011. }
  1012. if (morkF.MinorProessStatus)
  1013. {
  1014. WriteData("M14.6", false);//机器人2号锅出餐完成复位
  1015. CleanModuleControl("Start");
  1016. DeviceProcessLogShow($"订单【{ morkF.MinorCurrentOrderId}】执行清洗操作");
  1017. morkF.MinorProcessFlag = false;
  1018. mainReset.Set();
  1019. }
  1020. //OrderChange(morkF.CurrentOrderId, ORDER_STATUS.COMPLETED_COOK);
  1021. }
  1022. /// <summary>
  1023. /// 任务复位重启
  1024. /// </summary>
  1025. //private void ResetProgram()
  1026. //{
  1027. // ThreadManage.GetInstance().StartLong(new Action(() =>
  1028. // {
  1029. // if (RTrig.GetInstance("ResetProgram").Start(morkF.DevicDataInite))
  1030. // {
  1031. // ThreadManage.GetInstance().StopTask("MainTask", new Action(() =>
  1032. // {
  1033. // ThreadManage.GetInstance().StopTask("ReadPLCData", new Action(() =>
  1034. // {
  1035. // morkF = null;
  1036. // morkF = new GVL_MorkF();
  1037. // ActionManage.GetInstance.Send("ResetProgram");
  1038. // ActionManage.GetInstance.Send("ClearOrders");
  1039. // ReadData();
  1040. // Main();
  1041. // }));
  1042. // }));
  1043. // }
  1044. // Thread.Sleep(10);
  1045. // }), "ResetProgram");
  1046. //}
  1047. /// <summary>
  1048. /// 翻转机下降及状态检测
  1049. /// </summary>
  1050. public void TurnDownStatusDetect()
  1051. {
  1052. TurnMachineOrientControl("Down");
  1053. if (morkF.MainProcessStatus)
  1054. {
  1055. while (!morkF.TurnMachineDownComplete)//等待翻转机下降完成
  1056. {
  1057. Task.Delay(5).Wait();
  1058. }
  1059. WriteData("M8.3", false);//下降完成复位
  1060. }
  1061. if (morkF.MinorProessStatus)
  1062. {
  1063. while (!morkF.SecondTurnMachineDownComplete)//等待翻转机下降完成
  1064. {
  1065. Task.Delay(5).Wait();
  1066. }
  1067. WriteData("M8.7", false);//下降完成复位
  1068. }
  1069. DeviceProcessLogShow($"翻转机下降完成");
  1070. //if (morkF.MaterialCount == 3 && morkF.MainProcessStatus)
  1071. //{
  1072. // morkF.MainProcessWait = true;
  1073. //}
  1074. //else if (morkF.MaterialCount == 3 && morkF.MinorProessStatus)
  1075. //{
  1076. // morkF.MinorProcessWait = true;
  1077. //}
  1078. }
  1079. /// <summary>
  1080. /// 翻转机上升及状态检测
  1081. /// </summary>
  1082. public void TurnUpStatusDetect()
  1083. {
  1084. while (morkF.RoobotIdle)//机器人忙碌
  1085. {
  1086. Task.Delay(5).Wait();
  1087. }
  1088. TurnMachineOrientControl("Top");//翻转机上升
  1089. if (morkF.MainProcessStatus)
  1090. {
  1091. while (!morkF.TurnMachineUpComplete)//等待翻转机上升完成以及取料完成
  1092. {
  1093. Task.Delay(5).Wait();
  1094. }
  1095. WriteData("M8.1", false);//上升完成复位
  1096. }
  1097. if (morkF.MinorProessStatus)
  1098. {
  1099. while (!morkF.SecondTurnMachineUpComplete)//等待翻转机上升完成以及取料完成
  1100. {
  1101. Task.Delay(5).Wait();
  1102. }
  1103. WriteData("M8.5", false);//上升完成复位
  1104. }
  1105. if (morkF.MainProcessStatus)//代表主流程执行的操作
  1106. {
  1107. if (!morkF.MainOrderMaterialCom)
  1108. {
  1109. WriteData("M14.3", true);//倒料
  1110. while (!morkF.FallMaterialComplete)//等待倒料完成
  1111. {
  1112. Task.Delay(5).Wait();
  1113. }
  1114. morkF.MaterialCount++;
  1115. WriteData("M14.3", false);//倒料复位
  1116. if (morkF.MaterialCount == 3)
  1117. {
  1118. //允许执行下一个订单流程
  1119. morkF.MaterialCount = 0;
  1120. morkF.MinorProcessFlag = true;
  1121. }
  1122. morkF.MainOrderMaterialCom = true;
  1123. DeviceProcessLogShow($"订单【{ morkF.MainCurrentOrderId}】,配料倒料完成");
  1124. }
  1125. else //辅程准备阻塞
  1126. {
  1127. morkF.MainProcessWait = true;
  1128. }
  1129. }
  1130. else if (morkF.MinorProessStatus)//代表辅流程执行的操作
  1131. {
  1132. if (!morkF.MinorOrderMaterialCom)
  1133. {
  1134. WriteData("M14.3", true);//倒料
  1135. while (!morkF.SecondFallMaterialComplete)//等待倒料完成
  1136. {
  1137. Task.Delay(5).Wait();
  1138. }
  1139. morkF.MaterialCount++;
  1140. WriteData("M14.3", false);//倒料复位
  1141. if (morkF.MaterialCount == 3)
  1142. {
  1143. //允许执行下一个订单流程
  1144. morkF.MaterialCount = 0;
  1145. morkF.MainProcessFlag = true;
  1146. }
  1147. morkF.MinorOrderMaterialCom = true;
  1148. DeviceProcessLogShow($"订单【{ morkF.MinorCurrentOrderId}】,配料倒料完成");
  1149. }
  1150. else //主流程准备阻塞
  1151. {
  1152. morkF.MinorProcessWait = true;
  1153. }
  1154. }
  1155. DeviceProcessLogShow("翻转机上升完成");
  1156. }
  1157. private void GetStatus(string key, Action<bool[]> action)
  1158. {
  1159. if (peripheralStatus.ContainsKey(key))
  1160. {
  1161. action((bool[])peripheralStatus[key]);//获取PLC指定地址的状态值
  1162. }
  1163. }
  1164. /// <summary>
  1165. /// 写数据
  1166. /// </summary>
  1167. /// <param name="address"></param>
  1168. /// <param name="value"></param>
  1169. private void WriteData(string address, object value)
  1170. {
  1171. EventBus.EventBus.GetInstance().Publish(new WriteModel() { DeviceId = DeviceId, Address = address, Value = value });
  1172. }
  1173. /// <summary>
  1174. /// 灶台档位调节
  1175. /// </summary>
  1176. public void KitchenAdjustGears(int number)
  1177. {
  1178. while (!morkF.PotInPlace)
  1179. {
  1180. Task.Delay(5).Wait();
  1181. }
  1182. switch (number)
  1183. {
  1184. case 0:
  1185. if (morkF.MainProcessStatus)
  1186. WriteData("M4.0", new bool[] { false, false, false, false, false, false, false, false });//0000 0000
  1187. if (morkF.MinorProessStatus)
  1188. WriteData("M5.0", new bool[] { false, false, false, false, false, false, false, false });//0000 0000
  1189. break;
  1190. case 1:
  1191. if (morkF.MainProcessStatus)
  1192. WriteData("M4.0", new bool[] { true, false, false, false, false, false, false, false });//0000 0001
  1193. if (morkF.MinorProessStatus)
  1194. WriteData("M5.0", new bool[] { true, false, false, false, false, false, false, false });//0000 0001
  1195. break;
  1196. case 2:
  1197. if (morkF.MainProcessStatus)
  1198. WriteData("M4.0", new bool[] { false, true, false, false, false, false, false, false });//0000 0010
  1199. if (morkF.MinorProessStatus)
  1200. WriteData("M5.0", new bool[] { false, true, false, false, false, false, false, false });//0000 0010
  1201. break;
  1202. case 3:
  1203. if (morkF.MainProcessStatus)
  1204. WriteData("M4.0", new bool[] { true, true, false, false, false, false, false, false });//0000 0011
  1205. if (morkF.MinorProessStatus)
  1206. WriteData("M5.0", new bool[] { true, true, false, false, false, false, false, false });//0000 0011
  1207. break;
  1208. case 4:
  1209. if (morkF.MainProcessStatus)
  1210. WriteData("M4.0", new bool[] { false, false, true, false, false, false, false, false });//0000 0100
  1211. if (morkF.MinorProessStatus)
  1212. WriteData("M5.0", new bool[] { false, false, true, false, false, false, false, false });//0000 0100
  1213. break;
  1214. case 5:
  1215. if (morkF.MainProcessStatus)
  1216. WriteData("M4.0", new bool[] { true, false, true, false, false, false, false, false });//0000 0101
  1217. if (morkF.MinorProessStatus)
  1218. WriteData("M5.0", new bool[] { true, false, true, false, false, false, false, false });//0000 0101
  1219. break;
  1220. case 6:
  1221. if (morkF.MainProcessStatus)
  1222. WriteData("M4.0", new bool[] { false, true, true, false, false, false, false, false });//0000 0110
  1223. if (morkF.MinorProessStatus)
  1224. WriteData("M5.0", new bool[] { false, true, true, false, false, false, false, false });//0000 0110
  1225. break;
  1226. case 7:
  1227. if (morkF.MainProcessStatus)
  1228. WriteData("M4.0", new bool[] { true, true, true, false, false, false, false, false });//0000 0111
  1229. if (morkF.MinorProessStatus)
  1230. WriteData("M5.0", new bool[] { true, true, true, false, false, false, false, false });//0000 0111
  1231. break;
  1232. case 8:
  1233. if (morkF.MainProcessStatus)
  1234. WriteData("M4.0", new bool[] { false, false, false, true, false, false, false, false });//0000 1000
  1235. if (morkF.MinorProessStatus)
  1236. WriteData("M5.0", new bool[] { false, false, false, true, false, false, false, false });//0000 1000
  1237. break;
  1238. case 9:
  1239. if (morkF.MainProcessStatus)
  1240. WriteData("M4.0", new bool[] { true, false, false, true, false, false, false, false });//0000 1001
  1241. if (morkF.MinorProessStatus)
  1242. WriteData("M5.0", new bool[] { true, false, false, true, false, false, false, false });//0000 1001
  1243. break;
  1244. }
  1245. if (morkF.MainProcessStatus)
  1246. DeviceProcessLogShow($"订单【{ morkF.MainCurrentOrderId}】执行取锅到灶台控制");
  1247. if (morkF.MinorProessStatus)
  1248. DeviceProcessLogShow($"订单【{ morkF.MinorCurrentOrderId}】执行取锅到灶台控制");
  1249. }
  1250. public void TurnMaterialStore(int loc)
  1251. {
  1252. switch (loc)
  1253. {
  1254. case 1:
  1255. WriteData("M13.0", true);
  1256. break;
  1257. case 2:
  1258. WriteData("M13.1", true);
  1259. break;
  1260. case 3:
  1261. WriteData("M13.2", true);
  1262. break;
  1263. case 4:
  1264. WriteData("M13.3", true);
  1265. break;
  1266. case 5:
  1267. WriteData("M13.4", true);
  1268. break;
  1269. }
  1270. }
  1271. public void PLCInite()
  1272. {
  1273. WriteData("M0.0", true);
  1274. }
  1275. /// <summary>
  1276. /// 供盘启动
  1277. /// </summary>
  1278. public void StartTakePlate()
  1279. {
  1280. WriteData("M1.1", true);
  1281. }
  1282. /// <summary>
  1283. /// 取锅到灶台
  1284. /// </summary>
  1285. public void TakePotToKitchen(int loc)
  1286. {
  1287. if (loc == 1)
  1288. WriteData("M14.0", true);
  1289. if (loc == 2)
  1290. WriteData("M14.4", true);
  1291. }
  1292. /// <summary>
  1293. /// 机器人出餐并将锅放置清洗台位置
  1294. /// </summary>
  1295. public void RobotOutMeal()
  1296. {
  1297. if (morkF.MainProcessStatus)
  1298. WriteData("M14.2", true);//1号锅出餐
  1299. if (morkF.MinorProessStatus)
  1300. WriteData("M14.6", true);//2号锅出餐
  1301. }
  1302. /// <summary>
  1303. /// 注油
  1304. /// </summary>
  1305. public void AddOil()
  1306. {
  1307. while (!morkF.PotInPlace)
  1308. {
  1309. Task.Delay(5).Wait();
  1310. }
  1311. if (morkF.MainProcessStatus)
  1312. WriteData("M2.7", true);//加油
  1313. if (morkF.MinorProessStatus)
  1314. WriteData("M3.1", true);//加油
  1315. WriteData("M0.7", true);//打开抽风机
  1316. DeviceProcessLogShow("开始注油");
  1317. while (!morkF.FallOilComplete || !morkF.SecondOilComplete)
  1318. {
  1319. Task.Delay(5).Wait();
  1320. }
  1321. DeviceProcessLogShow("注油完成");
  1322. }
  1323. /// <summary>
  1324. /// 翻转机方向控制
  1325. /// </summary>
  1326. /// <param name="orientation"></param>
  1327. public void TurnMachineOrientControl(string orientation)
  1328. {
  1329. switch (orientation)
  1330. {
  1331. case "Top": if (morkF.MainProcessStatus) WriteData("M8.0", true); if (morkF.MinorProessStatus) WriteData("M8.4", true); break;
  1332. case "Down": if (morkF.MainProcessStatus) WriteData("M8.2", true); if (morkF.MinorProessStatus) WriteData("M8.6", true); break;
  1333. }
  1334. DeviceProcessLogShow($"翻转机执行{orientation}操作");
  1335. }
  1336. /// <summary>
  1337. /// 翻转机档位控制
  1338. /// </summary>
  1339. public void TurnMachineGearsControl(int gear)
  1340. {
  1341. while (!morkF.PotInPlace)
  1342. {
  1343. Task.Delay(5).Wait();
  1344. }
  1345. switch (gear)
  1346. {
  1347. case 0: if (morkF.MainProcessStatus) WriteData("M7.0", true); Task.Delay(1000).Wait(); if (morkF.MinorProessStatus) WriteData("M7.4", true); break;//关闭翻炒机
  1348. case 1: if (morkF.MainProcessStatus) WriteData("M7.1", true); if (morkF.MinorProessStatus) WriteData("M7.5", true); break;//翻炒机1挡
  1349. case 2: if (morkF.MainProcessStatus) WriteData("M7.2", true); if (morkF.MinorProessStatus) WriteData("M7.6", true); break;//翻炒机2挡
  1350. case 3: if (morkF.MainProcessStatus) WriteData("M7.3", true); if (morkF.MinorProessStatus) WriteData("M7.7", true); break;//翻炒机3挡
  1351. }
  1352. DeviceProcessLogShow($"翻转机档位调至{gear}挡");
  1353. }
  1354. /// <summary>
  1355. /// 倒A,B,C料
  1356. /// </summary>
  1357. public void TakeBurden(int loc)
  1358. {
  1359. if (morkF.MainProcessStatus && morkF.PotInPlace)
  1360. WriteData("M14.1", true);//机器人倒料至1号锅
  1361. if (morkF.MinorProessStatus && morkF.SecondPotInPlace)
  1362. WriteData("M14.5", true);//机器人倒料至2号锅
  1363. }
  1364. /// <summary>
  1365. /// 清洗模组1启停控制
  1366. /// </summary>
  1367. public void CleanModuleControl(string status)
  1368. {
  1369. if (morkF.MainProcessStatus)
  1370. {
  1371. if (status == "Start")
  1372. {
  1373. WriteData("M1.4", true);
  1374. }
  1375. if (status == "Stop")
  1376. {
  1377. WriteData("M1.4", false);
  1378. }
  1379. DeviceProcessLogShow($"清洗模组1执行【{status}】操作");
  1380. }
  1381. if (morkF.MinorProessStatus)
  1382. {
  1383. if (status == "Start")
  1384. {
  1385. WriteData("M1.7", true);
  1386. }
  1387. if (status == "Stop")
  1388. {
  1389. WriteData("M1.7", false);
  1390. }
  1391. DeviceProcessLogShow($"清洗模组2执行【{status}】操作");
  1392. }
  1393. }
  1394. public override void Stop()
  1395. {
  1396. }
  1397. public override void SimOrder()
  1398. {
  1399. }
  1400. }
  1401. }