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

99 lines
4.8 KiB

  1. using BPASmartClient.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. namespace BPASmartClient.JXJFoodSmallStation.Model.Siemens
  11. {
  12. public class SiemensDeviceStatus
  13. {
  14. public SiemensHelper Siemens_PLC_S7 = new SiemensHelper();
  15. public bool IsConnected => Siemens_PLC_S7.IsConnected;
  16. public XL_Status_DB XL_Status = new XL_Status_DB();
  17. bool test;
  18. public void Init()
  19. {
  20. if (IsConnected)
  21. {
  22. ThreadManage.GetInstance().StartLong(new Action(() =>
  23. {
  24. var Start = this.Siemens_PLC_S7.ReadClass<XL_Start_DB>(2201);
  25. var Status = this.Siemens_PLC_S7.ReadClass<XL_Status_DB>(2231);
  26. var Finish = this.Siemens_PLC_S7.ReadClass<XL_Finish_DB>(2261);
  27. var DataColl = this.Siemens_PLC_S7.ReadClass<XL_DataColl_DB>(2291);
  28. if (Start != null && Start is XL_Start_DB st)
  29. {
  30. if (RTrig.GetInstance("DB2201.DBX450.0").Start(GVL_SmallStation.IsAllowSiemensSendRecipe) && GVL_SmallStation.SiemensSendRecipeStatus == 0)
  31. {
  32. GVL_SmallStation.SiemensSendRecipeStatus = 1;
  33. this.Siemens_PLC_S7.Write("DB2201.DBX450.0", true);
  34. }
  35. if (RTrig.GetInstance("Order_Request_ACK").Start(Start.Order_Request_ACK) && GVL_SmallStation.SiemensSendRecipeStatus == 1)
  36. {
  37. if (!string.IsNullOrEmpty(st.RecipeCode))
  38. {
  39. GVL_SmallStation.SiemensSendRecipeStatus = 2;
  40. ActionManage.GetInstance.Send("SiemensRecipeRecive", st);
  41. this.Siemens_PLC_S7.Write("DB2201.DBX450.0", false);
  42. }
  43. }
  44. if (TTrig.GetInstance("Order_Request_ACK_").Start(Start.Order_Request_ACK) && GVL_SmallStation.SiemensSendRecipeStatus == 2)
  45. {
  46. GVL_SmallStation.IsAllowSiemensSendRecipe = false;
  47. GVL_SmallStation.SiemensSendRecipeStatus = 3;
  48. //需要等待请求信号复位才能认为接收配方完成
  49. }
  50. }
  51. if (Finish != null && Finish is XL_Finish_DB FinishData)
  52. {
  53. if (RTrig.GetInstance("Ask_For_Finish_PLC").Start(FinishData.Ask_For_Finish_PLC) && GVL_SmallStation.SiemensSendRecipeStatus == 7)
  54. {
  55. FinishData.Order_No = "";
  56. FinishData.Product_Code = "";
  57. FinishData.Job_No = 0;
  58. for (int i = 0; i < 20; i++)
  59. {
  60. FinishData.Material[i] = new UDT1();
  61. }
  62. for (int i = 0; i < 10; i++)
  63. {
  64. FinishData.Powder[i] = new UDT2();
  65. }
  66. GVL_SmallStation.SiemensSendRecipeStatus = 0;
  67. FinishData.Ask_For_Finish = false;
  68. FinishData.DosingTime = 0;
  69. this.Siemens_PLC_S7.WriteClass<XL_Finish_DB>(FinishData, 2261);
  70. }
  71. }
  72. if (Status != null && Status is XL_Status_DB state)
  73. {
  74. for (int i = 0; i < XL_Status.Powder.Length; i++)
  75. {
  76. XL_Status.Powder[i] = new PowderStatus();
  77. }
  78. XL_Status = state;
  79. if (RTrig.GetInstance("Allow_AGV_Put[0]").Start(Status.AgvRequestPut))
  80. {
  81. ActionManage.GetInstance.Send("AGV放货架到位", Status);
  82. Status.AgvRequestPut = false;
  83. this.Siemens_PLC_S7.WriteClass<XL_Status_DB>(Status, 2);
  84. }
  85. }
  86. if (Status != null && RTrig.GetInstance("Allow_AGV_Put[1]").Start(Status.AgvRequestGet))
  87. {
  88. ActionManage.GetInstance.Send("AGV取货架到位", Status);
  89. Status.AgvRequestGet = false;
  90. this.Siemens_PLC_S7.WriteClass<XL_Status_DB>(Status, 2);
  91. }
  92. Thread.Sleep(10);
  93. }),"监听服务数据");
  94. }
  95. }
  96. }
  97. }