终端一体化运控平台
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

2373 satır
140 KiB

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