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

128 lines
6.1 KiB

  1. using BPA.Helper;
  2. using BPASmartClient.Modbus;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using BPASmartClient.S7Net;
  9. using System.Threading;
  10. using BPASmartClient.CustomResource.Pages.Model;
  11. namespace BPASmartClient.JXJFoodSmallStation.Model.Siemens
  12. {
  13. public class SiemensDeviceStatus
  14. {
  15. public SiemensHelper Siemens_PLC_S7 = new SiemensHelper();
  16. public bool IsConnected => Siemens_PLC_S7.IsConnected;
  17. public XL_Status_DB XL_Status = new XL_Status_DB();
  18. public XL_DataColl_DB DataColl = new XL_DataColl_DB();
  19. public void Init()
  20. {
  21. TaskManage.GetInstance.StartLong(new Action(() =>
  22. {
  23. if (IsConnected)
  24. {
  25. var Start = this.Siemens_PLC_S7.ReadClass<XL_Start_DB>(2201);
  26. var Status = this.Siemens_PLC_S7.ReadClass<XL_Status_DB>(2231);
  27. var Finish = this.Siemens_PLC_S7.ReadClass<XL_Finish_DB>(2261);
  28. //var DataColl = this.Siemens_PLC_S7.ReadClass<XL_DataColl_DB>(2291);
  29. if (Start != null && Start is XL_Start_DB st)
  30. {
  31. switch (GVL_SmallStation.GetInstance.SiemensSendRecipeStatus)
  32. {
  33. case 0:
  34. if (GVL_SmallStation.GetInstance.IsAllowSiemensSendRecipe)
  35. {
  36. this.Siemens_PLC_S7.Write("DB2201.DBX450.0", true);
  37. GVL_SmallStation.GetInstance.SiemensSendRecipeStatus = 1;
  38. }
  39. else
  40. {
  41. this.Siemens_PLC_S7.Write("DB2201.DBX450.0", false);
  42. }
  43. break;
  44. case 1:
  45. if (st.Order_Request_ACK)
  46. {
  47. if (!string.IsNullOrEmpty(st.RecipeCode))
  48. {
  49. GVL_SmallStation.GetInstance.SiemensSendRecipeStatus = 2;
  50. ActionManage.GetInstance.Send("SiemensRecipeRecive", st);
  51. this.Siemens_PLC_S7.Write("DB2201.DBX450.0", false);
  52. }
  53. }
  54. break;
  55. case 2:
  56. if (Start.Order_Request_ACK == false)
  57. {
  58. GVL_SmallStation.GetInstance.IsAllowSiemensSendRecipe = false;
  59. GVL_SmallStation.GetInstance.SiemensSendRecipeStatus = 3;
  60. }
  61. break;
  62. }
  63. if (RTrig.GetInstance("Order_Cancel").Start(st.Order_Cancel)) //订单取消
  64. {
  65. if (GVL_SmallStation.GetInstance.Order_Cancel == false)
  66. {
  67. GVL_SmallStation.GetInstance.Order_Cancel = true;
  68. GVL_SmallStation.GetInstance.Order_CancelRecipeCode = st.RecipeCode;
  69. GVL_SmallStation.GetInstance.OrderCancelStep = 0;
  70. MessageNotify.GetInstance.ShowRunLog($"西门子下发取消工单指令:{st.RecipeName}");
  71. }
  72. else
  73. {
  74. MessageNotify.GetInstance.ShowRunLog($"订单正在取消,请等待订单{ GVL_SmallStation.GetInstance.Order_CancelRecipeCode}取消完成,再取消订单:{st.RecipeName}");
  75. }
  76. }
  77. }
  78. if (Finish != null && Finish is XL_Finish_DB FinishData)
  79. {
  80. if (FinishData.Ask_For_Finish_PLC)
  81. {
  82. FinishData.Order_No = "";
  83. FinishData.Product_Code = "";
  84. FinishData.Job_No = 0;
  85. for (int i = 0; i < 20; i++)
  86. {
  87. FinishData.Material[i] = new UDT1();
  88. }
  89. for (int i = 0; i < 10; i++)
  90. {
  91. FinishData.Powder[i] = new UDT2();
  92. }
  93. FinishData.Ask_For_Finish = false;
  94. FinishData.DosingTime = 0;
  95. this.Siemens_PLC_S7.WriteClass<XL_Finish_DB>(FinishData, 2261);
  96. }
  97. }
  98. if (Status != null && Status is XL_Status_DB state)
  99. {
  100. for (int i = 0; i < XL_Status.Powder.Length; i++)
  101. {
  102. XL_Status.Powder[i] = new PowderStatus();
  103. }
  104. XL_Status = state;
  105. }
  106. //从海科plc的数采 发送给西门子plc
  107. var res = ProcessControl.GetInstance.HKDevice.DeviceStatus;
  108. if (res != null)
  109. {
  110. DataColl.HeartBeatWithPLC = res.HeartBeat;
  111. DataColl.SystemStart = res.DeviceRun;
  112. DataColl.SystemStop = res.DeviceStop;
  113. DataColl.SystemPause = res.DevicePause;
  114. DataColl.SystemEStop = res.DeviceEStop;
  115. DataColl.Mode = res.Mode;
  116. DataColl.Alarm = res.Alarm;
  117. this.Siemens_PLC_S7.WriteClass<XL_DataColl_DB>(DataColl, 2291);
  118. }
  119. }
  120. Thread.Sleep(10);
  121. }),"监听服务数据",true);
  122. }
  123. }
  124. }