终端一体化运控平台
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

183 Zeilen
8.4 KiB

  1. using BPASmartClient.CustomResource.Pages.Model;
  2. using BPA.Helper;
  3. using System;
  4. using System.Collections.ObjectModel;
  5. using System.Threading;
  6. namespace BPASmartClient.FoodStationTest.Model.HK_PLC
  7. {
  8. public class HKDeviceStatus
  9. {
  10. public BPA.Communication.Siemens HK_PLC_S7 = new BPA.Communication.Siemens();
  11. public bool IsConnected => HK_PLC_S7.IsConnected();
  12. public PlcReadAddressDB45 DeviceStatus = new PlcReadAddressDB45();
  13. public void Init()
  14. {
  15. TaskManage.GetInstance.StartLong(new Action(() =>
  16. {
  17. if (IsConnected)
  18. {
  19. var res = this.HK_PLC_S7.Read<PlcReadAddressDB45>(45);
  20. if (res.IsSuccess && res.Content != null && res.Content is PlcReadAddressDB45 data)
  21. {
  22. DeviceStatus = data;
  23. }
  24. var res1 = this.HK_PLC_S7.Read<PlcReadAddressDB3>(3);
  25. if (res1.IsSuccess && res1.Content != null && res1.Content is PlcReadAddressDB3 data1)
  26. {
  27. GVL_SmallStation.GetInstance.plcReadDataDB3 = data1;
  28. }
  29. }
  30. Thread.Sleep(10);
  31. }), "海科PLC设备状态", true);
  32. }
  33. private void TempStockBinPar(int num, ushort StockBinLocation, string info)
  34. {
  35. if (StockBinLocation >= 1 && StockBinLocation <= 8)
  36. {
  37. HK_PLC_S7.Write<bool>($"DB4.DBX{num}." + (StockBinLocation - 1), true);
  38. }
  39. else if (StockBinLocation >= 9 && StockBinLocation <= 15)
  40. {
  41. HK_PLC_S7.Write<bool>($"DB4.DBX{num + 1}." + (StockBinLocation - 9), true);
  42. }
  43. MessageNotify.GetInstance.ShowRunLog($"托盘{info}号桶在料仓{StockBinLocation}配料");
  44. }
  45. /// <summary>
  46. /// 下发配方数据
  47. /// </summary>
  48. /// <param name="BarrelNum">单个桶的编号</param>
  49. /// <param name="StockBinLocation">单个桶对应的料仓位置</param>
  50. public void StockBinPar(uint BarrelNum, ushort StockBinLocation, int TrayNum = 1)
  51. {
  52. if (IsConnected)
  53. {
  54. if (TrayNum == 1)
  55. {
  56. if (BarrelNum >= 6 && BarrelNum <= 8 && StockBinLocation >= 1 && StockBinLocation <= 15)
  57. {
  58. if (BarrelNum == 6)
  59. {
  60. TempStockBinPar(10, StockBinLocation, "1—1");
  61. }
  62. else if (BarrelNum == 7)
  63. {
  64. TempStockBinPar(12, StockBinLocation, "1—2");
  65. }
  66. else if (BarrelNum == 8)
  67. {
  68. TempStockBinPar(14, StockBinLocation, "1—3");
  69. }
  70. else if (BarrelNum == 4)
  71. {
  72. TempStockBinPar(16, StockBinLocation, "1—4");
  73. }
  74. }
  75. }
  76. else if (TrayNum == 2)
  77. {
  78. if (BarrelNum >= 1 && BarrelNum <= 4 && StockBinLocation >= 1 && StockBinLocation <= 15)
  79. {
  80. if (BarrelNum == 6)
  81. {
  82. TempStockBinPar(18, StockBinLocation, "2—1");
  83. }
  84. else if (BarrelNum == 7)
  85. {
  86. TempStockBinPar(20, StockBinLocation, "2—2");
  87. }
  88. else if (BarrelNum == 8)
  89. {
  90. TempStockBinPar(22, StockBinLocation, "2—3");
  91. }
  92. else if (BarrelNum == 4)
  93. {
  94. TempStockBinPar(24, StockBinLocation, "2—4");
  95. }
  96. }
  97. }
  98. }
  99. }
  100. public void IssueRecipeToPlc(ObservableCollection<RemoteRecipeRawMaterial> rawMaterials, int recipeLoction)
  101. {
  102. bool[] barrel = new bool[16];
  103. bool[] barrel1 = new bool[16];
  104. bool[] barrel2 = new bool[16];
  105. bool[] barrel3 = new bool[16];
  106. ushort barrel1_short = 0;
  107. ushort barrel2_short = 0;
  108. ushort barrel3_short = 0;
  109. foreach (var item in rawMaterials)
  110. {
  111. switch (item.RawMaterialBarrelNum)
  112. {
  113. case 6:
  114. barrel[item.RawMaterialLocation - 1] = true;
  115. barrel1[item.RawMaterialLocation - 1] = true;
  116. break;
  117. case 7:
  118. barrel[item.RawMaterialLocation - 1] = true;
  119. barrel2[item.RawMaterialLocation - 1] = true;
  120. break;
  121. case 8:
  122. barrel[item.RawMaterialLocation - 1] = true;
  123. barrel3[item.RawMaterialLocation - 1] = true;
  124. break;
  125. default:
  126. break;
  127. }
  128. }
  129. for (int i = 0; i < 16; i++)
  130. {
  131. if (recipeLoction == 0)
  132. {
  133. if (i >= 8)
  134. {
  135. HK_PLC_S7.Write<bool>("DB4.DBX15." + (i - 8), barrel1[i]);
  136. HK_PLC_S7.Write<bool>("DB4.DBX17." + (i - 8), barrel2[i]);
  137. HK_PLC_S7.Write<bool>("DB4.DBX19." + (i - 8), barrel3[i]);
  138. }
  139. else
  140. {
  141. HK_PLC_S7.Write<bool>("DB4.DBX14." + i, barrel1[i]);
  142. HK_PLC_S7.Write<bool>("DB4.DBX16." + i, barrel2[i]);
  143. HK_PLC_S7.Write<bool>("DB4.DBX18." + i, barrel3[i]);
  144. }
  145. barrel1_short = barrel1_short.SetBitValue((byte)(i + 1), barrel1[i]);
  146. barrel2_short = barrel2_short.SetBitValue((byte)(i + 1), barrel2[i]);
  147. barrel3_short = barrel3_short.SetBitValue((byte)(i + 1), barrel3[i]);
  148. GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeLoction] = GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeLoction].SetBitValue((byte)(i + 1), barrel[i]);
  149. }
  150. else if (recipeLoction == 1)
  151. {
  152. if (i >= 8)
  153. {
  154. HK_PLC_S7.Write<bool>("DB4.DBX21." + (i - 8), barrel1[i]);
  155. HK_PLC_S7.Write<bool>("DB4.DBX23." + (i - 8), barrel2[i]);
  156. HK_PLC_S7.Write<bool>("DB4.DBX25." + (i - 8), barrel3[i]);
  157. }
  158. else
  159. {
  160. HK_PLC_S7.Write<bool>("DB4.DBX20." + i, barrel1[i]);
  161. HK_PLC_S7.Write<bool>("DB4.DBX22." + i, barrel2[i]);
  162. HK_PLC_S7.Write<bool>("DB4.DBX24." + i, barrel3[i]);
  163. }
  164. barrel1_short = barrel1_short.SetBitValue((byte)(i + 1), barrel1[i]);
  165. barrel2_short = barrel2_short.SetBitValue((byte)(i + 1), barrel2[i]);
  166. barrel3_short = barrel3_short.SetBitValue((byte)(i + 1), barrel3[i]);
  167. GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeLoction] = GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeLoction].SetBitValue((byte)(i + 1), barrel[i]);
  168. }
  169. }
  170. MessageNotify.GetInstance.ShowRunLog($"配方下发,plc配方位置{recipeLoction},桶1料仓配料{barrel1_short},配料位置{barrel1_short.ToBinString()}");
  171. MessageNotify.GetInstance.ShowRunLog($"配方下发,plc配方位置{recipeLoction},桶2料仓配料{barrel2_short},配料位置{barrel2_short.ToBinString()}");
  172. MessageNotify.GetInstance.ShowRunLog($"配方下发,plc配方位置{recipeLoction},桶3料仓配料{barrel3_short},配料位置{barrel3_short.ToBinString()}");
  173. MessageNotify.GetInstance.ShowRunLog($"配方下发,plc配方位置{recipeLoction},料仓配料{GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeLoction]},配料位置{GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeLoction].ToBinString()}");
  174. }
  175. }
  176. }