终端一体化运控平台
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

1533 líneas
84 KiB

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