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

1822 lines
103 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 SiemensDeviceStatus SiemensDevice = new SiemensDeviceStatus();
  23. public HKDeviceStatus HKDevice = new HKDeviceStatus();
  24. DL_Finish_DB FinishData = new DL_Finish_DB();
  25. /// <summary>
  26. /// 西门子配方数据
  27. /// </summary>
  28. public ObservableCollection<RecipeData> SiemensRecipes = new ObservableCollection<RecipeData>();
  29. /// <summary>
  30. /// 本地配方数据
  31. /// </summary>
  32. public ObservableCollection<RecipeData> LocalRecipes = new ObservableCollection<RecipeData>();
  33. /// <summary>
  34. /// 配方等待执行
  35. /// </summary>
  36. public ObservableCollection<RecipeData> RecipeWaitExecute = new ObservableCollection<RecipeData>();
  37. /// <summary>
  38. /// 配方正在执行
  39. /// </summary>
  40. public ObservableCollection<RecipeData> RecipeExecuting = new ObservableCollection<RecipeData>();
  41. /// <summary>
  42. /// 配方执行完成
  43. /// </summary>
  44. public ObservableCollection<RecipeData> RecipeExecuteComple = new ObservableCollection<RecipeData>();
  45. /// <summary>
  46. /// 原料的名称和料仓的位置对应
  47. /// </summary>
  48. public Dictionary<string, short> RawMaterialsNamePos = new Dictionary<string, short>();
  49. public ObservableCollection<RawMaterial> RawMaterialsInfo => Json<RawMaterialData>.Data.RawMaterial;
  50. /// <summary>
  51. /// 西门子配方队列
  52. /// </summary>
  53. public ConcurrentQueue<string> SiemensRecipeQueue1 = new ConcurrentQueue<string>();
  54. public ConcurrentQueue<string> SiemensRecipeQueue2 = new ConcurrentQueue<string>();
  55. public ConcurrentQueue<string> SiemensRecipeQueue3 = new ConcurrentQueue<string>();
  56. public ConcurrentQueue<string> SiemensRecipeQueue4 = new ConcurrentQueue<string>();
  57. /// <summary>
  58. /// 本地配方队列
  59. /// </summary>
  60. public ConcurrentQueue<string> LocalRecipeQueue1 = new ConcurrentQueue<string>();
  61. public ConcurrentQueue<string> LocalRecipeQueue2 = new ConcurrentQueue<string>();
  62. public ConcurrentQueue<string> LocalRecipeQueue3 = new ConcurrentQueue<string>();
  63. public ConcurrentQueue<string> LocalRecipeQueue4 = new ConcurrentQueue<string>();
  64. public void Init()
  65. {
  66. testRawMaterialNameData();//自定义料仓名称
  67. ActionManage.GetInstance.CancelRegister("SiemensSendRecipe");
  68. ActionManage.GetInstance.Register(new Action<object>((res) =>
  69. {
  70. ObservableCollection<RawMaterial> RawMaterials = new ObservableCollection<RawMaterial>();
  71. if (SiemensDevice.IsConnected)
  72. {
  73. if (res != null && res is DL_Start_DB recipe)
  74. {
  75. RawMaterials.Clear();
  76. for (int i = 0; i < GVL_BigStation.Max_DosingSotckBinNum; i++)
  77. {
  78. if (RawMaterialsNamePos.ContainsKey(recipe.Material[i].Material_Name))
  79. {
  80. RawMaterials.Add(new RawMaterial()
  81. {
  82. RawMaterialName = recipe.Material[i].Material_Name,
  83. RawMaterialBarrelNum = recipe.Material[i].Material_BarrelNum,
  84. RawMaterialWeight = recipe.Material[i].Material_Weight,
  85. RawMaterialLocation = (int)RawMaterialsNamePos[recipe.Material[i].Material_Name]
  86. });
  87. }
  88. else
  89. {
  90. MessageNotify.GetInstance.ShowAlarmLog($"本地原料名称和西门子下发的原料名称无法对应,原料位置:{i}");
  91. }
  92. }
  93. App.Current.Dispatcher.Invoke(() =>
  94. {
  95. Json<RemoteRecipe>.Data.Recipes.Add(new RecipeData()
  96. {
  97. RecipeName = recipe.RecipeName,
  98. RecipeCode = recipe.RecipeCode,
  99. RawMaterial = RawMaterials,
  100. TrayCode = recipe.Job_No,
  101. IsWashingBarrel = recipe.Order_Type
  102. });
  103. });
  104. }
  105. }
  106. }), "SiemensSendRecipe", true);
  107. string HK_PLC_IP = ConfigurationManager.AppSettings["HKPlc_IP"];
  108. string Siemens_PLC_IP = ConfigurationManager.AppSettings["Siemens_IP"];
  109. GVL_BigStation.IsAllowHKPlcConnect = ConfigurationManager.AppSettings["HKPlc_Connect"].ToLower() == "true" ? true : false;
  110. GVL_BigStation.IsAllowSiemensConnect = ConfigurationManager.AppSettings["Siemens_Connect"].ToLower() == "true" ? true : false;
  111. try
  112. {
  113. if (GVL_BigStation.IsAllowHKPlcConnect)
  114. {
  115. HKDevice.HK_PLC_S7.Connect(S7.Net.CpuType.S71500, HK_PLC_IP);
  116. }
  117. }
  118. catch (Exception ex)
  119. {
  120. MessageNotify.GetInstance.ShowAlarmLog("海科plc连接失败,等待重新连接");
  121. }
  122. finally
  123. {
  124. HKDevice.Init();
  125. MessageNotify.GetInstance.ShowRunLog("海科plc初始化");
  126. if (HKDevice.IsConnected && GVL_BigStation.IsAllowHKPlcConnect)
  127. {
  128. MessageNotify.GetInstance.ShowRunLog("海科plc连接成功");
  129. }
  130. }
  131. try
  132. {
  133. if (GVL_BigStation.IsAllowSiemensConnect)
  134. {
  135. SiemensDevice.Siemens_PLC_S7.Connect(S7.Net.CpuType.S71500, Siemens_PLC_IP);
  136. }
  137. }
  138. catch (Exception ex)
  139. {
  140. MessageNotify.GetInstance.ShowAlarmLog("西门子plc连接失败,等待重新连接");
  141. }
  142. finally
  143. {
  144. SiemensDevice.Init();
  145. MessageNotify.GetInstance.ShowRunLog("西门子plc初始化");
  146. if (SiemensDevice.IsConnected && GVL_BigStation.IsAllowSiemensConnect)
  147. {
  148. MessageNotify.GetInstance.ShowRunLog("西门子plc连接成功");
  149. }
  150. }
  151. ThreadManage.GetInstance().StartLong(new Action(() =>
  152. {
  153. if (!HKDevice.IsConnected && GVL_BigStation.IsAllowHKPlcConnect)
  154. {
  155. HKDevice.HK_PLC_S7.Connect(S7.Net.CpuType.S71500, HK_PLC_IP);
  156. MessageNotify.GetInstance.ShowRunLog("海科plc重新连接成功");
  157. }
  158. if (!SiemensDevice.IsConnected && GVL_BigStation.IsAllowSiemensConnect)
  159. {
  160. SiemensDevice.Siemens_PLC_S7.Connect(S7.Net.CpuType.S71500, Siemens_PLC_IP);
  161. MessageNotify.GetInstance.ShowRunLog("西门子plc重新连接");
  162. }
  163. GVL_BigStation.HeartBeatToPlc = !GVL_BigStation.HeartBeatToPlc;
  164. HKDevice.HK_PLC_S7.Write("DB99.DBX0.0", GVL_BigStation.HeartBeatToPlc);
  165. GVL_BigStation.HeartBeatFromPlc = HKDevice.PlcRead.HeartBeat;//读取plc心跳
  166. if (HKDevice.IsConnected)
  167. {
  168. if (GVL_BigStation.AGVPutTray.GetBitValue(1))
  169. {
  170. HKDevice.HK_PLC_S7.Write("DB99.DBX0.7", true);
  171. }
  172. else
  173. {
  174. HKDevice.HK_PLC_S7.Write("DB99.DBX0.7", false);
  175. }
  176. if (GVL_BigStation.AGVPutTray.GetBitValue(2))
  177. {
  178. HKDevice.HK_PLC_S7.Write("DB99.DBX1.0", true);
  179. }
  180. else
  181. {
  182. HKDevice.HK_PLC_S7.Write("DB99.DBX1.0", false);
  183. }
  184. if (GVL_BigStation.AGVPutTray.GetBitValue(3))
  185. {
  186. HKDevice.HK_PLC_S7.Write("DB99.DBX1.1", true);
  187. }
  188. else
  189. {
  190. HKDevice.HK_PLC_S7.Write("DB99.DBX1.1", false);
  191. }
  192. if (GVL_BigStation.AGVPutTray.GetBitValue(4))
  193. {
  194. HKDevice.HK_PLC_S7.Write("DB99.DBX1.2", true);
  195. }
  196. else
  197. {
  198. HKDevice.HK_PLC_S7.Write("DB99.DBX1.2", false);
  199. }
  200. if (GVL_BigStation.AGVPutTray.GetBitValue(5))
  201. {
  202. HKDevice.HK_PLC_S7.Write("DB99.DBX1.3", true);
  203. }
  204. else
  205. {
  206. HKDevice.HK_PLC_S7.Write("DB99.DBX1.3", false);
  207. }
  208. GVL_BigStation.TraySensor = GVL_BigStation.TraySensor.SetBitValue(1, HKDevice.PlcRead.Tray1Sensor);
  209. GVL_BigStation.TraySensor = GVL_BigStation.TraySensor.SetBitValue(2, HKDevice.PlcRead.Tray2Sensor);
  210. GVL_BigStation.TraySensor = GVL_BigStation.TraySensor.SetBitValue(3, HKDevice.PlcRead.Tray3Sensor);
  211. GVL_BigStation.TraySensor = GVL_BigStation.TraySensor.SetBitValue(4, HKDevice.PlcRead.Tray4Sensor);
  212. GVL_BigStation.TraySensor = GVL_BigStation.TraySensor.SetBitValue(5, HKDevice.PlcRead.Tray5Sensor);
  213. GVL_BigStation.TrayCylinder = GVL_BigStation.TrayCylinder.SetBitValue(1, !HKDevice.PlcRead.Tray1Cylinder);
  214. GVL_BigStation.TrayCylinder = GVL_BigStation.TrayCylinder.SetBitValue(2, !HKDevice.PlcRead.Tray2Cylinder);
  215. GVL_BigStation.TrayCylinder = GVL_BigStation.TrayCylinder.SetBitValue(3, !HKDevice.PlcRead.Tray3Cylinder);
  216. GVL_BigStation.TrayCylinder = GVL_BigStation.TrayCylinder.SetBitValue(4, !HKDevice.PlcRead.Tray4Cylinder);
  217. GVL_BigStation.TrayCylinder = GVL_BigStation.TrayCylinder.SetBitValue(5, !HKDevice.PlcRead.Tray5Cylinder);
  218. if (HKDevice.PlcRead.IsAllowIssueRecipe1 || HKDevice.PlcRead.IsAllowIssueRecipe2 || HKDevice.PlcRead.IsAllowIssueRecipe3 || HKDevice.PlcRead.IsAllowIssueRecipe4)
  219. {
  220. GVL_BigStation.Order_Request = true;
  221. }
  222. }
  223. if (SiemensDevice.IsConnected)
  224. {
  225. GVL_BigStation.AGVPutTray = SiemensDevice.DL_Status.AGV_Put_Done;
  226. GVL_BigStation.AGVGetTray = SiemensDevice.DL_Status.AGV_Get_Done;
  227. SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBW30", GVL_BigStation.TraySensor);
  228. SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBW32", GVL_BigStation.TrayCylinder);
  229. SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBW34", (ushort)15);
  230. }
  231. Thread.Sleep(10);
  232. }),"海科plc和西门子数据交互",true);
  233. LocalRecipeQueue1.Clear();
  234. LocalRecipeQueue2.Clear();
  235. LocalRecipeQueue3.Clear();
  236. LocalRecipeQueue4.Clear();
  237. SiemensRecipeQueue1.Clear();
  238. SiemensRecipeQueue2.Clear();
  239. SiemensRecipeQueue3.Clear();
  240. SiemensRecipeQueue4.Clear();
  241. ThreadManage.GetInstance().StartLong(new Action(() =>
  242. {
  243. testRawMaterialNameData();//自定义料仓名称
  244. if (GVL_BigStation.IsUseLocalRecipe)
  245. {
  246. LocalRecipeRecevice();
  247. LocalRecipeDosing();
  248. }
  249. else
  250. {
  251. ReceviceData();
  252. RecipeInfoToHKPLC();
  253. }
  254. Thread.Sleep(10);
  255. }), "配方数据执行流程", true);
  256. }
  257. private void LocalRecipeRecevice()
  258. {
  259. if (LocalRecipes.Count > 0)
  260. {
  261. foreach (var data in LocalRecipes)
  262. {
  263. if (LocalRecipeQueue1.Count == 0 && !LocalRecipeQueue2.Contains(data.RecipeCode) && !LocalRecipeQueue3.Contains(data.RecipeCode) && !LocalRecipeQueue4.Contains(data.RecipeCode))
  264. {
  265. if (!(LocalRecipeQueue1.Contains(data.RecipeCode)))
  266. {
  267. LocalRecipeQueue1.Enqueue(data.RecipeCode);
  268. }
  269. }
  270. else if (LocalRecipeQueue2.Count == 0 && !LocalRecipeQueue1.Contains(data.RecipeCode) && !LocalRecipeQueue3.Contains(data.RecipeCode) && !LocalRecipeQueue4.Contains(data.RecipeCode))
  271. {
  272. if (!(LocalRecipeQueue2.Contains(data.RecipeCode)))
  273. {
  274. LocalRecipeQueue2.Enqueue(data.RecipeCode);
  275. }
  276. }
  277. else if (LocalRecipeQueue3.Count == 0 && !LocalRecipeQueue1.Contains(data.RecipeCode) && !LocalRecipeQueue2.Contains(data.RecipeCode) && !LocalRecipeQueue4.Contains(data.RecipeCode))
  278. {
  279. if (!(LocalRecipeQueue3.Contains(data.RecipeCode)))
  280. {
  281. LocalRecipeQueue3.Enqueue(data.RecipeCode);
  282. }
  283. }
  284. else if (LocalRecipeQueue4.Count == 0 && !LocalRecipeQueue1.Contains(data.RecipeCode) && !LocalRecipeQueue2.Contains(data.RecipeCode) && !LocalRecipeQueue3.Contains(data.RecipeCode))
  285. {
  286. if (!(LocalRecipeQueue4.Contains(data.RecipeCode)))
  287. {
  288. LocalRecipeQueue4.Enqueue(data.RecipeCode);
  289. }
  290. }
  291. }
  292. }
  293. else
  294. {
  295. LocalRecipeQueue1.Clear();
  296. LocalRecipeQueue2.Clear();
  297. LocalRecipeQueue3.Clear();
  298. LocalRecipeQueue4.Clear();
  299. GVL_BigStation.Recipe1DosingStatus = 0;
  300. GVL_BigStation.Recipe2DosingStatus = 0;
  301. GVL_BigStation.Recipe3DosingStatus = 0;
  302. GVL_BigStation.Recipe4DosingStatus = 0;
  303. }
  304. }
  305. private void LocalRecipeDosing()
  306. {
  307. if (LocalRecipeQueue1.Count > 0)
  308. {
  309. int index = Array.FindIndex(LocalRecipes.ToArray(), p => p.RecipeCode == LocalRecipeQueue1.ElementAt(0));
  310. if (index >= 0 && index < LocalRecipes.Count)
  311. {
  312. string code = LocalRecipes.ElementAt(index).RecipeCode;
  313. int trayCode = LocalRecipes.ElementAt(index).TrayCode;
  314. bool Inplace = false;
  315. switch (trayCode)
  316. {
  317. case 1:
  318. Inplace = HKDevice.PlcRead.Tray1InPlace;
  319. HKDevice.HK_PLC_S7.Write("DB99.DBX0.7", GVL_BigStation.AGVPutTray.GetBitValue(1));
  320. break;
  321. case 2:
  322. Inplace = HKDevice.PlcRead.Tray2InPlace;
  323. HKDevice.HK_PLC_S7.Write("DB99.DBX1.0", GVL_BigStation.AGVPutTray.GetBitValue(2));
  324. break;
  325. case 3:
  326. Inplace = HKDevice.PlcRead.Tray3InPlace;
  327. HKDevice.HK_PLC_S7.Write("DB99.DBX1.1", GVL_BigStation.AGVPutTray.GetBitValue(3));
  328. break;
  329. case 4:
  330. Inplace = HKDevice.PlcRead.Tray4InPlace;
  331. HKDevice.HK_PLC_S7.Write("DB99.DBX1.2", GVL_BigStation.AGVPutTray.GetBitValue(4));
  332. break;
  333. case 5:
  334. Inplace = HKDevice.PlcRead.Tray5InPlace;
  335. HKDevice.HK_PLC_S7.Write("DB99.DBX1.3", GVL_BigStation.AGVPutTray.GetBitValue(5));
  336. break;
  337. default:
  338. break;
  339. }
  340. if (HKDevice.PlcRead.IsAllowIssueRecipe1 && GVL_BigStation.Recipe1DosingStatus == 0 && Inplace)//配方1是否允许下发配发
  341. {
  342. HKDevice.StockBinPar(LocalRecipes.ElementAt(index));
  343. HKDevice.HK_PLC_S7.Write("DB99.DBX0.3", true);
  344. GVL_BigStation.Recipe1DosingStatus = 1;
  345. MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},下发完成");
  346. }
  347. if (HKDevice.PlcRead.ReceiveFinishRecipe1 && GVL_BigStation.Recipe1DosingStatus == 1)
  348. {
  349. GVL_BigStation.Recipe1DosingStatus = 2;
  350. HKDevice.HK_PLC_S7.Write("DB99.DBX0.3", false);
  351. StockBinParReset();
  352. MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},PLC接收配方完成");
  353. }
  354. if (GVL_BigStation.Recipe1DosingStatus == 2 && HKDevice.PlcRead.Recipe1DosingFinish)
  355. {
  356. GVL_BigStation.Recipe1DosingStatus = 3;
  357. switch (trayCode)
  358. {
  359. case 1:
  360. HKDevice.HK_PLC_S7.Write("DB99.DBX0.7", false);
  361. break;
  362. case 2:
  363. HKDevice.HK_PLC_S7.Write("DB99.DBX1.0", false);
  364. break;
  365. case 3:
  366. HKDevice.HK_PLC_S7.Write("DB99.DBX1.1", false);
  367. break;
  368. case 4:
  369. HKDevice.HK_PLC_S7.Write("DB99.DBX1.2", false);
  370. break;
  371. case 5:
  372. HKDevice.HK_PLC_S7.Write("DB99.DBX1.3", false);
  373. break;
  374. default:
  375. break;
  376. }
  377. MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}配料完成");
  378. foreach (var item in LocalRecipes.ElementAt(index).RawMaterial)
  379. {
  380. if (item.RawMaterialLocation == 1)
  381. {
  382. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin1ActualWeight;
  383. }
  384. else if (item.RawMaterialLocation == 2)
  385. {
  386. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin2ActualWeight;
  387. }
  388. else if (item.RawMaterialLocation == 3)
  389. {
  390. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin3ActualWeight;
  391. }
  392. else if (item.RawMaterialLocation == 4)
  393. {
  394. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin4ActualWeight;
  395. }
  396. else if (item.RawMaterialLocation == 5)
  397. {
  398. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin5ActualWeight;
  399. }
  400. else if (item.RawMaterialLocation == 6)
  401. {
  402. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin6ActualWeight;
  403. }
  404. else if (item.RawMaterialLocation == 7)
  405. {
  406. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin7ActualWeight;
  407. }
  408. else if (item.RawMaterialLocation == 8)
  409. {
  410. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin8ActualWeight;
  411. }
  412. else if (item.RawMaterialLocation == 9)
  413. {
  414. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin9ActualWeight;
  415. }
  416. else if (item.RawMaterialLocation == 10)
  417. {
  418. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin10ActualWeight;
  419. }
  420. else if (item.RawMaterialLocation == 11)
  421. {
  422. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin11ActualWeight;
  423. }
  424. else if (item.RawMaterialLocation == 12)
  425. {
  426. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin12ActualWeight;
  427. }
  428. else if (item.RawMaterialLocation == 13)
  429. {
  430. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin13ActualWeight;
  431. }
  432. else if (item.RawMaterialLocation == 14)
  433. {
  434. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin14ActualWeight;
  435. }
  436. }
  437. LocalRecipeQueue1.TryDequeue(out code);
  438. RecipeExecuteComple.Add(LocalRecipes.ElementAt(index));//将配方添加到完成列表
  439. //App.Current.Dispatcher.Invoke(() => {
  440. // Json<LocalRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
  441. //});
  442. LocalRecipes.RemoveAt(index);
  443. GVL_BigStation.Recipe1DosingStatus = 0;
  444. }
  445. }
  446. }
  447. if (LocalRecipeQueue2.Count > 0)
  448. {
  449. int index = Array.FindIndex(LocalRecipes.ToArray(), p => p.RecipeCode == LocalRecipeQueue2.ElementAt(0));
  450. if (index >= 0 && index < LocalRecipes.Count)
  451. {
  452. string code = LocalRecipes.ElementAt(index).RecipeCode;
  453. int trayCode = LocalRecipes.ElementAt(index).TrayCode;
  454. bool Inplace = false;
  455. switch (trayCode)
  456. {
  457. case 1:
  458. Inplace = HKDevice.PlcRead.Tray1InPlace;
  459. HKDevice.HK_PLC_S7.Write("DB99.DBX0.7", GVL_BigStation.AGVPutTray.GetBitValue(1));
  460. break;
  461. case 2:
  462. Inplace = HKDevice.PlcRead.Tray2InPlace;
  463. HKDevice.HK_PLC_S7.Write("DB99.DBX1.0", GVL_BigStation.AGVPutTray.GetBitValue(2));
  464. break;
  465. case 3:
  466. Inplace = HKDevice.PlcRead.Tray3InPlace;
  467. HKDevice.HK_PLC_S7.Write("DB99.DBX1.1", GVL_BigStation.AGVPutTray.GetBitValue(3));
  468. break;
  469. case 4:
  470. Inplace = HKDevice.PlcRead.Tray4InPlace;
  471. HKDevice.HK_PLC_S7.Write("DB99.DBX1.2", GVL_BigStation.AGVPutTray.GetBitValue(4));
  472. break;
  473. case 5:
  474. Inplace = HKDevice.PlcRead.Tray5InPlace;
  475. HKDevice.HK_PLC_S7.Write("DB99.DBX1.3", GVL_BigStation.AGVPutTray.GetBitValue(5));
  476. break;
  477. default:
  478. break;
  479. }
  480. if (HKDevice.PlcRead.IsAllowIssueRecipe2 && GVL_BigStation.Recipe2DosingStatus == 0 &&Inplace)//配方2是否允许下发配发
  481. {
  482. HKDevice.StockBinPar(LocalRecipes.ElementAt(index));
  483. HKDevice.HK_PLC_S7.Write("DB99.DBX0.4", true);
  484. GVL_BigStation.Recipe2DosingStatus = 1;
  485. MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}下发完成");
  486. }
  487. if (HKDevice.PlcRead.ReceiveFinishRecipe2 && GVL_BigStation.Recipe2DosingStatus == 1)
  488. {
  489. GVL_BigStation.Recipe2DosingStatus = 2;
  490. HKDevice.HK_PLC_S7.Write("DB99.DBX0.4", false);
  491. StockBinParReset();
  492. MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}配方配料");
  493. }
  494. if (GVL_BigStation.Recipe2DosingStatus == 2 && HKDevice.PlcRead.Recipe2DosingFinish)
  495. {
  496. switch (trayCode)
  497. {
  498. case 1:
  499. HKDevice.HK_PLC_S7.Write("DB99.DBX0.7", false);
  500. break;
  501. case 2:
  502. HKDevice.HK_PLC_S7.Write("DB99.DBX1.0", false);
  503. break;
  504. case 3:
  505. HKDevice.HK_PLC_S7.Write("DB99.DBX1.1", false);
  506. break;
  507. case 4:
  508. HKDevice.HK_PLC_S7.Write("DB99.DBX1.2", false);
  509. break;
  510. case 5:
  511. HKDevice.HK_PLC_S7.Write("DB99.DBX1.3", false);
  512. break;
  513. default:
  514. break;
  515. }
  516. GVL_BigStation.Recipe2DosingStatus = 3;
  517. MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}配料完成");
  518. foreach (var item in LocalRecipes.ElementAt(index).RawMaterial)
  519. {
  520. if (item.RawMaterialLocation == 1)
  521. {
  522. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin1ActualWeight;
  523. }
  524. else if (item.RawMaterialLocation == 2)
  525. {
  526. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin2ActualWeight;
  527. }
  528. else if (item.RawMaterialLocation == 3)
  529. {
  530. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin3ActualWeight;
  531. }
  532. else if (item.RawMaterialLocation == 4)
  533. {
  534. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin4ActualWeight;
  535. }
  536. else if (item.RawMaterialLocation == 5)
  537. {
  538. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin5ActualWeight;
  539. }
  540. else if (item.RawMaterialLocation == 6)
  541. {
  542. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin6ActualWeight;
  543. }
  544. else if (item.RawMaterialLocation == 7)
  545. {
  546. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin7ActualWeight;
  547. }
  548. else if (item.RawMaterialLocation == 8)
  549. {
  550. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin8ActualWeight;
  551. }
  552. else if (item.RawMaterialLocation == 9)
  553. {
  554. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin9ActualWeight;
  555. }
  556. else if (item.RawMaterialLocation == 10)
  557. {
  558. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin10ActualWeight;
  559. }
  560. else if (item.RawMaterialLocation == 11)
  561. {
  562. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin11ActualWeight;
  563. }
  564. else if (item.RawMaterialLocation == 12)
  565. {
  566. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin12ActualWeight;
  567. }
  568. else if (item.RawMaterialLocation == 13)
  569. {
  570. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin13ActualWeight;
  571. }
  572. else if (item.RawMaterialLocation == 14)
  573. {
  574. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin14ActualWeight;
  575. }
  576. }
  577. LocalRecipeQueue2.TryDequeue(out code);
  578. RecipeExecuteComple.Add(LocalRecipes.ElementAt(index));//将该配方添加到下
  579. //App.Current.Dispatcher.Invoke(() => {
  580. // Json<LocalRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
  581. //});
  582. LocalRecipes.RemoveAt(index);
  583. GVL_BigStation.Recipe2DosingStatus = 0;
  584. }
  585. }
  586. }
  587. if (LocalRecipeQueue3.Count > 0)
  588. {
  589. int index = Array.FindIndex(LocalRecipes.ToArray(), p => p.RecipeCode == LocalRecipeQueue3.ElementAt(0));
  590. if (index >= 0 && index < LocalRecipes.Count)
  591. {
  592. string code = LocalRecipes.ElementAt(index).RecipeCode;
  593. int trayCode = LocalRecipes.ElementAt(index).TrayCode;
  594. bool Inplace = false;
  595. switch (trayCode)
  596. {
  597. case 1:
  598. Inplace = HKDevice.PlcRead.Tray1InPlace;
  599. HKDevice.HK_PLC_S7.Write("DB99.DBX0.7", GVL_BigStation.AGVPutTray.GetBitValue(1));
  600. break;
  601. case 2:
  602. Inplace = HKDevice.PlcRead.Tray2InPlace;
  603. HKDevice.HK_PLC_S7.Write("DB99.DBX1.0", GVL_BigStation.AGVPutTray.GetBitValue(2));
  604. break;
  605. case 3:
  606. Inplace = HKDevice.PlcRead.Tray3InPlace;
  607. HKDevice.HK_PLC_S7.Write("DB99.DBX1.1", GVL_BigStation.AGVPutTray.GetBitValue(3));
  608. break;
  609. case 4:
  610. Inplace = HKDevice.PlcRead.Tray4InPlace;
  611. HKDevice.HK_PLC_S7.Write("DB99.DBX1.2", GVL_BigStation.AGVPutTray.GetBitValue(4));
  612. break;
  613. case 5:
  614. Inplace = HKDevice.PlcRead.Tray5InPlace;
  615. HKDevice.HK_PLC_S7.Write("DB99.DBX1.3", GVL_BigStation.AGVPutTray.GetBitValue(5));
  616. break;
  617. default:
  618. break;
  619. }
  620. if (HKDevice.PlcRead.IsAllowIssueRecipe3 && GVL_BigStation.Recipe3DosingStatus == 0 && Inplace)//配方3是否允许下发配发
  621. {
  622. HKDevice.StockBinPar(LocalRecipes.ElementAt(index));
  623. HKDevice.HK_PLC_S7.Write("DB99.DBX0.5", true);
  624. GVL_BigStation.Recipe3DosingStatus = 1;
  625. MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}下发完成");
  626. }
  627. if (HKDevice.PlcRead.ReceiveFinishRecipe3 && GVL_BigStation.Recipe3DosingStatus == 1)
  628. {
  629. GVL_BigStation.Recipe3DosingStatus = 2;
  630. HKDevice.HK_PLC_S7.Write("DB99.DBX0.5", false);
  631. StockBinParReset();
  632. MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}配方配料");
  633. }
  634. if (HKDevice.PlcRead.Recipe3DosingFinish && GVL_BigStation.Recipe3DosingStatus == 2)
  635. {
  636. switch (trayCode)
  637. {
  638. case 1:
  639. HKDevice.HK_PLC_S7.Write("DB99.DBX0.7", false);
  640. break;
  641. case 2:
  642. HKDevice.HK_PLC_S7.Write("DB99.DBX1.0", false);
  643. break;
  644. case 3:
  645. HKDevice.HK_PLC_S7.Write("DB99.DBX1.1", false);
  646. break;
  647. case 4:
  648. HKDevice.HK_PLC_S7.Write("DB99.DBX1.2", false);
  649. break;
  650. case 5:
  651. HKDevice.HK_PLC_S7.Write("DB99.DBX1.3", false);
  652. break;
  653. default:
  654. break;
  655. }
  656. GVL_BigStation.Recipe3DosingStatus = 3;
  657. MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}配料完成");
  658. foreach (var item in LocalRecipes.ElementAt(index).RawMaterial)
  659. {
  660. if (item.RawMaterialLocation == 1)
  661. {
  662. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin1ActualWeight;
  663. }
  664. else if (item.RawMaterialLocation == 2)
  665. {
  666. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin2ActualWeight;
  667. }
  668. else if (item.RawMaterialLocation == 3)
  669. {
  670. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin3ActualWeight;
  671. }
  672. else if (item.RawMaterialLocation == 4)
  673. {
  674. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin4ActualWeight;
  675. }
  676. else if (item.RawMaterialLocation == 5)
  677. {
  678. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin5ActualWeight;
  679. }
  680. else if (item.RawMaterialLocation == 6)
  681. {
  682. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin6ActualWeight;
  683. }
  684. else if (item.RawMaterialLocation == 7)
  685. {
  686. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin7ActualWeight;
  687. }
  688. else if (item.RawMaterialLocation == 8)
  689. {
  690. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin8ActualWeight;
  691. }
  692. else if (item.RawMaterialLocation == 9)
  693. {
  694. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin9ActualWeight;
  695. }
  696. else if (item.RawMaterialLocation == 10)
  697. {
  698. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin10ActualWeight;
  699. }
  700. else if (item.RawMaterialLocation == 11)
  701. {
  702. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin11ActualWeight;
  703. }
  704. else if (item.RawMaterialLocation == 12)
  705. {
  706. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin12ActualWeight;
  707. }
  708. else if (item.RawMaterialLocation == 13)
  709. {
  710. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin13ActualWeight;
  711. }
  712. else if (item.RawMaterialLocation == 14)
  713. {
  714. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin14ActualWeight;
  715. }
  716. }
  717. HKDevice.HK_PLC_S7.Write<bool>("DB98.DBX1.1", false);
  718. LocalRecipeQueue3.TryDequeue(out code);
  719. RecipeExecuteComple.Add(LocalRecipes.ElementAt(index));//将该配方添加到下
  720. //App.Current.Dispatcher.Invoke(() => {
  721. // Json<LocalRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
  722. //});
  723. LocalRecipes.RemoveAt(index);
  724. GVL_BigStation.Recipe3DosingStatus = 0;
  725. }
  726. }
  727. }
  728. if (LocalRecipeQueue4.Count > 0)
  729. {
  730. int index = Array.FindIndex(LocalRecipes.ToArray(), p => p.RecipeCode == LocalRecipeQueue4.ElementAt(0));
  731. if (index >= 0 && index < LocalRecipes.Count)
  732. {
  733. string code = LocalRecipes.ElementAt(index).RecipeCode;
  734. int trayCode = LocalRecipes.ElementAt(index).TrayCode;
  735. bool Inplace = false;
  736. switch (trayCode)
  737. {
  738. case 1:
  739. Inplace = HKDevice.PlcRead.Tray1InPlace;
  740. HKDevice.HK_PLC_S7.Write("DB99.DBX0.7", GVL_BigStation.AGVPutTray.GetBitValue(1));
  741. break;
  742. case 2:
  743. Inplace = HKDevice.PlcRead.Tray2InPlace;
  744. HKDevice.HK_PLC_S7.Write("DB99.DBX1.0", GVL_BigStation.AGVPutTray.GetBitValue(2));
  745. break;
  746. case 3:
  747. Inplace = HKDevice.PlcRead.Tray3InPlace;
  748. HKDevice.HK_PLC_S7.Write("DB99.DBX1.1", GVL_BigStation.AGVPutTray.GetBitValue(3));
  749. break;
  750. case 4:
  751. Inplace = HKDevice.PlcRead.Tray4InPlace;
  752. HKDevice.HK_PLC_S7.Write("DB99.DBX1.2", GVL_BigStation.AGVPutTray.GetBitValue(4));
  753. break;
  754. case 5:
  755. Inplace = HKDevice.PlcRead.Tray5InPlace;
  756. HKDevice.HK_PLC_S7.Write("DB99.DBX1.3", GVL_BigStation.AGVPutTray.GetBitValue(5));
  757. break;
  758. default:
  759. break;
  760. }
  761. if (HKDevice.PlcRead.IsAllowIssueRecipe4 && GVL_BigStation.Recipe4DosingStatus == 0 && Inplace)//配方4是否允许下发配发
  762. {
  763. HKDevice.StockBinPar(LocalRecipes.ElementAt(index));
  764. HKDevice.HK_PLC_S7.Write("DB99.DBX0.6", true);
  765. GVL_BigStation.Recipe4DosingStatus = 1;
  766. MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}下发完成");
  767. }
  768. if (HKDevice.PlcRead.ReceiveFinishRecipe4 && GVL_BigStation.Recipe4DosingStatus == 1)
  769. {
  770. GVL_BigStation.Recipe4DosingStatus = 2;
  771. HKDevice.HK_PLC_S7.Write("DB99.DBX0.6", false);
  772. StockBinParReset();
  773. MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}配方配料");
  774. }
  775. if (GVL_BigStation.Recipe4DosingStatus == 2 && HKDevice.PlcRead.Recipe4DosingFinish)
  776. {
  777. switch (trayCode)
  778. {
  779. case 1:
  780. HKDevice.HK_PLC_S7.Write("DB99.DBX0.7", false);
  781. break;
  782. case 2:
  783. HKDevice.HK_PLC_S7.Write("DB99.DBX1.0", false);
  784. break;
  785. case 3:
  786. HKDevice.HK_PLC_S7.Write("DB99.DBX1.1", false);
  787. break;
  788. case 4:
  789. HKDevice.HK_PLC_S7.Write("DB99.DBX1.2", false);
  790. break;
  791. case 5:
  792. HKDevice.HK_PLC_S7.Write("DB99.DBX1.3", false);
  793. break;
  794. default:
  795. break;
  796. }
  797. GVL_BigStation.Recipe4DosingStatus = 3;
  798. MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}配料完成");
  799. foreach (var item in LocalRecipes.ElementAt(index).RawMaterial)
  800. {
  801. if (item.RawMaterialLocation == 1)
  802. {
  803. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin1ActualWeight;
  804. }
  805. else if (item.RawMaterialLocation == 2)
  806. {
  807. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin2ActualWeight;
  808. }
  809. else if (item.RawMaterialLocation == 3)
  810. {
  811. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin3ActualWeight;
  812. }
  813. else if (item.RawMaterialLocation == 4)
  814. {
  815. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin4ActualWeight;
  816. }
  817. else if (item.RawMaterialLocation == 5)
  818. {
  819. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin5ActualWeight;
  820. }
  821. else if (item.RawMaterialLocation == 6)
  822. {
  823. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin6ActualWeight;
  824. }
  825. else if (item.RawMaterialLocation == 7)
  826. {
  827. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin7ActualWeight;
  828. }
  829. else if (item.RawMaterialLocation == 8)
  830. {
  831. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin8ActualWeight;
  832. }
  833. else if (item.RawMaterialLocation == 9)
  834. {
  835. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin9ActualWeight;
  836. }
  837. else if (item.RawMaterialLocation == 10)
  838. {
  839. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin10ActualWeight;
  840. }
  841. else if (item.RawMaterialLocation == 11)
  842. {
  843. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin11ActualWeight;
  844. }
  845. else if (item.RawMaterialLocation == 12)
  846. {
  847. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin12ActualWeight;
  848. }
  849. else if (item.RawMaterialLocation == 13)
  850. {
  851. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin13ActualWeight;
  852. }
  853. else if (item.RawMaterialLocation == 14)
  854. {
  855. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin14ActualWeight;
  856. }
  857. }
  858. HKDevice.HK_PLC_S7.Write<bool>("DB98.DBX1.3", false);
  859. LocalRecipeQueue4.TryDequeue(out code);
  860. RecipeExecuteComple.Add(LocalRecipes.ElementAt(index));//将该配方添加到下
  861. //App.Current.Dispatcher.Invoke(() => {
  862. // Json<LocalRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
  863. //});
  864. LocalRecipes.RemoveAt(index);
  865. GVL_BigStation.Recipe4DosingStatus = 0;
  866. }
  867. }
  868. }
  869. }
  870. private void ReceviceData()
  871. {
  872. SiemensRecipes = Json<RemoteRecipe>.Data.Recipes;
  873. if (SiemensRecipes.Count > 0)
  874. {
  875. foreach (var data in SiemensRecipes)
  876. {
  877. if (SiemensRecipeQueue1.Count == 0 && !SiemensRecipeQueue2.Contains(data.RecipeCode) && !SiemensRecipeQueue3.Contains(data.RecipeCode) && !SiemensRecipeQueue4.Contains(data.RecipeCode))
  878. {
  879. if (!(SiemensRecipeQueue1.Contains(data.RecipeCode)))
  880. {
  881. if (SiemensDevice.DL_Status is DL_Status_DB status)
  882. {
  883. if (GVL_BigStation.SiemensSendRecipeStatus == 3)
  884. {
  885. SiemensDevice.Siemens_PLC_S7.WriteString(2331, data.RecipeCode, 10);
  886. SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", true);
  887. MessageNotify.GetInstance.ShowRunLog($"配方1,发送配方编号和请求配料标志给西门子");
  888. GVL_BigStation.SiemensSendRecipeStatus = 4;
  889. }
  890. if (GVL_BigStation.SiemensSendRecipeStatus == 4)
  891. {
  892. if (SiemensDevice.DL_Status.Dosing_Start_ACK)
  893. {
  894. SiemensDevice.Siemens_PLC_S7.WriteString(2331, "", 10);
  895. SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", false);
  896. MessageNotify.GetInstance.ShowRunLog($"配方1,西门子确认开始配料");
  897. GVL_BigStation.SiemensSendRecipeStatus = 5;
  898. }
  899. }
  900. if (GVL_BigStation.SiemensSendRecipeStatus == 5)
  901. {
  902. if (SiemensDevice.DL_Status.Dosing_Start_ACK == false)
  903. {
  904. SiemensRecipeQueue1.Enqueue(data.RecipeCode);
  905. MessageNotify.GetInstance.ShowRunLog($"配方1,配方:{data.RecipeCode},加入队列");
  906. GVL_BigStation.SiemensSendRecipeStatus = 0;
  907. }
  908. }
  909. }
  910. }
  911. }
  912. else if (SiemensRecipeQueue2.Count == 0 && !SiemensRecipeQueue1.Contains(data.RecipeCode) && !SiemensRecipeQueue3.Contains(data.RecipeCode) && !SiemensRecipeQueue4.Contains(data.RecipeCode))
  913. {
  914. if (!(SiemensRecipeQueue2.Contains(data.RecipeCode)))
  915. {
  916. if (SiemensDevice.DL_Status is DL_Status_DB status)
  917. {
  918. if (GVL_BigStation.SiemensSendRecipeStatus == 3)
  919. {
  920. SiemensDevice.Siemens_PLC_S7.WriteString(2331, data.RecipeCode, 10);
  921. SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", true);
  922. MessageNotify.GetInstance.ShowRunLog($"配方2,发送配方编号和请求配料标志给西门子");
  923. GVL_BigStation.SiemensSendRecipeStatus = 4;
  924. }
  925. if (GVL_BigStation.SiemensSendRecipeStatus == 4)
  926. {
  927. if (SiemensDevice.DL_Status.Dosing_Start_ACK)
  928. {
  929. SiemensDevice.Siemens_PLC_S7.WriteString(2331, "", 10);
  930. SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", false);
  931. MessageNotify.GetInstance.ShowRunLog($"配方2,西门子确认开始配料");
  932. GVL_BigStation.SiemensSendRecipeStatus = 5;
  933. }
  934. }
  935. if (GVL_BigStation.SiemensSendRecipeStatus == 5)
  936. {
  937. if (SiemensDevice.DL_Status.Dosing_Start_ACK == false)
  938. {
  939. SiemensRecipeQueue2.Enqueue(data.RecipeCode);
  940. MessageNotify.GetInstance.ShowRunLog($"配方2,配方:{data.RecipeCode},加入队列");
  941. GVL_BigStation.SiemensSendRecipeStatus = 0;
  942. }
  943. }
  944. }
  945. }
  946. }
  947. else if (SiemensRecipeQueue3.Count == 0 && !SiemensRecipeQueue1.Contains(data.RecipeCode) && !SiemensRecipeQueue2.Contains(data.RecipeCode) && !SiemensRecipeQueue4.Contains(data.RecipeCode))
  948. {
  949. if (!(SiemensRecipeQueue3.Contains(data.RecipeCode)))
  950. {
  951. if (SiemensDevice.DL_Status is DL_Status_DB status)
  952. {
  953. if (GVL_BigStation.SiemensSendRecipeStatus == 3)
  954. {
  955. SiemensDevice.Siemens_PLC_S7.WriteString(2331, data.RecipeCode, 10);
  956. SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", true);
  957. MessageNotify.GetInstance.ShowRunLog($"配方3,发送配方编号和请求配料标志给西门子");
  958. GVL_BigStation.SiemensSendRecipeStatus = 4;
  959. }
  960. if (GVL_BigStation.SiemensSendRecipeStatus == 4)
  961. {
  962. if (SiemensDevice.DL_Status.Dosing_Start_ACK)
  963. {
  964. SiemensDevice.Siemens_PLC_S7.WriteString(2331, "", 10);
  965. SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", false);
  966. MessageNotify.GetInstance.ShowRunLog($"配方3,西门子确认开始配料");
  967. GVL_BigStation.SiemensSendRecipeStatus = 5;
  968. }
  969. }
  970. if (GVL_BigStation.SiemensSendRecipeStatus == 5)
  971. {
  972. if (SiemensDevice.DL_Status.Dosing_Start_ACK == false)
  973. {
  974. SiemensRecipeQueue3.Enqueue(data.RecipeCode);
  975. MessageNotify.GetInstance.ShowRunLog($"配方3,配方:{data.RecipeCode},加入队列");
  976. GVL_BigStation.SiemensSendRecipeStatus = 0;
  977. }
  978. }
  979. }
  980. }
  981. }
  982. else if (SiemensRecipeQueue4.Count == 0 && !SiemensRecipeQueue1.Contains(data.RecipeCode) && !SiemensRecipeQueue2.Contains(data.RecipeCode) && !SiemensRecipeQueue3.Contains(data.RecipeCode))
  983. {
  984. if (!(SiemensRecipeQueue4.Contains(data.RecipeCode)))
  985. {
  986. if (SiemensDevice.DL_Status is DL_Status_DB status)
  987. {
  988. if (GVL_BigStation.SiemensSendRecipeStatus == 3)
  989. {
  990. SiemensDevice.Siemens_PLC_S7.WriteString(2331, data.RecipeCode, 10);
  991. SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", true);
  992. MessageNotify.GetInstance.ShowRunLog($"配方4,发送配方编号和请求配料标志给西门子");
  993. GVL_BigStation.SiemensSendRecipeStatus = 4;
  994. }
  995. if (GVL_BigStation.SiemensSendRecipeStatus == 4)
  996. {
  997. if (SiemensDevice.DL_Status.Dosing_Start_ACK)
  998. {
  999. SiemensDevice.Siemens_PLC_S7.WriteString(2331, "", 10);
  1000. SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", false);
  1001. MessageNotify.GetInstance.ShowRunLog($"配方4,西门子确认开始配料");
  1002. GVL_BigStation.SiemensSendRecipeStatus = 5;
  1003. }
  1004. }
  1005. if (GVL_BigStation.SiemensSendRecipeStatus == 5)
  1006. {
  1007. if (SiemensDevice.DL_Status.Dosing_Start_ACK == false)
  1008. {
  1009. SiemensRecipeQueue4.Enqueue(data.RecipeCode);
  1010. MessageNotify.GetInstance.ShowRunLog($"配方4,配方:{data.RecipeCode},加入队列");
  1011. GVL_BigStation.SiemensSendRecipeStatus = 0;
  1012. }
  1013. }
  1014. }
  1015. }
  1016. }
  1017. }
  1018. }
  1019. else
  1020. {
  1021. SiemensRecipeQueue1.Clear();
  1022. SiemensRecipeQueue2.Clear();
  1023. SiemensRecipeQueue3.Clear();
  1024. SiemensRecipeQueue4.Clear();
  1025. GVL_BigStation.Recipe1DosingStatus = 0;
  1026. GVL_BigStation.Recipe2DosingStatus = 0;
  1027. GVL_BigStation.Recipe3DosingStatus = 0;
  1028. GVL_BigStation.Recipe4DosingStatus = 0;
  1029. }
  1030. if (GVL_BigStation.Order_Cancel) //订单取消
  1031. {
  1032. if (!string.IsNullOrEmpty(GVL_BigStation.Order_CancelRecipeCode))
  1033. {
  1034. int index = Array.FindIndex(Json<RemoteRecipe>.Data.Recipes.ToArray(), p => p.RecipeCode == GVL_BigStation.Order_CancelRecipeCode);
  1035. if (index >= 0)
  1036. {
  1037. string code = GVL_BigStation.Order_CancelRecipeCode;
  1038. short TrayCode = (short)Json<RemoteRecipe>.Data.Recipes.ElementAt(index).TrayCode;
  1039. if (SiemensRecipeQueue1.Contains(code) || SiemensRecipeQueue2.Contains(code) || SiemensRecipeQueue3.Contains(code) || SiemensRecipeQueue4.Contains(code))
  1040. {
  1041. if (SiemensRecipeQueue1.Contains(code))
  1042. {
  1043. App.Current.Dispatcher.Invoke(() =>
  1044. {
  1045. Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);
  1046. });
  1047. if (GVL_BigStation.Recipe1DosingStatus != 0)
  1048. {
  1049. HKDevice.HK_PLC_S7.Write("DB99.DBX230.0", true);
  1050. HKDevice.HK_PLC_S7.Write("DB99.DBW232", (short)TrayCode);
  1051. MessageNotify.GetInstance.ShowRunLog($"PLC正在执行配料流程,取消订单:{code}");
  1052. }
  1053. else
  1054. {
  1055. MessageNotify.GetInstance.ShowRunLog($"AGV未到达工站前,未给plc下发配方,取消订单:{code}");
  1056. }
  1057. GVL_BigStation.Recipe1DosingStatus = 0;
  1058. SiemensRecipeQueue1.TryDequeue(out code);
  1059. SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX320.2", false);
  1060. SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", true);
  1061. MessageNotify.GetInstance.ShowRunLog($"队列1,西门子取消订单完成,订单号:{code}");
  1062. }
  1063. if (SiemensRecipeQueue2.Contains(code))
  1064. {
  1065. GVL_BigStation.Recipe2DosingStatus = 0;
  1066. App.Current.Dispatcher.Invoke(() =>
  1067. {
  1068. Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);
  1069. });
  1070. if (GVL_BigStation.Recipe2DosingStatus != 0)
  1071. {
  1072. HKDevice.HK_PLC_S7.Write("DB99.DBX230.0", true);
  1073. HKDevice.HK_PLC_S7.Write("DB99.DBW232", (short)TrayCode);
  1074. MessageNotify.GetInstance.ShowRunLog($"PLC正在执行配料流程,取消订单:{code}");
  1075. }
  1076. else
  1077. {
  1078. MessageNotify.GetInstance.ShowRunLog($"AGV未到达工站前,未给plc下发配方,取消订单:{code}");
  1079. }
  1080. GVL_BigStation.Recipe2DosingStatus = 0;
  1081. SiemensRecipeQueue2.TryDequeue(out code);
  1082. SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX320.2", false);
  1083. SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", true);
  1084. MessageNotify.GetInstance.ShowRunLog($"队列2,西门子取消订单完成,订单号:{code}");
  1085. }
  1086. if (SiemensRecipeQueue3.Contains(code))
  1087. {
  1088. GVL_BigStation.Recipe3DosingStatus = 0;
  1089. App.Current.Dispatcher.Invoke(() =>
  1090. {
  1091. Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);
  1092. });
  1093. if (GVL_BigStation.Recipe3DosingStatus != 0)
  1094. {
  1095. HKDevice.HK_PLC_S7.Write("DB99.DBX230.0", true);
  1096. HKDevice.HK_PLC_S7.Write("DB99.DBW232", (short)TrayCode);
  1097. MessageNotify.GetInstance.ShowRunLog($"PLC正在执行配料流程,取消订单:{code}");
  1098. }
  1099. else
  1100. {
  1101. MessageNotify.GetInstance.ShowRunLog($"AGV未到达工站前,未给plc下发配方,取消订单:{code}");
  1102. }
  1103. GVL_BigStation.Recipe3DosingStatus = 0;
  1104. SiemensRecipeQueue3.TryDequeue(out code);
  1105. SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX320.2", false);
  1106. SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", true);
  1107. MessageNotify.GetInstance.ShowRunLog($"队列3,西门子取消订单完成,订单号:{code}");
  1108. }
  1109. if (SiemensRecipeQueue4.Contains(code))
  1110. {
  1111. GVL_BigStation.Recipe4DosingStatus = 0;
  1112. App.Current.Dispatcher.Invoke(() =>
  1113. {
  1114. Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);
  1115. });
  1116. if (GVL_BigStation.Recipe4DosingStatus != 0)
  1117. {
  1118. HKDevice.HK_PLC_S7.Write("DB99.DBX230.0", true);
  1119. HKDevice.HK_PLC_S7.Write("DB99.DBW232", (short)TrayCode);
  1120. MessageNotify.GetInstance.ShowRunLog($"PLC正在执行配料流程,取消订单:{code}");
  1121. }
  1122. else
  1123. {
  1124. MessageNotify.GetInstance.ShowRunLog($"AGV未到达工站前,未给plc下发配方,取消订单:{code}");
  1125. }
  1126. GVL_BigStation.Recipe4DosingStatus = 0;
  1127. SiemensRecipeQueue4.TryDequeue(out code);
  1128. SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX320.2", false);
  1129. SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", true);
  1130. MessageNotify.GetInstance.ShowRunLog($"队列4,西门子取消订单完成,订单号:{code}");
  1131. }
  1132. GVL_BigStation.Order_Cancel = false;
  1133. GVL_BigStation.Order_CancelRecipeCode = "";
  1134. }
  1135. else
  1136. {
  1137. if (GVL_BigStation.SiemensSendRecipeStatus != 0 || GVL_BigStation.SiemensSendRecipeStatus != 1)
  1138. {
  1139. GVL_BigStation.SiemensSendRecipeStatus = 0;
  1140. App.Current.Dispatcher.Invoke(() =>
  1141. {
  1142. Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);
  1143. });
  1144. MessageNotify.GetInstance.ShowRunLog($"正在执行请求订单流程,配方还未到PLC,订单号:{GVL_BigStation.Order_CancelRecipeCode}");
  1145. }
  1146. else
  1147. {
  1148. MessageNotify.GetInstance.ShowRunLog($"订单取消异常,订单号:{GVL_BigStation.Order_CancelRecipeCode}");
  1149. }
  1150. GVL_BigStation.Order_Cancel = false;
  1151. GVL_BigStation.Order_CancelRecipeCode = "";
  1152. SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX320.2", false);
  1153. SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", true);
  1154. }
  1155. }
  1156. else
  1157. {
  1158. GVL_BigStation.Order_Cancel = false;
  1159. GVL_BigStation.Order_CancelRecipeCode = "";
  1160. SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX320.2", false);
  1161. SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", true);
  1162. MessageNotify.GetInstance.ShowRunLog($"西门子取消订单,但未找到订单:{GVL_BigStation.Order_CancelRecipeCode}");
  1163. }
  1164. }
  1165. }
  1166. }
  1167. private void RecipeInfoToHKPLC()
  1168. {
  1169. if (SiemensRecipeQueue1.Count > 0)
  1170. {
  1171. int index = Array.FindIndex(SiemensRecipes.ToArray(), p => p.RecipeCode == SiemensRecipeQueue1.ElementAt(0));
  1172. if (index >= 0 && index < SiemensRecipes.Count)
  1173. {
  1174. string code = SiemensRecipes.ElementAt(index).RecipeCode;
  1175. int trayCode = SiemensRecipes.ElementAt(index).TrayCode;
  1176. bool Inplace = false;
  1177. switch (trayCode)
  1178. {
  1179. case 1:
  1180. Inplace = HKDevice.PlcRead.Tray1InPlace;
  1181. break;
  1182. case 2:
  1183. Inplace = HKDevice.PlcRead.Tray2InPlace;
  1184. break;
  1185. case 3:
  1186. Inplace = HKDevice.PlcRead.Tray3InPlace;
  1187. break;
  1188. case 4:
  1189. Inplace = HKDevice.PlcRead.Tray4InPlace;
  1190. break;
  1191. case 5:
  1192. Inplace = HKDevice.PlcRead.Tray5InPlace;
  1193. break;
  1194. default:
  1195. break;
  1196. }
  1197. if (HKDevice.PlcRead.IsAllowIssueRecipe1 && GVL_BigStation.Recipe1DosingStatus == 0 && Inplace)//配方1是否允许下发配发
  1198. {
  1199. GVL_BigStation.DosingRecipe1Time = DateTime.Now;
  1200. HKDevice.StockBinPar(SiemensRecipes.ElementAt(index));
  1201. if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
  1202. {
  1203. HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", true);//洗桶
  1204. MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},订单类型为洗桶");
  1205. }
  1206. HKDevice.HK_PLC_S7.Write("DB99.DBX0.3", true);
  1207. GVL_BigStation.Recipe1DosingStatus = 1;
  1208. MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},下发完成");
  1209. }
  1210. if (HKDevice.PlcRead.ReceiveFinishRecipe1 && GVL_BigStation.Recipe1DosingStatus == 1)
  1211. {
  1212. HKDevice.HK_PLC_S7.Write("DB99.DBX0.3", false);
  1213. StockBinParReset();
  1214. MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},PLC接收配方完成");
  1215. GVL_BigStation.Recipe1DosingStatus = 2;
  1216. }
  1217. if (GVL_BigStation.Recipe1DosingStatus == 2 && HKDevice.PlcRead.Recipe1DosingFinish)
  1218. {
  1219. GVL_BigStation.Recipe1DosingFinish = true;
  1220. GVL_BigStation.Recipe1DosingStatus = 3;
  1221. MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}配料完成");
  1222. foreach (var item in SiemensRecipes.ElementAt(index).RawMaterial)
  1223. {
  1224. if (item.RawMaterialLocation == 1)
  1225. {
  1226. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin1ActualWeight;
  1227. }
  1228. else if (item.RawMaterialLocation == 2)
  1229. {
  1230. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin2ActualWeight;
  1231. }
  1232. else if (item.RawMaterialLocation == 3)
  1233. {
  1234. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin3ActualWeight;
  1235. }
  1236. else if (item.RawMaterialLocation == 4)
  1237. {
  1238. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin4ActualWeight;
  1239. }
  1240. else if (item.RawMaterialLocation == 5)
  1241. {
  1242. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin5ActualWeight;
  1243. }
  1244. else if (item.RawMaterialLocation == 6)
  1245. {
  1246. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin6ActualWeight;
  1247. }
  1248. else if (item.RawMaterialLocation == 7)
  1249. {
  1250. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin7ActualWeight;
  1251. }
  1252. else if (item.RawMaterialLocation == 8)
  1253. {
  1254. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin8ActualWeight;
  1255. }
  1256. else if (item.RawMaterialLocation == 9)
  1257. {
  1258. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin9ActualWeight;
  1259. }
  1260. else if (item.RawMaterialLocation == 10)
  1261. {
  1262. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin10ActualWeight;
  1263. }
  1264. else if (item.RawMaterialLocation == 11)
  1265. {
  1266. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin11ActualWeight;
  1267. }
  1268. else if (item.RawMaterialLocation == 12)
  1269. {
  1270. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin12ActualWeight;
  1271. }
  1272. else if (item.RawMaterialLocation == 13)
  1273. {
  1274. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin13ActualWeight;
  1275. }
  1276. else if (item.RawMaterialLocation == 14)
  1277. {
  1278. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin14ActualWeight;
  1279. }
  1280. }
  1281. if (SiemensDevice.IsConnected)
  1282. {
  1283. FinishData.Order_No = SiemensRecipes.ElementAt(index).RecipeCode;
  1284. FinishData.Product_Code = SiemensRecipes.ElementAt(index).RecipeName;
  1285. FinishData.job_No = (short)SiemensRecipes.ElementAt(index).TrayCode;
  1286. for (int i = 0; i < FinishData.Material.Length; i++)
  1287. {
  1288. FinishData.Material[i] = new UDT1();
  1289. }
  1290. for (int i = 0; i < SiemensRecipes.ElementAt(index).RawMaterial.Count; i++)
  1291. {
  1292. FinishData.Material[i].Material_Name = SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialName;
  1293. FinishData.Material[i].Material_BarrelNum = (short)SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialBarrelNum;
  1294. FinishData.Material[i].Material_Laying_Off_Weight = Math.Abs(SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).Laying_Off_Weight);
  1295. }
  1296. FinishData.Ask_For_Finish = true;
  1297. double a = DateTime.Now.Subtract(GVL_BigStation.DosingRecipe1Time).TotalSeconds;
  1298. FinishData.ProcessTime = Convert.ToInt16(a);
  1299. SiemensDevice.Siemens_PLC_S7.WriteClass<DL_Finish_DB>(FinishData, 2361);
  1300. MessageNotify.GetInstance.ShowRunLog($"配方配料完成,将信号反馈给西门子");
  1301. }
  1302. SiemensRecipeQueue1.TryDequeue(out code);
  1303. RecipeExecuteComple.Add(SiemensRecipes.ElementAt(index));//将配方添加到完成列表
  1304. if (!GVL_BigStation.IsUseLocalRecipe)
  1305. {
  1306. App.Current.Dispatcher.Invoke(() =>
  1307. {
  1308. Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
  1309. });
  1310. }
  1311. else
  1312. {
  1313. App.Current.Dispatcher.Invoke(() =>
  1314. {
  1315. Json<LocalRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
  1316. });
  1317. }
  1318. GVL_BigStation.Recipe1DosingStatus = 0;
  1319. }
  1320. }
  1321. }
  1322. if (SiemensRecipeQueue2.Count > 0)
  1323. {
  1324. int index = Array.FindIndex(SiemensRecipes.ToArray(), p => p.RecipeCode == SiemensRecipeQueue2.ElementAt(0));
  1325. if (index >= 0 && index < SiemensRecipes.Count)
  1326. {
  1327. string code = SiemensRecipes.ElementAt(index).RecipeCode;
  1328. int trayCode = SiemensRecipes.ElementAt(index).TrayCode;
  1329. bool Inplace = false;
  1330. switch (trayCode)
  1331. {
  1332. case 1:
  1333. Inplace = HKDevice.PlcRead.Tray1InPlace;
  1334. break;
  1335. case 2:
  1336. Inplace = HKDevice.PlcRead.Tray2InPlace;
  1337. break;
  1338. case 3:
  1339. Inplace = HKDevice.PlcRead.Tray3InPlace;
  1340. break;
  1341. case 4:
  1342. Inplace = HKDevice.PlcRead.Tray4InPlace;
  1343. break;
  1344. case 5:
  1345. Inplace = HKDevice.PlcRead.Tray5InPlace;
  1346. break;
  1347. default:
  1348. break;
  1349. }
  1350. if (HKDevice.PlcRead.IsAllowIssueRecipe2 && GVL_BigStation.Recipe2DosingStatus == 0 && Inplace)//配方2是否允许下发配发
  1351. {
  1352. GVL_BigStation.DosingRecipe2Time = DateTime.Now;
  1353. HKDevice.StockBinPar(SiemensRecipes.ElementAt(index));
  1354. if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
  1355. {
  1356. HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", true);//洗桶
  1357. MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},订单类型为洗桶");
  1358. }
  1359. HKDevice.HK_PLC_S7.Write("DB99.DBX0.4", true);
  1360. GVL_BigStation.Recipe2DosingStatus = 1;
  1361. MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},下发完成");
  1362. }
  1363. if (HKDevice.PlcRead.ReceiveFinishRecipe2 && GVL_BigStation.Recipe2DosingStatus == 1)
  1364. {
  1365. GVL_BigStation.Recipe2DosingStatus = 2;
  1366. HKDevice.HK_PLC_S7.Write("DB99.DBX0.4", false);
  1367. StockBinParReset();
  1368. MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},PLC接收配方完成");
  1369. }
  1370. if (GVL_BigStation.Recipe2DosingStatus == 2 && HKDevice.PlcRead.Recipe2DosingFinish)
  1371. {
  1372. GVL_BigStation.Recipe2DosingFinish = true;
  1373. GVL_BigStation.Recipe2DosingStatus = 3;
  1374. MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}配料完成");
  1375. foreach (var item in SiemensRecipes.ElementAt(index).RawMaterial)
  1376. {
  1377. if (item.RawMaterialLocation == 1)
  1378. {
  1379. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin1ActualWeight;
  1380. }
  1381. else if (item.RawMaterialLocation == 2)
  1382. {
  1383. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin2ActualWeight;
  1384. }
  1385. else if (item.RawMaterialLocation == 3)
  1386. {
  1387. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin3ActualWeight;
  1388. }
  1389. else if (item.RawMaterialLocation == 4)
  1390. {
  1391. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin4ActualWeight;
  1392. }
  1393. else if (item.RawMaterialLocation == 5)
  1394. {
  1395. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin5ActualWeight;
  1396. }
  1397. else if (item.RawMaterialLocation == 6)
  1398. {
  1399. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin6ActualWeight;
  1400. }
  1401. else if (item.RawMaterialLocation == 7)
  1402. {
  1403. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin7ActualWeight;
  1404. }
  1405. else if (item.RawMaterialLocation == 8)
  1406. {
  1407. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin8ActualWeight;
  1408. }
  1409. else if (item.RawMaterialLocation == 9)
  1410. {
  1411. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin9ActualWeight;
  1412. }
  1413. else if (item.RawMaterialLocation == 10)
  1414. {
  1415. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin10ActualWeight;
  1416. }
  1417. else if (item.RawMaterialLocation == 11)
  1418. {
  1419. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin11ActualWeight;
  1420. }
  1421. else if (item.RawMaterialLocation == 12)
  1422. {
  1423. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin12ActualWeight;
  1424. }
  1425. else if (item.RawMaterialLocation == 13)
  1426. {
  1427. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin13ActualWeight;
  1428. }
  1429. else if (item.RawMaterialLocation == 14)
  1430. {
  1431. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin14ActualWeight;
  1432. }
  1433. }
  1434. if (SiemensDevice.IsConnected)
  1435. {
  1436. FinishData.Order_No = SiemensRecipes.ElementAt(index).RecipeCode;
  1437. FinishData.Product_Code = SiemensRecipes.ElementAt(index).RecipeName;
  1438. FinishData.job_No = (short)SiemensRecipes.ElementAt(index).TrayCode;
  1439. for (int i = 0; i < FinishData.Material.Length; i++)
  1440. {
  1441. FinishData.Material[i] = new UDT1();
  1442. }
  1443. for (int i = 0; i < SiemensRecipes.ElementAt(index).RawMaterial.Count; i++)
  1444. {
  1445. FinishData.Material[i].Material_Name = SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialName;
  1446. FinishData.Material[i].Material_BarrelNum = (short)SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialBarrelNum;
  1447. FinishData.Material[i].Material_Laying_Off_Weight = Math.Abs(SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).Laying_Off_Weight);
  1448. }
  1449. FinishData.Ask_For_Finish = true;
  1450. double a = DateTime.Now.Subtract(GVL_BigStation.DosingRecipe2Time).TotalSeconds;
  1451. FinishData.ProcessTime = Convert.ToInt16(a);
  1452. SiemensDevice.Siemens_PLC_S7.WriteClass<DL_Finish_DB>(FinishData, 2361);
  1453. MessageNotify.GetInstance.ShowRunLog($"配方配料完成,将信号反馈给西门子");
  1454. }
  1455. SiemensRecipeQueue2.TryDequeue(out code);
  1456. RecipeExecuteComple.Add(SiemensRecipes.ElementAt(index));
  1457. if (!GVL_BigStation.IsUseLocalRecipe)
  1458. {
  1459. App.Current.Dispatcher.Invoke(() =>
  1460. {
  1461. Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
  1462. });
  1463. }
  1464. else
  1465. {
  1466. App.Current.Dispatcher.Invoke(() =>
  1467. {
  1468. Json<LocalRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
  1469. });
  1470. }
  1471. GVL_BigStation.Recipe2DosingStatus = 0;
  1472. }
  1473. }
  1474. }
  1475. if (SiemensRecipeQueue3.Count > 0)
  1476. {
  1477. int index = Array.FindIndex(SiemensRecipes.ToArray(), p => p.RecipeCode == SiemensRecipeQueue3.ElementAt(0));
  1478. if (index >= 0 && index < SiemensRecipes.Count)
  1479. {
  1480. string code = SiemensRecipes.ElementAt(index).RecipeCode;
  1481. int trayCode = SiemensRecipes.ElementAt(index).TrayCode;
  1482. bool Inplace = false;
  1483. switch (trayCode)
  1484. {
  1485. case 1:
  1486. Inplace = HKDevice.PlcRead.Tray1InPlace;
  1487. break;
  1488. case 2:
  1489. Inplace = HKDevice.PlcRead.Tray2InPlace;
  1490. break;
  1491. case 3:
  1492. Inplace = HKDevice.PlcRead.Tray3InPlace;
  1493. break;
  1494. case 4:
  1495. Inplace = HKDevice.PlcRead.Tray4InPlace;
  1496. break;
  1497. case 5:
  1498. Inplace = HKDevice.PlcRead.Tray5InPlace;
  1499. break;
  1500. default:
  1501. break;
  1502. }
  1503. if (HKDevice.PlcRead.IsAllowIssueRecipe3 && GVL_BigStation.Recipe3DosingStatus == 0 && Inplace)//配方3是否允许下发配发
  1504. {
  1505. GVL_BigStation.DosingRecipe3Time = DateTime.Now;
  1506. HKDevice.StockBinPar(SiemensRecipes.ElementAt(index));
  1507. if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
  1508. {
  1509. HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", true);//洗桶
  1510. MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},订单类型为洗桶");
  1511. }
  1512. HKDevice.HK_PLC_S7.Write("DB99.DBX0.5", true);
  1513. GVL_BigStation.Recipe3DosingStatus = 1;
  1514. MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},下发完成");
  1515. }
  1516. if (HKDevice.PlcRead.ReceiveFinishRecipe3 && GVL_BigStation.Recipe3DosingStatus == 1)
  1517. {
  1518. GVL_BigStation.Recipe3DosingStatus = 2;
  1519. HKDevice.HK_PLC_S7.Write("DB99.DBX0.5", false);
  1520. StockBinParReset();
  1521. MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},PLC接收配方完成");
  1522. }
  1523. if (HKDevice.PlcRead.Recipe3DosingFinish && GVL_BigStation.Recipe3DosingStatus == 2)
  1524. {
  1525. GVL_BigStation.Recipe3DosingFinish = true;
  1526. GVL_BigStation.Recipe3DosingStatus = 3;
  1527. MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}配料完成");
  1528. foreach (var item in SiemensRecipes.ElementAt(index).RawMaterial)
  1529. {
  1530. if (item.RawMaterialLocation == 1)
  1531. {
  1532. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin1ActualWeight;
  1533. }
  1534. else if (item.RawMaterialLocation == 2)
  1535. {
  1536. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin2ActualWeight;
  1537. }
  1538. else if (item.RawMaterialLocation == 3)
  1539. {
  1540. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin3ActualWeight;
  1541. }
  1542. else if (item.RawMaterialLocation == 4)
  1543. {
  1544. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin4ActualWeight;
  1545. }
  1546. else if (item.RawMaterialLocation == 5)
  1547. {
  1548. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin5ActualWeight;
  1549. }
  1550. else if (item.RawMaterialLocation == 6)
  1551. {
  1552. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin6ActualWeight;
  1553. }
  1554. else if (item.RawMaterialLocation == 7)
  1555. {
  1556. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin7ActualWeight;
  1557. }
  1558. else if (item.RawMaterialLocation == 8)
  1559. {
  1560. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin8ActualWeight;
  1561. }
  1562. else if (item.RawMaterialLocation == 9)
  1563. {
  1564. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin9ActualWeight;
  1565. }
  1566. else if (item.RawMaterialLocation == 10)
  1567. {
  1568. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin10ActualWeight;
  1569. }
  1570. else if (item.RawMaterialLocation == 11)
  1571. {
  1572. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin11ActualWeight;
  1573. }
  1574. else if (item.RawMaterialLocation == 12)
  1575. {
  1576. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin12ActualWeight;
  1577. }
  1578. else if (item.RawMaterialLocation == 13)
  1579. {
  1580. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin13ActualWeight;
  1581. }
  1582. else if (item.RawMaterialLocation == 14)
  1583. {
  1584. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin14ActualWeight;
  1585. }
  1586. }
  1587. if (SiemensDevice.IsConnected)
  1588. {
  1589. FinishData.Order_No = SiemensRecipes.ElementAt(index).RecipeCode;
  1590. FinishData.Product_Code = SiemensRecipes.ElementAt(index).RecipeName;
  1591. FinishData.job_No = (short)SiemensRecipes.ElementAt(index).TrayCode;
  1592. for (int i = 0; i < FinishData.Material.Length; i++)
  1593. {
  1594. FinishData.Material[i] = new UDT1();
  1595. }
  1596. for (int i = 0; i < SiemensRecipes.ElementAt(index).RawMaterial.Count; i++)
  1597. {
  1598. FinishData.Material[i].Material_Name = SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialName;
  1599. FinishData.Material[i].Material_BarrelNum = (short)SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialBarrelNum;
  1600. FinishData.Material[i].Material_Laying_Off_Weight = Math.Abs(SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).Laying_Off_Weight);
  1601. }
  1602. FinishData.Ask_For_Finish = true;
  1603. double a = DateTime.Now.Subtract(GVL_BigStation.DosingRecipe3Time).TotalSeconds;
  1604. FinishData.ProcessTime = Convert.ToInt16(a);
  1605. SiemensDevice.Siemens_PLC_S7.WriteClass<DL_Finish_DB>(FinishData, 2361);
  1606. MessageNotify.GetInstance.ShowRunLog($"配方配料完成,将信号反馈给西门子");
  1607. }
  1608. SiemensRecipeQueue3.TryDequeue(out code);
  1609. RecipeExecuteComple.Add(SiemensRecipes.ElementAt(index));//将该配方添加到下
  1610. if (!GVL_BigStation.IsUseLocalRecipe)
  1611. {
  1612. App.Current.Dispatcher.Invoke(() =>
  1613. {
  1614. Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
  1615. });
  1616. }
  1617. else
  1618. {
  1619. App.Current.Dispatcher.Invoke(() =>
  1620. {
  1621. Json<LocalRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
  1622. });
  1623. }
  1624. GVL_BigStation.Recipe3DosingStatus = 0;
  1625. }
  1626. }
  1627. }
  1628. if (SiemensRecipeQueue4.Count > 0)
  1629. {
  1630. int index = Array.FindIndex(SiemensRecipes.ToArray(), p => p.RecipeCode == SiemensRecipeQueue4.ElementAt(0));
  1631. if (index >= 0 && index < SiemensRecipes.Count)
  1632. {
  1633. string code = SiemensRecipes.ElementAt(index).RecipeCode;
  1634. int trayCode = SiemensRecipes.ElementAt(index).TrayCode;
  1635. bool Inplace = false;
  1636. switch (trayCode)
  1637. {
  1638. case 1:
  1639. Inplace = HKDevice.PlcRead.Tray1InPlace;
  1640. break;
  1641. case 2:
  1642. Inplace = HKDevice.PlcRead.Tray2InPlace;
  1643. break;
  1644. case 3:
  1645. Inplace = HKDevice.PlcRead.Tray3InPlace;
  1646. break;
  1647. case 4:
  1648. Inplace = HKDevice.PlcRead.Tray4InPlace;
  1649. break;
  1650. case 5:
  1651. Inplace = HKDevice.PlcRead.Tray5InPlace;
  1652. break;
  1653. default:
  1654. break;
  1655. }
  1656. if (HKDevice.PlcRead.IsAllowIssueRecipe4 && GVL_BigStation.Recipe4DosingStatus == 0 && Inplace)//配方4是否允许下发配发
  1657. {
  1658. GVL_BigStation.DosingRecipe4Time = DateTime.Now;
  1659. HKDevice.StockBinPar(SiemensRecipes.ElementAt(index));
  1660. if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
  1661. {
  1662. HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", true);//洗桶
  1663. MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},订单类型为洗桶");
  1664. }
  1665. HKDevice.HK_PLC_S7.Write("DB99.DBX0.6", true);
  1666. GVL_BigStation.Recipe4DosingStatus = 1;
  1667. MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},下发完成");
  1668. }
  1669. if (HKDevice.PlcRead.ReceiveFinishRecipe4 && GVL_BigStation.Recipe4DosingStatus == 1)
  1670. {
  1671. GVL_BigStation.Recipe4DosingStatus = 2;
  1672. HKDevice.HK_PLC_S7.Write("DB99.DBX0.6", false);
  1673. StockBinParReset();
  1674. MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},PLC接收配方完成");
  1675. }
  1676. if (GVL_BigStation.Recipe4DosingStatus == 2 && HKDevice.PlcRead.Recipe4DosingFinish)
  1677. {
  1678. GVL_BigStation.Recipe1DosingFinish = true;
  1679. GVL_BigStation.Recipe4DosingStatus = 3;
  1680. MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}配料完成");
  1681. foreach (var item in SiemensRecipes.ElementAt(index).RawMaterial)
  1682. {
  1683. if (item.RawMaterialLocation == 1)
  1684. {
  1685. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin1ActualWeight;
  1686. }
  1687. else if (item.RawMaterialLocation == 2)
  1688. {
  1689. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin2ActualWeight;
  1690. }
  1691. else if (item.RawMaterialLocation == 3)
  1692. {
  1693. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin3ActualWeight;
  1694. }
  1695. else if (item.RawMaterialLocation == 4)
  1696. {
  1697. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin4ActualWeight;
  1698. }
  1699. else if (item.RawMaterialLocation == 5)
  1700. {
  1701. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin5ActualWeight;
  1702. }
  1703. else if (item.RawMaterialLocation == 6)
  1704. {
  1705. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin6ActualWeight;
  1706. }
  1707. else if (item.RawMaterialLocation == 7)
  1708. {
  1709. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin7ActualWeight;
  1710. }
  1711. else if (item.RawMaterialLocation == 8)
  1712. {
  1713. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin8ActualWeight;
  1714. }
  1715. else if (item.RawMaterialLocation == 9)
  1716. {
  1717. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin9ActualWeight;
  1718. }
  1719. else if (item.RawMaterialLocation == 10)
  1720. {
  1721. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin10ActualWeight;
  1722. }
  1723. else if (item.RawMaterialLocation == 11)
  1724. {
  1725. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin11ActualWeight;
  1726. }
  1727. else if (item.RawMaterialLocation == 12)
  1728. {
  1729. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin12ActualWeight;
  1730. }
  1731. else if (item.RawMaterialLocation == 13)
  1732. {
  1733. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin13ActualWeight;
  1734. }
  1735. else if (item.RawMaterialLocation == 14)
  1736. {
  1737. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin14ActualWeight;
  1738. }
  1739. }
  1740. if (SiemensDevice.IsConnected)
  1741. {
  1742. FinishData.Order_No = SiemensRecipes.ElementAt(index).RecipeCode;
  1743. FinishData.Product_Code = SiemensRecipes.ElementAt(index).RecipeName;
  1744. FinishData.job_No = (short)SiemensRecipes.ElementAt(index).TrayCode;
  1745. for (int i = 0; i < FinishData.Material.Length; i++)
  1746. {
  1747. FinishData.Material[i] = new UDT1();
  1748. }
  1749. for (int i = 0; i < SiemensRecipes.ElementAt(index).RawMaterial.Count; i++)
  1750. {
  1751. FinishData.Material[i].Material_Name = SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialName;
  1752. FinishData.Material[i].Material_BarrelNum = (short)SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialBarrelNum;
  1753. FinishData.Material[i].Material_Laying_Off_Weight = Math.Abs(SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).Laying_Off_Weight);
  1754. }
  1755. FinishData.Ask_For_Finish = true;
  1756. double a = DateTime.Now.Subtract(GVL_BigStation.DosingRecipe4Time).TotalSeconds;
  1757. FinishData.ProcessTime = Convert.ToInt16(a);
  1758. SiemensDevice.Siemens_PLC_S7.WriteClass<DL_Finish_DB>(FinishData, 2361);
  1759. MessageNotify.GetInstance.ShowRunLog($"配方配料完成,将信号反馈给西门子");
  1760. }
  1761. SiemensRecipeQueue4.TryDequeue(out code);
  1762. RecipeExecuteComple.Add(SiemensRecipes.ElementAt(index));//将该配方添加到下
  1763. if (!GVL_BigStation.IsUseLocalRecipe)
  1764. {
  1765. App.Current.Dispatcher.Invoke(() =>
  1766. {
  1767. Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
  1768. });
  1769. }
  1770. else
  1771. {
  1772. App.Current.Dispatcher.Invoke(() =>
  1773. {
  1774. Json<LocalRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
  1775. });
  1776. }
  1777. GVL_BigStation.Recipe4DosingStatus = 0;
  1778. }
  1779. }
  1780. }
  1781. }
  1782. /// <summary>
  1783. /// 下发plc的配方数据复位
  1784. /// </summary>
  1785. private void StockBinParReset()
  1786. {
  1787. HKDevice.HK_PLC_S7.Write("DB99.DBW2.0", 0);//
  1788. HKDevice.HK_PLC_S7.Write("DB99.DBW4.0", 0);
  1789. for (int i = 0; i < 56; i++)
  1790. {
  1791. string address2 = "DB99.DBD" + (6 + 4 * i);
  1792. HKDevice.HK_PLC_S7.Write(address2, 0);
  1793. }
  1794. }
  1795. private void testRawMaterialNameData()
  1796. {
  1797. /* RawMaterialsInfo.Clear();
  1798. RawMaterialsInfo.Add(new RawMaterial() { RawMaterialName = "0007", RawMaterialLocation = 1 });//备料大蒜
  1799. RawMaterialsInfo.Add(new RawMaterial() { RawMaterialName = "0015", RawMaterialLocation = 2 });//花椒酱
  1800. RawMaterialsInfo.Add(new RawMaterial() { RawMaterialName = "0005", RawMaterialLocation = 3 });//榨菜丁
  1801. RawMaterialsInfo.Add(new RawMaterial() { RawMaterialName = "0018", RawMaterialLocation = 4 });//炸豌豆
  1802. RawMaterialsInfo.Add(new RawMaterial() { RawMaterialName = "0019", RawMaterialLocation = 5 });//高水分糍粑海椒
  1803. RawMaterialsInfo.Add(new RawMaterial() { RawMaterialName = "0033", RawMaterialLocation = 6 });//辣豆瓣*/
  1804. /*RawMaterialsInfo.Add(new RawMaterial() { RawMaterialName = "0030", RawMaterialLocation = 11 });//备用生姜
  1805. RawMaterialsInfo.Add(new RawMaterial() { RawMaterialName = "0012", RawMaterialLocation = 12 });//豆豉细粒*/
  1806. foreach (var material in RawMaterialsInfo)
  1807. {
  1808. if (!string.IsNullOrEmpty(material.RawMaterialName))
  1809. {
  1810. if (!RawMaterialsNamePos.ContainsKey(material.RawMaterialName))
  1811. {
  1812. RawMaterialsNamePos.Add(material.RawMaterialName, (short)material.RawMaterialLocation);
  1813. }
  1814. }
  1815. }
  1816. }
  1817. }
  1818. }