终端一体化运控平台
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

2165 righe
100 KiB

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