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

260 Zeilen
12 KiB

  1. using BPASmartClient.CustomResource.Pages.Model;
  2. using BPASmartClient.Helper;
  3. using BPASmartClient.JXJFoodBigStation.Model.HK_PLC;
  4. using BPASmartClient.JXJFoodBigStation.Model.Siemens;
  5. using BPASmartClient.Modbus;
  6. using System;
  7. using System.Collections.Concurrent;
  8. using System.Collections.Generic;
  9. using System.Collections.ObjectModel;
  10. using System.Configuration;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading;
  14. using System.Threading.Tasks;
  15. namespace BPASmartClient.JXJFoodBigStation.Model
  16. {
  17. public class ProcessControl
  18. {
  19. private volatile static ProcessControl _Instance;
  20. public static ProcessControl GetInstance => _Instance ?? (_Instance = new ProcessControl());
  21. private ProcessControl() { }
  22. public ObservableCollection<RemoteRecipeRawMaterial> RawMaterials { get; set; } = new ObservableCollection<RemoteRecipeRawMaterial>();
  23. public SiemensDeviceStatus SiemensDevice = new SiemensDeviceStatus();
  24. public HKDeviceStatus HKDevice = new HKDeviceStatus();
  25. GVL_BigStation BigStation = new GVL_BigStation();
  26. /// <summary>
  27. /// 接收原料数据
  28. /// </summary>
  29. public RecipeRawMaterial RawMaterial;
  30. public void Init()
  31. {
  32. ActionManage.GetInstance.Register(new Action(() =>
  33. {
  34. if (SiemensDevice.IsConnected)
  35. {
  36. var res = SiemensDevice.Siemens_PLC_S7.Read(SiemensCommAddress.RecipeName);
  37. var res1 = SiemensDevice.Siemens_PLC_S7.Read(SiemensCommAddress.RecipeID);
  38. int res2 = SiemensDevice.Siemens_PLC_S7.ReadClass(RawMaterial, 0, 0);
  39. if ((res != null && res is string recipeName) &&
  40. (res1 != null && res1 is uint recipeID) &&
  41. (res2 > 0))
  42. {
  43. int index = Array.FindIndex(Json<RemoteRecipeDataColl>.Data.Recipes.ToArray(), p => p.RecipeCode == recipeID);
  44. if (!(index >= 0))
  45. {
  46. RawMaterials.Clear();
  47. for (int i = 0; i < 15; i++)
  48. {
  49. RawMaterials.Add(new RemoteRecipeRawMaterial()
  50. {
  51. RawMaterialBarrelNum = RawMaterial.RawMaterialBarrelNum[i],
  52. RawMaterialLocation = RawMaterial.RawMaterialLocation[i],
  53. RawMaterialWeight = RawMaterial.RawMaterialWeight[i]
  54. });
  55. }
  56. Json<RemoteRecipeDataColl>.Data.Recipes.Add(new RemoteRecipeData()
  57. {
  58. RecipeName = recipeName,
  59. RecipeCode = recipeID,
  60. RawMaterial = RawMaterials
  61. });
  62. }
  63. else
  64. {
  65. MessageLog.GetInstance.AlarmLog("配方列表中存在该配方ID");
  66. }
  67. }
  68. }
  69. }), "西门子下发配方", true);
  70. ActionManage.GetInstance.Register(new Action(() =>
  71. {
  72. if (SiemensDevice.IsConnected)
  73. {
  74. var res = SiemensDevice.Siemens_PLC_S7.Read(SiemensCommAddress.TrayLocationNum);
  75. var res1 = SiemensDevice.Siemens_PLC_S7.Read(SiemensCommAddress.RecipeID);
  76. if (res != null && res is int TrayLocation && res1 != null && res1 is int recipeId)
  77. {
  78. int index = Array.FindIndex(Json<RemoteRecipeDataColl>.Data.Recipes.ToArray(), p => p.RecipeCode == recipeId);
  79. if (index >= 0 && index < Json<RemoteRecipeDataColl>.Data.Recipes.Count)
  80. {
  81. Json<RemoteRecipeDataColl>.Data.Recipes.ElementAt(index).TrayCode = TrayLocation;
  82. }
  83. }
  84. }
  85. }), "AGV到位信号", true);//根据下发的配方ID将 托盘的位置信息添加到配方中
  86. string HK_PLC_IP = ConfigurationManager.AppSettings["HKPlc_IP"];
  87. string Siemens_PLC_IP = ConfigurationManager.AppSettings["Siemens_IP"];
  88. try
  89. {
  90. //HKDevice.HK_PLC_S7.Connect(S7.Net.CpuType.S7200Smart, HK_PLC_IP);
  91. //SiemensDevice.Siemens_PLC_S7.Connect(S7.Net.CpuType.S71500, Siemens_PLC_IP);
  92. if (HKDevice.IsConnected)
  93. {
  94. HKDevice.Init();
  95. }
  96. if (SiemensDevice.IsConnected)
  97. {
  98. SiemensDevice.Init();
  99. }
  100. }
  101. catch(Exception ex)
  102. {
  103. }
  104. BigStation.RecipeQueue.Clear();
  105. Json<RemoteRecipeDataColl>.Data.Recipes = TestData.GetInstance.Recipes;//添加测试数据
  106. ThreadManage.GetInstance().StartLong(new Action(() =>
  107. {
  108. ReceviceData();
  109. RecipeInfoToHKPLC();
  110. Thread.Sleep(10);
  111. }), "流程处理", true);
  112. ThreadManage.GetInstance().StartLong(new Action(() => {
  113. if (HKDevice.IsConnected && SiemensDevice.IsConnected)
  114. {
  115. AgvGetInDelivery();
  116. AgvGetInPickUp();
  117. }
  118. Thread.Sleep(10);
  119. }), "AGV进站送取货", true);
  120. }
  121. /// <summary>
  122. /// AGV进站送货
  123. /// </summary>
  124. private void AgvGetInDelivery()
  125. {
  126. switch (BigStation.AgvDeliveryPosition)
  127. {
  128. case 0:
  129. if (RTrig.GetInstance("").Start(SiemensDevice.Siemens_PLC_S7.Read(SiemensCommAddress.DeliveryAGVApply) is bool))
  130. {
  131. BigStation.AgvDeliveryPosition = 1;
  132. HKDevice.HK_PLC_S7.Write(HKPlcCommAddress.DeliveryAGVApply, true);
  133. }
  134. break;
  135. case 1:
  136. if (RTrig.GetInstance("").Start(HKDevice.HK_PLC_S7.Read(HKPlcCommAddress.DeliveryAGVIsApply) is bool))
  137. {
  138. BigStation.AgvDeliveryPosition = 2;
  139. SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.DeliveryAGVIsApply, true);
  140. }
  141. break;
  142. case 2:
  143. if (RTrig.GetInstance("").Start(SiemensDevice.Siemens_PLC_S7.Read(SiemensCommAddress.DeliveryAGVApplyJack) is bool))
  144. {
  145. BigStation.AgvDeliveryPosition = 3;
  146. HKDevice.HK_PLC_S7.Write(HKPlcCommAddress.DeliveryAGVApplyJack, true);
  147. }
  148. break;
  149. case 3:
  150. if (RTrig.GetInstance("").Start(HKDevice.HK_PLC_S7.Read(HKPlcCommAddress.DeliveryAGVIsApplyJack) is bool))
  151. {
  152. BigStation.AgvDeliveryPosition = 4;
  153. SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.DeliveryAGVIsApplyJack, true);
  154. }
  155. break;
  156. case 4:
  157. if (RTrig.GetInstance("").Start(SiemensDevice.Siemens_PLC_S7.Read(SiemensCommAddress.DeliveryAGVFinsih) is bool))
  158. {
  159. BigStation.AgvDeliveryPosition = 5;
  160. HKDevice.HK_PLC_S7.Write(HKPlcCommAddress.DeliveryAGVFinsih, true);
  161. }
  162. break;
  163. case 5:
  164. if (RTrig.GetInstance("").Start(HKDevice.HK_PLC_S7.Read(HKPlcCommAddress.StationHaveCargo) is bool))
  165. {
  166. BigStation.AgvDeliveryPosition = 0;
  167. SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.StationHaveCargo, true);
  168. }
  169. break;
  170. default:
  171. break;
  172. }
  173. //获取工位上是否有小车
  174. SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.StationIsExistCar, (bool)
  175. HKDevice.HK_PLC_S7.Read(HKPlcCommAddress.StationIsExistCar));
  176. }
  177. /// <summary>
  178. /// AGV进站取货
  179. /// </summary>
  180. private void AgvGetInPickUp()
  181. {
  182. switch (BigStation.AgvPickUpPosition)
  183. {
  184. case 0:
  185. if (RTrig.GetInstance("").Start(SiemensDevice.Siemens_PLC_S7.Read(SiemensCommAddress.PickAGVApply) is bool))
  186. {
  187. BigStation.AgvPickUpPosition = 1;
  188. HKDevice.HK_PLC_S7.Write(HKPlcCommAddress.PickAGVApply, true);
  189. }
  190. break;
  191. case 1:
  192. if (RTrig.GetInstance("").Start(HKDevice.HK_PLC_S7.Read(HKPlcCommAddress.PickAGVIsApply) is bool))
  193. {
  194. BigStation.AgvPickUpPosition = 2;
  195. SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.PickAGVIsApply, true);
  196. }
  197. break;
  198. case 2:
  199. if (RTrig.GetInstance("").Start(SiemensDevice.Siemens_PLC_S7.Read(SiemensCommAddress.PickCargoAGVFinish) is bool))
  200. {
  201. BigStation.AgvPickUpPosition = 3;
  202. HKDevice.HK_PLC_S7.Write(HKPlcCommAddress.PickCargoAGVFinish, true);
  203. }
  204. break;
  205. case 3:
  206. if (RTrig.GetInstance("").Start(HKDevice.HK_PLC_S7.Read(HKPlcCommAddress.PickAGVFinish) is bool))
  207. {
  208. BigStation.AgvPickUpPosition = 0;
  209. SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.PickAGVFinish, true);
  210. }
  211. break;
  212. default:
  213. break;
  214. }
  215. }
  216. private void ReceviceData()
  217. {
  218. BigStation.RemoteRecipes = Json<RemoteRecipeDataColl>.Data.Recipes;
  219. if (Json<RemoteRecipeDataColl>.Data.Recipes.Count > 0)
  220. {
  221. foreach (var data in Json<RemoteRecipeDataColl>.Data.Recipes)
  222. {
  223. if(!(BigStation.RecipeQueue.Contains(data.RecipeCode)))
  224. BigStation.RecipeQueue.Enqueue(data.RecipeCode);
  225. }
  226. }
  227. }
  228. private void RecipeInfoToHKPLC()
  229. {
  230. if (BigStation.RecipeQueue.Count > 0)
  231. {
  232. int index = Array.FindIndex(BigStation.RemoteRecipes.ToArray(), p => p.RecipeCode == BigStation.RecipeQueue.ElementAt(0));
  233. if (index >= 0 && index <= BigStation.RemoteRecipes.Count)
  234. {
  235. long code = BigStation.RemoteRecipes.ElementAt(index).RecipeCode;
  236. if (RTrig.GetInstance("IsAllowDosing").Start(HKDevice.HK_PLC_S7.Read(HKPlcCommAddress.IsAllowDosing) is bool a))
  237. {
  238. foreach (var item in BigStation.RemoteRecipes.ElementAt(index).RawMaterial)
  239. {
  240. HKDevice.StockBinPar((uint)item.RawMaterialBarrelNum, (ushort)item.RawMaterialLocation);
  241. }
  242. HKDevice.AllowDosingSignReset();
  243. BigStation.IssueRecipeFinish = true;
  244. }
  245. if (RTrig.GetInstance("StockState").Start(HKDevice.HK_PLC_S7.Read(HKPlcCommAddress.RecipeDosingFinish) is bool))
  246. {
  247. HKDevice.RecipeDosingFinishReset();
  248. BigStation.RecipeQueue.TryDequeue(out code);
  249. Json<RemoteRecipeDataColl>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
  250. }
  251. }
  252. }
  253. }
  254. }
  255. }