终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

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