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

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