终端一体化运控平台
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

2610 lignes
151 KiB

  1. using BPA.Message;
  2. using BPASmartClient.CustomResource.Pages.Model;
  3. using BPASmartClient.Helper;
  4. using BPASmartClient.JXJFoodBigStation.Model.HK_PLC;
  5. using BPASmartClient.JXJFoodBigStation.Model.Siemens;
  6. using BPASmartClient.Modbus;
  7. using System;
  8. using System.Collections.Concurrent;
  9. using System.Collections.Generic;
  10. using System.Collections.ObjectModel;
  11. using System.Configuration;
  12. using System.Linq;
  13. using System.Reflection;
  14. using System.Text;
  15. using System.Threading;
  16. using System.Threading.Tasks;
  17. namespace BPASmartClient.JXJFoodBigStation.Model
  18. {
  19. public class ProcessControl
  20. {
  21. private volatile static ProcessControl _Instance;
  22. public static ProcessControl GetInstance => _Instance ?? (_Instance = new ProcessControl());
  23. private ProcessControl() { }
  24. public SiemensDeviceStatus SiemensDevice = new SiemensDeviceStatus();
  25. public HKDeviceStatus HKDevice = new HKDeviceStatus();
  26. DL_Finish_DB FinishData = new DL_Finish_DB();
  27. /// <summary>
  28. /// 西门子配方数据
  29. /// </summary>
  30. public ObservableCollection<RecipeData> SiemensRecipes { get; set; } = new ObservableCollection<RecipeData>();
  31. /// <summary>
  32. /// 本地配方数据
  33. /// </summary>
  34. public ObservableCollection<RecipeData> LocalRecipes { get; set; } = new ObservableCollection<RecipeData>();
  35. /// <summary>
  36. /// 配方等待执行
  37. /// </summary>
  38. public ObservableCollection<RecipeData> RecipeWaitExecute { get; set; } = new ObservableCollection<RecipeData>();
  39. /// <summary>
  40. /// 配方正在执行
  41. /// </summary>
  42. public ObservableCollection<RecipeData> RecipeExecuting { get; set; } = new ObservableCollection<RecipeData>();
  43. /// <summary>
  44. /// 配方执行完成
  45. /// </summary>
  46. public ObservableCollection<RecipeData> RecipeExecuteComple { get; set; } = new ObservableCollection<RecipeData>();
  47. /// <summary>
  48. /// 原料的名称和料仓的位置对应
  49. /// </summary>
  50. public ConcurrentDictionary<int, string> RawMaterialsNamePos { get; set; } = new ConcurrentDictionary<int, string>();
  51. /// <summary>
  52. /// 硬件料仓的原料信息
  53. /// </summary>
  54. public ObservableCollection<RawMaterial> HardWareRawMaterialInfo { get; set; } = new ObservableCollection<RawMaterial>();
  55. public ObservableCollection<RawMaterial> RawMaterialsInfo { get; set; } = new ObservableCollection<RawMaterial>();
  56. /// <summary>
  57. /// 西门子配方队列
  58. /// </summary>
  59. public ConcurrentQueue<string> SiemensRecipeQueue1 = new ConcurrentQueue<string>();
  60. public ConcurrentQueue<string> SiemensRecipeQueue2 = new ConcurrentQueue<string>();
  61. public ConcurrentQueue<string> SiemensRecipeQueue3 = new ConcurrentQueue<string>();
  62. public ConcurrentQueue<string> SiemensRecipeQueue4 = new ConcurrentQueue<string>();
  63. public ConcurrentDictionary<int, ConcurrentQueue<string>> SiemensRecipeQueue = new ConcurrentDictionary<int, ConcurrentQueue<string>>();
  64. public ObservableCollection<RecipeDosing> recipe = new ObservableCollection<RecipeDosing>();
  65. /// <summary>
  66. /// 本地配方队列
  67. /// </summary>
  68. public ConcurrentQueue<string> LocalRecipeQueue1 = new ConcurrentQueue<string>();
  69. public ConcurrentQueue<string> LocalRecipeQueue2 = new ConcurrentQueue<string>();
  70. public ConcurrentQueue<string> LocalRecipeQueue3 = new ConcurrentQueue<string>();
  71. public ConcurrentQueue<string> LocalRecipeQueue4 = new ConcurrentQueue<string>();
  72. /// <summary>
  73. /// 海科PLC的IP
  74. /// </summary>
  75. public string HK_PLC_IP = ConfigurationManager.AppSettings["HKPlc_IP"];
  76. /// <summary>
  77. /// 西门子PLC的IP
  78. /// </summary>
  79. public string Siemens_PLC_IP = ConfigurationManager.AppSettings["Siemens_IP"];
  80. public void Init()
  81. {
  82. ActionManage.GetInstance.Register(new Action<object>((res) =>
  83. {
  84. ObservableCollection<RawMaterial> RawMaterials = new ObservableCollection<RawMaterial>();
  85. if (SiemensDevice.IsConnected)
  86. {
  87. if (res != null && res is DL_Start_DB recipe)
  88. {
  89. RawMaterials.Clear();
  90. for (int i = 0; i < GVL_BigStation.Max_DosingSotckBinNum; i++)
  91. {
  92. if (string.IsNullOrEmpty(recipe.Material[i].Material_Name))
  93. {
  94. }
  95. else
  96. {
  97. int index = RawMaterialsNamePos.Values.ToList().IndexOf(recipe.Material[i].Material_Name);
  98. if (index >= 0)
  99. {
  100. RawMaterials.Add(new RawMaterial()
  101. {
  102. RawMaterialName = recipe.Material[i].Material_Name,
  103. RawMaterialBarrelNum = recipe.Material[i].Material_BarrelNum,
  104. RawMaterialWeight = recipe.Material[i].Material_Weight,
  105. RawMaterialLocation = RawMaterialsNamePos.Keys.ToList()[index]
  106. });
  107. }
  108. else
  109. {
  110. MessageNotify.GetInstance.ShowRunLog($"本地缺少原料【{recipe.Material[i].Material_Name}】,和西门子下发的原料名称无法对应。");
  111. }
  112. }
  113. }
  114. App.Current.Dispatcher.Invoke(() =>
  115. {
  116. Json<RemoteRecipe>.Data.Recipes.Add(new RecipeData()
  117. {
  118. RecipeName = recipe.RecipeName,
  119. RecipeCode = recipe.RecipeCode,
  120. RawMaterial = RawMaterials,
  121. TrayCode = recipe.Job_No,
  122. IsWashingBarrel = recipe.Order_Type,
  123. //OrderType=recipe.Order_Type?"洗桶":"配料",
  124. RecipesSource=RecipeSource.远程
  125. });
  126. });
  127. }
  128. }
  129. }), "SiemensSendRecipe", true);
  130. DeviceConnectInit();//设备连接初始化
  131. ThreadInit();//线程初始化
  132. VarResetInit();//变量初始化
  133. }
  134. #region 本地配方--暂时不使用
  135. private void LocalRecipeRecevice()
  136. {
  137. if (LocalRecipes.Count > 0)
  138. {
  139. foreach (var data in LocalRecipes)
  140. {
  141. if (LocalRecipeQueue1.Count == 0 && !LocalRecipeQueue2.Contains(data.RecipeCode) && !LocalRecipeQueue3.Contains(data.RecipeCode) && !LocalRecipeQueue4.Contains(data.RecipeCode) && HKDevice.PlcRead.IsAllowIssueRecipe1)
  142. {
  143. if (!(LocalRecipeQueue1.Contains(data.RecipeCode)))
  144. {
  145. LocalRecipeQueue1.Enqueue(data.RecipeCode);
  146. }
  147. }
  148. else if (LocalRecipeQueue2.Count == 0 && !LocalRecipeQueue1.Contains(data.RecipeCode) && !LocalRecipeQueue3.Contains(data.RecipeCode) && !LocalRecipeQueue4.Contains(data.RecipeCode) && HKDevice.PlcRead.IsAllowIssueRecipe2)
  149. {
  150. if (!(LocalRecipeQueue2.Contains(data.RecipeCode)))
  151. {
  152. LocalRecipeQueue2.Enqueue(data.RecipeCode);
  153. }
  154. }
  155. else if (LocalRecipeQueue3.Count == 0 && !LocalRecipeQueue1.Contains(data.RecipeCode) && !LocalRecipeQueue2.Contains(data.RecipeCode) && !LocalRecipeQueue4.Contains(data.RecipeCode) && HKDevice.PlcRead.IsAllowIssueRecipe3)
  156. {
  157. if (!(LocalRecipeQueue3.Contains(data.RecipeCode)))
  158. {
  159. LocalRecipeQueue3.Enqueue(data.RecipeCode);
  160. }
  161. }
  162. else if (LocalRecipeQueue4.Count == 0 && !LocalRecipeQueue1.Contains(data.RecipeCode) && !LocalRecipeQueue2.Contains(data.RecipeCode) && !LocalRecipeQueue3.Contains(data.RecipeCode) && HKDevice.PlcRead.IsAllowIssueRecipe4)
  163. {
  164. if (!(LocalRecipeQueue4.Contains(data.RecipeCode)))
  165. {
  166. LocalRecipeQueue4.Enqueue(data.RecipeCode);
  167. }
  168. }
  169. }
  170. }
  171. else
  172. {
  173. LocalRecipeQueue1.Clear();
  174. LocalRecipeQueue2.Clear();
  175. LocalRecipeQueue3.Clear();
  176. LocalRecipeQueue4.Clear();
  177. GVL_BigStation.BarrelWasherSign = false;
  178. GVL_BigStation.Recipe1DosingStatus = 0;
  179. GVL_BigStation.Recipe2DosingStatus = 0;
  180. GVL_BigStation.Recipe3DosingStatus = 0;
  181. GVL_BigStation.Recipe4DosingStatus = 0;
  182. }
  183. }
  184. private void LocalRecipeDosing()
  185. {
  186. if (LocalRecipeQueue1.Count > 0)
  187. {
  188. int index = Array.FindIndex(LocalRecipes.ToArray(), p => p.RecipeCode == LocalRecipeQueue1.ElementAt(0));
  189. if (index >= 0 && index < LocalRecipes.Count)
  190. {
  191. string code = LocalRecipes.ElementAt(index).RecipeCode;
  192. int trayCode = LocalRecipes.ElementAt(index).TrayCode;
  193. bool Inplace = false;
  194. switch (trayCode)
  195. {
  196. case 1:
  197. Inplace = HKDevice.PlcRead.Tray1InPlace;
  198. HKDevice.HK_PLC_S7.Write("DB99.DBX0.7", GVL_BigStation.AGVPutTray.GetBitValue(1));
  199. break;
  200. case 2:
  201. Inplace = HKDevice.PlcRead.Tray2InPlace;
  202. HKDevice.HK_PLC_S7.Write("DB99.DBX1.0", GVL_BigStation.AGVPutTray.GetBitValue(2));
  203. break;
  204. case 3:
  205. Inplace = HKDevice.PlcRead.Tray3InPlace;
  206. HKDevice.HK_PLC_S7.Write("DB99.DBX1.1", GVL_BigStation.AGVPutTray.GetBitValue(3));
  207. break;
  208. case 4:
  209. Inplace = HKDevice.PlcRead.Tray4InPlace;
  210. HKDevice.HK_PLC_S7.Write("DB99.DBX1.2", GVL_BigStation.AGVPutTray.GetBitValue(4));
  211. break;
  212. case 5:
  213. Inplace = HKDevice.PlcRead.Tray5InPlace;
  214. HKDevice.HK_PLC_S7.Write("DB99.DBX1.3", GVL_BigStation.AGVPutTray.GetBitValue(5));
  215. break;
  216. default:
  217. break;
  218. }
  219. if (HKDevice.PlcRead.IsAllowIssueRecipe1 && GVL_BigStation.Recipe1DosingStatus == 0 && Inplace)//配方1是否允许下发配发
  220. {
  221. if (LocalRecipes.ElementAt(index).IsWashingBarrel)
  222. {
  223. if (!GVL_BigStation.BarrelWasherSign)
  224. {
  225. GVL_BigStation.BarrelWasherSign = true;
  226. HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", true);//洗桶
  227. MessageNotify.GetInstance.ShowRunLog($"配方1,配方编号:{code},托盘编号:{trayCode},订单类型为洗桶");
  228. HKDevice.WritePlcRecipeData(LocalRecipes.ElementAt(index));
  229. HKDevice.HK_PLC_S7.Write("DB99.DBX0.3", true);
  230. GVL_BigStation.Recipe1DosingStatus = 1;
  231. MessageNotify.GetInstance.ShowRunLog($"配方1,配方编号:{code},托盘编号:{trayCode},下发完成");
  232. }
  233. }
  234. else
  235. {
  236. HKDevice.WritePlcRecipeData(LocalRecipes.ElementAt(index));
  237. HKDevice.HK_PLC_S7.Write("DB99.DBX0.3", true);
  238. GVL_BigStation.Recipe1DosingStatus = 1;
  239. MessageNotify.GetInstance.ShowRunLog($"配方1,配方编号:{code},托盘编号:{trayCode},下发完成");
  240. }
  241. }
  242. if (HKDevice.PlcRead.ReceiveFinishRecipe1 && GVL_BigStation.Recipe1DosingStatus == 1)
  243. {
  244. if (LocalRecipes.ElementAt(index).IsWashingBarrel)
  245. {
  246. HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", false);//洗桶复位
  247. MessageNotify.GetInstance.ShowRunLog($"配方1,配方编号:{code},托盘编号:{trayCode},洗桶信号复位");
  248. }
  249. HKDevice.HK_PLC_S7.Write("DB99.DBX0.3", false);
  250. StockBinParReset();
  251. GVL_BigStation.Recipe1DosingStatus = 2;
  252. MessageNotify.GetInstance.ShowRunLog($"配方1,配方编号:{code},托盘编号:{trayCode},PLC接收配方完成");
  253. }
  254. if (GVL_BigStation.Recipe1DosingStatus == 2 && HKDevice.PlcRead.Recipe1DosingFinish)
  255. {
  256. if (LocalRecipes.ElementAt(index).IsWashingBarrel)
  257. {
  258. GVL_BigStation.BarrelWasherSign = false;
  259. }
  260. GVL_BigStation.Recipe1DosingStatus = 3;
  261. switch (trayCode)
  262. {
  263. case 1:
  264. HKDevice.HK_PLC_S7.Write("DB99.DBX0.7", false);
  265. break;
  266. case 2:
  267. HKDevice.HK_PLC_S7.Write("DB99.DBX1.0", false);
  268. break;
  269. case 3:
  270. HKDevice.HK_PLC_S7.Write("DB99.DBX1.1", false);
  271. break;
  272. case 4:
  273. HKDevice.HK_PLC_S7.Write("DB99.DBX1.2", false);
  274. break;
  275. case 5:
  276. HKDevice.HK_PLC_S7.Write("DB99.DBX1.3", false);
  277. break;
  278. default:
  279. break;
  280. }
  281. MessageNotify.GetInstance.ShowRunLog($"配方1,配方编号:{code},托盘编号:{trayCode},配料完成");
  282. foreach (var item in LocalRecipes.ElementAt(index).RawMaterial)
  283. {
  284. if (item.RawMaterialLocation == 1)
  285. {
  286. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin1ActualWeight;
  287. }
  288. else if (item.RawMaterialLocation == 2)
  289. {
  290. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin2ActualWeight;
  291. }
  292. else if (item.RawMaterialLocation == 3)
  293. {
  294. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin3ActualWeight;
  295. }
  296. else if (item.RawMaterialLocation == 4)
  297. {
  298. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin4ActualWeight;
  299. }
  300. else if (item.RawMaterialLocation == 5)
  301. {
  302. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin5ActualWeight;
  303. }
  304. else if (item.RawMaterialLocation == 6)
  305. {
  306. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin6ActualWeight;
  307. }
  308. else if (item.RawMaterialLocation == 7)
  309. {
  310. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin7ActualWeight;
  311. }
  312. else if (item.RawMaterialLocation == 8)
  313. {
  314. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin8ActualWeight;
  315. }
  316. else if (item.RawMaterialLocation == 9)
  317. {
  318. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin9ActualWeight;
  319. }
  320. else if (item.RawMaterialLocation == 10)
  321. {
  322. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin10ActualWeight;
  323. }
  324. else if (item.RawMaterialLocation == 11)
  325. {
  326. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin11ActualWeight;
  327. }
  328. else if (item.RawMaterialLocation == 12)
  329. {
  330. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin12ActualWeight;
  331. }
  332. else if (item.RawMaterialLocation == 13)
  333. {
  334. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin13ActualWeight;
  335. }
  336. else if (item.RawMaterialLocation == 14)
  337. {
  338. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin14ActualWeight;
  339. }
  340. }
  341. LocalRecipeQueue1.TryDequeue(out code);
  342. //App.Current.Dispatcher.Invoke(() => {
  343. // Json<LocalRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
  344. //});
  345. LocalRecipes.RemoveAt(index);
  346. GVL_BigStation.Recipe1DosingStatus = 0;
  347. }
  348. }
  349. }
  350. if (LocalRecipeQueue2.Count > 0)
  351. {
  352. int index = Array.FindIndex(LocalRecipes.ToArray(), p => p.RecipeCode == LocalRecipeQueue2.ElementAt(0));
  353. if (index >= 0 && index < LocalRecipes.Count)
  354. {
  355. string code = LocalRecipes.ElementAt(index).RecipeCode;
  356. int trayCode = LocalRecipes.ElementAt(index).TrayCode;
  357. bool Inplace = false;
  358. switch (trayCode)
  359. {
  360. case 1:
  361. Inplace = HKDevice.PlcRead.Tray1InPlace;
  362. HKDevice.HK_PLC_S7.Write("DB99.DBX0.7", GVL_BigStation.AGVPutTray.GetBitValue(1));
  363. break;
  364. case 2:
  365. Inplace = HKDevice.PlcRead.Tray2InPlace;
  366. HKDevice.HK_PLC_S7.Write("DB99.DBX1.0", GVL_BigStation.AGVPutTray.GetBitValue(2));
  367. break;
  368. case 3:
  369. Inplace = HKDevice.PlcRead.Tray3InPlace;
  370. HKDevice.HK_PLC_S7.Write("DB99.DBX1.1", GVL_BigStation.AGVPutTray.GetBitValue(3));
  371. break;
  372. case 4:
  373. Inplace = HKDevice.PlcRead.Tray4InPlace;
  374. HKDevice.HK_PLC_S7.Write("DB99.DBX1.2", GVL_BigStation.AGVPutTray.GetBitValue(4));
  375. break;
  376. case 5:
  377. Inplace = HKDevice.PlcRead.Tray5InPlace;
  378. HKDevice.HK_PLC_S7.Write("DB99.DBX1.3", GVL_BigStation.AGVPutTray.GetBitValue(5));
  379. break;
  380. default:
  381. break;
  382. }
  383. if (HKDevice.PlcRead.IsAllowIssueRecipe2 && GVL_BigStation.Recipe2DosingStatus == 0 && Inplace)//配方2是否允许下发配发
  384. {
  385. if (LocalRecipes.ElementAt(index).IsWashingBarrel)
  386. {
  387. if (!GVL_BigStation.BarrelWasherSign)
  388. {
  389. GVL_BigStation.BarrelWasherSign = true;
  390. HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", true);//洗桶
  391. MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},订单类型为洗桶");
  392. HKDevice.WritePlcRecipeData(LocalRecipes.ElementAt(index));
  393. HKDevice.HK_PLC_S7.Write("DB99.DBX0.4", true);
  394. GVL_BigStation.Recipe2DosingStatus = 1;
  395. MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}下发完成");
  396. }
  397. }
  398. else
  399. {
  400. HKDevice.WritePlcRecipeData(LocalRecipes.ElementAt(index));
  401. HKDevice.HK_PLC_S7.Write("DB99.DBX0.4", true);
  402. GVL_BigStation.Recipe2DosingStatus = 1;
  403. MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}下发完成");
  404. }
  405. }
  406. if (HKDevice.PlcRead.ReceiveFinishRecipe2 && GVL_BigStation.Recipe2DosingStatus == 1)
  407. {
  408. if (LocalRecipes.ElementAt(index).IsWashingBarrel)
  409. {
  410. HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", false);//洗桶复位
  411. MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},洗桶信号复位");
  412. }
  413. GVL_BigStation.Recipe2DosingStatus = 2;
  414. HKDevice.HK_PLC_S7.Write("DB99.DBX0.4", false);
  415. StockBinParReset();
  416. MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}配方配料");
  417. }
  418. if (GVL_BigStation.Recipe2DosingStatus == 2 && HKDevice.PlcRead.Recipe2DosingFinish)
  419. {
  420. if (LocalRecipes.ElementAt(index).IsWashingBarrel)
  421. {
  422. GVL_BigStation.BarrelWasherSign = false;
  423. }
  424. switch (trayCode)
  425. {
  426. case 1:
  427. HKDevice.HK_PLC_S7.Write("DB99.DBX0.7", false);
  428. break;
  429. case 2:
  430. HKDevice.HK_PLC_S7.Write("DB99.DBX1.0", false);
  431. break;
  432. case 3:
  433. HKDevice.HK_PLC_S7.Write("DB99.DBX1.1", false);
  434. break;
  435. case 4:
  436. HKDevice.HK_PLC_S7.Write("DB99.DBX1.2", false);
  437. break;
  438. case 5:
  439. HKDevice.HK_PLC_S7.Write("DB99.DBX1.3", false);
  440. break;
  441. default:
  442. break;
  443. }
  444. GVL_BigStation.Recipe2DosingStatus = 3;
  445. MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}配料完成");
  446. foreach (var item in LocalRecipes.ElementAt(index).RawMaterial)
  447. {
  448. if (item.RawMaterialLocation == 1)
  449. {
  450. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin1ActualWeight;
  451. }
  452. else if (item.RawMaterialLocation == 2)
  453. {
  454. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin2ActualWeight;
  455. }
  456. else if (item.RawMaterialLocation == 3)
  457. {
  458. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin3ActualWeight;
  459. }
  460. else if (item.RawMaterialLocation == 4)
  461. {
  462. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin4ActualWeight;
  463. }
  464. else if (item.RawMaterialLocation == 5)
  465. {
  466. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin5ActualWeight;
  467. }
  468. else if (item.RawMaterialLocation == 6)
  469. {
  470. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin6ActualWeight;
  471. }
  472. else if (item.RawMaterialLocation == 7)
  473. {
  474. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin7ActualWeight;
  475. }
  476. else if (item.RawMaterialLocation == 8)
  477. {
  478. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin8ActualWeight;
  479. }
  480. else if (item.RawMaterialLocation == 9)
  481. {
  482. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin9ActualWeight;
  483. }
  484. else if (item.RawMaterialLocation == 10)
  485. {
  486. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin10ActualWeight;
  487. }
  488. else if (item.RawMaterialLocation == 11)
  489. {
  490. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin11ActualWeight;
  491. }
  492. else if (item.RawMaterialLocation == 12)
  493. {
  494. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin12ActualWeight;
  495. }
  496. else if (item.RawMaterialLocation == 13)
  497. {
  498. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin13ActualWeight;
  499. }
  500. else if (item.RawMaterialLocation == 14)
  501. {
  502. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin14ActualWeight;
  503. }
  504. }
  505. LocalRecipeQueue2.TryDequeue(out code);
  506. LocalRecipes.RemoveAt(index);
  507. GVL_BigStation.Recipe2DosingStatus = 0;
  508. }
  509. }
  510. }
  511. if (LocalRecipeQueue3.Count > 0)
  512. {
  513. int index = Array.FindIndex(LocalRecipes.ToArray(), p => p.RecipeCode == LocalRecipeQueue3.ElementAt(0));
  514. if (index >= 0 && index < LocalRecipes.Count)
  515. {
  516. string code = LocalRecipes.ElementAt(index).RecipeCode;
  517. int trayCode = LocalRecipes.ElementAt(index).TrayCode;
  518. bool Inplace = false;
  519. switch (trayCode)
  520. {
  521. case 1:
  522. Inplace = HKDevice.PlcRead.Tray1InPlace;
  523. HKDevice.HK_PLC_S7.Write("DB99.DBX0.7", GVL_BigStation.AGVPutTray.GetBitValue(1));
  524. break;
  525. case 2:
  526. Inplace = HKDevice.PlcRead.Tray2InPlace;
  527. HKDevice.HK_PLC_S7.Write("DB99.DBX1.0", GVL_BigStation.AGVPutTray.GetBitValue(2));
  528. break;
  529. case 3:
  530. Inplace = HKDevice.PlcRead.Tray3InPlace;
  531. HKDevice.HK_PLC_S7.Write("DB99.DBX1.1", GVL_BigStation.AGVPutTray.GetBitValue(3));
  532. break;
  533. case 4:
  534. Inplace = HKDevice.PlcRead.Tray4InPlace;
  535. HKDevice.HK_PLC_S7.Write("DB99.DBX1.2", GVL_BigStation.AGVPutTray.GetBitValue(4));
  536. break;
  537. case 5:
  538. Inplace = HKDevice.PlcRead.Tray5InPlace;
  539. HKDevice.HK_PLC_S7.Write("DB99.DBX1.3", GVL_BigStation.AGVPutTray.GetBitValue(5));
  540. break;
  541. default:
  542. break;
  543. }
  544. if (HKDevice.PlcRead.IsAllowIssueRecipe3 && GVL_BigStation.Recipe3DosingStatus == 0 && Inplace)//配方3是否允许下发配发
  545. {
  546. if (LocalRecipes.ElementAt(index).IsWashingBarrel)
  547. {
  548. if (!GVL_BigStation.BarrelWasherSign)
  549. {
  550. GVL_BigStation.BarrelWasherSign = true;
  551. HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", true);//洗桶
  552. MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},订单类型为洗桶");
  553. HKDevice.WritePlcRecipeData(LocalRecipes.ElementAt(index));
  554. HKDevice.HK_PLC_S7.Write("DB99.DBX0.5", true);
  555. GVL_BigStation.Recipe3DosingStatus = 1;
  556. MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}下发完成");
  557. }
  558. }
  559. else
  560. {
  561. HKDevice.WritePlcRecipeData(LocalRecipes.ElementAt(index));
  562. HKDevice.HK_PLC_S7.Write("DB99.DBX0.5", true);
  563. GVL_BigStation.Recipe3DosingStatus = 1;
  564. MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}下发完成");
  565. }
  566. }
  567. if (HKDevice.PlcRead.ReceiveFinishRecipe3 && GVL_BigStation.Recipe3DosingStatus == 1)
  568. {
  569. if (LocalRecipes.ElementAt(index).IsWashingBarrel)
  570. {
  571. HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", false);//洗桶复位
  572. MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},洗桶信号复位");
  573. }
  574. GVL_BigStation.Recipe3DosingStatus = 2;
  575. HKDevice.HK_PLC_S7.Write("DB99.DBX0.5", false);
  576. StockBinParReset();
  577. MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}配方配料");
  578. }
  579. if (HKDevice.PlcRead.Recipe3DosingFinish && GVL_BigStation.Recipe3DosingStatus == 2)
  580. {
  581. if (LocalRecipes.ElementAt(index).IsWashingBarrel)
  582. {
  583. GVL_BigStation.BarrelWasherSign = false;
  584. }
  585. switch (trayCode)
  586. {
  587. case 1:
  588. HKDevice.HK_PLC_S7.Write("DB99.DBX0.7", false);
  589. break;
  590. case 2:
  591. HKDevice.HK_PLC_S7.Write("DB99.DBX1.0", false);
  592. break;
  593. case 3:
  594. HKDevice.HK_PLC_S7.Write("DB99.DBX1.1", false);
  595. break;
  596. case 4:
  597. HKDevice.HK_PLC_S7.Write("DB99.DBX1.2", false);
  598. break;
  599. case 5:
  600. HKDevice.HK_PLC_S7.Write("DB99.DBX1.3", false);
  601. break;
  602. default:
  603. break;
  604. }
  605. GVL_BigStation.Recipe3DosingStatus = 3;
  606. MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}配料完成");
  607. foreach (var item in LocalRecipes.ElementAt(index).RawMaterial)
  608. {
  609. if (item.RawMaterialLocation == 1)
  610. {
  611. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin1ActualWeight;
  612. }
  613. else if (item.RawMaterialLocation == 2)
  614. {
  615. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin2ActualWeight;
  616. }
  617. else if (item.RawMaterialLocation == 3)
  618. {
  619. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin3ActualWeight;
  620. }
  621. else if (item.RawMaterialLocation == 4)
  622. {
  623. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin4ActualWeight;
  624. }
  625. else if (item.RawMaterialLocation == 5)
  626. {
  627. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin5ActualWeight;
  628. }
  629. else if (item.RawMaterialLocation == 6)
  630. {
  631. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin6ActualWeight;
  632. }
  633. else if (item.RawMaterialLocation == 7)
  634. {
  635. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin7ActualWeight;
  636. }
  637. else if (item.RawMaterialLocation == 8)
  638. {
  639. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin8ActualWeight;
  640. }
  641. else if (item.RawMaterialLocation == 9)
  642. {
  643. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin9ActualWeight;
  644. }
  645. else if (item.RawMaterialLocation == 10)
  646. {
  647. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin10ActualWeight;
  648. }
  649. else if (item.RawMaterialLocation == 11)
  650. {
  651. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin11ActualWeight;
  652. }
  653. else if (item.RawMaterialLocation == 12)
  654. {
  655. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin12ActualWeight;
  656. }
  657. else if (item.RawMaterialLocation == 13)
  658. {
  659. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin13ActualWeight;
  660. }
  661. else if (item.RawMaterialLocation == 14)
  662. {
  663. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin14ActualWeight;
  664. }
  665. }
  666. HKDevice.HK_PLC_S7.Write<bool>("DB98.DBX1.1", false);
  667. LocalRecipeQueue3.TryDequeue(out code);
  668. LocalRecipes.RemoveAt(index);
  669. GVL_BigStation.Recipe3DosingStatus = 0;
  670. }
  671. }
  672. }
  673. if (LocalRecipeQueue4.Count > 0)
  674. {
  675. int index = Array.FindIndex(LocalRecipes.ToArray(), p => p.RecipeCode == LocalRecipeQueue4.ElementAt(0));
  676. if (index >= 0 && index < LocalRecipes.Count)
  677. {
  678. string code = LocalRecipes.ElementAt(index).RecipeCode;
  679. int trayCode = LocalRecipes.ElementAt(index).TrayCode;
  680. bool Inplace = false;
  681. switch (trayCode)
  682. {
  683. case 1:
  684. Inplace = HKDevice.PlcRead.Tray1InPlace;
  685. HKDevice.HK_PLC_S7.Write("DB99.DBX0.7", GVL_BigStation.AGVPutTray.GetBitValue(1));
  686. break;
  687. case 2:
  688. Inplace = HKDevice.PlcRead.Tray2InPlace;
  689. HKDevice.HK_PLC_S7.Write("DB99.DBX1.0", GVL_BigStation.AGVPutTray.GetBitValue(2));
  690. break;
  691. case 3:
  692. Inplace = HKDevice.PlcRead.Tray3InPlace;
  693. HKDevice.HK_PLC_S7.Write("DB99.DBX1.1", GVL_BigStation.AGVPutTray.GetBitValue(3));
  694. break;
  695. case 4:
  696. Inplace = HKDevice.PlcRead.Tray4InPlace;
  697. HKDevice.HK_PLC_S7.Write("DB99.DBX1.2", GVL_BigStation.AGVPutTray.GetBitValue(4));
  698. break;
  699. case 5:
  700. Inplace = HKDevice.PlcRead.Tray5InPlace;
  701. HKDevice.HK_PLC_S7.Write("DB99.DBX1.3", GVL_BigStation.AGVPutTray.GetBitValue(5));
  702. break;
  703. default:
  704. break;
  705. }
  706. if (HKDevice.PlcRead.IsAllowIssueRecipe4 && GVL_BigStation.Recipe4DosingStatus == 0 && Inplace)//配方4是否允许下发配发
  707. {
  708. if (LocalRecipes.ElementAt(index).IsWashingBarrel)
  709. {
  710. if (!GVL_BigStation.BarrelWasherSign)
  711. {
  712. GVL_BigStation.BarrelWasherSign = true;
  713. HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", true);//洗桶
  714. MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},订单类型为洗桶");
  715. HKDevice.WritePlcRecipeData(LocalRecipes.ElementAt(index));
  716. HKDevice.HK_PLC_S7.Write("DB99.DBX0.6", true);
  717. GVL_BigStation.Recipe4DosingStatus = 1;
  718. MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}下发完成");
  719. }
  720. }
  721. else
  722. {
  723. HKDevice.WritePlcRecipeData(LocalRecipes.ElementAt(index));
  724. HKDevice.HK_PLC_S7.Write("DB99.DBX0.6", true);
  725. GVL_BigStation.Recipe4DosingStatus = 1;
  726. MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}下发完成");
  727. }
  728. }
  729. if (HKDevice.PlcRead.ReceiveFinishRecipe4 && GVL_BigStation.Recipe4DosingStatus == 1)
  730. {
  731. if (LocalRecipes.ElementAt(index).IsWashingBarrel)
  732. {
  733. HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", false);//洗桶复位
  734. MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},洗桶信号复位");
  735. }
  736. GVL_BigStation.Recipe4DosingStatus = 2;
  737. HKDevice.HK_PLC_S7.Write("DB99.DBX0.6", false);
  738. StockBinParReset();
  739. MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}配方配料");
  740. }
  741. if (GVL_BigStation.Recipe4DosingStatus == 2 && HKDevice.PlcRead.Recipe4DosingFinish)
  742. {
  743. if (LocalRecipes.ElementAt(index).IsWashingBarrel)
  744. {
  745. GVL_BigStation.BarrelWasherSign = false;
  746. }
  747. switch (trayCode)
  748. {
  749. case 1:
  750. HKDevice.HK_PLC_S7.Write("DB99.DBX0.7", false);
  751. break;
  752. case 2:
  753. HKDevice.HK_PLC_S7.Write("DB99.DBX1.0", false);
  754. break;
  755. case 3:
  756. HKDevice.HK_PLC_S7.Write("DB99.DBX1.1", false);
  757. break;
  758. case 4:
  759. HKDevice.HK_PLC_S7.Write("DB99.DBX1.2", false);
  760. break;
  761. case 5:
  762. HKDevice.HK_PLC_S7.Write("DB99.DBX1.3", false);
  763. break;
  764. default:
  765. break;
  766. }
  767. GVL_BigStation.Recipe4DosingStatus = 3;
  768. MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}配料完成");
  769. foreach (var item in LocalRecipes.ElementAt(index).RawMaterial)
  770. {
  771. if (item.RawMaterialLocation == 1)
  772. {
  773. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin1ActualWeight;
  774. }
  775. else if (item.RawMaterialLocation == 2)
  776. {
  777. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin2ActualWeight;
  778. }
  779. else if (item.RawMaterialLocation == 3)
  780. {
  781. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin3ActualWeight;
  782. }
  783. else if (item.RawMaterialLocation == 4)
  784. {
  785. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin4ActualWeight;
  786. }
  787. else if (item.RawMaterialLocation == 5)
  788. {
  789. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin5ActualWeight;
  790. }
  791. else if (item.RawMaterialLocation == 6)
  792. {
  793. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin6ActualWeight;
  794. }
  795. else if (item.RawMaterialLocation == 7)
  796. {
  797. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin7ActualWeight;
  798. }
  799. else if (item.RawMaterialLocation == 8)
  800. {
  801. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin8ActualWeight;
  802. }
  803. else if (item.RawMaterialLocation == 9)
  804. {
  805. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin9ActualWeight;
  806. }
  807. else if (item.RawMaterialLocation == 10)
  808. {
  809. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin10ActualWeight;
  810. }
  811. else if (item.RawMaterialLocation == 11)
  812. {
  813. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin11ActualWeight;
  814. }
  815. else if (item.RawMaterialLocation == 12)
  816. {
  817. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin12ActualWeight;
  818. }
  819. else if (item.RawMaterialLocation == 13)
  820. {
  821. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin13ActualWeight;
  822. }
  823. else if (item.RawMaterialLocation == 14)
  824. {
  825. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin14ActualWeight;
  826. }
  827. }
  828. HKDevice.HK_PLC_S7.Write<bool>("DB98.DBX1.3", false);
  829. LocalRecipeQueue4.TryDequeue(out code);
  830. LocalRecipes.RemoveAt(index);
  831. GVL_BigStation.Recipe4DosingStatus = 0;
  832. }
  833. }
  834. }
  835. }
  836. #endregion
  837. /// <summary>
  838. /// 将西门子配方,添加到队列中
  839. /// </summary>
  840. private void ReceviceData()
  841. {
  842. SiemensRecipes = Json<RemoteRecipe>.Data.Recipes;
  843. if (SiemensRecipes.Count > 0)
  844. {
  845. foreach (var data in SiemensRecipes)
  846. {
  847. if (data.RecipesSource == RecipeSource.远程)
  848. {
  849. if (SiemensRecipeQueue1.Count == 0 && !SiemensRecipeQueue2.Contains(data.RecipeCode) && !SiemensRecipeQueue3.Contains(data.RecipeCode) && !SiemensRecipeQueue4.Contains(data.RecipeCode) && HKDevice.PlcRead.IsAllowIssueRecipe1 && data.TrayCode == 1)
  850. {
  851. if (!(SiemensRecipeQueue1.Contains(data.RecipeCode)))
  852. {
  853. if (SiemensDevice.DL_Status is DL_Status_DB status)
  854. {
  855. switch (GVL_BigStation.SiemensSendRecipeStatus)
  856. {
  857. case 3:
  858. SiemensDevice.Siemens_PLC_S7.WriteString(2331, data.RecipeCode, 10);
  859. SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", true);
  860. MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方:【{data.RecipeCode}】发送配方编号和请求配料标志给西门子");
  861. GVL_BigStation.SiemensSendRecipeStatus = 4;
  862. break;
  863. case 4:
  864. if (SiemensDevice.DL_Status.Dosing_Start_ACK)
  865. {
  866. SiemensDevice.Siemens_PLC_S7.WriteString(2331, "", 10);
  867. SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", false);
  868. MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方:【{data.RecipeCode}】西门子确认开始配料");
  869. GVL_BigStation.SiemensSendRecipeStatus = 5;
  870. }
  871. break;
  872. case 5:
  873. if (SiemensDevice.DL_Status.Dosing_Start_ACK == false)
  874. {
  875. SiemensRecipeQueue1.Enqueue(data.RecipeCode);
  876. MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方:【{data.RecipeCode}】,加入队列");
  877. GVL_BigStation.SiemensSendRecipeStatus = 0;
  878. }
  879. break;
  880. default:
  881. break;
  882. }
  883. }
  884. }
  885. }
  886. else if (SiemensRecipeQueue2.Count == 0 && !SiemensRecipeQueue1.Contains(data.RecipeCode) && !SiemensRecipeQueue3.Contains(data.RecipeCode) && !SiemensRecipeQueue4.Contains(data.RecipeCode) && HKDevice.PlcRead.IsAllowIssueRecipe2 && data.TrayCode == 2)
  887. {
  888. if (!(SiemensRecipeQueue2.Contains(data.RecipeCode)))
  889. {
  890. if (SiemensDevice.DL_Status is DL_Status_DB status)
  891. {
  892. if (GVL_BigStation.SiemensSendRecipeStatus == 3)
  893. {
  894. SiemensDevice.Siemens_PLC_S7.WriteString(2331, data.RecipeCode, 10);
  895. SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", true);
  896. MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方:【{data.RecipeCode}】发送配方编号和请求配料标志给西门子");
  897. GVL_BigStation.SiemensSendRecipeStatus = 4;
  898. }
  899. if (GVL_BigStation.SiemensSendRecipeStatus == 4)
  900. {
  901. if (SiemensDevice.DL_Status.Dosing_Start_ACK)
  902. {
  903. SiemensDevice.Siemens_PLC_S7.WriteString(2331, "", 10);
  904. SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", false);
  905. MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方:【{data.RecipeCode}】西门子确认开始配料");
  906. GVL_BigStation.SiemensSendRecipeStatus = 5;
  907. }
  908. }
  909. if (GVL_BigStation.SiemensSendRecipeStatus == 5)
  910. {
  911. if (SiemensDevice.DL_Status.Dosing_Start_ACK == false)
  912. {
  913. SiemensRecipeQueue2.Enqueue(data.RecipeCode);
  914. MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方:【{data.RecipeCode}】,加入队列");
  915. GVL_BigStation.SiemensSendRecipeStatus = 0;
  916. }
  917. }
  918. }
  919. }
  920. }
  921. else if (SiemensRecipeQueue3.Count == 0 && !SiemensRecipeQueue1.Contains(data.RecipeCode) && !SiemensRecipeQueue2.Contains(data.RecipeCode) && !SiemensRecipeQueue4.Contains(data.RecipeCode) && HKDevice.PlcRead.IsAllowIssueRecipe3 && data.TrayCode == 3)
  922. {
  923. if (!(SiemensRecipeQueue3.Contains(data.RecipeCode)))
  924. {
  925. if (SiemensDevice.DL_Status is DL_Status_DB status)
  926. {
  927. if (GVL_BigStation.SiemensSendRecipeStatus == 3)
  928. {
  929. SiemensDevice.Siemens_PLC_S7.WriteString(2331, data.RecipeCode, 10);
  930. SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", true);
  931. MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方:【{data.RecipeCode}】发送配方编号和请求配料标志给西门子");
  932. GVL_BigStation.SiemensSendRecipeStatus = 4;
  933. }
  934. if (GVL_BigStation.SiemensSendRecipeStatus == 4)
  935. {
  936. if (SiemensDevice.DL_Status.Dosing_Start_ACK)
  937. {
  938. SiemensDevice.Siemens_PLC_S7.WriteString(2331, "", 10);
  939. SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", false);
  940. MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方:【{data.RecipeCode}】西门子确认开始配料");
  941. GVL_BigStation.SiemensSendRecipeStatus = 5;
  942. }
  943. }
  944. if (GVL_BigStation.SiemensSendRecipeStatus == 5)
  945. {
  946. if (SiemensDevice.DL_Status.Dosing_Start_ACK == false)
  947. {
  948. SiemensRecipeQueue3.Enqueue(data.RecipeCode);
  949. MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方:【{data.RecipeCode}】,加入队列");
  950. GVL_BigStation.SiemensSendRecipeStatus = 0;
  951. }
  952. }
  953. }
  954. }
  955. }
  956. else if (SiemensRecipeQueue4.Count == 0 && !SiemensRecipeQueue1.Contains(data.RecipeCode) && !SiemensRecipeQueue2.Contains(data.RecipeCode) && !SiemensRecipeQueue3.Contains(data.RecipeCode) && HKDevice.PlcRead.IsAllowIssueRecipe4 && data.TrayCode == 4)
  957. {
  958. if (!(SiemensRecipeQueue4.Contains(data.RecipeCode)))
  959. {
  960. if (SiemensDevice.DL_Status is DL_Status_DB status)
  961. {
  962. if (GVL_BigStation.SiemensSendRecipeStatus == 3)
  963. {
  964. SiemensDevice.Siemens_PLC_S7.WriteString(2331, data.RecipeCode, 10);
  965. SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", true);
  966. MessageNotify.GetInstance.ShowRunLog($"配方4,配方:【{data.RecipeCode}】发送配方编号和请求配料标志给西门子");
  967. GVL_BigStation.SiemensSendRecipeStatus = 4;
  968. }
  969. if (GVL_BigStation.SiemensSendRecipeStatus == 4)
  970. {
  971. if (SiemensDevice.DL_Status.Dosing_Start_ACK)
  972. {
  973. SiemensDevice.Siemens_PLC_S7.WriteString(2331, "", 10);
  974. SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", false);
  975. MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方:【{data.RecipeCode}】西门子确认开始配料");
  976. GVL_BigStation.SiemensSendRecipeStatus = 5;
  977. }
  978. }
  979. if (GVL_BigStation.SiemensSendRecipeStatus == 5)
  980. {
  981. if (SiemensDevice.DL_Status.Dosing_Start_ACK == false)
  982. {
  983. SiemensRecipeQueue4.Enqueue(data.RecipeCode);
  984. MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方:【{data.RecipeCode}】,加入队列");
  985. GVL_BigStation.SiemensSendRecipeStatus = 0;
  986. }
  987. }
  988. }
  989. }
  990. }
  991. }
  992. else
  993. {
  994. if (SiemensRecipeQueue1.Count == 0 && !SiemensRecipeQueue2.Contains(data.RecipeCode) && !SiemensRecipeQueue3.Contains(data.RecipeCode) && !SiemensRecipeQueue4.Contains(data.RecipeCode) && HKDevice.PlcRead.IsAllowIssueRecipe1 && data.TrayCode == 1)
  995. {
  996. SiemensRecipeQueue1.Enqueue(data.RecipeCode);
  997. MessageNotify.GetInstance.ShowRunLog($"本地配方,配方:【{data.RecipeCode}】,加入队列【1】");
  998. }
  999. else if (SiemensRecipeQueue2.Count == 0 && !SiemensRecipeQueue1.Contains(data.RecipeCode) && !SiemensRecipeQueue3.Contains(data.RecipeCode) && !SiemensRecipeQueue4.Contains(data.RecipeCode) && HKDevice.PlcRead.IsAllowIssueRecipe2 && data.TrayCode == 2)
  1000. {
  1001. SiemensRecipeQueue2.Enqueue(data.RecipeCode);
  1002. MessageNotify.GetInstance.ShowRunLog($"本地配方,配方:【{data.RecipeCode}】,加入队列【2】");
  1003. }
  1004. else if (SiemensRecipeQueue3.Count == 0 && !SiemensRecipeQueue1.Contains(data.RecipeCode) && !SiemensRecipeQueue2.Contains(data.RecipeCode) && !SiemensRecipeQueue4.Contains(data.RecipeCode) && HKDevice.PlcRead.IsAllowIssueRecipe3 && data.TrayCode == 3)
  1005. {
  1006. SiemensRecipeQueue3.Enqueue(data.RecipeCode);
  1007. MessageNotify.GetInstance.ShowRunLog($"本地配方,配方:【{data.RecipeCode}】,加入队列【3】");
  1008. }
  1009. else if (SiemensRecipeQueue4.Count == 0 && !SiemensRecipeQueue1.Contains(data.RecipeCode) && !SiemensRecipeQueue2.Contains(data.RecipeCode) && !SiemensRecipeQueue3.Contains(data.RecipeCode) && HKDevice.PlcRead.IsAllowIssueRecipe4 && data.TrayCode == 4)
  1010. {
  1011. SiemensRecipeQueue4.Enqueue(data.RecipeCode);
  1012. MessageNotify.GetInstance.ShowRunLog($"本地配方,配方:【{data.RecipeCode}】,加入队列【4】");
  1013. }
  1014. }
  1015. }
  1016. }
  1017. else
  1018. {
  1019. SiemensRecipeQueue1.Clear();
  1020. SiemensRecipeQueue2.Clear();
  1021. SiemensRecipeQueue3.Clear();
  1022. SiemensRecipeQueue4.Clear();
  1023. GVL_BigStation.BarrelWasherSign = false;
  1024. GVL_BigStation.Recipe1DosingStatus = 0;
  1025. GVL_BigStation.Recipe2DosingStatus = 0;
  1026. GVL_BigStation.Recipe3DosingStatus = 0;
  1027. GVL_BigStation.Recipe4DosingStatus = 0;
  1028. }
  1029. }
  1030. /// <summary>
  1031. /// 订单取消
  1032. /// </summary>
  1033. public void Order_Cancel()
  1034. {
  1035. if (GVL_BigStation.Order_Cancel) //订单取消
  1036. {
  1037. if (!string.IsNullOrEmpty(GVL_BigStation.Order_CancelRecipeCode))
  1038. {
  1039. string code = GVL_BigStation.Order_CancelRecipeCode;
  1040. int index = Array.FindIndex(Json<RemoteRecipe>.Data.Recipes.ToArray(), p => p.RecipeCode == GVL_BigStation.Order_CancelRecipeCode);
  1041. short TrayCode = 0;
  1042. if (index >= 0)
  1043. {
  1044. TrayCode = (short)Json<RemoteRecipe>.Data.Recipes.ElementAt(index).TrayCode;
  1045. }
  1046. switch (GVL_BigStation.Order_CancelStep)
  1047. {
  1048. case 0:
  1049. if (index == -1)
  1050. {
  1051. GVL_BigStation.Order_CancelStep = 10;
  1052. }
  1053. else
  1054. {
  1055. if (SiemensRecipeQueue1.Contains(code) || SiemensRecipeQueue2.Contains(code) || SiemensRecipeQueue3.Contains(code) || SiemensRecipeQueue4.Contains(code))
  1056. {
  1057. GVL_BigStation.Order_CancelStep = 30;
  1058. }
  1059. else
  1060. {
  1061. GVL_BigStation.Order_CancelStep = 20;
  1062. }
  1063. //以下为新增,复位DB99托盘号,配方号,桶重量参数,以及配方下发确认和配料完成。
  1064. StockBinParReset();
  1065. }
  1066. break;
  1067. case 10:
  1068. SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", true);
  1069. GVL_BigStation.Order_CancelStep = 11;
  1070. break;
  1071. case 11:
  1072. if (SiemensDevice.Siemens_PLC_S7.Read<bool>("DB2301.DBX320.2") == false)
  1073. {
  1074. SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", false);
  1075. GVL_BigStation.Order_CancelStep = 12;
  1076. }
  1077. break;
  1078. case 12:
  1079. MessageNotify.GetInstance.ShowRunLog($"西门子取消订单,但未找到订单:【{GVL_BigStation.Order_CancelRecipeCode}】");
  1080. GVL_BigStation.Order_Cancel = false;
  1081. GVL_BigStation.Order_CancelRecipeCode = "";
  1082. GVL_BigStation.Order_CancelStep = 0;
  1083. break;
  1084. case 20:
  1085. SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", true);
  1086. GVL_BigStation.Order_CancelStep = 21;
  1087. break;
  1088. case 21:
  1089. if (SiemensDevice.Siemens_PLC_S7.Read<bool>("DB2301.DBX320.2") == false)
  1090. {
  1091. SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", false);
  1092. GVL_BigStation.Order_CancelStep = 22;
  1093. }
  1094. break;
  1095. case 22:
  1096. GVL_BigStation.SiemensSendRecipeStatus = 0;
  1097. App.Current.Dispatcher.Invoke(() =>
  1098. {
  1099. Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);
  1100. });
  1101. MessageNotify.GetInstance.ShowRunLog($"正在执行请求取消订单流程,配方还未到PLC,订单号:【{GVL_BigStation.Order_CancelRecipeCode}】");
  1102. GVL_BigStation.Order_Cancel = false;
  1103. GVL_BigStation.Order_CancelRecipeCode = "";
  1104. GVL_BigStation.Order_CancelStep = 0;
  1105. break;
  1106. case 30:
  1107. if (SiemensRecipeQueue1.Contains(code))
  1108. {
  1109. GVL_BigStation.Order_CancelStep = 31;
  1110. }
  1111. else if (SiemensRecipeQueue2.Contains(code))
  1112. {
  1113. GVL_BigStation.Order_CancelStep = 41;
  1114. }
  1115. else if (SiemensRecipeQueue3.Contains(code))
  1116. {
  1117. GVL_BigStation.Order_CancelStep = 51;
  1118. }
  1119. else if (SiemensRecipeQueue4.Contains(code))
  1120. {
  1121. GVL_BigStation.Order_CancelStep = 61;
  1122. }
  1123. break;
  1124. case 31:
  1125. if (GVL_BigStation.Recipe1DosingStatus != 0)
  1126. {
  1127. MessageNotify.GetInstance.ShowRunLog($"海科PLC写入{HKDevice.HK_PLC_S7.Write("DB99.DBX230.0", true)}");
  1128. MessageNotify.GetInstance.ShowRunLog($"海科PLC写入{HKDevice.HK_PLC_S7.Write("DB99.DBW232", (short)TrayCode)}");
  1129. HKDevice.HK_PLC_S7.Write("DB99.DBX0.3", false);
  1130. HKDevice.HK_PLC_S7.Write("DB99.DBX1.4", false);
  1131. GVL_BigStation.Recipe1DosingFinish = false;
  1132. GVL_BigStation.Recipe1DosingStatus = 0;
  1133. GVL_BigStation.Order_CancelStep = 32;
  1134. MessageNotify.GetInstance.ShowRunLog($"PLC正在执行配料流程,取消订单:{code}");
  1135. }
  1136. else
  1137. {
  1138. GVL_BigStation.Order_CancelStep = 32;
  1139. MessageNotify.GetInstance.ShowRunLog($"AGV未到达工站前,未给plc下发配方,取消订单:【{code}】");
  1140. }
  1141. break;
  1142. case 32:
  1143. SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", true);
  1144. GVL_BigStation.Order_CancelStep = 33;
  1145. break;
  1146. case 33:
  1147. if (SiemensDevice.Siemens_PLC_S7.Read<bool>("DB2301.DBX320.2") == false)
  1148. {
  1149. SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", false);
  1150. App.Current.Dispatcher.Invoke(() =>
  1151. {
  1152. Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);
  1153. });
  1154. SiemensRecipeQueue1.TryDequeue(out code);
  1155. GVL_BigStation.Order_CancelStep = 0;
  1156. GVL_BigStation.Order_Cancel = false;
  1157. GVL_BigStation.Order_CancelRecipeCode = "";
  1158. MessageNotify.GetInstance.ShowRunLog($"队列1,西门子取消订单完成,订单号:【{code}】");
  1159. }
  1160. break;
  1161. case 41:
  1162. if (GVL_BigStation.Recipe2DosingStatus != 0)
  1163. {
  1164. MessageNotify.GetInstance.ShowRunLog($"海科PLC写入{HKDevice.HK_PLC_S7.Write("DB99.DBX230.0", true)}");
  1165. MessageNotify.GetInstance.ShowRunLog($"海科PLC写入{HKDevice.HK_PLC_S7.Write("DB99.DBW232", (short)TrayCode)}");
  1166. HKDevice.HK_PLC_S7.Write("DB99.DBX0.4", false);
  1167. HKDevice.HK_PLC_S7.Write("DB99.DBX1.5", false);
  1168. GVL_BigStation.Recipe2DosingFinish = false;
  1169. GVL_BigStation.Recipe2DosingStatus = 0;
  1170. GVL_BigStation.Order_CancelStep = 42;
  1171. MessageNotify.GetInstance.ShowRunLog($"PLC正在执行配料流程,取消订单:【{code}】");
  1172. }
  1173. else
  1174. {
  1175. GVL_BigStation.Order_CancelStep = 42;
  1176. MessageNotify.GetInstance.ShowRunLog($"AGV未到达工站前,未给plc下发配方,取消订单:【{code}】");
  1177. }
  1178. break;
  1179. case 42:
  1180. SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", true);
  1181. GVL_BigStation.Order_CancelStep = 43;
  1182. break;
  1183. case 43:
  1184. if (SiemensDevice.Siemens_PLC_S7.Read<bool>("DB2301.DBX320.2") == false)
  1185. {
  1186. SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", false);
  1187. App.Current.Dispatcher.Invoke(() =>
  1188. {
  1189. Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);
  1190. });
  1191. SiemensRecipeQueue2.TryDequeue(out code);
  1192. GVL_BigStation.Order_CancelStep = 0;
  1193. GVL_BigStation.Order_Cancel = false;
  1194. GVL_BigStation.Order_CancelRecipeCode = "";
  1195. MessageNotify.GetInstance.ShowRunLog($"队列2,西门子取消订单完成,订单号:【{code}】");
  1196. }
  1197. break;
  1198. case 51:
  1199. if (GVL_BigStation.Recipe3DosingStatus != 0)
  1200. {
  1201. MessageNotify.GetInstance.ShowRunLog($"海科PLC写入{HKDevice.HK_PLC_S7.Write("DB99.DBX230.0", true)}");
  1202. MessageNotify.GetInstance.ShowRunLog($"海科PLC写入{HKDevice.HK_PLC_S7.Write("DB99.DBW232", (short)TrayCode)}");
  1203. HKDevice.HK_PLC_S7.Write("DB99.DBX0.5", false);
  1204. HKDevice.HK_PLC_S7.Write("DB99.DBX1.6", false);
  1205. GVL_BigStation.Recipe3DosingFinish = false;
  1206. GVL_BigStation.Recipe3DosingStatus = 0;
  1207. GVL_BigStation.Order_CancelStep = 52;
  1208. MessageNotify.GetInstance.ShowRunLog($"PLC正在执行配料流程,取消订单:【{code}】");
  1209. }
  1210. else
  1211. {
  1212. GVL_BigStation.Order_CancelStep = 52;
  1213. MessageNotify.GetInstance.ShowRunLog($"AGV未到达工站前,未给plc下发配方,取消订单:【{code}】");
  1214. }
  1215. break;
  1216. case 52:
  1217. SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", true);
  1218. GVL_BigStation.Order_CancelStep = 53;
  1219. break;
  1220. case 53:
  1221. if (SiemensDevice.Siemens_PLC_S7.Read<bool>("DB2301.DBX320.2") == false)
  1222. {
  1223. SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", false);
  1224. App.Current.Dispatcher.Invoke(() =>
  1225. {
  1226. Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);
  1227. });
  1228. SiemensRecipeQueue3.TryDequeue(out code);
  1229. GVL_BigStation.Order_CancelStep = 0;
  1230. GVL_BigStation.Order_Cancel = false;
  1231. GVL_BigStation.Order_CancelRecipeCode = "";
  1232. MessageNotify.GetInstance.ShowRunLog($"队列3,西门子取消订单完成,订单号:【{code}】");
  1233. }
  1234. break;
  1235. case 61:
  1236. if (GVL_BigStation.Recipe4DosingStatus != 0)
  1237. {
  1238. MessageNotify.GetInstance.ShowRunLog($"海科PLC写入{HKDevice.HK_PLC_S7.Write("DB99.DBX230.0", true)}");
  1239. MessageNotify.GetInstance.ShowRunLog($"海科PLC写入{HKDevice.HK_PLC_S7.Write("DB99.DBW232", (short)TrayCode)}");
  1240. HKDevice.HK_PLC_S7.Write("DB99.DBX0.6", false);
  1241. HKDevice.HK_PLC_S7.Write("DB99.DBX1.7", false);
  1242. GVL_BigStation.Recipe4DosingFinish = false;
  1243. GVL_BigStation.Recipe4DosingStatus = 0;
  1244. GVL_BigStation.Order_CancelStep = 62;
  1245. MessageNotify.GetInstance.ShowRunLog($"PLC正在执行配料流程,取消订单:【{code}】");
  1246. }
  1247. else
  1248. {
  1249. GVL_BigStation.Order_CancelStep = 62;
  1250. MessageNotify.GetInstance.ShowRunLog($"AGV未到达工站前,未给plc下发配方,取消订单:【{code}】");
  1251. }
  1252. break;
  1253. case 62:
  1254. SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", true);
  1255. GVL_BigStation.Order_CancelStep = 63;
  1256. break;
  1257. case 63:
  1258. if (SiemensDevice.Siemens_PLC_S7.Read<bool>("DB2301.DBX320.2") == false)
  1259. {
  1260. SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", false);
  1261. App.Current.Dispatcher.Invoke(() =>
  1262. {
  1263. Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);
  1264. });
  1265. SiemensRecipeQueue4.TryDequeue(out code);
  1266. GVL_BigStation.Order_CancelStep = 0;
  1267. GVL_BigStation.Order_Cancel = false;
  1268. GVL_BigStation.Order_CancelRecipeCode = "";
  1269. MessageNotify.GetInstance.ShowRunLog($"队列4,西门子取消订单完成,订单号:【{code}】");
  1270. }
  1271. break;
  1272. default:
  1273. break;
  1274. }
  1275. }
  1276. }
  1277. }
  1278. /// <summary>
  1279. /// 配方队列,在配料过程中的逻辑处理
  1280. /// </summary>
  1281. private void RecipeInfoToHKPLC()
  1282. {
  1283. if (SiemensRecipeQueue1.Count > 0)
  1284. {
  1285. int index = Array.FindIndex(SiemensRecipes.ToArray(), p => p.RecipeCode == SiemensRecipeQueue1.ElementAt(0));
  1286. if (index >= 0 && index < SiemensRecipes.Count)
  1287. {
  1288. string code = SiemensRecipes.ElementAt(index).RecipeCode;
  1289. int trayCode = SiemensRecipes.ElementAt(index).TrayCode;
  1290. bool Inplace = false;
  1291. switch (trayCode)
  1292. {
  1293. case 1:
  1294. Inplace = HKDevice.PlcRead.Tray1InPlace;//上位机给plc发送AGV到位信号,plc固定托盘后反馈托盘是否到位
  1295. break;
  1296. case 2:
  1297. Inplace = HKDevice.PlcRead.Tray2InPlace;
  1298. break;
  1299. case 3:
  1300. Inplace = HKDevice.PlcRead.Tray3InPlace;
  1301. break;
  1302. case 4:
  1303. Inplace = HKDevice.PlcRead.Tray4InPlace;
  1304. break;
  1305. case 5:
  1306. Inplace = HKDevice.PlcRead.Tray5InPlace;
  1307. break;
  1308. default:
  1309. break;
  1310. }
  1311. if (HKDevice.PlcRead.IsAllowIssueRecipe1 && GVL_BigStation.Recipe1DosingStatus == 0 && Inplace)//配方队列【1】是否允许下发配发
  1312. {
  1313. if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
  1314. {
  1315. if (!GVL_BigStation.BarrelWasherSign)
  1316. {
  1317. GVL_BigStation.BarrelWasherSign = true;
  1318. HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", true);//洗桶
  1319. MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方编号:{code},托盘编号:{trayCode},订单类型为洗桶");
  1320. GVL_BigStation.DosingRecipe1Time = DateTime.Now;
  1321. HKDevice.WritePlcRecipeData(SiemensRecipes.ElementAt(index));
  1322. HKDevice.HK_PLC_S7.Write("DB99.DBX0.3", true);
  1323. GVL_BigStation.Recipe1DosingStatus = 1;
  1324. MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方编号:{code},托盘编号:{trayCode},下发完成");
  1325. }
  1326. }
  1327. else
  1328. {
  1329. GVL_BigStation.DosingRecipe1Time = DateTime.Now;
  1330. HKDevice.WritePlcRecipeData(SiemensRecipes.ElementAt(index));
  1331. HKDevice.HK_PLC_S7.Write("DB99.DBX0.3", true);
  1332. GVL_BigStation.Recipe1DosingStatus = 1;
  1333. MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方编号:{code},托盘编号:{trayCode},下发完成");
  1334. }
  1335. }
  1336. if (HKDevice.PlcRead.ReceiveFinishRecipe1 && GVL_BigStation.Recipe1DosingStatus == 1)
  1337. {
  1338. if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
  1339. {
  1340. HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", false);//洗桶
  1341. MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方编号:{code},托盘编号:{trayCode},洗桶复位");
  1342. }
  1343. HKDevice.HK_PLC_S7.Write("DB99.DBX0.3", false);
  1344. StockBinParReset();
  1345. MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方编号:{code},托盘编号:{trayCode},PLC接收配方完成");
  1346. GVL_BigStation.Recipe1DosingStatus = 2;
  1347. }
  1348. if (GVL_BigStation.Recipe1DosingStatus == 2 && HKDevice.PlcRead.Recipe1DosingFinish)
  1349. {
  1350. if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
  1351. {
  1352. GVL_BigStation.BarrelWasherSign = false;
  1353. }
  1354. GVL_BigStation.Recipe1DosingFinish = true;
  1355. //GVL_BigStation.Recipe1DosingStatus = 3;
  1356. MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方编号:{code},托盘编号:{trayCode},配料完成");
  1357. ReadStockBinDosingWeight(SiemensRecipes.ElementAt(index));
  1358. //2023-8-21:如果不是MES系统下发的配方,不要返回结束数据。
  1359. if (SiemensRecipes.ElementAt(index).RecipesSource==RecipeSource.远程 /*!GVL_BigStation.IsUseLocalRecipe*/)
  1360. {
  1361. FinishData.Order_No = SiemensRecipes.ElementAt(index).RecipeCode;
  1362. FinishData.Product_Code = SiemensRecipes.ElementAt(index).RecipeName;
  1363. FinishData.job_No = (short)SiemensRecipes.ElementAt(index).TrayCode;
  1364. for (int i = 0; i < FinishData.Material.Length; i++)
  1365. {
  1366. FinishData.Material[i] = new UDT1();
  1367. }
  1368. for (int i = 0; i < SiemensRecipes.ElementAt(index).RawMaterial.Count; i++)
  1369. {
  1370. FinishData.Material[i].Material_Name = SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialName;
  1371. FinishData.Material[i].Material_BarrelNum = (short)SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialBarrelNum;
  1372. FinishData.Material[i].Material_Laying_Off_Weight = Math.Abs(SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).Laying_Off_Weight);
  1373. MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方编号:{code},托盘编号:{trayCode},原料名称:{FinishData.Material[i].Material_Name},原料桶号:{FinishData.Material[i].Material_BarrelNum},配料重量:{FinishData.Material[i].Material_Laying_Off_Weight}kg");
  1374. }
  1375. FinishData.Ask_For_Finish = true;
  1376. double a = DateTime.Now.Subtract(GVL_BigStation.DosingRecipe1Time).TotalSeconds;
  1377. FinishData.ProcessTime = Convert.ToInt16(a);
  1378. //SiemensDevice.Siemens_PLC_S7.WriteClass<DL_Finish_DB>(FinishData, 2361);
  1379. }
  1380. GVL_BigStation.Recipe1DosingStatus = 30;
  1381. HKDevice.HK_PLC_S7.Write("DB99.DBX1.4", true);
  1382. }
  1383. if (GVL_BigStation.Recipe1DosingStatus == 30)
  1384. {
  1385. if (SiemensRecipes.ElementAt(index).RecipesSource == RecipeSource.远程)
  1386. {
  1387. if (SiemensDevice.IsConnected)
  1388. {
  1389. if (SiemensDevice.Siemens_PLC_S7.Read<bool>("DB2361.DBX0.0"))
  1390. {
  1391. //SiemensDevice.Siemens_PLC_S7.Write<bool>("DB2361.DBX330.0", false, 5);
  1392. CleanFinishData();
  1393. if (GVL_BigStation.Recipe1DosingFinish)
  1394. GVL_BigStation.Recipe1DosingFinish = false;
  1395. MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方编号:【{code}】,托盘编号:【{trayCode}】,配料完成,已将完成数据反馈至MES系统。");
  1396. GVL_BigStation.Recipe1DosingStatus = 40;
  1397. }
  1398. else
  1399. {
  1400. SiemensDevice.Siemens_PLC_S7.WriteClass<DL_Finish_DB>(FinishData, 2361);
  1401. Thread.Sleep(1500);
  1402. }
  1403. }
  1404. }
  1405. else
  1406. {
  1407. MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方编号:【{code}】,托盘编号:【{trayCode}】,配料完成,配方为本地下发未将完成数据反馈至MES系统。");
  1408. GVL_BigStation.Recipe1DosingStatus = 40;
  1409. }
  1410. }
  1411. if (GVL_BigStation.Recipe1DosingStatus == 40 && HKDevice.PlcRead.Recipe1DosingFinish == false)
  1412. {
  1413. HKDevice.HK_PLC_S7.Write("DB99.DBX1.4", false);
  1414. SiemensRecipeQueue1.TryDequeue(out code);
  1415. App.Current.Dispatcher.Invoke(() =>
  1416. {
  1417. Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
  1418. });
  1419. GVL_BigStation.Recipe1DosingStatus = 0;
  1420. MessageNotify.GetInstance.ShowRunLog($"配方队列【1】,配方编号:{code},托盘编号:{trayCode},复位plc配料完成信号");
  1421. }
  1422. }
  1423. }
  1424. if (SiemensRecipeQueue2.Count > 0)
  1425. {
  1426. int index = Array.FindIndex(SiemensRecipes.ToArray(), p => p.RecipeCode == SiemensRecipeQueue2.ElementAt(0));
  1427. if (index >= 0 && index < SiemensRecipes.Count)
  1428. {
  1429. string code = SiemensRecipes.ElementAt(index).RecipeCode;
  1430. int trayCode = SiemensRecipes.ElementAt(index).TrayCode;
  1431. bool Inplace = false;
  1432. switch (trayCode)
  1433. {
  1434. case 1:
  1435. Inplace = HKDevice.PlcRead.Tray1InPlace;
  1436. break;
  1437. case 2:
  1438. Inplace = HKDevice.PlcRead.Tray2InPlace;
  1439. break;
  1440. case 3:
  1441. Inplace = HKDevice.PlcRead.Tray3InPlace;
  1442. break;
  1443. case 4:
  1444. Inplace = HKDevice.PlcRead.Tray4InPlace;
  1445. break;
  1446. case 5:
  1447. Inplace = HKDevice.PlcRead.Tray5InPlace;
  1448. break;
  1449. default:
  1450. break;
  1451. }
  1452. if (HKDevice.PlcRead.IsAllowIssueRecipe2 && GVL_BigStation.Recipe2DosingStatus == 0 && Inplace)//配方队列【2】是否允许下发配发
  1453. {
  1454. if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
  1455. {
  1456. if (!GVL_BigStation.BarrelWasherSign)
  1457. {
  1458. GVL_BigStation.BarrelWasherSign = true;
  1459. HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", true);//洗桶
  1460. MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方编号:{code},托盘编号:{trayCode},订单类型为洗桶");
  1461. GVL_BigStation.DosingRecipe2Time = DateTime.Now;
  1462. HKDevice.WritePlcRecipeData(SiemensRecipes.ElementAt(index));
  1463. HKDevice.HK_PLC_S7.Write("DB99.DBX0.4", true);
  1464. GVL_BigStation.Recipe2DosingStatus = 1;
  1465. MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方编号:{code},托盘编号:{trayCode},下发完成");
  1466. }
  1467. }
  1468. else
  1469. {
  1470. GVL_BigStation.DosingRecipe2Time = DateTime.Now;
  1471. HKDevice.WritePlcRecipeData(SiemensRecipes.ElementAt(index));
  1472. HKDevice.HK_PLC_S7.Write("DB99.DBX0.4", true);
  1473. GVL_BigStation.Recipe2DosingStatus = 1;
  1474. MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方编号:{code},托盘编号:{trayCode},下发完成");
  1475. }
  1476. }
  1477. if (HKDevice.PlcRead.ReceiveFinishRecipe2 && GVL_BigStation.Recipe2DosingStatus == 1)
  1478. {
  1479. if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
  1480. {
  1481. HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", false);//洗桶
  1482. MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方编号:{code},托盘编号:{trayCode},洗桶复位");
  1483. }
  1484. HKDevice.HK_PLC_S7.Write("DB99.DBX0.4", false);
  1485. StockBinParReset();
  1486. GVL_BigStation.Recipe2DosingStatus = 2;
  1487. MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方编号:{code},托盘编号:{trayCode},PLC接收配方完成");
  1488. }
  1489. if (GVL_BigStation.Recipe2DosingStatus == 2 && HKDevice.PlcRead.Recipe2DosingFinish)
  1490. {
  1491. if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
  1492. {
  1493. GVL_BigStation.BarrelWasherSign = false;
  1494. }
  1495. GVL_BigStation.Recipe2DosingFinish = true;
  1496. MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方编号:{code},托盘编号:{trayCode},配料完成");
  1497. ReadStockBinDosingWeight(SiemensRecipes.ElementAt(index));
  1498. if (SiemensRecipes.ElementAt(index).RecipesSource == RecipeSource.远程 /*!GVL_BigStation.IsUseLocalRecipe*/)
  1499. {
  1500. FinishData.Order_No = SiemensRecipes.ElementAt(index).RecipeCode;
  1501. FinishData.Product_Code = SiemensRecipes.ElementAt(index).RecipeName;
  1502. FinishData.job_No = (short)SiemensRecipes.ElementAt(index).TrayCode;
  1503. for (int i = 0; i < FinishData.Material.Length; i++)
  1504. {
  1505. FinishData.Material[i] = new UDT1();
  1506. }
  1507. for (int i = 0; i < SiemensRecipes.ElementAt(index).RawMaterial.Count; i++)
  1508. {
  1509. FinishData.Material[i].Material_Name = SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialName;
  1510. FinishData.Material[i].Material_BarrelNum = (short)SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialBarrelNum;
  1511. FinishData.Material[i].Material_Laying_Off_Weight = Math.Abs(SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).Laying_Off_Weight);
  1512. MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方编号:{code},托盘编号:{trayCode},原料名称:{FinishData.Material[i].Material_Name},原料桶号:{FinishData.Material[i].Material_BarrelNum},配料重量:{FinishData.Material[i].Material_Laying_Off_Weight}kg");
  1513. }
  1514. FinishData.Ask_For_Finish = true;
  1515. double a = DateTime.Now.Subtract(GVL_BigStation.DosingRecipe2Time).TotalSeconds;
  1516. FinishData.ProcessTime = Convert.ToInt16(a);
  1517. //SiemensDevice.Siemens_PLC_S7.WriteClass<DL_Finish_DB>(FinishData, 2361);
  1518. }
  1519. HKDevice.HK_PLC_S7.Write("DB99.DBX1.5", true);
  1520. GVL_BigStation.Recipe2DosingStatus = 30;
  1521. }
  1522. if (GVL_BigStation.Recipe2DosingStatus == 30)
  1523. {
  1524. if (SiemensRecipes.ElementAt(index).RecipesSource == RecipeSource.远程)
  1525. {
  1526. if (SiemensDevice.IsConnected)
  1527. {
  1528. if (SiemensDevice.Siemens_PLC_S7.Read<bool>("DB2361.DBX0.0"))
  1529. {
  1530. // SiemensDevice.Siemens_PLC_S7.Write<bool>("DB2361.DBX330.0", false, 5);
  1531. CleanFinishData();
  1532. if (GVL_BigStation.Recipe2DosingFinish)
  1533. GVL_BigStation.Recipe2DosingFinish = false;
  1534. MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方编号:【{code}】,托盘编号:【{trayCode}】,配料完成,已将完成数据反馈至MES系统。");
  1535. GVL_BigStation.Recipe2DosingStatus = 40;
  1536. }
  1537. else
  1538. {
  1539. SiemensDevice.Siemens_PLC_S7.WriteClass<DL_Finish_DB>(FinishData, 2361);
  1540. Thread.Sleep(1500);
  1541. }
  1542. }
  1543. }
  1544. else
  1545. {
  1546. MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方编号:【{code}】,托盘编号:【{trayCode}】,配料完成,配方为本地下发未将完成数据反馈至MES系统。");
  1547. GVL_BigStation.Recipe2DosingStatus = 40;
  1548. }
  1549. }
  1550. if (GVL_BigStation.Recipe2DosingStatus == 40 && HKDevice.PlcRead.Recipe2DosingFinish == false)
  1551. {
  1552. HKDevice.HK_PLC_S7.Write("DB99.DBX1.5", false);
  1553. SiemensRecipeQueue2.TryDequeue(out code);
  1554. RecipeExecuteComple.Add(SiemensRecipes.ElementAt(index));
  1555. App.Current.Dispatcher.Invoke(() =>
  1556. {
  1557. Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
  1558. });
  1559. GVL_BigStation.Recipe2DosingStatus = 0;
  1560. MessageNotify.GetInstance.ShowRunLog($"配方队列【2】,配方编号:{code},托盘编号:{trayCode},,复位plc配料完成信号");
  1561. }
  1562. }
  1563. }
  1564. if (SiemensRecipeQueue3.Count > 0)
  1565. {
  1566. int index = Array.FindIndex(SiemensRecipes.ToArray(), p => p.RecipeCode == SiemensRecipeQueue3.ElementAt(0));
  1567. if (index >= 0 && index < SiemensRecipes.Count)
  1568. {
  1569. string code = SiemensRecipes.ElementAt(index).RecipeCode;
  1570. int trayCode = SiemensRecipes.ElementAt(index).TrayCode;
  1571. bool Inplace = false;
  1572. switch (trayCode)
  1573. {
  1574. case 1:
  1575. Inplace = HKDevice.PlcRead.Tray1InPlace;
  1576. break;
  1577. case 2:
  1578. Inplace = HKDevice.PlcRead.Tray2InPlace;
  1579. break;
  1580. case 3:
  1581. Inplace = HKDevice.PlcRead.Tray3InPlace;
  1582. break;
  1583. case 4:
  1584. Inplace = HKDevice.PlcRead.Tray4InPlace;
  1585. break;
  1586. case 5:
  1587. Inplace = HKDevice.PlcRead.Tray5InPlace;
  1588. break;
  1589. default:
  1590. break;
  1591. }
  1592. if (HKDevice.PlcRead.IsAllowIssueRecipe3 && GVL_BigStation.Recipe3DosingStatus == 0 && Inplace)//配方队列【3】是否允许下发配发
  1593. {
  1594. if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
  1595. {
  1596. if (!GVL_BigStation.BarrelWasherSign)//其他配方在洗桶时,等待其他配方洗完,在发送数据
  1597. {
  1598. GVL_BigStation.BarrelWasherSign = true;
  1599. HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", true);//洗桶
  1600. MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方编号:{code},托盘编号:{trayCode},订单类型为洗桶");
  1601. GVL_BigStation.DosingRecipe3Time = DateTime.Now;
  1602. HKDevice.WritePlcRecipeData(SiemensRecipes.ElementAt(index));
  1603. HKDevice.HK_PLC_S7.Write("DB99.DBX0.5", true);
  1604. GVL_BigStation.Recipe3DosingStatus = 1;
  1605. MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方编号:{code},托盘编号:{trayCode},下发完成");
  1606. }
  1607. }
  1608. else
  1609. {
  1610. GVL_BigStation.DosingRecipe3Time = DateTime.Now;
  1611. HKDevice.WritePlcRecipeData(SiemensRecipes.ElementAt(index));
  1612. HKDevice.HK_PLC_S7.Write("DB99.DBX0.5", true);
  1613. GVL_BigStation.Recipe3DosingStatus = 1;
  1614. MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方编号:{code},托盘编号:{trayCode},下发完成");
  1615. }
  1616. }
  1617. if (HKDevice.PlcRead.ReceiveFinishRecipe3 && GVL_BigStation.Recipe3DosingStatus == 1)
  1618. {
  1619. if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
  1620. {
  1621. HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", false);//洗桶
  1622. MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方编号:{code},托盘编号:{trayCode},洗桶复位");
  1623. }
  1624. HKDevice.HK_PLC_S7.Write("DB99.DBX0.5", false);
  1625. StockBinParReset();
  1626. GVL_BigStation.Recipe3DosingStatus = 2;
  1627. MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方编号:{code},托盘编号:{trayCode},PLC接收配方完成");
  1628. }
  1629. if (HKDevice.PlcRead.Recipe3DosingFinish && GVL_BigStation.Recipe3DosingStatus == 2)
  1630. {
  1631. if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
  1632. {
  1633. GVL_BigStation.BarrelWasherSign = false;
  1634. }
  1635. GVL_BigStation.Recipe3DosingFinish = true;
  1636. //GVL_BigStation.Recipe3DosingStatus = 3;
  1637. MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方编号:{code},托盘编号:{trayCode},配料完成");
  1638. ReadStockBinDosingWeight(SiemensRecipes.ElementAt(index));
  1639. if (SiemensDevice.IsConnected && SiemensRecipes.ElementAt(index).RecipesSource == RecipeSource.远程 /*!GVL_BigStation.IsUseLocalRecipe*/)
  1640. {
  1641. FinishData.Order_No = SiemensRecipes.ElementAt(index).RecipeCode;
  1642. FinishData.Product_Code = SiemensRecipes.ElementAt(index).RecipeName;
  1643. FinishData.job_No = (short)SiemensRecipes.ElementAt(index).TrayCode;
  1644. for (int i = 0; i < FinishData.Material.Length; i++)
  1645. {
  1646. FinishData.Material[i] = new UDT1();
  1647. }
  1648. for (int i = 0; i < SiemensRecipes.ElementAt(index).RawMaterial.Count; i++)
  1649. {
  1650. FinishData.Material[i].Material_Name = SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialName;
  1651. FinishData.Material[i].Material_BarrelNum = (short)SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialBarrelNum;
  1652. FinishData.Material[i].Material_Laying_Off_Weight = Math.Abs(SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).Laying_Off_Weight);
  1653. MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方编号:{code},托盘编号:{trayCode},原料名称:{FinishData.Material[i].Material_Name},原料桶号:{FinishData.Material[i].Material_BarrelNum},配料重量:{FinishData.Material[i].Material_Laying_Off_Weight}kg");
  1654. }
  1655. FinishData.Ask_For_Finish = true;
  1656. double a = DateTime.Now.Subtract(GVL_BigStation.DosingRecipe3Time).TotalSeconds;
  1657. FinishData.ProcessTime = Convert.ToInt16(a);
  1658. //SiemensDevice.Siemens_PLC_S7.WriteClass<DL_Finish_DB>(FinishData, 2361);
  1659. }
  1660. HKDevice.HK_PLC_S7.Write("DB99.DBX1.6", true);
  1661. GVL_BigStation.Recipe3DosingStatus = 30;
  1662. }
  1663. if (GVL_BigStation.Recipe3DosingStatus == 30)
  1664. {
  1665. if (SiemensRecipes.ElementAt(index).RecipesSource == RecipeSource.远程)
  1666. {
  1667. if (SiemensDevice.IsConnected)
  1668. {
  1669. if (SiemensDevice.Siemens_PLC_S7.Read<bool>("DB2361.DBX0.0"))
  1670. {
  1671. //SiemensDevice.Siemens_PLC_S7.Write<bool>("DB2361.DBX330.0", false, 5);
  1672. CleanFinishData();
  1673. if (GVL_BigStation.Recipe3DosingFinish)
  1674. GVL_BigStation.Recipe3DosingFinish = false;
  1675. MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方编号:【{code}】,托盘编号:【{trayCode}】,配料完成,已将完成数据反馈至MES系统。");
  1676. GVL_BigStation.Recipe3DosingStatus = 40;
  1677. }
  1678. else
  1679. {
  1680. SiemensDevice.Siemens_PLC_S7.WriteClass<DL_Finish_DB>(FinishData, 2361);
  1681. Thread.Sleep(1500);
  1682. }
  1683. }
  1684. }
  1685. else
  1686. {
  1687. MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方编号:【{code}】,托盘编号:【{trayCode}】,配料完成,配方为本地下发未将完成数据反馈至MES系统。");
  1688. GVL_BigStation.Recipe3DosingStatus = 40;
  1689. }
  1690. }
  1691. if (GVL_BigStation.Recipe3DosingStatus == 40 && HKDevice.PlcRead.Recipe3DosingFinish == false)
  1692. {
  1693. HKDevice.HK_PLC_S7.Write("DB99.DBX1.6", false);
  1694. SiemensRecipeQueue3.TryDequeue(out code);
  1695. App.Current.Dispatcher.Invoke(() =>
  1696. {
  1697. Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
  1698. });
  1699. GVL_BigStation.Recipe3DosingStatus = 0;
  1700. MessageNotify.GetInstance.ShowRunLog($"配方队列【3】,配方编号:{code},托盘编号:{trayCode},复位plc配料完成信号");
  1701. }
  1702. }
  1703. }
  1704. if (SiemensRecipeQueue4.Count > 0)
  1705. {
  1706. int index = Array.FindIndex(SiemensRecipes.ToArray(), p => p.RecipeCode == SiemensRecipeQueue4.ElementAt(0));
  1707. if (index >= 0 && index < SiemensRecipes.Count)
  1708. {
  1709. string code = SiemensRecipes.ElementAt(index).RecipeCode;
  1710. int trayCode = SiemensRecipes.ElementAt(index).TrayCode;
  1711. bool Inplace = false;
  1712. switch (trayCode)
  1713. {
  1714. case 1:
  1715. Inplace = HKDevice.PlcRead.Tray1InPlace;
  1716. break;
  1717. case 2:
  1718. Inplace = HKDevice.PlcRead.Tray2InPlace;
  1719. break;
  1720. case 3:
  1721. Inplace = HKDevice.PlcRead.Tray3InPlace;
  1722. break;
  1723. case 4:
  1724. Inplace = HKDevice.PlcRead.Tray4InPlace;
  1725. break;
  1726. case 5:
  1727. Inplace = HKDevice.PlcRead.Tray5InPlace;
  1728. break;
  1729. default:
  1730. break;
  1731. }
  1732. if (HKDevice.PlcRead.IsAllowIssueRecipe4 && GVL_BigStation.Recipe4DosingStatus == 0 && Inplace)//配方队列【4】是否允许下发配发
  1733. {
  1734. if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
  1735. {
  1736. if (!GVL_BigStation.BarrelWasherSign)//其他配方在洗桶时,等待其他配方洗完,在发送数据
  1737. {
  1738. GVL_BigStation.BarrelWasherSign = true;
  1739. HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", true);//洗桶
  1740. MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方编号:{code},托盘编号:{trayCode},订单类型为洗桶");
  1741. GVL_BigStation.DosingRecipe4Time = DateTime.Now;
  1742. HKDevice.WritePlcRecipeData(SiemensRecipes.ElementAt(index));
  1743. HKDevice.HK_PLC_S7.Write("DB99.DBX0.6", true);
  1744. GVL_BigStation.Recipe4DosingStatus = 1;
  1745. MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方编号:{code},托盘编号:{trayCode},下发完成");
  1746. }
  1747. }
  1748. else
  1749. {
  1750. GVL_BigStation.DosingRecipe4Time = DateTime.Now;
  1751. HKDevice.WritePlcRecipeData(SiemensRecipes.ElementAt(index));
  1752. HKDevice.HK_PLC_S7.Write("DB99.DBX0.6", true);
  1753. GVL_BigStation.Recipe4DosingStatus = 1;
  1754. MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方编号:{code},托盘编号:{trayCode},下发完成");
  1755. }
  1756. }
  1757. if (HKDevice.PlcRead.ReceiveFinishRecipe4 && GVL_BigStation.Recipe4DosingStatus == 1)
  1758. {
  1759. if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
  1760. {
  1761. HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", false);//洗桶
  1762. MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方编号:{code},托盘编号:{trayCode},洗桶复位");
  1763. }
  1764. GVL_BigStation.Recipe4DosingStatus = 2;
  1765. HKDevice.HK_PLC_S7.Write("DB99.DBX0.6", false);
  1766. StockBinParReset();
  1767. MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方编号:{code},托盘编号:{trayCode},PLC接收配方完成");
  1768. }
  1769. if (GVL_BigStation.Recipe4DosingStatus == 2 && HKDevice.PlcRead.Recipe4DosingFinish)
  1770. {
  1771. if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
  1772. {
  1773. GVL_BigStation.BarrelWasherSign = false;
  1774. }
  1775. GVL_BigStation.Recipe4DosingFinish = true;
  1776. //GVL_BigStation.Recipe4DosingStatus = 3;
  1777. MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方编号:{code},托盘编号:{trayCode},配料完成");
  1778. ReadStockBinDosingWeight(SiemensRecipes.ElementAt(index));
  1779. if (SiemensDevice.IsConnected && SiemensRecipes.ElementAt(index).RecipesSource == RecipeSource.远程 /*!GVL_BigStation.IsUseLocalRecipe*/)
  1780. {
  1781. FinishData.Order_No = SiemensRecipes.ElementAt(index).RecipeCode;
  1782. FinishData.Product_Code = SiemensRecipes.ElementAt(index).RecipeName;
  1783. FinishData.job_No = (short)SiemensRecipes.ElementAt(index).TrayCode;
  1784. for (int i = 0; i < FinishData.Material.Length; i++)
  1785. {
  1786. FinishData.Material[i] = new UDT1();
  1787. }
  1788. for (int i = 0; i < SiemensRecipes.ElementAt(index).RawMaterial.Count; i++)
  1789. {
  1790. FinishData.Material[i].Material_Name = SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialName;
  1791. FinishData.Material[i].Material_BarrelNum = (short)SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialBarrelNum;
  1792. FinishData.Material[i].Material_Laying_Off_Weight = Math.Abs(SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).Laying_Off_Weight);
  1793. MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方编号:{code},托盘编号:{trayCode},原料名称:{FinishData.Material[i].Material_Name},原料桶号:{FinishData.Material[i].Material_BarrelNum},配料重量:{FinishData.Material[i].Material_Laying_Off_Weight}kg");
  1794. }
  1795. FinishData.Ask_For_Finish = true;
  1796. double a = DateTime.Now.Subtract(GVL_BigStation.DosingRecipe4Time).TotalSeconds;
  1797. FinishData.ProcessTime = Convert.ToInt16(a);
  1798. //SiemensDevice.Siemens_PLC_S7.WriteClass<DL_Finish_DB>(FinishData, 2361);
  1799. }
  1800. HKDevice.HK_PLC_S7.Write("DB99.DBX1.7", true);
  1801. GVL_BigStation.Recipe4DosingStatus = 30;
  1802. }
  1803. if (GVL_BigStation.Recipe4DosingStatus == 30)
  1804. {
  1805. if (SiemensRecipes.ElementAt(index).RecipesSource == RecipeSource.远程)
  1806. {
  1807. if (SiemensDevice.IsConnected)
  1808. {
  1809. if (SiemensDevice.Siemens_PLC_S7.Read<bool>("DB2361.DBX0.0"))
  1810. {
  1811. // SiemensDevice.Siemens_PLC_S7.Write<bool>("DB2361.DBX330.0", false, 5);
  1812. CleanFinishData();
  1813. if (GVL_BigStation.Recipe4DosingFinish)
  1814. GVL_BigStation.Recipe4DosingFinish = false;
  1815. MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方编号:【{code}】,托盘编号:【{trayCode}】,配料完成,已将完成数据反馈至MES系统。");
  1816. GVL_BigStation.Recipe4DosingStatus = 40;
  1817. }
  1818. else
  1819. {
  1820. SiemensDevice.Siemens_PLC_S7.WriteClass<DL_Finish_DB>(FinishData, 2361);
  1821. Thread.Sleep(1500);
  1822. }
  1823. }
  1824. }
  1825. else
  1826. {
  1827. MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方编号:【{code}】,托盘编号:【{trayCode}】,配料完成,配方为本地下发未将完成数据反馈至MES系统。");
  1828. GVL_BigStation.Recipe4DosingStatus = 40;
  1829. }
  1830. }
  1831. if (GVL_BigStation.Recipe4DosingStatus == 40 && HKDevice.PlcRead.Recipe4DosingFinish == false)
  1832. {
  1833. HKDevice.HK_PLC_S7.Write("DB99.DBX1.7", false);
  1834. SiemensRecipeQueue4.TryDequeue(out code);
  1835. App.Current.Dispatcher.Invoke(() =>
  1836. {
  1837. Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
  1838. });
  1839. GVL_BigStation.Recipe4DosingStatus = 0;
  1840. MessageNotify.GetInstance.ShowRunLog($"配方队列【4】,配方编号:{code},托盘编号:{trayCode},复位plc配料完成信号");
  1841. }
  1842. }
  1843. }
  1844. }
  1845. /// <summary>
  1846. /// 下发plc的配方数据复位
  1847. /// </summary>
  1848. private void StockBinParReset()
  1849. {
  1850. HKDevice.HK_PLC_S7.Write("DB99.DBW2.0", 0);
  1851. HKDevice.HK_PLC_S7.Write("DB99.DBW4.0", 0);
  1852. for (int i = 0; i < 56; i++)
  1853. {
  1854. string address2 = "DB99.DBD" + (6 + 4 * i);
  1855. HKDevice.HK_PLC_S7.Write(address2, 0);
  1856. }
  1857. }
  1858. private void testRawMaterialNameData()
  1859. {
  1860. //RawMaterialsInfo = Json<RawMaterialData>.Data.RawMaterial;
  1861. /*foreach (var material in RawMaterialsInfo)
  1862. {
  1863. if (!string.IsNullOrEmpty(material.RawMaterialName))
  1864. {
  1865. if (!RawMaterialsNamePos.ContainsKey(material.RawMaterialName))
  1866. {
  1867. RawMaterialsNamePos.Add(material.RawMaterialName, (short)material.RawMaterialLocation);
  1868. }
  1869. }
  1870. }*/
  1871. if (RawMaterialsNamePos.Count == 14)
  1872. {
  1873. for (int i = 0; i < typeof(StockBinName).GetProperties().Length; i++)
  1874. {
  1875. PropertyInfo pro = GVL_BigStation.stockBinName.GetType().GetProperty(typeof(StockBinName).GetProperties()[i].Name);
  1876. RawMaterialsNamePos[i + 1] = pro.GetValue(GVL_BigStation.stockBinName, null).ToString();
  1877. }
  1878. }
  1879. else
  1880. {
  1881. RawMaterialsNamePos.TryAdd(1, GVL_BigStation.stockBinName.RawMaterialName1);
  1882. RawMaterialsNamePos.TryAdd(2, GVL_BigStation.stockBinName.RawMaterialName2);
  1883. RawMaterialsNamePos.TryAdd(3, GVL_BigStation.stockBinName.RawMaterialName3);
  1884. RawMaterialsNamePos.TryAdd(4, GVL_BigStation.stockBinName.RawMaterialName4);
  1885. RawMaterialsNamePos.TryAdd(5, GVL_BigStation.stockBinName.RawMaterialName5);
  1886. RawMaterialsNamePos.TryAdd(6, GVL_BigStation.stockBinName.RawMaterialName6);
  1887. RawMaterialsNamePos.TryAdd(7, GVL_BigStation.stockBinName.RawMaterialName7);
  1888. RawMaterialsNamePos.TryAdd(8, GVL_BigStation.stockBinName.RawMaterialName8);
  1889. RawMaterialsNamePos.TryAdd(9, GVL_BigStation.stockBinName.RawMaterialName9);
  1890. RawMaterialsNamePos.TryAdd(10, GVL_BigStation.stockBinName.RawMaterialName10);
  1891. RawMaterialsNamePos.TryAdd(11, GVL_BigStation.stockBinName.RawMaterialName11);
  1892. RawMaterialsNamePos.TryAdd(12, GVL_BigStation.stockBinName.RawMaterialName12);
  1893. RawMaterialsNamePos.TryAdd(13, GVL_BigStation.stockBinName.RawMaterialName13);
  1894. RawMaterialsNamePos.TryAdd(14, GVL_BigStation.stockBinName.RawMaterialName14);
  1895. foreach (var item in RawMaterialsNamePos)
  1896. {
  1897. HardWareRawMaterialInfo.Add(new RawMaterial() { RawMaterialCount = HardWareRawMaterialInfo.Count + 1, RawMaterialLocation = item.Key, RawMaterialName = item.Value, RawMaterialChineseName = "" });
  1898. }
  1899. }
  1900. foreach (var item in RawMaterialsNamePos)
  1901. {
  1902. int num = Array.FindIndex(Json<BomMaterial>.Data.RawMaterials.ToArray(), p => p.RawMaterialName == item.Value);
  1903. int index = Array.FindIndex(HardWareRawMaterialInfo.ToArray(), p => p.RawMaterialLocation == item.Key);
  1904. if (index == -1)
  1905. {
  1906. HardWareRawMaterialInfo.Clear();
  1907. }
  1908. else if (num >= 0 && index >= 0)
  1909. {
  1910. string name = Json<BomMaterial>.Data.RawMaterials.ElementAt(num).RawMaterialChineseName;
  1911. HardWareRawMaterialInfo.ElementAt(index).RawMaterialLocation = item.Key;
  1912. HardWareRawMaterialInfo.ElementAt(index).RawMaterialName = item.Value;
  1913. HardWareRawMaterialInfo.ElementAt(index).RawMaterialChineseName = name;
  1914. }
  1915. else if (num == -1)
  1916. {
  1917. HardWareRawMaterialInfo.ElementAt(index).RawMaterialLocation = item.Key;
  1918. HardWareRawMaterialInfo.ElementAt(index).RawMaterialName = "";
  1919. HardWareRawMaterialInfo.ElementAt(index).RawMaterialChineseName = "";
  1920. }
  1921. }
  1922. RawMaterialsInfo = HardWareRawMaterialInfo;
  1923. }
  1924. /// <summary>
  1925. /// MES的物料名称和物料编码对应
  1926. /// </summary>
  1927. public void RawMaterialNameWithCode()
  1928. {
  1929. GVL_BigStation.RawMaterialsNameCode.Add("0001", "色拉油");
  1930. GVL_BigStation.RawMaterialsNameCode.Add("0002", "一级菜油");
  1931. GVL_BigStation.RawMaterialsNameCode.Add("0003", "菜籽油");
  1932. GVL_BigStation.RawMaterialsNameCode.Add("0004", "青花椒油");
  1933. GVL_BigStation.RawMaterialsNameCode.Add("0005", "卤牛肉丁");
  1934. GVL_BigStation.RawMaterialsNameCode.Add("0006", "冻鸡肉丁");
  1935. GVL_BigStation.RawMaterialsNameCode.Add("0007", "香菇丁");
  1936. GVL_BigStation.RawMaterialsNameCode.Add("0008", "高水分糍粑海椒");
  1937. GVL_BigStation.RawMaterialsNameCode.Add("0009", "低水分糍粑海椒");
  1938. GVL_BigStation.RawMaterialsNameCode.Add("0010", "辣豆瓣");
  1939. GVL_BigStation.RawMaterialsNameCode.Add("0011", "整豆豉");
  1940. GVL_BigStation.RawMaterialsNameCode.Add("0012", "豆豉细粒");
  1941. GVL_BigStation.RawMaterialsNameCode.Add("0013", "卤黄豆");
  1942. GVL_BigStation.RawMaterialsNameCode.Add("0014", "野山椒粒");
  1943. GVL_BigStation.RawMaterialsNameCode.Add("0015", "竹笋丁");
  1944. GVL_BigStation.RawMaterialsNameCode.Add("0016", "香辣酱辣椒酱");
  1945. GVL_BigStation.RawMaterialsNameCode.Add("0017", "芽菜粒");
  1946. GVL_BigStation.RawMaterialsNameCode.Add("0018", "榨菜丁");
  1947. GVL_BigStation.RawMaterialsNameCode.Add("0019", "盐菜");
  1948. GVL_BigStation.RawMaterialsNameCode.Add("0020", "洋葱丁");
  1949. GVL_BigStation.RawMaterialsNameCode.Add("0021", "番茄酱");
  1950. GVL_BigStation.RawMaterialsNameCode.Add("0022", "甜豆瓣");
  1951. GVL_BigStation.RawMaterialsNameCode.Add("0023", "甜面酱");
  1952. GVL_BigStation.RawMaterialsNameCode.Add("0024", "芝麻酱");
  1953. GVL_BigStation.RawMaterialsNameCode.Add("0025", "炸花生");
  1954. GVL_BigStation.RawMaterialsNameCode.Add("0026", "盐渍青椒丁");
  1955. GVL_BigStation.RawMaterialsNameCode.Add("0027", "备料剁红椒");
  1956. GVL_BigStation.RawMaterialsNameCode.Add("0028", "萝卜丁");
  1957. GVL_BigStation.RawMaterialsNameCode.Add("0029", "油芝麻");
  1958. GVL_BigStation.RawMaterialsNameCode.Add("0030", "生姜");
  1959. GVL_BigStation.RawMaterialsNameCode.Add("0031", "大蒜");
  1960. GVL_BigStation.RawMaterialsNameCode.Add("0032", "榨菜酱");
  1961. GVL_BigStation.RawMaterialsNameCode.Add("0033", "炸碗豆");
  1962. GVL_BigStation.RawMaterialsNameCode.Add("0034", "大头菜丁");
  1963. GVL_BigStation.RawMaterialsNameCode.Add("0035", "酱油");
  1964. GVL_BigStation.RawMaterialsNameCode.Add("0036", "I+G");
  1965. GVL_BigStation.RawMaterialsNameCode.Add("0037", "味精");
  1966. GVL_BigStation.RawMaterialsNameCode.Add("0038", "白糖");
  1967. GVL_BigStation.RawMaterialsNameCode.Add("0039", "食盐");
  1968. GVL_BigStation.RawMaterialsNameCode.Add("0040", "花椒酱");
  1969. GVL_BigStation.RawMaterialsNameCode.Add("0041", "调味膏2");
  1970. GVL_BigStation.RawMaterialsNameCode.Add("0042", "调味膏5");
  1971. GVL_BigStation.RawMaterialsNameCode.Add("0043", "十三香调味膏");
  1972. GVL_BigStation.RawMaterialsNameCode.Add("0044", "酱香膏");
  1973. GVL_BigStation.RawMaterialsNameCode.Add("0045", "芽菜香料粉");
  1974. GVL_BigStation.RawMaterialsNameCode.Add("0046", "香料A");
  1975. GVL_BigStation.RawMaterialsNameCode.Add("0047", "香料D");
  1976. GVL_BigStation.RawMaterialsNameCode.Add("0048", "猪肉精膏");
  1977. GVL_BigStation.RawMaterialsNameCode.Add("0049", "调味膏3");
  1978. GVL_BigStation.RawMaterialsNameCode.Add("0050", "柠檬酸粉");
  1979. GVL_BigStation.RawMaterialsNameCode.Add("0051", "辣椒红");
  1980. GVL_BigStation.RawMaterialsNameCode.Add("0052", "辣椒油树脂");
  1981. GVL_BigStation.RawMaterialsNameCode.Add("0053", "水态混和酸");
  1982. GVL_BigStation.RawMaterialsNameCode.Add("0054", "加水稀释后防腐剂");
  1983. GVL_BigStation.RawMaterialsNameCode.Add("0055", "异维C钠粉");
  1984. GVL_BigStation.RawMaterialsNameCode.Add("0056", "琼脂粉");
  1985. GVL_BigStation.RawMaterialsNameCode.Add("0057", "香葱油");
  1986. GVL_BigStation.RawMaterialsNameCode.Add("0058", "水态甜味剂");
  1987. GVL_BigStation.RawMaterialsNameCode.Add("0059", "孜然粉");
  1988. GVL_BigStation.RawMaterialsNameCode.Add("0060", "孜然油");
  1989. }
  1990. /// <summary>
  1991. /// 设备连接 西门子和海科PLC
  1992. /// </summary>
  1993. public void DeviceConnectInit()
  1994. {
  1995. GVL_BigStation.IsAllowHKPlcConnect = ConfigurationManager.AppSettings["HKPlc_Connect"].ToLower() == "true" ? true : false;
  1996. GVL_BigStation.IsAllowSiemensConnect = ConfigurationManager.AppSettings["Siemens_Connect"].ToLower() == "true" ? true : false;
  1997. try
  1998. {
  1999. if (GVL_BigStation.IsAllowHKPlcConnect)
  2000. {
  2001. HKDevice.HK_PLC_S7.Connect(S7.Net.CpuType.S71500, HK_PLC_IP);
  2002. }
  2003. }
  2004. catch (Exception ex)
  2005. {
  2006. MessageNotify.GetInstance.ShowRunLog("海科plc连接失败,等待重新连接");
  2007. }
  2008. finally
  2009. {
  2010. HKDevice.Init();
  2011. MessageNotify.GetInstance.ShowRunLog("海科plc初始化");
  2012. if (HKDevice.IsConnected && GVL_BigStation.IsAllowHKPlcConnect)
  2013. {
  2014. MessageNotify.GetInstance.ShowRunLog("海科plc连接成功");
  2015. }
  2016. }
  2017. try
  2018. {
  2019. if (GVL_BigStation.IsAllowSiemensConnect)
  2020. {
  2021. SiemensDevice.Siemens_PLC_S7.Connect(S7.Net.CpuType.S71500, Siemens_PLC_IP);
  2022. }
  2023. }
  2024. catch (Exception ex)
  2025. {
  2026. MessageNotify.GetInstance.ShowRunLog("西门子plc连接失败,等待重新连接");
  2027. }
  2028. finally
  2029. {
  2030. SiemensDevice.Init();
  2031. MessageNotify.GetInstance.ShowRunLog("西门子plc初始化");
  2032. if (SiemensDevice.IsConnected && GVL_BigStation.IsAllowSiemensConnect)
  2033. {
  2034. MessageNotify.GetInstance.ShowRunLog("西门子plc连接成功");
  2035. }
  2036. }
  2037. }
  2038. public void ThreadInit()
  2039. {
  2040. ThreadManage.GetInstance().StartLong(new Action(() =>
  2041. {
  2042. if (!HKDevice.IsConnected && GVL_BigStation.IsAllowHKPlcConnect)
  2043. {
  2044. HKDevice.HK_PLC_S7.Connect(S7.Net.CpuType.S71500, HK_PLC_IP);
  2045. MessageNotify.GetInstance.ShowRunLog("海科plc重新连接成功");
  2046. }
  2047. if (!SiemensDevice.IsConnected && GVL_BigStation.IsAllowSiemensConnect)
  2048. {
  2049. SiemensDevice.Siemens_PLC_S7.Connect(S7.Net.CpuType.S71500, Siemens_PLC_IP);
  2050. MessageNotify.GetInstance.ShowRunLog("西门子plc重新连接");
  2051. }
  2052. Thread.Sleep(10);
  2053. }), "西门子和海科PLC重新连接", true);
  2054. ThreadManage.GetInstance().StartLong(new Action(() =>
  2055. {
  2056. GVL_BigStation.HeartBeatToPlc = !GVL_BigStation.HeartBeatToPlc;
  2057. HKDevice.HK_PLC_S7.Write("DB99.DBX0.0", GVL_BigStation.HeartBeatToPlc);
  2058. GVL_BigStation.HeartBeatFromPlc = HKDevice.PlcRead.HeartBeat;//读取plc心跳
  2059. if (HKDevice.IsConnected)
  2060. {
  2061. if (GVL_BigStation.AGVPutTray.GetBitValue(1))
  2062. {
  2063. HKDevice.HK_PLC_S7.Write("DB99.DBX0.7", true);
  2064. }
  2065. else
  2066. {
  2067. HKDevice.HK_PLC_S7.Write("DB99.DBX0.7", false);
  2068. }
  2069. if (GVL_BigStation.AGVPutTray.GetBitValue(2))
  2070. {
  2071. HKDevice.HK_PLC_S7.Write("DB99.DBX1.0", true);
  2072. }
  2073. else
  2074. {
  2075. HKDevice.HK_PLC_S7.Write("DB99.DBX1.0", false);
  2076. }
  2077. if (GVL_BigStation.AGVPutTray.GetBitValue(3))
  2078. {
  2079. HKDevice.HK_PLC_S7.Write("DB99.DBX1.1", true);
  2080. }
  2081. else
  2082. {
  2083. HKDevice.HK_PLC_S7.Write("DB99.DBX1.1", false);
  2084. }
  2085. if (GVL_BigStation.AGVPutTray.GetBitValue(4))
  2086. {
  2087. HKDevice.HK_PLC_S7.Write("DB99.DBX1.2", true);
  2088. }
  2089. else
  2090. {
  2091. HKDevice.HK_PLC_S7.Write("DB99.DBX1.2", false);
  2092. }
  2093. if (GVL_BigStation.AGVPutTray.GetBitValue(5))
  2094. {
  2095. HKDevice.HK_PLC_S7.Write("DB99.DBX1.3", true);
  2096. }
  2097. else
  2098. {
  2099. HKDevice.HK_PLC_S7.Write("DB99.DBX1.3", false);
  2100. }
  2101. GVL_BigStation.TraySensor = GVL_BigStation.TraySensor.SetBitValue(1, HKDevice.PlcRead.Tray1Sensor);
  2102. GVL_BigStation.TraySensor = GVL_BigStation.TraySensor.SetBitValue(2, HKDevice.PlcRead.Tray2Sensor);
  2103. GVL_BigStation.TraySensor = GVL_BigStation.TraySensor.SetBitValue(3, HKDevice.PlcRead.Tray3Sensor);
  2104. GVL_BigStation.TraySensor = GVL_BigStation.TraySensor.SetBitValue(4, HKDevice.PlcRead.Tray4Sensor);
  2105. GVL_BigStation.TraySensor = GVL_BigStation.TraySensor.SetBitValue(5, HKDevice.PlcRead.Tray5Sensor);
  2106. GVL_BigStation.TrayCylinder = GVL_BigStation.TrayCylinder.SetBitValue(1, !HKDevice.PlcRead.Tray1Cylinder);
  2107. GVL_BigStation.TrayCylinder = GVL_BigStation.TrayCylinder.SetBitValue(2, !HKDevice.PlcRead.Tray2Cylinder);
  2108. GVL_BigStation.TrayCylinder = GVL_BigStation.TrayCylinder.SetBitValue(3, !HKDevice.PlcRead.Tray3Cylinder);
  2109. GVL_BigStation.TrayCylinder = GVL_BigStation.TrayCylinder.SetBitValue(4, !HKDevice.PlcRead.Tray4Cylinder);
  2110. GVL_BigStation.TrayCylinder = GVL_BigStation.TrayCylinder.SetBitValue(5, !HKDevice.PlcRead.Tray5Cylinder);
  2111. if (HKDevice.PlcRead.IsAllowIssueRecipe1 || HKDevice.PlcRead.IsAllowIssueRecipe2 || HKDevice.PlcRead.IsAllowIssueRecipe3 || HKDevice.PlcRead.IsAllowIssueRecipe4)
  2112. {
  2113. GVL_BigStation.Order_Request = true;
  2114. }
  2115. }
  2116. if (SiemensDevice.IsConnected)
  2117. {
  2118. GVL_BigStation.AGVPutTray = SiemensDevice.DL_Status.AGV_Put_Done;
  2119. GVL_BigStation.AGVGetTray = SiemensDevice.DL_Status.AGV_Get_Done;
  2120. SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBW30", GVL_BigStation.TraySensor);
  2121. SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBW32", GVL_BigStation.TrayCylinder);
  2122. SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBW34", (ushort)GVL_BigStation.TrayEnable);
  2123. }
  2124. Thread.Sleep(10);
  2125. }), "海科plc和西门子数据交互", true);
  2126. ThreadManage.GetInstance().StartLong(new Action(() =>
  2127. {
  2128. testRawMaterialNameData();//自定义料仓名称
  2129. if (GVL_BigStation.Order_Cancel)
  2130. {
  2131. Order_Cancel();
  2132. }
  2133. else
  2134. {
  2135. /*if (GVL_BigStation.IsUseLocalRecipe)
  2136. {
  2137. LocalRecipeRecevice();
  2138. LocalRecipeDosing();
  2139. }
  2140. else
  2141. {*/
  2142. ReceviceData();
  2143. RecipeInfoToHKPLC();
  2144. /* }*/
  2145. }
  2146. Thread.Sleep(10);
  2147. }), "配方数据执行流程", true);
  2148. }
  2149. /// <summary>
  2150. /// 初始化变量复位
  2151. /// </summary>
  2152. public void VarResetInit()
  2153. {
  2154. LocalRecipeQueue1.Clear();
  2155. LocalRecipeQueue2.Clear();
  2156. LocalRecipeQueue3.Clear();
  2157. LocalRecipeQueue4.Clear();
  2158. SiemensRecipeQueue1.Clear();
  2159. SiemensRecipeQueue2.Clear();
  2160. SiemensRecipeQueue3.Clear();
  2161. SiemensRecipeQueue4.Clear();
  2162. }
  2163. public void RecipeDosing()
  2164. {
  2165. GVL_BigStation.AllowIssueRecipe[0] = HKDevice.PlcRead.IsAllowIssueRecipe1;
  2166. GVL_BigStation.AllowIssueRecipe[1] = HKDevice.PlcRead.IsAllowIssueRecipe2;
  2167. GVL_BigStation.AllowIssueRecipe[2] = HKDevice.PlcRead.IsAllowIssueRecipe3;
  2168. GVL_BigStation.AllowIssueRecipe[3] = HKDevice.PlcRead.IsAllowIssueRecipe4;
  2169. GVL_BigStation.ReceviceFinishRecipe[0] = HKDevice.PlcRead.ReceiveFinishRecipe1;
  2170. GVL_BigStation.ReceviceFinishRecipe[1] = HKDevice.PlcRead.ReceiveFinishRecipe2;
  2171. GVL_BigStation.ReceviceFinishRecipe[2] = HKDevice.PlcRead.ReceiveFinishRecipe3;
  2172. GVL_BigStation.ReceviceFinishRecipe[3] = HKDevice.PlcRead.ReceiveFinishRecipe4;
  2173. GVL_BigStation.DosingFinishRecipe[0] = HKDevice.PlcRead.Recipe1DosingFinish;
  2174. GVL_BigStation.DosingFinishRecipe[1] = HKDevice.PlcRead.Recipe2DosingFinish;
  2175. GVL_BigStation.DosingFinishRecipe[2] = HKDevice.PlcRead.Recipe3DosingFinish;
  2176. GVL_BigStation.DosingFinishRecipe[3] = HKDevice.PlcRead.Recipe4DosingFinish;
  2177. GVL_BigStation.IsTrayArrive[0] = HKDevice.PlcRead.Tray1InPlace;
  2178. GVL_BigStation.IsTrayArrive[1] = HKDevice.PlcRead.Tray2InPlace;
  2179. GVL_BigStation.IsTrayArrive[2] = HKDevice.PlcRead.Tray3InPlace;
  2180. GVL_BigStation.IsTrayArrive[3] = HKDevice.PlcRead.Tray4InPlace;
  2181. GVL_BigStation.IsTrayArrive[4] = HKDevice.PlcRead.Tray5InPlace;
  2182. #region 接收配方
  2183. SiemensRecipes = Json<RemoteRecipe>.Data.Recipes;
  2184. if (SiemensRecipes.Count > 0)
  2185. {
  2186. foreach (var data in SiemensRecipes)
  2187. {
  2188. foreach (var item in SiemensRecipeQueue)
  2189. {
  2190. if (item.Value.Count == 0 && item.Key == data.TrayCode && GVL_BigStation.AllowIssueRecipe[item.Key - 1])
  2191. {
  2192. if (SiemensDevice.DL_Status is DL_Status_DB status)
  2193. {
  2194. switch (GVL_BigStation.SiemensSendRecipeStatus)
  2195. {
  2196. case 3:
  2197. SiemensDevice.Siemens_PLC_S7.WriteString(2331, data.RecipeCode, 10);
  2198. SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", true);
  2199. MessageNotify.GetInstance.ShowRunLog($"配方1,发送配方编号和请求配料标志给西门子");
  2200. GVL_BigStation.SiemensSendRecipeStatus = 4;
  2201. break;
  2202. case 4:
  2203. if (SiemensDevice.DL_Status.Dosing_Start_ACK)
  2204. {
  2205. SiemensDevice.Siemens_PLC_S7.WriteString(2331, "", 10);
  2206. SiemensDevice.Siemens_PLC_S7.Write("DB2331.DBX28.0", false);
  2207. MessageNotify.GetInstance.ShowRunLog($"配方1,西门子确认开始配料");
  2208. GVL_BigStation.SiemensSendRecipeStatus = 5;
  2209. }
  2210. break;
  2211. case 5:
  2212. if (SiemensDevice.DL_Status.Dosing_Start_ACK == false)
  2213. {
  2214. item.Value.Enqueue(data.RecipeCode);
  2215. MessageNotify.GetInstance.ShowRunLog($"配方1,配方:{data.RecipeCode},加入队列");
  2216. GVL_BigStation.SiemensSendRecipeStatus = 0;
  2217. }
  2218. break;
  2219. default:
  2220. break;
  2221. }
  2222. }
  2223. }
  2224. }
  2225. }
  2226. }
  2227. else
  2228. {
  2229. SiemensRecipeQueue.Clear();
  2230. GVL_BigStation.BarrelWasherSign = false;
  2231. for (int i = 0; i < GVL_BigStation.RecipeDosingStatus.Length; i++)
  2232. {
  2233. GVL_BigStation.RecipeDosingStatus[i] = 0;
  2234. }
  2235. }
  2236. #endregion
  2237. #region 取消配方
  2238. if (GVL_BigStation.Order_Cancel) //订单取消
  2239. {
  2240. if (!string.IsNullOrEmpty(GVL_BigStation.Order_CancelRecipeCode))
  2241. {
  2242. string code = GVL_BigStation.Order_CancelRecipeCode;
  2243. int index = Array.FindIndex(Json<RemoteRecipe>.Data.Recipes.ToArray(), p => p.RecipeCode == GVL_BigStation.Order_CancelRecipeCode);
  2244. short TrayCode = 0;
  2245. if (index >= 0)
  2246. {
  2247. TrayCode = (short)Json<RemoteRecipe>.Data.Recipes.ElementAt(index).TrayCode;
  2248. }
  2249. switch (GVL_BigStation.Order_CancelStep)
  2250. {
  2251. case 0:
  2252. if (index == -1)
  2253. {
  2254. GVL_BigStation.Order_CancelStep = 10;
  2255. }
  2256. else
  2257. {
  2258. GVL_BigStation.Order_CancelStep = 20;
  2259. foreach (var item in SiemensRecipeQueue)
  2260. {
  2261. if (item.Value.Contains(code))
  2262. {
  2263. GVL_BigStation.Order_CancelStep = 30;
  2264. }
  2265. }
  2266. }
  2267. break;
  2268. case 10:
  2269. SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", true);
  2270. GVL_BigStation.Order_CancelStep = 11;
  2271. break;
  2272. case 11:
  2273. if (SiemensDevice.Siemens_PLC_S7.Read<bool>("DB2301.DBX320.2") == false)
  2274. {
  2275. SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", false);
  2276. GVL_BigStation.Order_CancelStep = 12;
  2277. }
  2278. break;
  2279. case 12:
  2280. MessageNotify.GetInstance.ShowRunLog($"西门子取消订单,但未找到订单:{GVL_BigStation.Order_CancelRecipeCode}");
  2281. GVL_BigStation.Order_Cancel = false;
  2282. GVL_BigStation.Order_CancelRecipeCode = "";
  2283. GVL_BigStation.Order_CancelStep = 0;
  2284. break;
  2285. case 20:
  2286. SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", true);
  2287. GVL_BigStation.Order_CancelStep = 21;
  2288. break;
  2289. case 21:
  2290. if (SiemensDevice.Siemens_PLC_S7.Read<bool>("DB2301.DBX320.2") == false)
  2291. {
  2292. SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", false);
  2293. GVL_BigStation.Order_CancelStep = 22;
  2294. }
  2295. break;
  2296. case 22:
  2297. GVL_BigStation.SiemensSendRecipeStatus = 0;
  2298. App.Current.Dispatcher.Invoke(() =>
  2299. {
  2300. Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);
  2301. });
  2302. MessageNotify.GetInstance.ShowRunLog($"正在执行请求订单流程,配方还未到PLC,订单号:{GVL_BigStation.Order_CancelRecipeCode}");
  2303. GVL_BigStation.Order_Cancel = false;
  2304. GVL_BigStation.Order_CancelRecipeCode = "";
  2305. GVL_BigStation.Order_CancelStep = 0;
  2306. break;
  2307. case 30:
  2308. foreach (var item in SiemensRecipeQueue)
  2309. {
  2310. if (item.Value.Contains(code))
  2311. {
  2312. if (GVL_BigStation.RecipeDosingStatus[item.Key - 1] != 0)
  2313. {
  2314. HKDevice.HK_PLC_S7.Write("DB99.DBX230.0", true);
  2315. HKDevice.HK_PLC_S7.Write("DB99.DBW232", (short)TrayCode);
  2316. GVL_BigStation.RecipeDosingStatus[item.Key - 1] = 0;
  2317. item.Value.TryDequeue(out code);
  2318. GVL_BigStation.Order_CancelStep = 32;
  2319. MessageNotify.GetInstance.ShowRunLog($"PLC正在执行配料流程,取消订单:{code}");
  2320. }
  2321. else
  2322. {
  2323. GVL_BigStation.Order_CancelStep = 32;
  2324. MessageNotify.GetInstance.ShowRunLog($"AGV未到达工站前,未给plc下发配方,取消订单:{code}");
  2325. }
  2326. }
  2327. }
  2328. break;
  2329. case 32:
  2330. SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", true);
  2331. GVL_BigStation.Order_CancelStep = 33;
  2332. break;
  2333. case 33:
  2334. if (SiemensDevice.Siemens_PLC_S7.Read<bool>("DB2301.DBX320.2") == false)
  2335. {
  2336. SiemensDevice.Siemens_PLC_S7.Write("DB2301.DBX330.1", false);
  2337. App.Current.Dispatcher.Invoke(() =>
  2338. {
  2339. Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);
  2340. });
  2341. GVL_BigStation.Order_CancelStep = 0;
  2342. MessageNotify.GetInstance.ShowRunLog($"队列1,西门子取消订单完成,订单号:{code}");
  2343. }
  2344. break;
  2345. default:
  2346. break;
  2347. }
  2348. }
  2349. }
  2350. #endregion
  2351. #region 配料
  2352. foreach (var data in SiemensRecipeQueue)
  2353. {
  2354. int index = Array.FindIndex(SiemensRecipes.ToArray(), p => p.RecipeCode == data.Value.ElementAt(0));
  2355. if (index >= 0 && index < SiemensRecipes.Count)
  2356. {
  2357. string code = SiemensRecipes.ElementAt(index).RecipeCode;
  2358. int trayCode = SiemensRecipes.ElementAt(index).TrayCode;
  2359. if (GVL_BigStation.RecipeDosingStatus[data.Key] == 0 && GVL_BigStation.AllowIssueRecipe[data.Key] && GVL_BigStation.IsTrayArrive[trayCode - 1])//配方4是否允许下发配发
  2360. {
  2361. if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
  2362. {
  2363. if (!GVL_BigStation.BarrelWasherSign)//其他配方在洗桶时,等待其他配方洗完,在发送数据
  2364. {
  2365. GVL_BigStation.BarrelWasherSign = true;
  2366. HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", true);//洗桶
  2367. MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},订单类型为洗桶");
  2368. GVL_BigStation.RecipeDosingTime[data.Key] = DateTime.Now;
  2369. HKDevice.WritePlcRecipeData(SiemensRecipes.ElementAt(index));
  2370. HKDevice.HK_PLC_S7.Write($"DB99.DBX0.{2 + data.Key}", true);
  2371. GVL_BigStation.RecipeDosingStatus[data.Key] = 1;
  2372. MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},下发完成");
  2373. }
  2374. }
  2375. else
  2376. {
  2377. GVL_BigStation.RecipeDosingTime[data.Key] = DateTime.Now;
  2378. HKDevice.WritePlcRecipeData(SiemensRecipes.ElementAt(index));
  2379. HKDevice.HK_PLC_S7.Write($"DB99.DBX0.{2 + data.Key}", true);
  2380. GVL_BigStation.RecipeDosingStatus[data.Key] = 1;
  2381. MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},下发完成");
  2382. }
  2383. }
  2384. if (GVL_BigStation.RecipeDosingStatus[data.Key] == 1 && GVL_BigStation.ReceviceFinishRecipe[data.Key])
  2385. {
  2386. if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
  2387. {
  2388. HKDevice.HK_PLC_S7.Write("DB99.DBX0.1", false);//洗桶
  2389. MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},洗桶复位");
  2390. }
  2391. GVL_BigStation.RecipeDosingStatus[data.Key] = 2;
  2392. HKDevice.HK_PLC_S7.Write($"DB99.DBX0.{2 + data.Key}", true);
  2393. StockBinParReset();
  2394. MessageNotify.GetInstance.ShowRunLog($"配方编号:{code},托盘编号:{trayCode},PLC接收配方完成");
  2395. }
  2396. if (GVL_BigStation.RecipeDosingStatus[data.Key] == 2 && GVL_BigStation.DosingFinishRecipe[data.Key])
  2397. {
  2398. if (SiemensRecipes.ElementAt(index).IsWashingBarrel)
  2399. {
  2400. GVL_BigStation.BarrelWasherSign = false;
  2401. }
  2402. MessageNotify.GetInstance.ShowRunLog($"配方状态:{code}配料完成");
  2403. ReadStockBinDosingWeight(SiemensRecipes.ElementAt(index));
  2404. if (SiemensDevice.IsConnected)
  2405. {
  2406. FinishData.Order_No = SiemensRecipes.ElementAt(index).RecipeCode;
  2407. FinishData.Product_Code = SiemensRecipes.ElementAt(index).RecipeName;
  2408. FinishData.job_No = (short)SiemensRecipes.ElementAt(index).TrayCode;
  2409. for (int i = 0; i < FinishData.Material.Length; i++)
  2410. {
  2411. FinishData.Material[i] = new UDT1();
  2412. }
  2413. for (int i = 0; i < SiemensRecipes.ElementAt(index).RawMaterial.Count; i++)
  2414. {
  2415. FinishData.Material[i].Material_Name = SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialName;
  2416. FinishData.Material[i].Material_BarrelNum = (short)SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialBarrelNum;
  2417. FinishData.Material[i].Material_Laying_Off_Weight = Math.Abs(SiemensRecipes.ElementAt(index).RawMaterial.ElementAt(i).Laying_Off_Weight);
  2418. MessageNotify.GetInstance.ShowRunLog($"配方{data.Key},配方编号:{code},托盘编号:{trayCode},原料名称:{FinishData.Material[i].Material_Name},原料桶号:{FinishData.Material[i].Material_BarrelNum},配料重量:{FinishData.Material[i].Material_Laying_Off_Weight}kg");
  2419. }
  2420. FinishData.Ask_For_Finish = true;
  2421. double a = DateTime.Now.Subtract(GVL_BigStation.RecipeDosingTime[data.Key]).TotalSeconds;
  2422. FinishData.ProcessTime = Convert.ToInt16(a);
  2423. SiemensDevice.Siemens_PLC_S7.WriteClass<DL_Finish_DB>(FinishData, 2361);
  2424. MessageNotify.GetInstance.ShowRunLog($"{code}配方配料完成,将信号反馈给西门子");
  2425. }
  2426. data.Value.TryDequeue(out code);
  2427. if (!GVL_BigStation.IsUseLocalRecipe)
  2428. {
  2429. App.Current.Dispatcher.Invoke(() =>
  2430. {
  2431. Json<RemoteRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
  2432. });
  2433. }
  2434. else
  2435. {
  2436. App.Current.Dispatcher.Invoke(() =>
  2437. {
  2438. Json<LocalRecipe>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
  2439. });
  2440. }
  2441. HKDevice.HK_PLC_S7.Write($"DB99.DBX1.{data.Key + 3}", true);
  2442. GVL_BigStation.RecipeDosingStatus[data.Key] = 3;
  2443. }
  2444. if (GVL_BigStation.RecipeDosingStatus[data.Key] == 3 && GVL_BigStation.DosingFinishRecipe[data.Key] == false)
  2445. {
  2446. HKDevice.HK_PLC_S7.Write($"DB99.DBX1.{data.Key + 3}", false);
  2447. GVL_BigStation.RecipeDosingStatus[data.Key] = 0;
  2448. }
  2449. }
  2450. }
  2451. #endregion
  2452. }
  2453. /// <summary>
  2454. /// 读取配料完成时,每个料仓的配料重量
  2455. /// </summary>
  2456. /// <param name="recipes"></param>
  2457. public void ReadStockBinDosingWeight(RecipeData recipes)
  2458. {
  2459. foreach (var item in recipes.RawMaterial)
  2460. {
  2461. if (item.RawMaterialLocation == 1)
  2462. {
  2463. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin1ActualWeight;
  2464. }
  2465. else if (item.RawMaterialLocation == 2)
  2466. {
  2467. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin2ActualWeight;
  2468. }
  2469. else if (item.RawMaterialLocation == 3)
  2470. {
  2471. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin3ActualWeight;
  2472. }
  2473. else if (item.RawMaterialLocation == 4)
  2474. {
  2475. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin4ActualWeight;
  2476. }
  2477. else if (item.RawMaterialLocation == 5)
  2478. {
  2479. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin5ActualWeight;
  2480. }
  2481. else if (item.RawMaterialLocation == 6)
  2482. {
  2483. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin6ActualWeight;
  2484. }
  2485. else if (item.RawMaterialLocation == 7)
  2486. {
  2487. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin7ActualWeight;
  2488. }
  2489. else if (item.RawMaterialLocation == 8)
  2490. {
  2491. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin8ActualWeight;
  2492. }
  2493. else if (item.RawMaterialLocation == 9)
  2494. {
  2495. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin9ActualWeight;
  2496. }
  2497. else if (item.RawMaterialLocation == 10)
  2498. {
  2499. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin10ActualWeight;
  2500. }
  2501. else if (item.RawMaterialLocation == 11)
  2502. {
  2503. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin11ActualWeight;
  2504. }
  2505. else if (item.RawMaterialLocation == 12)
  2506. {
  2507. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin12ActualWeight;
  2508. }
  2509. else if (item.RawMaterialLocation == 13)
  2510. {
  2511. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin13ActualWeight;
  2512. }
  2513. else if (item.RawMaterialLocation == 14)
  2514. {
  2515. item.Laying_Off_Weight = HKDevice.PlcRead.StockBin14ActualWeight;
  2516. }
  2517. }
  2518. }
  2519. /// <summary>
  2520. /// 发送操作,直到收到确认信号
  2521. /// </summary>
  2522. /// <param name="operate"></param>
  2523. /// <param name="ack"></param>
  2524. /// <param name="retrySecond"></param>
  2525. /// <returns></returns>
  2526. /// <exception cref="ArgumentNullException"></exception>
  2527. private bool SendDataOperation(Action operate, Func<bool> ack, int retrySecond = 3)
  2528. {
  2529. if (operate is null)
  2530. {
  2531. throw new ArgumentNullException("operate", "需要执行的操作不可为Null。");
  2532. }
  2533. if (ack is null)
  2534. {
  2535. throw new ArgumentNullException("ack", "验证确认的委托不可为Null。");
  2536. }
  2537. var isSuccess = false;
  2538. var isConnected = SiemensDevice.IsConnected;
  2539. var retryDelay = TimeSpan.FromSeconds(retrySecond);
  2540. operate?.Invoke();
  2541. isSuccess = ack.Invoke();
  2542. while (!isSuccess)
  2543. {
  2544. if (isConnected)
  2545. {
  2546. Thread.Sleep(retryDelay);
  2547. operate?.Invoke();
  2548. isSuccess = isSuccess && ack.Invoke();
  2549. }
  2550. }
  2551. return isSuccess;
  2552. }
  2553. private void CleanFinishData()
  2554. {
  2555. if ((GVL_BigStation.Recipe1DosingFinish || GVL_BigStation.Recipe2DosingFinish || GVL_BigStation.Recipe3DosingFinish || GVL_BigStation.Recipe4DosingFinish))
  2556. {
  2557. FinishData.Order_No = "";
  2558. FinishData.Product_Code = "";
  2559. FinishData.job_No = 0;
  2560. for (int i = 0; i < 20; i++)
  2561. {
  2562. FinishData.Material[i] = new UDT1();
  2563. }
  2564. FinishData.Ask_For_Finish = false;
  2565. FinishData.ProcessTime = 0;
  2566. SiemensDevice.Siemens_PLC_S7.WriteClass<DL_Finish_DB>(FinishData, 2361);
  2567. }
  2568. }
  2569. }
  2570. }