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

181 lines
8.1 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 BPASmartClient.CustomResource.Pages.Model;
  10. namespace BPASmartClient.JXJFoodSmallStation.Model.HK_PLC
  11. {
  12. public class HKDeviceStatus
  13. {
  14. public SiemensHelper HK_PLC_S7 = new SiemensHelper();
  15. public bool IsConnected => HK_PLC_S7.IsConnected;
  16. public void Init()
  17. {
  18. if (IsConnected)
  19. {
  20. ThreadManage.GetInstance().StartLong(new Action(() =>
  21. {
  22. }),"信号收发处理");
  23. }
  24. }
  25. /// <summary>
  26. /// 单个配料机配料完成
  27. /// </summary>
  28. /// <param name="value"></param>
  29. public void SingleDosing(uint value)
  30. {
  31. if (IsConnected)
  32. {
  33. HK_PLC_S7.Write(HKPlcCommAddress.SingleStockBinLocationToPLC, value);
  34. HK_PLC_S7.Write(HKPlcCommAddress.SingleDosingFinishToPLC, (ushort)1);
  35. }
  36. }
  37. /// <summary>
  38. /// 复位plc允许接料信号
  39. /// </summary>
  40. public void AllowDosingSignReset()
  41. {
  42. HK_PLC_S7.Write(HKPlcCommAddress.IsAllowDosing,(ushort)0);
  43. }
  44. /// <summary>
  45. /// 复位plc到达某料仓信号
  46. /// </summary>
  47. public void StockStateSignReset()
  48. {
  49. HK_PLC_S7.Write(HKPlcCommAddress.StockState, (ushort)0);
  50. }
  51. /// <summary>
  52. /// 复位一个配方配料完成信号
  53. /// </summary>
  54. public void RecipeDosingFinishReset()
  55. {
  56. HK_PLC_S7.Write(HKPlcCommAddress.RecipeDosingFinish, (ushort)0);
  57. }
  58. /// <summary>
  59. /// 下发配方数据
  60. /// </summary>
  61. /// <param name="BarrelNum">单个桶的编号</param>
  62. /// <param name="StockBinLocation">单个桶对应的料仓位置</param>
  63. public void StockBinPar(uint BarrelNum, ushort StockBinLocation, int TrayNum = 1)
  64. {
  65. if (IsConnected)
  66. {
  67. if (TrayNum == 1)
  68. {
  69. if (BarrelNum >= 1 && BarrelNum <= 4 && StockBinLocation >= 1 && StockBinLocation <= 15)
  70. {
  71. if (BarrelNum == 1)
  72. {
  73. if (StockBinLocation >= 1 && StockBinLocation <= 8)
  74. {
  75. HK_PLC_S7.Write<bool>("DB4.DBX10." + (StockBinLocation - 1), true);
  76. }
  77. else if (StockBinLocation >= 9 && StockBinLocation <= 15)
  78. {
  79. HK_PLC_S7.Write<bool>("DB4.DBX11." + (StockBinLocation - 9), true);
  80. }
  81. MessageLog.GetInstance.ShowRunLog($"托盘1—1号桶在料仓{StockBinLocation}配料");
  82. }
  83. else if (BarrelNum == 2)
  84. {
  85. if (StockBinLocation >= 1 && StockBinLocation <= 8)
  86. {
  87. HK_PLC_S7.Write<bool>("DB4.DBX12." + (StockBinLocation - 1), true);
  88. }
  89. else if (StockBinLocation >= 9 && StockBinLocation <= 15)
  90. {
  91. HK_PLC_S7.Write<bool>("DB4.DBX13." + (StockBinLocation - 9), true);
  92. }
  93. MessageLog.GetInstance.ShowRunLog($"托盘1—2号桶在料仓{StockBinLocation}配料");
  94. }
  95. else if (BarrelNum == 3)
  96. {
  97. if (StockBinLocation >= 1 && StockBinLocation <= 8)
  98. {
  99. HK_PLC_S7.Write<bool>("DB4.DBX14." + (StockBinLocation - 1), true);
  100. }
  101. else if (StockBinLocation >= 9 && StockBinLocation <= 15)
  102. {
  103. HK_PLC_S7.Write<bool>("DB4.DBX15." + (StockBinLocation - 9), true);
  104. }
  105. MessageLog.GetInstance.ShowRunLog($"托盘1—3号桶在料仓{StockBinLocation}配料");
  106. }
  107. else if (BarrelNum == 4)
  108. {
  109. if (StockBinLocation >= 1 && StockBinLocation <= 8)
  110. {
  111. HK_PLC_S7.Write<bool>("DB4.DBX16." + (StockBinLocation - 1), true);
  112. }
  113. else if (StockBinLocation >= 9 && StockBinLocation <= 15)
  114. {
  115. HK_PLC_S7.Write<bool>("DB4.DBX17." + (StockBinLocation - 9), true);
  116. }
  117. MessageLog.GetInstance.ShowRunLog($"托盘1—4号桶在料仓{StockBinLocation}配料");
  118. }
  119. }
  120. }
  121. else if (TrayNum == 2)
  122. {
  123. if (BarrelNum >= 1 && BarrelNum <= 4 && StockBinLocation >= 1 && StockBinLocation <= 15)
  124. {
  125. if (BarrelNum == 1)
  126. {
  127. if (StockBinLocation >= 1 && StockBinLocation <= 8)
  128. {
  129. HK_PLC_S7.Write<bool>("DB4.DBX18." + (StockBinLocation - 1), true);
  130. }
  131. else if (StockBinLocation >= 9 && StockBinLocation <= 15)
  132. {
  133. HK_PLC_S7.Write<bool>("DB4.DBX19." + (StockBinLocation - 9), true);
  134. }
  135. MessageLog.GetInstance.ShowRunLog($"托盘2—1号桶在料仓{StockBinLocation}配料");
  136. }
  137. else if (BarrelNum == 2)
  138. {
  139. if (StockBinLocation >= 1 && StockBinLocation <= 8)
  140. {
  141. HK_PLC_S7.Write<bool>("DB4.DBX20." + (StockBinLocation - 1), true);
  142. }
  143. else if (StockBinLocation >= 9 && StockBinLocation <= 15)
  144. {
  145. HK_PLC_S7.Write<bool>("DB4.DBX21." + (StockBinLocation - 9), true);
  146. }
  147. MessageLog.GetInstance.ShowRunLog($"托盘2—2号桶在料仓{StockBinLocation}配料");
  148. }
  149. else if (BarrelNum == 3)
  150. {
  151. if (StockBinLocation >= 1 && StockBinLocation <= 8)
  152. {
  153. HK_PLC_S7.Write<bool>("DB4.DBX22." + (StockBinLocation - 1), true);
  154. }
  155. else if (StockBinLocation >= 9 && StockBinLocation <= 15)
  156. {
  157. HK_PLC_S7.Write<bool>("DB4.DBX23." + (StockBinLocation - 9), true);
  158. }
  159. MessageLog.GetInstance.ShowRunLog($"托盘2—3号桶在料仓{StockBinLocation}配料");
  160. }
  161. else if (BarrelNum == 4)
  162. {
  163. if (StockBinLocation >= 1 && StockBinLocation <= 8)
  164. {
  165. HK_PLC_S7.Write<bool>("DB4.DBX24." + (StockBinLocation - 1), true);
  166. }
  167. else if (StockBinLocation >= 9 && StockBinLocation <= 15)
  168. {
  169. HK_PLC_S7.Write<bool>("DB4.DBX25." + (StockBinLocation - 9), true);
  170. }
  171. MessageLog.GetInstance.ShowRunLog($"托盘2—4号桶在料仓{StockBinLocation}配料");
  172. }
  173. }
  174. }
  175. }
  176. }
  177. }
  178. }