终端一体化运控平台
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

155 wiersze
6.8 KiB

  1. using BPASmartClient.Helper;
  2. using BPASmartClient.JXJFoodBigStation.Model.HK_PLC;
  3. using BPASmartClient.JXJFoodBigStation.Model.Siemens;
  4. using BPASmartClient.Modbus;
  5. using System;
  6. using System.Collections.Concurrent;
  7. using System.Collections.Generic;
  8. using System.Collections.ObjectModel;
  9. using System.Configuration;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace BPASmartClient.JXJFoodBigStation.Model
  14. {
  15. public class ProcessControl
  16. {
  17. private volatile static ProcessControl _Instance;
  18. public static ProcessControl GetInstance => _Instance ?? (_Instance = new ProcessControl());
  19. private ProcessControl() { }
  20. public ObservableCollection<RemoteRecipeData> RemoteRecipes;
  21. ConcurrentQueue<long> RecipeQueue = new ConcurrentQueue<long>();
  22. ConcurrentQueue<string> DeviceQueue = new ConcurrentQueue<string>();
  23. public ObservableCollection<RemoteRecipeRawMaterial> RawMaterials { get; set; } = new ObservableCollection<RemoteRecipeRawMaterial>();
  24. public SiemensDeviceStatus SiemensDevice = new SiemensDeviceStatus();
  25. public HKDeviceStatus HKDevice = new HKDeviceStatus();
  26. public void Init()
  27. {
  28. string HK_PLC_IP = ConfigurationManager.AppSettings["HKPlc_IP"];
  29. string HK_PLC_Port = ConfigurationManager.AppSettings["HKPlc_Port"];
  30. string Siemens_PLC_IP = ConfigurationManager.AppSettings["Siemens_IP"];
  31. string Siemens_PLC_Port = ConfigurationManager.AppSettings["Siemens_Port"];
  32. Task.Run(new Action(() =>
  33. {
  34. HKDevice.ModBusHK.ModbusTcpConnect(HK_PLC_IP, int.Parse(HK_PLC_Port));
  35. SiemensDevice.SiemensTcp.ModbusTcpConnect(Siemens_PLC_IP, int.Parse(Siemens_PLC_Port));
  36. if (HKDevice.IsConnected)
  37. {
  38. HKDevice.Init();
  39. }
  40. if (SiemensDevice.IsConnected)
  41. {
  42. SiemensDevice.Init();
  43. }
  44. }));
  45. ActionManage.GetInstance.Register(new Action(()=>
  46. {
  47. }), "给流水线下发配方数据", true);
  48. ActionManage.GetInstance.Register(new Action(() =>
  49. {
  50. if (SiemensDevice.IsConnected)
  51. {
  52. var res = SiemensDevice.SiemensTcp.GetString(SiemensCommAddress.RecipeName, (ushort)20);
  53. var res1 = SiemensDevice.SiemensTcp.Read(SiemensCommAddress.RecipeID);
  54. var res2 = SiemensDevice.SiemensTcp.Read(SiemensCommAddress.RawMaterial);
  55. if ((res != null && res is string recipeName) &&
  56. (res1 != null && res1 is uint recipeID) &&
  57. (res2 != null && res2 is ushort[] rawMaterial))
  58. {
  59. RawMaterials.Clear();
  60. RawMaterials.Add(new RemoteRecipeRawMaterial()
  61. {
  62. RawMaterialBarrelNum = rawMaterial[0],
  63. RawMaterialLocation= rawMaterial[1],
  64. RawMaterialWeight= rawMaterial[2]
  65. });
  66. Json<RemoteRecipeDataColl>.Data.Recipes.Add(new RemoteRecipeData()
  67. {
  68. RecipeName = recipeName,
  69. RecipeCode = recipeID,
  70. RawMaterial = RawMaterials
  71. });
  72. }
  73. }
  74. }), "西门子下发配方", true);
  75. ActionManage.GetInstance.Register(new Action(() =>
  76. {
  77. if (SiemensDevice.IsConnected)
  78. {
  79. var res = SiemensDevice.SiemensTcp.Read(SiemensCommAddress.TrayLocationNum);
  80. var res1 = SiemensDevice.SiemensTcp.Read(SiemensCommAddress.RecipeID);
  81. if (res != null && res is int TrayLocation && res1 != null && res1 is int recipeId)
  82. {
  83. int index = Array.FindIndex(Json<RemoteRecipeDataColl>.Data.Recipes.ToArray(), p => p.RecipeCode == recipeId);
  84. if (index >= 0 && index < Json<RemoteRecipeDataColl>.Data.Recipes.Count)
  85. {
  86. Json<RemoteRecipeDataColl>.Data.Recipes.ElementAt(index).TrayCode = TrayLocation;
  87. }
  88. }
  89. }
  90. }), "AGV到位信号", true);//根据下发的配方ID将 托盘的位置信息添加到配方中
  91. RecipeQueue.Clear();
  92. ReceviceData();
  93. ThreadManage.GetInstance().StartLong(new Action(() =>
  94. {
  95. RecipeInfoToHKPLC();
  96. }), "流程处理", true);
  97. }
  98. private void ReceviceData()
  99. {
  100. RemoteRecipes = Json<RemoteRecipeDataColl>.Data.Recipes;
  101. RawMaterials = TestData.GetInstance.RawMaterials;//添加测试数据
  102. if (Json<RemoteRecipeDataColl>.Data.Recipes.Count > 0)
  103. {
  104. foreach (var data in Json<RemoteRecipeDataColl>.Data.Recipes)
  105. {
  106. if(!(RecipeQueue.Contains(data.RecipeCode)))
  107. RecipeQueue.Enqueue(data.RecipeCode);
  108. }
  109. }
  110. }
  111. /// <summary>
  112. /// 当前料仓的位置
  113. /// </summary>
  114. private int StockInIsWork;
  115. /// <summary>
  116. /// 单个配方执行完成标志
  117. /// </summary>
  118. private bool RecipeFinfish;
  119. private void RecipeInfoToHKPLC()
  120. {
  121. if (RecipeQueue.Count > 0)
  122. {
  123. int index = Array.FindIndex(RemoteRecipes.ToArray(), p => p.RecipeCode == RecipeQueue.ElementAt(0));
  124. if (index >= 0 && index <= RemoteRecipes.Count)
  125. {
  126. long code = RemoteRecipes.ElementAt(index).RecipeCode;
  127. if (RTrig.GetInstance("IsAllowDosing").Start(HKDevice.ModBusHK.Read(HKPlcCommAddress.IsAllowDosing) is bool a))
  128. {
  129. foreach (var item in RemoteRecipes.ElementAt(index).RawMaterial)
  130. {
  131. HKDevice.StockBinPar((uint)item.RawMaterialBarrelNum, (ushort)item.RawMaterialLocation);
  132. }
  133. HKDevice.AllowDosingSignReset();
  134. }
  135. if (RTrig.GetInstance("StockState").Start(HKDevice.ModBusHK.Read(HKPlcCommAddress.RecipeDosingFinish) is bool))
  136. {
  137. HKDevice.RecipeDosingFinishReset();
  138. RecipeQueue.TryDequeue(out code);
  139. }
  140. }
  141. }
  142. }
  143. private void HKPLCIsWork()
  144. {
  145. }
  146. }
  147. }