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

1084 lines
61 KiB

  1. using BPASmartClient.CustomResource.Pages.Model;
  2. using BPASmartClient.Helper;
  3. using BPASmartClient.JXJFoodSmallStation.Model.HK_PLC;
  4. using BPASmartClient.JXJFoodSmallStation.Model.Siemens;
  5. using BPASmartClient.JXJFoodSmallStation.Model.WindSend;
  6. using BPASmartClient.Modbus;
  7. using System;
  8. using System.Collections.Concurrent;
  9. using System.Collections.Generic;
  10. using System.Collections.ObjectModel;
  11. using System.Configuration;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading;
  15. using System.Threading.Tasks;
  16. namespace BPASmartClient.JXJFoodSmallStation.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. /// <summary>
  24. /// 配方数据
  25. /// </summary>
  26. public ObservableCollection<RemoteRecipeData> RemoteRecipes = new ObservableCollection<RemoteRecipeData>();
  27. /// <summary>
  28. /// 原料的名称和料仓的位置对应
  29. /// </summary>
  30. public Dictionary<string, short> RawMaterialsNamePos = new Dictionary<string, short>();
  31. /// <summary>
  32. /// 配方队列
  33. /// </summary>
  34. public ConcurrentQueue<string> RecipeQueue = new ConcurrentQueue<string>();
  35. public ConcurrentQueue<string> RecipeQueueTray2 = new ConcurrentQueue<string>();
  36. public SiemensDeviceStatus SiemensDevice = new SiemensDeviceStatus();
  37. public HKDeviceStatus HKDevice = new HKDeviceStatus();
  38. public WindSendDeviceStatus WindSendDevice = new WindSendDeviceStatus();
  39. XL_Finish_DB RecipeFinishInfo = new XL_Finish_DB();
  40. /// <summary>
  41. /// 风送PLC的DB块
  42. /// </summary>
  43. XL_WindSendData_DB WindSendData = new XL_WindSendData_DB();
  44. /// <summary>
  45. /// 接收原料数据
  46. /// </summary>
  47. public RecipeRawMaterial RawMaterial;
  48. public void Init()
  49. {
  50. for (int i = 0; i < 16; i++)
  51. {
  52. if (DeviceInquire.GetInstance.GetDevice(i).DeviceName != null)
  53. {
  54. if (!RawMaterialsNamePos.ContainsKey(DeviceInquire.GetInstance.GetDevice(i).DeviceName))
  55. {
  56. RawMaterialsNamePos.Add(DeviceInquire.GetInstance.GetDevice(i).DeviceName, (short)DeviceInquire.GetInstance.GetDevice(i).deviceStatus.DeviceNum);
  57. }
  58. }
  59. }
  60. ActionManage.GetInstance.CancelRegister("SiemensRecipeRecive");
  61. ActionManage.GetInstance.Register(new Action<object>((res) =>
  62. {
  63. ObservableCollection<RemoteRecipeRawMaterial> RawMaterials = new ObservableCollection<RemoteRecipeRawMaterial>();
  64. ObservableCollection<WindSendRawMaterial> WindSendData = new ObservableCollection<WindSendRawMaterial>();
  65. if (SiemensDevice.IsConnected)
  66. {
  67. if (res != null && res is XL_Start_DB recipe)
  68. {
  69. RawMaterials.Clear();
  70. for (int i = 0; i < GVL_SmallStation.Max_DosingSotckBinNum; i++)
  71. {
  72. if (!string.IsNullOrEmpty(recipe.Material[i].Material_Name))
  73. {
  74. if (RawMaterialsNamePos.ContainsKey(recipe.Material[i].Material_Name))
  75. {
  76. RawMaterials.Add(new RemoteRecipeRawMaterial()
  77. {
  78. RawMaterialName = recipe.Material[i].Material_Name,
  79. RawMaterialBarrelNum = recipe.Material[i].Material_BarrelNum,
  80. RawMaterialWeight = recipe.Material[i].Material_Weight,
  81. RawMaterialLocation = (int)RawMaterialsNamePos[recipe.Material[i].Material_Name]
  82. });
  83. }
  84. else
  85. {
  86. //MessageNotify.GetInstance.AlarmLog("配方名称与本地不符合");
  87. }
  88. }
  89. else
  90. {
  91. break;
  92. }
  93. }
  94. for (int i = 0; i < GVL_SmallStation.Max_PowderSotckBinNum; i++)
  95. {
  96. if (!string.IsNullOrEmpty(recipe.Powder[i].Powder_Name))
  97. {
  98. WindSendData.Add(new WindSendRawMaterial()
  99. {
  100. RawMaterialName = recipe.Powder[i].Powder_Name,
  101. RawMaterialWeight = recipe.Powder[i].Powder_Weight
  102. });
  103. }
  104. else
  105. {
  106. break;
  107. }
  108. }
  109. Json<RemoteRecipeDataColl>.Data.Recipes.Add(new RemoteRecipeData()
  110. {
  111. RecipeName = recipe.RecipeName,
  112. RecipeCode = recipe.RecipeCode,
  113. RawMaterial = RawMaterials,
  114. TrayCode = recipe.TrayCode,
  115. WindSend = WindSendData
  116. });
  117. }
  118. }
  119. }), "SiemensRecipeRecive", true);
  120. ActionManage.GetInstance.CancelRegister("WindSendDosingFinish");
  121. ActionManage.GetInstance.Register(new Action(() =>
  122. {
  123. GVL_SmallStation.GetInstance.WindSendDosingFinish = true;
  124. }),"WindSendDosingFinish",true);
  125. ActionManage.GetInstance.CancelRegister("LocalSimulationRecipeIssue");
  126. ActionManage.GetInstance.Register(new Action<Object>((res) =>
  127. {
  128. if (res != null && res is RemoteRecipeData recipe)
  129. {
  130. Json<RemoteRecipeDataColl>.Data.Recipes.Add(recipe);
  131. }
  132. }), "LocalSimulationRecipeIssue", true);
  133. string HK_PLC_IP = ConfigurationManager.AppSettings["HKPlc_IP"];
  134. string Siemens_PLC_IP = ConfigurationManager.AppSettings["Siemens_IP"];
  135. string WindSend_PLC_IP = ConfigurationManager.AppSettings["WindSend_IP"];
  136. try
  137. {
  138. //HKDevice.HK_PLC_S7.Connect(S7.Net.CpuType.S71200, HK_PLC_IP);
  139. //SiemensDevice.Siemens_PLC_S7.Connect(S7.Net.CpuType.S71500, Siemens_PLC_IP);
  140. //WindSendDevice.Siemens_PLC_S7.Connect(S7.Net.CpuType.S71200,WindSend_PLC_IP);
  141. if (HKDevice.IsConnected)
  142. {
  143. HKDevice.Init();
  144. MessageNotify.GetInstance.ShowRunLog("海科plc连接成功,并初始化完成");
  145. }
  146. if (SiemensDevice.IsConnected)
  147. {
  148. SiemensDevice.Init();
  149. MessageNotify.GetInstance.ShowRunLog("西门子plc连接成功,并初始化完成");
  150. }
  151. if (WindSendDevice.IsConnected)
  152. {
  153. WindSendDevice.Init();
  154. MessageNotify.GetInstance.ShowRunLog("风送plc连接成功,并初始化完成");
  155. }
  156. }
  157. catch(Exception ex)
  158. {
  159. }
  160. ActionManage.GetInstance.CancelRegister("SystemStart");
  161. ActionManage.GetInstance.Register(new Action(() =>
  162. {
  163. HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.0", true);
  164. }), "SystemStart", true);
  165. ActionManage.GetInstance.CancelRegister("SystemStop");
  166. ActionManage.GetInstance.Register(new Action(() =>
  167. {
  168. HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.0", false);
  169. }), "SystemStop", true);
  170. ActionManage.GetInstance.CancelRegister("SystemPause");
  171. ActionManage.GetInstance.Register(new Action(() =>
  172. {
  173. HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.2", true);
  174. }), "SystemPause", true);
  175. ActionManage.GetInstance.CancelRegister("SystemReset");
  176. ActionManage.GetInstance.Register(new Action(() =>
  177. {
  178. HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.2", false);
  179. }), "SystemReset", true);
  180. ActionManage.GetInstance.CancelRegister("SystemAutoMode");
  181. ActionManage.GetInstance.Register(new Action(() =>
  182. {
  183. HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.1", false);
  184. }), "SystemAutoMode", true);
  185. ActionManage.GetInstance.CancelRegister("SystemDebugMode");
  186. ActionManage.GetInstance.Register(new Action(() =>
  187. {
  188. HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.1", true);
  189. }), "SystemDebugMode", true);
  190. RecipeQueue.Clear();
  191. //Json<RemoteRecipeDataColl>.Data.Recipes = TestData.GetInstance.Recipes;//添加测试数据
  192. ThreadManage.GetInstance().StartLong(new Action(() =>
  193. {
  194. HeartHKPlc();
  195. ReceviceData();
  196. RecipeInfoToHKPLC();
  197. Thread.Sleep(10);
  198. }), "西门子配发下发流程处理", true);
  199. /* ThreadManage.GetInstance().StartLong(new Action(() =>
  200. {
  201. if (SiemensDevice.IsConnected && HKDevice.IsConnected)
  202. {
  203. *//*AgvGetInDelivery();
  204. AgvGetInPickUp();*//*
  205. }
  206. Thread.Sleep(10);
  207. }), "AGV进站送取货", true);*/
  208. ThreadManage.GetInstance().StartLong(new Action(() =>
  209. {
  210. if (HKDevice.IsConnected)
  211. {
  212. //GetStatus();
  213. ManualOpen();
  214. ManualClose();
  215. }
  216. Thread.Sleep(10);
  217. }), "手动操作", true);
  218. }
  219. private void GetStatus()
  220. {
  221. for (int i = 0; i < 8; i++)
  222. {
  223. GVL_SmallStation.GetInstance.Cylinder_JackInfo[i] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX0." + i);
  224. }
  225. for (int i = 0; i < 7; i++)
  226. {
  227. GVL_SmallStation.GetInstance.Cylinder_JackInfo[i + 8] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX0." + i);
  228. }/*
  229. ActionManage.GetInstance.Register(new Action(() =>
  230. {
  231. HKDevice.HK_PLC_S7.Write<bool>("M10.0", true);
  232. }), "ManualEStop", true);
  233. ActionManage.GetInstance.Register(new Action(() =>
  234. {
  235. HKDevice.HK_PLC_S7.Write<bool>("M10.0", false);
  236. }), "ManualEReset", true);*/
  237. }
  238. private void ManualOpen()
  239. {
  240. ActionManage.GetInstance.Register(new Action<object>((o) =>
  241. {
  242. if (o != null)
  243. {
  244. if (o.ToString().Contains("升降气缸"))
  245. {
  246. int index = Convert.ToInt16(o.ToString().Substring(o.ToString().Length - 1));
  247. switch (index)
  248. {
  249. case 1:
  250. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX0.0", true);
  251. break;
  252. case 2:
  253. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX0.1", true);
  254. break;
  255. case 3:
  256. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX0.2", true);
  257. break;
  258. case 4:
  259. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX0.3", true);
  260. break;
  261. case 5:
  262. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX0.4", true);
  263. break;
  264. case 6:
  265. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX0.5", true);
  266. break;
  267. case 7:
  268. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX0.6", true);
  269. break;
  270. case 8:
  271. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX0.7", true);
  272. break;
  273. case 9:
  274. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX1.0", true);
  275. break;
  276. case 10:
  277. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX1.1", true);
  278. break;
  279. case 11:
  280. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX1.2", true);
  281. break;
  282. case 12:
  283. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX1.3", true);
  284. break;
  285. case 13:
  286. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX1.4", true);
  287. break;
  288. case 14:
  289. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX1.5", true);
  290. break;
  291. case 15:
  292. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX1.6", true);
  293. break;
  294. default:
  295. break;
  296. }
  297. }
  298. else if (o.ToString().Contains("阻挡气缸"))
  299. {
  300. int index = Convert.ToInt16(o.ToString().Substring(o.ToString().Length - 1));
  301. switch (index)
  302. {
  303. case 1:
  304. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX1.7", true);
  305. break;
  306. case 2:
  307. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX2.0", true);
  308. break;
  309. case 3:
  310. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX2.1", true);
  311. break;
  312. case 4:
  313. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX2.2", true);
  314. break;
  315. case 5:
  316. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX2.3", true);
  317. break;
  318. case 6:
  319. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX2.4", true);
  320. break;
  321. case 7:
  322. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX2.5", true);
  323. break;
  324. case 8:
  325. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX2.6", true);
  326. break;
  327. case 9:
  328. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX2.7", true);
  329. break;
  330. case 10:
  331. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX3.0", true);
  332. break;
  333. case 11:
  334. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX3.1", true);
  335. break;
  336. case 12:
  337. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX3.2", true);
  338. break;
  339. case 13:
  340. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX3.3", true);
  341. break;
  342. case 14:
  343. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX3.4", true);
  344. break;
  345. case 15:
  346. HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX3.5", true);
  347. break;
  348. default:
  349. break;
  350. }
  351. }
  352. else if (o.ToString().Contains("进料桶顶升气缸"))
  353. {
  354. HKDevice.HK_PLC_S7.Write("DB5.DBX3.6", true);
  355. }
  356. else if (o.ToString().Contains("出料桶顶升气缸1"))
  357. {
  358. HKDevice.HK_PLC_S7.Write("DB5.DBX3.7", true);
  359. }
  360. else if (o.ToString().Contains("出料桶顶升气缸2"))
  361. {
  362. HKDevice.HK_PLC_S7.Write("DB5.DBX4.0", true);
  363. }
  364. else if (o.ToString().Contains("出料桶顶升气缸3"))
  365. {
  366. HKDevice.HK_PLC_S7.Write("DB5.DBX4.1", true);
  367. }
  368. else if (o.ToString().Contains("托盘气缸1_1"))
  369. {
  370. HKDevice.HK_PLC_S7.Write("DB5.DBX4.2", true);
  371. }
  372. else if (o.ToString().Contains("托盘气缸1_2"))
  373. {
  374. HKDevice.HK_PLC_S7.Write("DB5.DBX4.3", true);
  375. }
  376. else if (o.ToString().Contains("托盘气缸2_1"))
  377. {
  378. HKDevice.HK_PLC_S7.Write("DB5.DBX4.4", true);
  379. }
  380. else if (o.ToString().Contains("托盘气缸2_2"))
  381. {
  382. HKDevice.HK_PLC_S7.Write("DB5.DBX4.5", true);
  383. }
  384. }
  385. }), "ManualOpen", true);//根据下发的配方ID将 托盘的位置信息添加到配方中
  386. }
  387. private void ManualClose()
  388. {
  389. ActionManage.GetInstance.Register(new Action<object>((o) =>
  390. {
  391. if (o != null)
  392. {
  393. if (o.ToString().Contains("升降气缸"))
  394. {
  395. int index = Convert.ToInt16(o.ToString().Substring(o.ToString().Length - 1));
  396. switch (index)
  397. {
  398. case 1:
  399. HKDevice.HK_PLC_S7.Write("DB5.DBX0.0", false);
  400. break;
  401. case 2:
  402. HKDevice.HK_PLC_S7.Write("DB5.DBX0.1", false);
  403. break;
  404. case 3:
  405. HKDevice.HK_PLC_S7.Write("DB5.DBX0.2", false);
  406. break;
  407. case 4:
  408. HKDevice.HK_PLC_S7.Write("DB5.DBX0.3", false);
  409. break;
  410. case 5:
  411. HKDevice.HK_PLC_S7.Write("DB5.DBX0.4", false);
  412. break;
  413. case 6:
  414. HKDevice.HK_PLC_S7.Write("DB5.DBX0.5", false);
  415. break;
  416. case 7:
  417. HKDevice.HK_PLC_S7.Write("DB5.DBX0.6", false);
  418. break;
  419. case 8:
  420. HKDevice.HK_PLC_S7.Write("DB5.DBX0.7", false);
  421. break;
  422. case 9:
  423. HKDevice.HK_PLC_S7.Write("DB5.DBX1.0", false);
  424. break;
  425. case 10:
  426. HKDevice.HK_PLC_S7.Write("DB5.DBX1.1", false);
  427. break;
  428. case 11:
  429. HKDevice.HK_PLC_S7.Write("DB5.DBX1.2", false);
  430. break;
  431. case 12:
  432. HKDevice.HK_PLC_S7.Write("DB5.DBX1.3", false);
  433. break;
  434. case 13:
  435. HKDevice.HK_PLC_S7.Write("DB5.DBX1.4", false);
  436. break;
  437. case 14:
  438. HKDevice.HK_PLC_S7.Write("DB5.DBX1.5", false);
  439. break;
  440. case 15:
  441. HKDevice.HK_PLC_S7.Write("DB5.DBX1.6", false);
  442. break;
  443. default:
  444. break;
  445. }
  446. }
  447. else if (o.ToString().Contains("阻挡气缸"))
  448. {
  449. int index = Convert.ToInt16(o.ToString().Substring(o.ToString().Length - 1));
  450. switch (index)
  451. {
  452. case 1:
  453. HKDevice.HK_PLC_S7.Write("DB5.DBX1.7", false);
  454. break;
  455. case 2:
  456. HKDevice.HK_PLC_S7.Write("DB5.DBX2.0", false);
  457. break;
  458. case 3:
  459. HKDevice.HK_PLC_S7.Write("DB5.DBX2.1", false);
  460. break;
  461. case 4:
  462. HKDevice.HK_PLC_S7.Write("DB5.DBX2.2", false);
  463. break;
  464. case 5:
  465. HKDevice.HK_PLC_S7.Write("DB5.DBX2.3", false);
  466. break;
  467. case 6:
  468. HKDevice.HK_PLC_S7.Write("DB5.DBX2.4", false);
  469. break;
  470. case 7:
  471. HKDevice.HK_PLC_S7.Write("DB5.DBX2.5", false);
  472. break;
  473. case 8:
  474. HKDevice.HK_PLC_S7.Write("DB5.DBX2.6", false);
  475. break;
  476. case 9:
  477. HKDevice.HK_PLC_S7.Write("DB5.DBX2.7", false);
  478. break;
  479. case 10:
  480. HKDevice.HK_PLC_S7.Write("DB5.DBX3.0", false);
  481. break;
  482. case 11:
  483. HKDevice.HK_PLC_S7.Write("DB5.DBX3.1", false);
  484. break;
  485. case 12:
  486. HKDevice.HK_PLC_S7.Write("DB5.DBX3.2", false);
  487. break;
  488. case 13:
  489. HKDevice.HK_PLC_S7.Write("DB5.DBX3.3", false);
  490. break;
  491. case 14:
  492. HKDevice.HK_PLC_S7.Write("DB5.DBX3.4", false);
  493. break;
  494. case 15:
  495. HKDevice.HK_PLC_S7.Write("DB5.DBX3.5", false);
  496. break;
  497. default:
  498. break;
  499. }
  500. }
  501. else if (o.ToString().Contains("进料桶顶升气缸"))
  502. {
  503. HKDevice.HK_PLC_S7.Write("DB5.DBX3.6", false);
  504. }
  505. else if (o.ToString().Contains("出料桶顶升气缸1"))
  506. {
  507. HKDevice.HK_PLC_S7.Write("DB5.DBX3.7", false);
  508. }
  509. else if (o.ToString().Contains("出料桶顶升气缸2"))
  510. {
  511. HKDevice.HK_PLC_S7.Write("DB5.DBX4.0", false);
  512. }
  513. else if (o.ToString().Contains("出料桶顶升气缸3"))
  514. {
  515. HKDevice.HK_PLC_S7.Write("DB5.DBX4.1", false);
  516. }
  517. else if (o.ToString().Contains("托盘气缸1_1"))
  518. {
  519. HKDevice.HK_PLC_S7.Write("DB5.DBX4.2", false);
  520. }
  521. else if (o.ToString().Contains("托盘气缸1_2"))
  522. {
  523. HKDevice.HK_PLC_S7.Write("DB5.DBX4.3", false);
  524. }
  525. else if (o.ToString().Contains("托盘气缸2_1"))
  526. {
  527. HKDevice.HK_PLC_S7.Write("DB5.DBX4.4", false);
  528. }
  529. else if (o.ToString().Contains("托盘气缸2_2"))
  530. {
  531. HKDevice.HK_PLC_S7.Write("DB5.DBX4.5", false);
  532. }
  533. }
  534. }), "ManualClose", true);//根据下发的配方ID将 托盘的位置信息添加到配方中
  535. }
  536. /// <summary>
  537. /// AGV进站送货
  538. /// </summary>
  539. private void AgvGetInDelivery()
  540. {
  541. switch (GVL_SmallStation.GetInstance.AgvDeliveryPosition)
  542. {
  543. case 0:
  544. if (RTrig.GetInstance("").Start(SiemensDevice.Siemens_PLC_S7.Read<object>(SiemensCommAddress.DeliveryAGVApply) is bool))
  545. {
  546. GVL_SmallStation.GetInstance.AgvDeliveryPosition = 1;
  547. HKDevice.HK_PLC_S7.Write(HKPlcCommAddress.DeliveryAGVApply, true);
  548. }
  549. break;
  550. case 1:
  551. if (RTrig.GetInstance("").Start(HKDevice.HK_PLC_S7.Read<bool>(HKPlcCommAddress.DeliveryAGVIsApply)))
  552. {
  553. GVL_SmallStation.GetInstance.AgvDeliveryPosition = 2;
  554. SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.DeliveryAGVIsApply, true);
  555. }
  556. break;
  557. case 2:
  558. if (RTrig.GetInstance("").Start(SiemensDevice.Siemens_PLC_S7.Read<object>(SiemensCommAddress.DeliveryAGVApplyJack) is bool))
  559. {
  560. GVL_SmallStation.GetInstance.AgvDeliveryPosition = 3;
  561. HKDevice.HK_PLC_S7.Write(HKPlcCommAddress.DeliveryAGVApplyJack, true);
  562. }
  563. break;
  564. case 3:
  565. if (RTrig.GetInstance("").Start(HKDevice.HK_PLC_S7.Read<bool>(HKPlcCommAddress.DeliveryAGVIsApplyJack)))
  566. {
  567. GVL_SmallStation.GetInstance.AgvDeliveryPosition = 4;
  568. SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.DeliveryAGVIsApplyJack, true);
  569. }
  570. break;
  571. case 4:
  572. if (RTrig.GetInstance("").Start(SiemensDevice.Siemens_PLC_S7.Read<object>(SiemensCommAddress.DeliveryAGVFinsih) is bool))
  573. {
  574. GVL_SmallStation.GetInstance.AgvDeliveryPosition = 5;
  575. HKDevice.HK_PLC_S7.Write(HKPlcCommAddress.DeliveryAGVFinsih, true);
  576. }
  577. break;
  578. case 5:
  579. if (RTrig.GetInstance("").Start(HKDevice.HK_PLC_S7.Read<bool>(HKPlcCommAddress.StationHaveCargo)))
  580. {
  581. GVL_SmallStation.GetInstance.AgvDeliveryPosition = 0;
  582. SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.StationHaveCargo, true);
  583. }
  584. break;
  585. default:
  586. break;
  587. }
  588. //获取工位上是否有小车
  589. SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.StationIsExistCar, (bool)
  590. HKDevice.HK_PLC_S7.Read<bool>(HKPlcCommAddress.StationIsExistTray));
  591. }
  592. /// <summary>
  593. /// AGV进站取货
  594. /// </summary>
  595. private void AgvGetInPickUp()
  596. {
  597. switch (GVL_SmallStation.GetInstance.AgvPickUpPosition)
  598. {
  599. case 0:
  600. if (RTrig.GetInstance("").Start(SiemensDevice.Siemens_PLC_S7.Read<bool>(SiemensCommAddress.PickAGVApply)))
  601. {
  602. GVL_SmallStation.GetInstance.AgvPickUpPosition = 1;
  603. HKDevice.HK_PLC_S7.Write(HKPlcCommAddress.PickAGVApply, true);
  604. }
  605. break;
  606. case 1:
  607. if (RTrig.GetInstance("").Start(HKDevice.HK_PLC_S7.Read<bool>(HKPlcCommAddress.PickAGVIsApply)))
  608. {
  609. GVL_SmallStation.GetInstance.AgvPickUpPosition = 2;
  610. SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.PickAGVIsApply, true);
  611. }
  612. break;
  613. case 2:
  614. if (RTrig.GetInstance("").Start(SiemensDevice.Siemens_PLC_S7.Read<bool>(SiemensCommAddress.PickCargoAGVFinish)))
  615. {
  616. GVL_SmallStation.GetInstance.AgvPickUpPosition = 3;
  617. HKDevice.HK_PLC_S7.Write(HKPlcCommAddress.PickCargoAGVFinish, true);
  618. }
  619. break;
  620. case 3:
  621. if (RTrig.GetInstance("").Start(HKDevice.HK_PLC_S7.Read<bool>(HKPlcCommAddress.PickAGVFinish)))
  622. {
  623. GVL_SmallStation.GetInstance.AgvPickUpPosition = 0;
  624. SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.PickAGVFinish, true);
  625. }
  626. break;
  627. default:
  628. break;
  629. }
  630. }
  631. private void HeartHKPlc()
  632. {
  633. if (HKDevice.IsConnected)
  634. {
  635. GVL_SmallStation.GetInstance.HeartBeatToPlc = !GVL_SmallStation.GetInstance.HeartBeatToPlc;
  636. HKDevice.HK_PLC_S7.Write("DB4.DBX0.0", GVL_SmallStation.GetInstance.HeartBeatToPlc);
  637. GVL_SmallStation.GetInstance.HeartBeatFromPlc = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX0.0");
  638. }
  639. }
  640. /// <summary>
  641. /// 将配方添加到配方队列中
  642. /// </summary>
  643. private void ReceviceData()
  644. {
  645. RemoteRecipes = Json<RemoteRecipeDataColl>.Data.Recipes;
  646. if (RemoteRecipes.Count > 0)
  647. {
  648. foreach (var data in RemoteRecipes)
  649. {
  650. if (data.TrayCode == 1)
  651. {
  652. if (!(RecipeQueue.Contains(data.RecipeCode)))
  653. {
  654. RecipeQueue.Enqueue(data.RecipeCode);
  655. }
  656. }
  657. else if(data.TrayCode == 2)
  658. {
  659. if (!(RecipeQueueTray2.Contains(data.RecipeCode)))
  660. {
  661. RecipeQueueTray2.Enqueue(data.RecipeCode);
  662. }
  663. }
  664. }
  665. }
  666. else
  667. {
  668. RecipeQueue.Clear();
  669. RecipeQueueTray2.Clear();
  670. GVL_SmallStation.GetInstance.RecipeStatusID = 0;
  671. GVL_SmallStation.GetInstance.RecipeStatusIDTray2 = 0;
  672. }
  673. }
  674. /// <summary>
  675. /// 执行配方队列中的第一个配方
  676. /// </summary>
  677. private void RecipeInfoToHKPLC()
  678. {
  679. if (RecipeQueue.Count > 0)
  680. {
  681. int index = Array.FindIndex(RemoteRecipes.ToArray(), p => p.RecipeCode == RecipeQueue.ElementAt(0));
  682. if (index >= 0 && index < RemoteRecipes.Count)
  683. {
  684. string code = RemoteRecipes.ElementAt(index).RecipeCode;
  685. int trayCode = RemoteRecipes.ElementAt(index).TrayCode;
  686. string recipeName = RemoteRecipes.ElementAt(index).RecipeName;
  687. string windSend = RemoteRecipes.ElementAt(index).ToString();
  688. if (trayCode == 1)
  689. {
  690. if (GVL_SmallStation.GetInstance.RecipeStatusID == 0)
  691. {
  692. if (GVL_SmallStation.GetInstance.IsUseWindSend)
  693. {
  694. GVL_SmallStation.GetInstance.IsUseWindSend = false;
  695. WindSendData.TargetRecipeCode = code;
  696. if (RemoteRecipes.ElementAt(index).WindSend.ElementAt(0).RawMaterialName == DeviceName.原料1.ToString())
  697. {
  698. WindSendData.RawMaterial1_SetWeight = RemoteRecipes.ElementAt(index).WindSend.ElementAt(0).RawMaterialWeight;
  699. }
  700. if (RemoteRecipes.ElementAt(index).WindSend.ElementAt(1).RawMaterialName == DeviceName.原料2.ToString())
  701. {
  702. WindSendData.RawMaterial2_SetWeight = RemoteRecipes.ElementAt(index).WindSend.ElementAt(1).RawMaterialWeight;
  703. }
  704. if (RemoteRecipes.ElementAt(index).WindSend.ElementAt(2).RawMaterialName == DeviceName.原料3.ToString())
  705. {
  706. WindSendData.RawMaterial3_SetWeight = RemoteRecipes.ElementAt(index).WindSend.ElementAt(2).RawMaterialWeight;
  707. }
  708. if (RemoteRecipes.ElementAt(index).WindSend.ElementAt(3).RawMaterialName == DeviceName.原料4.ToString())
  709. {
  710. WindSendData.RawMaterial4_SetWeight = RemoteRecipes.ElementAt(index).WindSend.ElementAt(3).RawMaterialWeight;
  711. }
  712. if (RemoteRecipes.ElementAt(index).WindSend.ElementAt(4).RawMaterialName == DeviceName.原料5.ToString())
  713. {
  714. WindSendData.RawMaterial5_SetWeight = RemoteRecipes.ElementAt(index).WindSend.ElementAt(4).RawMaterialWeight;
  715. }
  716. WindSendDevice.Siemens_PLC_S7.WriteClass<XL_WindSendData_DB>(WindSendData, 5);
  717. }
  718. foreach (var item in RemoteRecipes.ElementAt(index).RawMaterial)
  719. {
  720. HKDevice.StockBinPar((uint)item.RawMaterialBarrelNum, (ushort)item.RawMaterialLocation);
  721. }
  722. HKDevice.HK_PLC_S7.Write("DB4.DBX1.3", true);
  723. GVL_SmallStation.GetInstance.RecipeStatusID = 1;
  724. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},下发完成");
  725. HKDevice.HK_PLC_S7.Write("DB3.DBX1.3", true);
  726. }
  727. if (HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX1.3") && GVL_SmallStation.GetInstance.RecipeStatusID == 1)
  728. {
  729. HKDevice.HK_PLC_S7.Write("DB3.DBX1.3", false);
  730. GVL_SmallStation.GetInstance.RecipeStatusID = 2;
  731. MessageNotify.GetInstance.ShowRunLog($"托盘1,{ recipeName}plc端 配方接收完成");
  732. }
  733. if (GVL_SmallStation.GetInstance.RecipeStatusID == 2)
  734. {
  735. if (RTrig.GetInstance("DB3.DBX50.0").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX50.0")))
  736. {
  737. var res = HKDevice.HK_PLC_S7.Read<float>("DB3.DBD10");
  738. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},1号桶,{res}料仓,允许配料");
  739. if (res > 0 && res is float loc)
  740. {
  741. int loc_index = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == loc);
  742. float weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeight;
  743. if (loc_index >= 0)
  744. {
  745. DeviceInquire.GetInstance.GetDevice((int)loc)?.Start(weight);//根据料仓编号 启动并写入每个原料重量
  746. GVL_SmallStation.GetInstance.StockInIsWork = (int)loc;
  747. //HKDevice.HK_PLC_S7.Write("DB3.DBX50.0", false);
  748. }
  749. GVL_SmallStation.GetInstance.DosingTray1 = true;
  750. GVL_SmallStation.GetInstance.DosingTray1Loc = (int)loc;
  751. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},1号桶,{(int)loc}号仓,配料完成");
  752. }
  753. }
  754. else if(RTrig.GetInstance("DB3.DBX50.1").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX50.1")))
  755. {
  756. var res = HKDevice.HK_PLC_S7.Read<float>("DB3.DBD14");
  757. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},2号桶,{res}料仓,允许配料");
  758. if (res > 0 && res is float loc)
  759. {
  760. int loc_index = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == loc);
  761. float weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeight;
  762. if (loc_index >= 0)
  763. {
  764. DeviceInquire.GetInstance.GetDevice((int)loc)?.Start(weight);//启动并写入每个原料重量
  765. GVL_SmallStation.GetInstance.StockInIsWork = (int)loc;
  766. //HKDevice.HK_PLC_S7.Write("DB3.DBX50.1", false);
  767. }
  768. GVL_SmallStation.GetInstance.DosingTray1 = true;
  769. GVL_SmallStation.GetInstance.DosingTray1Loc = (int)loc;
  770. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},2号桶,{(int)loc}号仓,配料完成");
  771. }
  772. }
  773. else if (RTrig.GetInstance("DB3.DBX50.2").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX50.2")))
  774. {
  775. var res = HKDevice.HK_PLC_S7.Read<float>("DB3.DBD18");
  776. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},3号桶,{res}料仓,允许配料");
  777. if (res > 0 && res is float loc)
  778. {
  779. int loc_index = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == loc);
  780. float weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeight;
  781. if (loc_index >= 0)
  782. {
  783. DeviceInquire.GetInstance.GetDevice((int)loc)?.Start(weight);//启动并写入每个原料重量
  784. GVL_SmallStation.GetInstance.StockInIsWork = (int)loc;
  785. //HKDevice.HK_PLC_S7.Write("DB3.DBX50.2", false);
  786. }
  787. GVL_SmallStation.GetInstance.DosingTray1 = true;
  788. GVL_SmallStation.GetInstance.DosingTray1Loc = (int)loc;
  789. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},3号桶,{(int)loc}号仓,配料完成");
  790. }
  791. }
  792. else if (RTrig.GetInstance("DB3.DBX50.3").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX50.3")))
  793. {
  794. var res = HKDevice.HK_PLC_S7.Read<float>("DB3.DBD22");
  795. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},4号桶,{res}料仓,允许配料");
  796. if (res > 0 && res is float loc)
  797. {
  798. int loc_index = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == loc);
  799. float weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeight;
  800. if (loc_index >= 0)
  801. {
  802. DeviceInquire.GetInstance.GetDevice((int)loc)?.Start(weight);//启动并写入每个原料重量
  803. GVL_SmallStation.GetInstance.StockInIsWork = (int)loc;
  804. //HKDevice.HK_PLC_S7.Write("DB3.DBX50.3", false);
  805. }
  806. GVL_SmallStation.GetInstance.DosingTray1 = true;
  807. GVL_SmallStation.GetInstance.DosingTray1Loc = (int)loc;
  808. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},4号桶,{(int)loc}号仓,配料完成");
  809. }
  810. }
  811. if (GVL_SmallStation.GetInstance.DosingTray1 && GVL_SmallStation.GetInstance.DosingTray1Loc > 0 && GVL_SmallStation.GetInstance.DosingTray1Loc < 16)
  812. {
  813. int i = GVL_SmallStation.GetInstance.DosingTray1Loc;
  814. if (RTrig.GetInstance("Tray1StatusDevice" + i).Start(DeviceInquire.GetInstance.GetDevice(i).deviceStatus.RunStatus == 3))
  815. {
  816. MessageNotify.GetInstance.ShowRunLog($"柔性味魔方,托盘1,配方:{recipeName},{i}号仓,配料完成");
  817. int res = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == i);
  818. RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(res).Laying_Off_Weight = DeviceInquire.GetInstance.GetDevice(i).deviceStatus.CutWeightFeedback;
  819. bool info = DeviceInquire.GetInstance.GetDevice(i).StatusReset();
  820. if (info)
  821. {
  822. MessageNotify.GetInstance.ShowRunLog($"柔性味魔方配料完成后复位 发送成功");
  823. }
  824. else
  825. {
  826. MessageNotify.GetInstance.ShowRunLog($"柔性味魔方配料完成后复位 发送失败");
  827. }
  828. if (i >= 1 && i <= 8)
  829. {
  830. string commInfo = HKDevice.HK_PLC_S7.Write("DB4.DBX30." + (i - 1), true, 4);
  831. MessageNotify.GetInstance.ShowRunLog(commInfo);
  832. }
  833. else if (i >= 9 && i <= 15)
  834. {
  835. string commInfo1 = HKDevice.HK_PLC_S7.Write("DB4.DBX31." + (i - 9), true, 4);
  836. MessageNotify.GetInstance.ShowRunLog(commInfo1);
  837. }
  838. GVL_SmallStation.GetInstance.DosingTray1 = false;
  839. GVL_SmallStation.GetInstance.DosingTray1Loc = 0;
  840. }
  841. }
  842. if (RTrig.GetInstance("配方配料完成").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX1.1")) && (GVL_SmallStation.GetInstance.WindSendDosingFinish || !GVL_SmallStation.GetInstance.IsUseWindSend))
  843. {
  844. var res = Json<RemoteRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == code);
  845. MessageNotify.GetInstance.ShowRunLog($"托盘1,配方{res.RecipeName},配料完成");
  846. RecipeFinishInfo.Order_No = RemoteRecipes.ElementAt(index).RecipeCode;
  847. RecipeFinishInfo.Product_Code = RemoteRecipes.ElementAt(index).RecipeName;
  848. for (int i = 0; i < RemoteRecipes.ElementAt(index).RawMaterial.Count; i++)
  849. {
  850. RecipeFinishInfo.Material[i] = new UDT1();
  851. RecipeFinishInfo.Material[i].Material_Name = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialName;
  852. RecipeFinishInfo.Material[i].Material_BarrelNum = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialBarrelNum;
  853. RecipeFinishInfo.Material[i].Material_Laying_Off_Weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).Laying_Off_Weight;
  854. }
  855. if (SiemensDevice.IsConnected)
  856. {
  857. RecipeFinishInfo.Ask_For_Finish = true;
  858. SiemensDevice.Siemens_PLC_S7.WriteClass<XL_Finish_DB>(RecipeFinishInfo, 2261);
  859. }
  860. App.Current.Dispatcher.Invoke(() =>
  861. {
  862. Json<RemoteRecipeDataColl>.Data.Recipes.Remove(res);
  863. });
  864. RecipeQueue.TryDequeue(out code);
  865. HKDevice.HK_PLC_S7.Write("DB3.DBX1.1", false);
  866. GVL_SmallStation.GetInstance.RecipeStatusID = 0;
  867. }
  868. }
  869. }
  870. }
  871. }
  872. if (RecipeQueueTray2.Count > 0)
  873. {
  874. int index = Array.FindIndex(RemoteRecipes.ToArray(), p => p.RecipeCode == RecipeQueueTray2.ElementAt(0));
  875. if (index >= 0 && index < RemoteRecipes.Count)
  876. {
  877. string code = RemoteRecipes.ElementAt(index).RecipeCode;
  878. int trayCode = RemoteRecipes.ElementAt(index).TrayCode;
  879. string recipeName = RemoteRecipes.ElementAt(index).RecipeName;
  880. if (trayCode == 2)
  881. {
  882. if (GVL_SmallStation.GetInstance.RecipeStatusIDTray2 == 0)
  883. {
  884. MessageNotify.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},初始化");
  885. foreach (var item in RemoteRecipes.ElementAt(index).RawMaterial)
  886. {
  887. HKDevice.StockBinPar((uint)item.RawMaterialBarrelNum, (ushort)item.RawMaterialLocation, 2);
  888. }
  889. HKDevice.HK_PLC_S7.Write("DB4.DBX1.4", true);
  890. GVL_SmallStation.GetInstance.RecipeStatusIDTray2 = 1;
  891. MessageNotify.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},下发完成");
  892. HKDevice.HK_PLC_S7.Write("DB3.DBX1.4", true);
  893. }
  894. if (HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX1.4") && GVL_SmallStation.GetInstance.RecipeStatusIDTray2 == 1)
  895. {
  896. HKDevice.HK_PLC_S7.Write("DB3.DBX1.4", false);
  897. GVL_SmallStation.GetInstance.RecipeStatusIDTray2 = 2;
  898. MessageNotify.GetInstance.ShowRunLog($"配方:{recipeName},plc端 配方接收完成");
  899. }
  900. if (GVL_SmallStation.GetInstance.RecipeStatusIDTray2 == 2)
  901. {
  902. if (RTrig.GetInstance("DB3.DBX50.4").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX50.4")))
  903. {
  904. var res = HKDevice.HK_PLC_S7.Read<float>("DB3.DBD26");
  905. MessageNotify.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},1号桶,{res}料仓,允许配料");
  906. if (res > 0 && res is float loc)
  907. {
  908. //int decimalNum = Convert.ToInt32(loc.ToString().Substring(loc.ToString().IndexOf(".") + 1));
  909. int loc_index = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == loc);
  910. double weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeight;
  911. if (loc_index >= 0)
  912. {
  913. DeviceInquire.GetInstance.GetDevice((int)loc)?.Start((uint)weight);//根据料仓编号 启动并写入每个原料重量
  914. GVL_SmallStation.GetInstance.StockInIsWork = (int)loc;
  915. //HKDevice.HK_PLC_S7.Write("DB3.DBX50.0", false);
  916. }
  917. GVL_SmallStation.GetInstance.DosingTray2 = true;
  918. GVL_SmallStation.GetInstance.DosingTray2Loc = (int)loc;
  919. MessageNotify.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},1号桶,{(int)loc}号仓,配料完成");
  920. }
  921. }
  922. else if (RTrig.GetInstance("DB3.DBX50.5").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX50.5")))
  923. {
  924. var res = HKDevice.HK_PLC_S7.Read<float>("DB3.DBD30");
  925. MessageNotify.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},2号桶,{res}料仓,允许配料");
  926. if (res > 0 && res is float loc)
  927. {
  928. int loc_index = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == loc);
  929. double weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeight;
  930. if (loc_index >= 0)
  931. {
  932. DeviceInquire.GetInstance.GetDevice((int)loc)?.Start((uint)weight);//启动并写入每个原料重量
  933. GVL_SmallStation.GetInstance.StockInIsWork = (int)loc;
  934. //HKDevice.HK_PLC_S7.Write("DB3.DBX50.5", false);
  935. }
  936. GVL_SmallStation.GetInstance.DosingTray2 = true;
  937. GVL_SmallStation.GetInstance.DosingTray2Loc = (int)loc;
  938. MessageNotify.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},2号桶,{(int)loc}号仓,配料完成");
  939. }
  940. }
  941. else if (RTrig.GetInstance("DB3.DBX50.6").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX50.6")))
  942. {
  943. var res = HKDevice.HK_PLC_S7.Read<float>("DB3.DBD34");
  944. MessageNotify.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},3号桶,{res}料仓,允许配料");
  945. if (res > 0 && res is float loc)
  946. {
  947. int loc_index = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == loc);
  948. double weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeight;
  949. if (loc_index >= 0)
  950. {
  951. DeviceInquire.GetInstance.GetDevice((int)loc)?.Start((uint)weight);//启动并写入每个原料重量
  952. GVL_SmallStation.GetInstance.StockInIsWork = (int)loc;
  953. //HKDevice.HK_PLC_S7.Write("DB3.DBX50.6", false);
  954. }
  955. GVL_SmallStation.GetInstance.DosingTray2 = true;
  956. GVL_SmallStation.GetInstance.DosingTray2Loc = (int)loc;
  957. MessageNotify.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},3号桶,{(int)loc}号仓,配料完成");
  958. }
  959. }
  960. else if (RTrig.GetInstance("DB3.DBX50.7").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX50.7")))
  961. {
  962. var res = HKDevice.HK_PLC_S7.Read<float>("DB3.DBD38");
  963. MessageNotify.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},4号桶,{res}料仓,允许配料");
  964. if (res > 0 && res is float loc)
  965. {
  966. int loc_index = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == loc);
  967. double weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeight;
  968. if (loc_index >= 0)
  969. {
  970. DeviceInquire.GetInstance.GetDevice((int)loc)?.Start((uint)weight);//启动并写入每个原料重量
  971. GVL_SmallStation.GetInstance.StockInIsWork = (int)loc;
  972. //HKDevice.HK_PLC_S7.Write("DB3.DBX50.7", false);
  973. }
  974. GVL_SmallStation.GetInstance.DosingTray2 = true;
  975. GVL_SmallStation.GetInstance.DosingTray2Loc = (int)loc;
  976. MessageNotify.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},4号桶,{(int)loc}号仓,配料完成");
  977. }
  978. }
  979. if (GVL_SmallStation.GetInstance.DosingTray2 == true && GVL_SmallStation.GetInstance.DosingTray1 == false && GVL_SmallStation.GetInstance.DosingTray2Loc > 0 && GVL_SmallStation.GetInstance.DosingTray2Loc < 16)
  980. {
  981. int i = GVL_SmallStation.GetInstance.DosingTray2Loc;
  982. if (RTrig.GetInstance("Tray2StatusDevice" + i).Start(DeviceInquire.GetInstance.GetDevice(i).deviceStatus.RunStatus == 3))
  983. {
  984. MessageNotify.GetInstance.ShowRunLog($"柔性味魔方,托盘2,配方:{recipeName},{i}号仓,配料完成");
  985. int res = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == i);
  986. RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(res).Laying_Off_Weight = DeviceInquire.GetInstance.GetDevice(i).deviceStatus.CutWeightFeedback;
  987. bool info = DeviceInquire.GetInstance.GetDevice(i).StatusReset();
  988. if (info)
  989. {
  990. MessageNotify.GetInstance.ShowRunLog($"柔性味魔方配料完成后复位 发送成功");
  991. }
  992. else
  993. {
  994. MessageNotify.GetInstance.ShowRunLog($"柔性味魔方配料完成后复位 发送失败");
  995. }
  996. if (i >= 1 && i <= 8)
  997. {
  998. string commInfo = HKDevice.HK_PLC_S7.Write("DB4.DBX30." + (i - 1), true, 4);
  999. MessageNotify.GetInstance.ShowRunLog(commInfo);
  1000. }
  1001. else if (i >= 9 && i <= 15)
  1002. {
  1003. string commInfo1 = HKDevice.HK_PLC_S7.Write("DB4.DBX31." + (i - 9), true, 4);
  1004. MessageNotify.GetInstance.ShowRunLog(commInfo1);
  1005. }
  1006. GVL_SmallStation.GetInstance.DosingTray2 = false;
  1007. GVL_SmallStation.GetInstance.DosingTray2Loc = 0;
  1008. }
  1009. }
  1010. if (RTrig.GetInstance("DB3.DBX1.2").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX1.2")))
  1011. {
  1012. var res = Json<RemoteRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == code);
  1013. MessageNotify.GetInstance.ShowRunLog($"托盘2,配方{res.RecipeName},配料完成");
  1014. RecipeFinishInfo.Order_No = RemoteRecipes.ElementAt(index).RecipeCode;
  1015. RecipeFinishInfo.Product_Code = RemoteRecipes.ElementAt(index).RecipeName;
  1016. for (int i = 0; i < RemoteRecipes.ElementAt(index).RawMaterial.Count; i++)
  1017. {
  1018. RecipeFinishInfo.Material[i] = new UDT1();
  1019. RecipeFinishInfo.Material[i].Material_Name = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialName;
  1020. RecipeFinishInfo.Material[i].Material_BarrelNum = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialBarrelNum;
  1021. RecipeFinishInfo.Material[i].Material_Laying_Off_Weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).Laying_Off_Weight;
  1022. }
  1023. if (SiemensDevice.IsConnected)
  1024. {
  1025. RecipeFinishInfo.Ask_For_Finish = true;
  1026. SiemensDevice.Siemens_PLC_S7.WriteClass<XL_Finish_DB>(RecipeFinishInfo, 2261);
  1027. }
  1028. App.Current.Dispatcher.Invoke(() =>
  1029. {
  1030. Json<RemoteRecipeDataColl>.Data.Recipes.Remove(res);
  1031. });
  1032. RecipeQueueTray2.TryDequeue(out code);
  1033. HKDevice.HK_PLC_S7.Write("DB3.DBX1.2", false);
  1034. GVL_SmallStation.GetInstance.RecipeStatusIDTray2 = 0;
  1035. }
  1036. }
  1037. }
  1038. }
  1039. }
  1040. }
  1041. private void StockBinInit()
  1042. {
  1043. for (int i = 1; i < 16; i++)
  1044. {
  1045. if (DeviceInquire.GetInstance.GetDevice(i).deviceStatus.RunStatus == 3)
  1046. {
  1047. DeviceInquire.GetInstance.GetDevice(i).StatusReset();
  1048. }
  1049. }
  1050. }
  1051. private void DosingDevice(int Index,int DeviceID)
  1052. {
  1053. if (RTrig.GetInstance("Tray2StatusDevice" + DeviceID).Start(DeviceInquire.GetInstance.GetDevice(DeviceID).deviceStatus.RunStatus == 3))
  1054. {
  1055. MessageNotify.GetInstance.ShowRunLog($"柔性味魔方,托盘2,配方:{RemoteRecipes.ElementAt(Index).RecipeName},{DeviceID}号仓,配料完成");
  1056. int res = Array.FindIndex(RemoteRecipes.ElementAt(Index).RawMaterial.ToArray(), p => p.RawMaterialLocation == DeviceID);
  1057. RemoteRecipes.ElementAt(Index).RawMaterial.ElementAt(res).Laying_Off_Weight = DeviceInquire.GetInstance.GetDevice(DeviceID).deviceStatus.CutWeightFeedback;
  1058. DeviceInquire.GetInstance.GetDevice(DeviceID).StatusReset();
  1059. if (DeviceID >= 1 && DeviceID <= 8)
  1060. {
  1061. HKDevice.HK_PLC_S7.Write("DB4.DBX30." + (DeviceID - 1), true);
  1062. }
  1063. else if (DeviceID >= 9 && DeviceID <= 15)
  1064. {
  1065. HKDevice.HK_PLC_S7.Write("DB4.DBX31." + (DeviceID - 9), true);
  1066. }
  1067. }
  1068. }
  1069. }
  1070. }