终端一体化运控平台
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

1003 líneas
46 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. GVL_MorkF morkF = new GVL_MorkF();//全局对象声明
  17. public StirFryBom stirFryBom = new StirFryBom();//创建获取流程的对象
  18. List<int> resultorder = new List<int>();//调试变量
  19. public static readonly object taskLock = new object();
  20. /// <summary>
  21. /// 入口
  22. /// </summary>
  23. public override void DoMain()
  24. {
  25. CommandRegist();//调试
  26. ServerInit();
  27. DataParse();//数据解析
  28. MessageLog.GetInstance.Show("MORKF 设备初始化完成");
  29. }
  30. #region 调试代码
  31. public void CommandRegist()
  32. {
  33. ActionManage.GetInstance.Register(PLCInite, "InitCommand");
  34. ActionManage.GetInstance.Register(InitialData, "SimultaorOrder");
  35. ActionManage.GetInstance.Register(TakePot, "TakePot");
  36. ActionManage.GetInstance.Register(TakePotReset, "TakePotReset");
  37. ActionManage.GetInstance.Register(TakeOff, "TakeOff");
  38. ActionManage.GetInstance.Register(OneBlock, "OneBlock");
  39. ActionManage.GetInstance.Register(TwoBlock, "TwoBlock");
  40. ActionManage.GetInstance.Register(ThreeBlock, "ThreeBlock");
  41. ActionManage.GetInstance.Register(OverTurnOff, "OverTurnOff");
  42. ActionManage.GetInstance.Register(OverOneBlock, "OverOneBlock");
  43. ActionManage.GetInstance.Register(OverTwoBlock, "OverTwoBlock");
  44. ActionManage.GetInstance.Register(OverThreeBlock, "OverThreeBlock");
  45. ActionManage.GetInstance.Register(OverGoOn, "OverGoOn");
  46. ActionManage.GetInstance.Register(OverGoDown, "OverGoDown");
  47. ActionManage.GetInstance.Register(ShreddCabbage, "ShreddCabbage");
  48. ActionManage.GetInstance.Register(FryPork, "FryPork");
  49. ActionManage.GetInstance.Register(XingBaoGu, "XingBaoGu");
  50. }
  51. /// <summary>
  52. /// 手撕包菜流程
  53. /// </summary>
  54. public void ShreddCabbage()
  55. {
  56. if (stirFryBom.StirFryActions.Count > 0)
  57. {
  58. stirFryBom.StirFryActions.Clear();
  59. }
  60. //流程
  61. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T1, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.清洗槽取锅 } });
  62. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T2, PotActions = new List<StirFryPotAction>() { StirFryPotAction.中火持续, StirFryPotAction.加油, StirFryPotAction.搅拌臂下位, StirFryPotAction.低速旋转 }, During = 25 });
  63. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T3, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止火力, StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });
  64. //stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T5, PotActions = new List<StirFryPotAction>() { StirFryPotAction.搅拌臂下位, StirFryPotAction.大火持续, StirFryPotAction.低速旋转 }, During = 5 });
  65. //stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T6, PotActions = new List<StirFryPotAction>() { StirFryPotAction.快速旋转 }, During = 50 });
  66. //stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T7, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止火力, StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });
  67. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T4, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.加入A料 } });
  68. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T5, PotActions = new List<StirFryPotAction>() { StirFryPotAction.大火持续, StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 25 });
  69. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T6, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止火力, StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });
  70. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T7, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.加入B料 } });
  71. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T5, PotActions = new List<StirFryPotAction>() { StirFryPotAction.大火持续, StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 15 });
  72. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T6, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止火力, StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });
  73. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T8, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.加入C料 } });
  74. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T9, PotActions = new List<StirFryPotAction>() { StirFryPotAction.大火持续, StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 55 });
  75. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T10, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止火力, StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });
  76. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T11, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.灶取锅 } });
  77. }
  78. /// <summary>
  79. /// 盐煎肉流程
  80. /// </summary>
  81. public void FryPork()
  82. {
  83. if (stirFryBom.StirFryActions.Count > 0)
  84. {
  85. stirFryBom.StirFryActions.Clear();
  86. }
  87. //流程
  88. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T1, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.清洗槽取锅 } });
  89. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T2, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止火力, StirFryPotAction.搅拌臂下位, StirFryPotAction.低速旋转 }, During = 15 });
  90. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T3, PotActions = new List<StirFryPotAction>() { StirFryPotAction.加油, StirFryPotAction.停止火力 }, During = 19 });
  91. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T4, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });
  92. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T5, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.加入A料 } });
  93. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T6, PotActions = new List<StirFryPotAction>() { StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 20 });
  94. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T7, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止火力 }, During = 35 });
  95. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T8, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位, } });
  96. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T9, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.加入B料 } });
  97. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T10, PotActions = new List<StirFryPotAction>() { StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 22 });
  98. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T11, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });
  99. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T12, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.加入C料 } });
  100. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T13, PotActions = new List<StirFryPotAction>() { StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 70 });
  101. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T14, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止火力, StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });
  102. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T15, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.灶取锅 } });
  103. }
  104. /// <summary>
  105. /// 酱烧杏鲍菇流程
  106. /// </summary>
  107. public void XingBaoGu()
  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 = 5 });
  116. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T3, PotActions = new List<StirFryPotAction>() { StirFryPotAction.加油 }, During = 12 });
  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 = 25 });
  120. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T7, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });
  121. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T8, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.加入B料 } });
  122. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T9, PotActions = new List<StirFryPotAction>() { StirFryPotAction.搅拌臂下位, StirFryPotAction.低速旋转 }, During = 30 });
  123. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T10, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止火力, StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });
  124. stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T11, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.灶取锅 } });
  125. }
  126. public void TakePot()
  127. {
  128. WriteData("M14.0", true);
  129. }
  130. public void TakePotReset()
  131. {
  132. WriteData("M14.0", false);
  133. }
  134. public void TakeOff()
  135. {
  136. WriteData("M4.0", new bool[] { false, false, false, false, false, false, false, false });//0000 0001
  137. }
  138. public void OneBlock()
  139. {
  140. //WriteData("M13.1", true);
  141. // WriteData("M4.0", new bool[] { true, false, false, false, false, false, false, false });//0000 0001
  142. //WriteData("M0.7", false);//无订单关闭抽风机
  143. WriteData("M13.0", true);
  144. }
  145. public void TwoBlock()
  146. {
  147. //WriteData("M13.1", false);
  148. WriteData("M4.0", new bool[] { false, true, false, false, false, false, false, false });//0000 0001
  149. }
  150. public void ThreeBlock()
  151. {
  152. // WriteData("M4.0", new bool[] { true, true, false, false, false, false, false, false });//0000 0001
  153. WriteData("M4.0", new bool[] { false, true, true, false, false, false, false, false });
  154. }
  155. public void OverTurnOff()
  156. {
  157. WriteData("M7.0", true);
  158. }
  159. public void OverOneBlock()
  160. {
  161. WriteData("M7.1", true);
  162. }
  163. public void OverTwoBlock()
  164. {
  165. WriteData("M7.2", true);
  166. }
  167. public void OverThreeBlock()
  168. {
  169. WriteData("M7.3", true);
  170. }
  171. public void OverGoOn()
  172. {
  173. WriteData("M8.0", true);
  174. }
  175. public void OverGoDown()
  176. {
  177. WriteData("M8.2", true);
  178. }
  179. public void FlowInite()
  180. {
  181. }
  182. /// <summary>
  183. /// 订单初始化
  184. /// </summary>
  185. private void InitialData()
  186. {
  187. ////模拟流程
  188. //if (stirFryBom.StirFryActions.Count > 0)
  189. //{
  190. // stirFryBom.StirFryActions.Clear();
  191. //}
  192. ////流程
  193. //stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T1, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.清洗槽取锅 } });
  194. //stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T2, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止火力 }, During = 3 });
  195. //stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T3, PotActions = new List<StirFryPotAction>() { StirFryPotAction.加油, StirFryPotAction.停止火力 }, During = 3 });
  196. //stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T4, PotActions = new List<StirFryPotAction>() { StirFryPotAction.搅拌臂下位, StirFryPotAction.停止火力, StirFryPotAction.低速旋转 }, During = 15 });
  197. //stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T5, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.加入A料, }, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止旋转 } });
  198. //stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T6, PotActions = new List<StirFryPotAction>() { StirFryPotAction.快速旋转, StirFryPotAction.停止火力 }, During = 5 });
  199. //stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T7, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.加入B料, }, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止火力, StirFryPotAction.停止旋转 } });
  200. //stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T8, PotActions = new List<StirFryPotAction>() { StirFryPotAction.快速旋转, StirFryPotAction.停止火力 }, During = 5 });
  201. //stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T9, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.加入C料, }, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止火力, StirFryPotAction.停止旋转 } });
  202. //stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T10, PotActions = new List<StirFryPotAction>() { StirFryPotAction.快速旋转, StirFryPotAction.停止火力 }, During = 3 });
  203. //stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T11, PotActions = new List<StirFryPotAction>() { StirFryPotAction.停止火力, StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });
  204. //stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T12, RobotActions = new List<StirFryRobotAction>() { StirFryRobotAction.灶取锅 } });
  205. //队列
  206. string subId = Guid.NewGuid().ToString();
  207. morkF.TakeMaterialQueue.Enqueue(new OrderLocInfo() { SuborderId = subId, MaterialLoc = 1 });//A料
  208. morkF.TakeMaterialQueue.Enqueue(new OrderLocInfo() { SuborderId = subId, MaterialLoc = 2 });//B料
  209. morkF.TakeMaterialQueue.Enqueue(new OrderLocInfo() { SuborderId = subId, MaterialLoc = 3 });//C料
  210. morkF.TakePlateQueue.Enqueue(new OrderLocInfo() { SuborderId = subId });
  211. resultorder.AddRange(new int[] { 1, 2, 3 });
  212. }
  213. #endregion
  214. public override void ResetProgram()
  215. {
  216. morkF = null;
  217. morkF = new GVL_MorkF();
  218. }
  219. /// <summary>
  220. /// PLC数据读取
  221. /// </summary>
  222. public override void ReadData()
  223. {
  224. GetStatus("M0.1", new Action<bool[]>((bools) =>
  225. {
  226. Initing = bools[0];
  227. morkF.InitialComplete = Initing;
  228. }));
  229. GetStatus("M1.0", new Action<bool[]>((bools) =>
  230. {
  231. morkF.ProvidePlateModule = bools[0];
  232. morkF.ProvidePlateComplete = bools[2];
  233. morkF.CleanModule = bools[3];
  234. morkF.CleanComplete = bools[5];
  235. }));
  236. GetStatus("M2.0", new Action<bool[]>((bools) =>
  237. {
  238. morkF.KitchenOneStatus = bools[1];
  239. morkF.FallOilComplete = bools[8];
  240. }));
  241. GetStatus("M8.0", new Action<bool[]>((bools) =>
  242. {
  243. morkF.TurnMachineUpComplete = bools[1];
  244. morkF.TurnMachineDownComplete = bools[3];
  245. }));
  246. GetStatus("M13.5", new Action<bool[]>((bools) =>
  247. {
  248. morkF.MaterialArriveComplete = bools[0];
  249. }));
  250. GetStatus("M16.0", new Action<bool[]>((bools) =>
  251. {
  252. morkF.PutPotToKitchenComlete = bools[1];
  253. morkF.TakeMaterialComplete = bools[2];
  254. morkF.FallMaterialComplete = bools[3];
  255. morkF.PlaceRinseTableComplete = bools[5];
  256. morkF.RoobotIdle = bools[6];
  257. }));
  258. }
  259. private void ServerInit()
  260. {
  261. //物料信息
  262. EventBus.EventBus.GetInstance().Subscribe<MaterialDeliveryEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  263. {
  264. if (@event == null) return;
  265. if (@event is MaterialDeliveryEvent material)
  266. {
  267. orderMaterialDelivery = material.orderMaterialDelivery;
  268. }
  269. });
  270. //配方数据信息
  271. EventBus.EventBus.GetInstance().Subscribe<RecipeBomEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  272. {
  273. if (@event == null) return;
  274. if (@event is RecipeBomEvent recipe)
  275. {
  276. recipeBoms = recipe.recipeBoms;
  277. WriteRecipeBoms();
  278. }
  279. });
  280. }
  281. private void OrderChange(string subid, ORDER_STATUS oRDER_STATUS)
  282. {
  283. EventBus.EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { Status = oRDER_STATUS, SubOrderId = subid });
  284. }
  285. /// <summary>
  286. /// 写入配方数据到 PLC
  287. /// </summary>
  288. private void WriteRecipeBoms()
  289. {
  290. //List<ushort> recipeBoms = new List<ushort>();
  291. //if (this.recipeBoms == null) return;
  292. //foreach (var item in this.recipeBoms.RecipeIds)
  293. //{
  294. // foreach (var rec in item.Recipes)
  295. // {
  296. // recipeBoms.Add((ushort)rec);
  297. // }
  298. //}
  299. //if (recipeBoms.Count > 0)
  300. //{
  301. // //配方数据地址范围:VW2000 - VW2278
  302. // WriteData("VW2000", recipeBoms.ToArray());
  303. //}
  304. //else { MessageLog.GetInstance.Show("配方数据为空"); }
  305. }
  306. /// <summary>
  307. /// 数据解析
  308. /// </summary>
  309. private void DataParse()
  310. {
  311. EventBus.EventBus.GetInstance().Subscribe<DoOrderEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle)
  312. {
  313. if (@event == null) return;
  314. if (@event is DoOrderEvent order)
  315. {
  316. if (order.MorkOrder.GoodBatchings == null) return;
  317. OrderCount++;
  318. MessageLog.GetInstance.Show($"接收到{OrderCount}次订单");
  319. foreach (var item in order.MorkOrder.GoodBatchings)
  320. {
  321. var res = orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId);
  322. if (res != null)
  323. {
  324. if (ushort.TryParse(res.BatchingLoc, out ushort loc))
  325. {
  326. //if (morkF.TakeMaterialQueue.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  327. //将一个商品的ABC料位置存入队列
  328. morkF.TakeMaterialQueue.Enqueue(new OrderLocInfo() { SuborderId = order.MorkOrder.SuborderId, BatchingId = res.BatchingId, MaterialLoc = ushort.Parse(res.BatchingLoc) });
  329. }
  330. //int index = 0;
  331. //if (recipeBoms != null)
  332. //{
  333. // index = Array.FindIndex(recipeBoms.RecipeIds?.ToArray(), p => p.RecipeId == order.MorkOrder.RecipeId);
  334. // index++;
  335. //}
  336. if (morkF.TakePlateQueue.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  337. morkF.TakePlateQueue.Enqueue(new OrderLocInfo()
  338. {
  339. SuborderId = order.MorkOrder.SuborderId,
  340. BatchingId = res.BatchingId
  341. //RecipeNumber = (index >= 1 && index <= 10) ? (ushort)index : (ushort)0
  342. });
  343. }
  344. }
  345. //根据ID 查找对应制作流程
  346. }
  347. });
  348. }
  349. //}
  350. /// <summary>
  351. /// 主任务
  352. /// </summary>
  353. public override void MainTask()
  354. {
  355. TakePlatelTask();
  356. TurntableControl();
  357. ProcessExecute();
  358. SingleProcess();
  359. }
  360. //机器人,锅灶流程执行
  361. public void ProcessExecute()
  362. {
  363. if (!morkF.ProcessExcuteLock)
  364. {
  365. morkF.ProcessExcuteLock = true;
  366. Task.Run(new Action(() =>
  367. {
  368. if (!morkF.RoobotIdle && morkF.InitialComplete && morkF.TakeMaterialQueue.Count > 0)
  369. {
  370. foreach (var res in stirFryBom.StirFryActions)//遍历所有流程
  371. {
  372. MessageLog.GetInstance.Show($"执行流程{res.Time}");
  373. //机器人线程
  374. Task taskRobot = Task.Run(new Action(() =>
  375. {
  376. foreach (var temp in res.RobotActions)
  377. {
  378. switch (temp)
  379. {
  380. case StirFryRobotAction.清洗槽取锅:
  381. TakePotTask();//执行取锅操作
  382. break;
  383. case StirFryRobotAction.加入A料:
  384. TakeBurdenATask();//执行取A料操作
  385. break;
  386. case StirFryRobotAction.加入B料:
  387. // TakeBurdenBTask();//执行取B料操作
  388. TakeBurdenATask();//执行取B料操作
  389. break;
  390. case StirFryRobotAction.加入C料:
  391. //TakeBurdenCTask();//执行取C料操作
  392. TakeBurdenATask();//执行取C料操作
  393. break;
  394. case StirFryRobotAction.灶取锅:
  395. OutDishTask();//执行出餐操作
  396. CleanPotTask();//洗锅操作
  397. break;
  398. }
  399. }
  400. }));
  401. //炒锅线程操作
  402. Task taskPot = Task.Run(new Action(() =>
  403. {
  404. foreach (var temp in res.PotActions)
  405. {
  406. switch (temp)
  407. {
  408. case StirFryPotAction.NONE:
  409. break;
  410. case StirFryPotAction.大火t1s:
  411. KitchenAdjustGears(3);
  412. Task.Delay(1000).Wait(); //大火加热1s//执行大火锅干操作
  413. break;
  414. case StirFryPotAction.加油:
  415. AddOil();//注油//执行加油操作
  416. break;
  417. case StirFryPotAction.中火t2s:
  418. KitchenAdjustGears(2);
  419. Task.Delay(2000).Wait();//执行操作
  420. break;
  421. case StirFryPotAction.小火持续:
  422. KitchenAdjustGears(1);
  423. break;
  424. case StirFryPotAction.中火持续:
  425. KitchenAdjustGears(5);
  426. break;
  427. case StirFryPotAction.大火持续:
  428. KitchenAdjustGears(6);
  429. break;
  430. case StirFryPotAction.停止火力:
  431. KitchenAdjustGears(0);//关闭灶加热
  432. break;
  433. case StirFryPotAction.搅拌臂上位:
  434. TurnUpStatusDetect();//执行搅拌臂上位操作
  435. break;
  436. case StirFryPotAction.搅拌臂下位:
  437. TurnDownStatusDetect();//执行搅拌臂下位操作
  438. break;
  439. case StirFryPotAction.低速旋转:
  440. TurnMachineGearsControl(1);//执行搅拌臂速度1挡操作
  441. break;
  442. case StirFryPotAction.快速旋转:
  443. TurnMachineGearsControl(2);//执行搅拌臂速度3挡操作
  444. break;
  445. case StirFryPotAction.停止旋转:
  446. TurnMachineGearsControl(0);//执行搅拌臂速度0挡操作
  447. break;
  448. }
  449. }
  450. }));
  451. Task.WhenAll(taskRobot, taskPot).Wait();//等待所有线程结束
  452. Task.Delay(res.During * 1000).Wait();//当前流程延迟
  453. }
  454. morkF.OutMealComplete = true;
  455. }
  456. else
  457. {
  458. morkF.ProcessExcuteLock = false;//解除流程互锁
  459. }
  460. }));
  461. }
  462. }
  463. /// <summary>
  464. /// 信号处理
  465. /// </summary>
  466. private void SingleProcess()
  467. {
  468. //出餐完成,相应变量复位
  469. if (morkF.OutMealComplete)
  470. {
  471. morkF.TakePlateLock = false;
  472. morkF.TakePotLock = false;
  473. morkF.PotInPlace = false;
  474. morkF.ProcessExcuteLock = false;
  475. }
  476. }
  477. /// <summary>
  478. /// 转台控制
  479. /// </summary>
  480. private void TurntableControl()
  481. {
  482. //正常轮询
  483. //if (morkF.TakeMaterialQueue.Count > 0 && !morkF.TurnTableLock)
  484. //{
  485. // var result = orderMaterialDelivery.BatchingInfo.Where(p => p.BatchingId == morkF.TakeMaterialQueue.ElementAt(0).BatchingId).ToList();
  486. // if (result != null)
  487. // {
  488. // if (ushort.TryParse(result[0].BatchingLoc, out ushort loc))
  489. // {
  490. // TurnMaterialStore(loc);
  491. // MessageLog.GetInstance.Show($"转台转到【{loc}】位置");
  492. // morkF.TurnTableLock = true; //取料完成后置false
  493. // }
  494. // }
  495. // else MessageLog.GetInstance.Show("未找到可用的物料信息");
  496. //}
  497. //调试代码
  498. if (morkF.TakeMaterialQueue.Count > 0 && !morkF.TurnTableLock)
  499. {
  500. // var result = orderMaterialDelivery.BatchingInfo.Where(p => p.BatchingId == morkF.TakeMaterialQueue.ElementAt(0).BatchingId).ToList();
  501. if (resultorder != null)
  502. {
  503. TurnMaterialStore(resultorder[0]);
  504. MessageLog.GetInstance.Show($"转台转到【{resultorder[0]}】位置");
  505. resultorder.RemoveAt(0);
  506. morkF.TurnTableLock = true; //取料完成后置false
  507. }
  508. else MessageLog.GetInstance.Show("未找到可用的物料信息");
  509. }
  510. }
  511. /// <summary>
  512. /// 供盘
  513. /// </summary>
  514. /// <exception cref="NotImplementedException"></exception>
  515. private void TakePlatelTask()
  516. {
  517. if (!morkF.RoobotIdle && morkF.InitialComplete && morkF.TakePlateQueue.Count > 0 && !morkF.ProvidePlateModule && !morkF.TakePlateLock)
  518. {
  519. if (morkF.TakePlateQueue.TryDequeue(out OrderLocInfo order))
  520. {
  521. StartTakePlate();
  522. morkF.CurrentOrderId = order.SuborderId;
  523. morkF.TakePlateLock = true; //订单完成后置false
  524. morkF.OutMealComplete = false;
  525. // OrderChange(morkF.CurrentOrderId, ORDER_STATUS.COOKING);
  526. MessageLog.GetInstance.Show($"订单【{ morkF.CurrentOrderId}】执行取碗控制");
  527. }
  528. }
  529. }
  530. /// <summary>
  531. /// 取锅到灶台
  532. /// </summary>
  533. /// <exception cref="NotImplementedException"></exception>
  534. private void TakePotTask()
  535. {
  536. while (!(!morkF.CleanModule && !morkF.KitchenOneStatus && morkF.CleanComplete))//等待清洗1准备就绪
  537. {
  538. Task.Delay(5).Wait();
  539. }
  540. while (morkF.RoobotIdle)//等待机器人空闲
  541. {
  542. Task.Delay(5).Wait();
  543. }
  544. TakePotToKitchen();
  545. WriteData("M1.5", false);//清洗模组1完成复位
  546. MessageLog.GetInstance.Show($"订单【{ morkF.CurrentOrderId}】执行取锅到灶台控制");
  547. while (!morkF.PutPotToKitchenComlete)
  548. {
  549. Task.Delay(5).Wait();
  550. }
  551. morkF.PotInPlace = morkF.PutPotToKitchenComlete;//锅到位
  552. WriteData("M14.0", false);//机器人取锅完成复位
  553. Thread.Sleep(2000);
  554. }
  555. /// <summary>
  556. /// 转台复位
  557. /// </summary>
  558. /// <param name="loc"></param>
  559. public void TurnReset(int loc)
  560. {
  561. switch (loc)
  562. {
  563. case 1: WriteData("M13.0", false); break;
  564. case 2: WriteData("M13.1", false); break;
  565. case 3: WriteData("M13.2", false); break;
  566. case 4: WriteData("M13.3", false); break;
  567. case 5: WriteData("M13.4", false); break;
  568. }
  569. }
  570. /// <summary>
  571. /// 取素菜A料
  572. /// </summary>
  573. private void TakeBurdenATask()
  574. {
  575. int loc = 0;
  576. while (morkF.RoobotIdle || !morkF.PotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅到位
  577. {
  578. Task.Delay(5).Wait();
  579. }
  580. if (morkF.TakeMaterialQueue.TryDequeue(out OrderLocInfo order))
  581. {
  582. loc = order.MaterialLoc;
  583. TakeBurden(loc);
  584. TurnReset(loc);//转台复位
  585. MessageLog.GetInstance.Show($"订单【{ order.SuborderId}】,执行到转台{loc}位置取料");
  586. }
  587. //等待取料完成
  588. while (!morkF.TakeMaterialComplete)
  589. {
  590. Task.Delay(5).Wait();
  591. }
  592. WriteData("M14.1", false);//机器人取料完成复位
  593. morkF.TurnTableLock = false;//转台互锁解除
  594. while (!morkF.FallMaterialComplete)//等待倒料完成
  595. {
  596. Task.Delay(5).Wait();
  597. }
  598. MessageLog.GetInstance.Show($"订单【{ order.SuborderId}】,转台{loc}配料倒料完成");
  599. }
  600. /// <summary>
  601. /// 取素菜B料
  602. /// </summary>
  603. private void TakeBurdenBTask()
  604. {
  605. while (morkF.RoobotIdle || !morkF.PotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅到位
  606. {
  607. Task.Delay(5).Wait();
  608. }
  609. if (morkF.TakeMaterialQueue.TryDequeue(out OrderLocInfo order))
  610. {
  611. int loc = order.MaterialLoc;
  612. TakeBurden(loc);
  613. TurnReset(loc);//转台复位
  614. MessageLog.GetInstance.Show($"订单【{ order.SuborderId}】,执行取B料");
  615. }
  616. //等待取料完成
  617. while (!morkF.TakeMaterialComplete)
  618. {
  619. Task.Delay(5).Wait();
  620. }
  621. WriteData("M14.1", false);//机器人取料完成复位
  622. morkF.TurnTableLock = false;//转台互锁解除
  623. while (!morkF.FallMaterialComplete)//等待倒料完成
  624. {
  625. Task.Delay(5).Wait();
  626. }
  627. MessageLog.GetInstance.Show($"订单【{ order.SuborderId}】,B料倒料完成");
  628. }
  629. /// <summary>
  630. /// 取调味品C料
  631. /// </summary>
  632. /// <exception cref="NotImplementedException"></exception>
  633. private void TakeBurdenCTask()
  634. {
  635. while (morkF.RoobotIdle || !morkF.PotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅到位
  636. {
  637. Task.Delay(5).Wait();
  638. }
  639. if (morkF.TakeMaterialQueue.TryDequeue(out OrderLocInfo order))
  640. {
  641. int loc = order.MaterialLoc;
  642. TakeBurden(loc);
  643. TurnReset(loc);//转台复位
  644. MessageLog.GetInstance.Show($"订单【{ order.SuborderId}】,执行取C料");
  645. }
  646. MessageLog.GetInstance.ShowEx($"剩余配料数量{morkF.TakeMaterialQueue.Count}");
  647. //等待取料完成
  648. while (!morkF.TakeMaterialComplete)
  649. {
  650. Task.Delay(5).Wait();
  651. }
  652. WriteData("M14.1", false);//机器人取料完成复位
  653. morkF.TurnTableLock = false;//转台互锁解除
  654. while (!morkF.FallMaterialComplete)
  655. {
  656. Task.Delay(5).Wait();
  657. }
  658. MessageLog.GetInstance.Show($"订单【{ order.SuborderId}】,C料倒料完成");
  659. //}
  660. }
  661. /// <summary>
  662. /// 出餐
  663. /// </summary>
  664. private void OutDishTask()
  665. {
  666. while (morkF.RoobotIdle || morkF.CleanModule || !morkF.ProvidePlateComplete)//等待条件满足
  667. {
  668. Task.Delay(5).Wait();
  669. }
  670. if (morkF.TakePlateQueue.Count == 0)
  671. {
  672. WriteData("M0.7", false);//无订单关闭抽风机
  673. }
  674. RobotOutMeal();
  675. WriteData("M1.2", false);//供盘复位
  676. MessageLog.GetInstance.Show($"订单【{morkF.CurrentOrderId}】正在出餐");
  677. }
  678. /// <summary>
  679. /// 洗锅放锅
  680. /// </summary>
  681. private void CleanPotTask()
  682. {
  683. while (!morkF.PlaceRinseTableComplete || morkF.CleanModule)
  684. {
  685. Task.Delay(5).Wait();
  686. }
  687. MessageLog.GetInstance.Show($"订单【{morkF.CurrentOrderId}】出餐完成");
  688. WriteData("M14.2", false);//机器人出餐完成复位
  689. //OrderChange(morkF.CurrentOrderId, ORDER_STATUS.COMPLETED_COOK);
  690. CleanModuleControl("Start");
  691. }
  692. /// <summary>
  693. /// 任务复位重启
  694. /// </summary>
  695. //private void ResetProgram()
  696. //{
  697. // ThreadManage.GetInstance().StartLong(new Action(() =>
  698. // {
  699. // if (RTrig.GetInstance("ResetProgram").Start(morkF.DevicDataInite))
  700. // {
  701. // ThreadManage.GetInstance().StopTask("MainTask", new Action(() =>
  702. // {
  703. // ThreadManage.GetInstance().StopTask("ReadPLCData", new Action(() =>
  704. // {
  705. // morkF = null;
  706. // morkF = new GVL_MorkF();
  707. // ActionManage.GetInstance.Send("ResetProgram");
  708. // ActionManage.GetInstance.Send("ClearOrders");
  709. // ReadData();
  710. // Main();
  711. // }));
  712. // }));
  713. // }
  714. // Thread.Sleep(10);
  715. // }), "ResetProgram");
  716. //}
  717. /// <summary>
  718. /// 翻转机下降及状态检测
  719. /// </summary>
  720. public void TurnDownStatusDetect()
  721. {
  722. TurnMachineOrientControl("Down");
  723. while (!morkF.TurnMachineDownComplete)//等待翻转机下降完成
  724. {
  725. Task.Delay(5).Wait();
  726. }
  727. WriteData("M8.3", false);//下降完成复位
  728. MessageLog.GetInstance.Show($"翻转机下降完成");
  729. }
  730. /// <summary>
  731. /// 翻转机上升及状态检测
  732. /// </summary>
  733. public void TurnUpStatusDetect()
  734. {
  735. while (morkF.RoobotIdle)//机器人忙碌
  736. {
  737. Task.Delay(5).Wait();
  738. }
  739. TurnMachineOrientControl("Top");//翻转机上升
  740. while (!morkF.TurnMachineUpComplete)//等待翻转机上升完成以及取料完成
  741. {
  742. Task.Delay(5).Wait();
  743. }
  744. WriteData("M8.1", false);//上升完成复位
  745. MessageLog.GetInstance.Show("翻转机上升完成");
  746. }
  747. private void GetStatus(string key, Action<bool[]> action)
  748. {
  749. if (peripheralStatus.ContainsKey(key))
  750. {
  751. action((bool[])peripheralStatus[key]);//获取PLC指定地址的状态值
  752. }
  753. }
  754. /// <summary>
  755. /// 写数据
  756. /// </summary>
  757. /// <param name="address"></param>
  758. /// <param name="value"></param>
  759. private void WriteData(string address, object value)
  760. {
  761. EventBus.EventBus.GetInstance().Publish(new WriteModel() { DeviceId = DeviceId, Address = address, Value = value });
  762. }
  763. /// <summary>
  764. /// 灶台档位调节
  765. /// </summary>
  766. public void KitchenAdjustGears(int number)
  767. {
  768. while (!morkF.PotInPlace)
  769. {
  770. Task.Delay(5).Wait();
  771. }
  772. switch (number)
  773. {
  774. case 0:
  775. WriteData("M4.0", new bool[] { false, false, false, false, false, false, false, false });//0000 0000
  776. break;
  777. case 1:
  778. WriteData("M4.0", new bool[] { true, false, false, false, false, false, false, false });//0000 0001
  779. break;
  780. case 2:
  781. WriteData("M4.0", new bool[] { false, true, false, false, false, false, false, false });//0000 0010
  782. break;
  783. case 3:
  784. WriteData("M4.0", new bool[] { true, true, false, false, false, false, false, false });//0000 0011
  785. break;
  786. case 4:
  787. WriteData("M4.0", new bool[] { false, false, true, false, false, false, false, false });//0000 0100
  788. break;
  789. case 5:
  790. WriteData("M4.0", new bool[] { true, false, true, false, false, false, false, false });//0000 0101
  791. break;
  792. case 6:
  793. WriteData("M4.0", new bool[] { false, true, true, false, false, false, false, false });//0000 0110
  794. break;
  795. case 7:
  796. WriteData("M4.0", new bool[] { true, true, true, false, false, false, false, false });//0000 0111
  797. break;
  798. case 8:
  799. WriteData("M4.0", new bool[] { false, false, false, true, false, false, false, false });//0000 1000
  800. break;
  801. case 9:
  802. WriteData("M4.0", new bool[] { true, false, false, true, false, false, false, false });//0000 1001
  803. break;
  804. }
  805. MessageLog.GetInstance.Show($"订单【{morkF.CurrentOrderId}】,加热档位调至{number}挡");
  806. }
  807. public void TurnMaterialStore(int loc)
  808. {
  809. switch (loc)
  810. {
  811. case 1:
  812. WriteData("M13.0", true);
  813. break;
  814. case 2:
  815. WriteData("M13.1", true);
  816. break;
  817. case 3:
  818. WriteData("M13.2", true);
  819. break;
  820. case 4:
  821. WriteData("M13.3", true);
  822. break;
  823. case 5:
  824. WriteData("M13.4", true);
  825. break;
  826. }
  827. }
  828. public void PLCInite()
  829. {
  830. WriteData("M0.0", true);
  831. }
  832. /// <summary>
  833. /// 供盘启动
  834. /// </summary>
  835. public void StartTakePlate()
  836. {
  837. WriteData("M1.1", true);
  838. }
  839. /// <summary>
  840. /// 取锅到灶台
  841. /// </summary>
  842. public void TakePotToKitchen()
  843. {
  844. WriteData("M14.0", true);
  845. }
  846. /// <summary>
  847. /// 机器人出餐并将锅放置清洗台位置
  848. /// </summary>
  849. public void RobotOutMeal()
  850. {
  851. WriteData("M14.2", true);
  852. }
  853. /// <summary>
  854. /// 注油
  855. /// </summary>
  856. public void AddOil()
  857. {
  858. while (!morkF.PotInPlace)
  859. {
  860. Task.Delay(5).Wait();
  861. }
  862. WriteData("M2.7", true);//加油
  863. WriteData("M0.7",true);//打开抽风机
  864. MessageLog.GetInstance.Show("开始注油");
  865. while (!morkF.FallOilComplete)
  866. {
  867. Task.Delay(5).Wait();
  868. }
  869. MessageLog.GetInstance.Show("注油完成");
  870. }
  871. /// <summary>
  872. /// 翻转机方向控制
  873. /// </summary>
  874. /// <param name="orientation"></param>
  875. public void TurnMachineOrientControl(string orientation)
  876. {
  877. switch (orientation)
  878. {
  879. case "Top": WriteData("M8.0", true); break;
  880. // case "Middle": WriteData("", 1); break;
  881. case "Down": WriteData("M8.2", true); break;
  882. }
  883. MessageLog.GetInstance.Show($"翻转机执行{orientation}操作");
  884. }
  885. /// <summary>
  886. /// 翻转机档位控制
  887. /// </summary>
  888. public void TurnMachineGearsControl(int gear)
  889. {
  890. while (!morkF.PotInPlace)
  891. {
  892. Task.Delay(5).Wait();
  893. }
  894. switch (gear)
  895. {
  896. case 0: WriteData("M7.0", true); Task.Delay(1000).Wait(); break;//关闭翻炒机
  897. case 1: WriteData("M7.1", true); break;//翻炒机1挡
  898. case 2: WriteData("M7.2", true); break;//翻炒机2挡
  899. case 3: WriteData("M7.3", true); break;//翻炒机3挡
  900. }
  901. MessageLog.GetInstance.Show($"翻转机档位调至{gear}挡");
  902. }
  903. /// <summary>
  904. /// 取A,B,C料
  905. /// </summary>
  906. public void TakeBurden(int loc)
  907. {
  908. WriteData("M14.1", true);//机器人取料
  909. }
  910. /// <summary>
  911. /// 清洗模组1启停控制
  912. /// </summary>
  913. public void CleanModuleControl(string status)
  914. {
  915. if (status == "Start")
  916. {
  917. WriteData("M1.4", true);
  918. }
  919. if (status == "Stop")
  920. {
  921. WriteData("M1.4", false);
  922. }
  923. MessageLog.GetInstance.Show($"清洗模组执行【{status}】操作");
  924. }
  925. public override void Stop()
  926. {
  927. }
  928. }
  929. }