终端一体化运控平台
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

108 строки
5.5 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.JXJFoodBigStation.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 DL_Status_DB DL_Status = new DL_Status_DB();
  18. bool printFirstLog = false;
  19. public void Init()
  20. {
  21. TaskManage.GetInstance.StartLong(new Action(() =>
  22. {
  23. if (IsConnected)
  24. {
  25. var res = this.Siemens_PLC_S7.ReadClass<DL_Start_DB>(2301);
  26. var res1 = this.Siemens_PLC_S7.ReadClass<DL_Status_DB>(2331);
  27. var res2 = this.Siemens_PLC_S7.ReadClass<DL_Finish_DB>(2361);
  28. //var res3 = this.Siemens_PLC_S7.ReadClass<DL_DataColl_DB>(2391);
  29. if (res != null && res is DL_Start_DB start)
  30. {
  31. if (GVL_BigStation.SiemensSendRecipeStatus == 0)
  32. {
  33. if (GVL_BigStation.Order_Request)
  34. {
  35. this.Siemens_PLC_S7.Write("DB2301.DBX330.0", true);
  36. MessageNotify.GetInstance.ShowRunLog($"向西门子请求订单");
  37. GVL_BigStation.SiemensSendRecipeStatus = 1;
  38. }
  39. else
  40. {
  41. this.Siemens_PLC_S7.Write("DB2301.DBX330.0", false);
  42. if (!printFirstLog)
  43. {
  44. printFirstLog = true;
  45. MessageNotify.GetInstance.ShowRunLog($"plc不允许下发订单");
  46. }
  47. }
  48. }
  49. if (RTrig.GetInstance("Order_Request_Ack").Start(start.Order_Request_Ack) && GVL_BigStation.SiemensSendRecipeStatus == 1)
  50. {
  51. printFirstLog = false;
  52. ActionManage.GetInstance.Send("SiemensSendRecipe", start);
  53. this.Siemens_PLC_S7.Write("DB2301.DBX330.0", false);
  54. MessageNotify.GetInstance.ShowRunLog($"西门子下发订单:{start.RecipeCode}");
  55. GVL_BigStation.SiemensSendRecipeStatus = 2;
  56. }
  57. if (TTrig.GetInstance("Order_Request_Ack").Start(start.Order_Request_Ack) && GVL_BigStation.SiemensSendRecipeStatus == 2)
  58. {
  59. GVL_BigStation.Order_Request = false;
  60. MessageNotify.GetInstance.ShowRunLog($"西门子确认上位机接收到订单:{start.RecipeName}");
  61. GVL_BigStation.SiemensSendRecipeStatus = 3;
  62. }
  63. if (RTrig.GetInstance("Order_Cancel").Start(start.Order_Cancel)) //订单取消
  64. {
  65. GVL_BigStation.Order_Cancel = true;
  66. GVL_BigStation.Order_CancelRecipeCode = start.RecipeCode;
  67. MessageNotify.GetInstance.ShowRunLog($"西门子下发取消工单指令:{start.RecipeName}");
  68. }
  69. }
  70. if (res1 != null && res1 is DL_Status_DB status)
  71. {
  72. DL_Status = status;
  73. }
  74. if (res2 != null && res2 is DL_Finish_DB finish)
  75. {
  76. if (finish.Ask_For_Finish_PLC &&(GVL_BigStation.Recipe1DosingFinish || GVL_BigStation.Recipe2DosingFinish || GVL_BigStation.Recipe3DosingFinish || GVL_BigStation.Recipe4DosingFinish))
  77. {
  78. finish.Order_No = "";
  79. finish.Product_Code = "";
  80. finish.job_No = 0;
  81. for (int i = 0; i < 20; i++)
  82. {
  83. finish.Material[i] = new UDT1();
  84. }
  85. finish.Ask_For_Finish = false;
  86. finish.ProcessTime = 0;
  87. this.Siemens_PLC_S7.WriteClass<DL_Finish_DB>(finish, 2361);
  88. if (GVL_BigStation.Recipe1DosingFinish) GVL_BigStation.Recipe1DosingFinish = false;
  89. if (GVL_BigStation.Recipe2DosingFinish) GVL_BigStation.Recipe2DosingFinish = false;
  90. if (GVL_BigStation.Recipe3DosingFinish) GVL_BigStation.Recipe3DosingFinish = false;
  91. if (GVL_BigStation.Recipe4DosingFinish) GVL_BigStation.Recipe4DosingFinish = false;
  92. }
  93. }
  94. Thread.Sleep(10);
  95. var dataColl = ProcessControl.GetInstance.HKDevice.DataColl;
  96. if (dataColl != null && dataColl is DL_DataColl_DB data)
  97. {
  98. Siemens_PLC_S7.WriteClass<DL_DataColl_DB>(data, 2391);
  99. }
  100. }
  101. Thread.Sleep(10);
  102. }), "西门子数据交互",true);
  103. }
  104. }
  105. }