终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1215 lines
57 KiB

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