终端一体化运控平台
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

672 строки
33 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.Modbus;
  6. using System;
  7. using System.Collections.Concurrent;
  8. using System.Collections.Generic;
  9. using System.Collections.ObjectModel;
  10. using System.Configuration;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading;
  14. using System.Threading.Tasks;
  15. namespace BPASmartClient.JXJFoodSmallStation.Model
  16. {
  17. public class ProcessControl
  18. {
  19. private volatile static ProcessControl _Instance;
  20. public static ProcessControl GetInstance => _Instance ?? (_Instance = new ProcessControl());
  21. private ProcessControl() { }
  22. public ObservableCollection<RemoteRecipeRawMaterial> RawMaterials { get; set; } = new ObservableCollection<RemoteRecipeRawMaterial>();
  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 SiemensDeviceStatus SiemensDevice = new SiemensDeviceStatus();
  36. public HKDeviceStatus HKDevice = new HKDeviceStatus();
  37. GVL_SmallStation SmallStation = new GVL_SmallStation();
  38. XL_Finish_DB RecipeFinishInfo = new XL_Finish_DB();
  39. /// <summary>
  40. /// 接收原料数据
  41. /// </summary>
  42. public RecipeRawMaterial RawMaterial;
  43. public void Init()
  44. {
  45. for (int i = 0; i < 16; i++)
  46. {
  47. if (DeviceInquire.GetInstance.GetDevice(i).DeviceName != null)
  48. {
  49. if (!RawMaterialsNamePos.ContainsKey(DeviceInquire.GetInstance.GetDevice(i).DeviceName))
  50. {
  51. RawMaterialsNamePos.Add(DeviceInquire.GetInstance.GetDevice(i).DeviceName, (short)DeviceInquire.GetInstance.GetDevice(i).deviceStatus.DeviceNum);
  52. }
  53. }
  54. }
  55. ActionManage.GetInstance.Register(new Action<XL_Start_DB>((res) =>
  56. {
  57. if (SiemensDevice.IsConnected)
  58. {
  59. if (res != null)
  60. {
  61. RawMaterials.Clear();
  62. for (int i = 0; i < 15; i++)
  63. {
  64. if (RawMaterialsNamePos.ContainsKey(res.Material[i].Material_Name))
  65. {
  66. RawMaterials.Add(new RemoteRecipeRawMaterial()
  67. {
  68. RawMaterialName = res.Material[i].Material_Name,
  69. RawMaterialBarrelNum = res.Material[i].Material_BarrelNum,
  70. RawMaterialWeight = res.Material[i].Material_Weight,
  71. RawMaterialLocation = (int)RawMaterialsNamePos[res.Material[i].Material_Name]
  72. });
  73. }
  74. else
  75. {
  76. //报警,配方的原料名称下发和设备不一致
  77. }
  78. }
  79. Json<RemoteRecipeDataColl>.Data.Recipes.Add(new RemoteRecipeData()
  80. {
  81. RecipeName = res.RecipeName,
  82. RecipeCode = res.RecipeCode,
  83. RawMaterial = RawMaterials,
  84. TrayCode = res.TrayCode
  85. });
  86. }
  87. }
  88. }), "西门子下发配方", true);
  89. string HK_PLC_IP = ConfigurationManager.AppSettings["HKPlc_IP"];
  90. string Siemens_PLC_IP = ConfigurationManager.AppSettings["Siemens_IP"];
  91. try
  92. {
  93. HKDevice.HK_PLC_S7.Connect(S7.Net.CpuType.S71200, HK_PLC_IP);
  94. //SiemensDevice.Siemens_PLC_S7.Connect(S7.Net.CpuType.S71500, Siemens_PLC_IP);
  95. if (HKDevice.IsConnected)
  96. {
  97. HKDevice.Init();
  98. }
  99. if (SiemensDevice.IsConnected)
  100. {
  101. SiemensDevice.Init();
  102. }
  103. }
  104. catch(Exception ex)
  105. {
  106. }
  107. RecipeQueue.Clear();
  108. //Json<RemoteRecipeDataColl>.Data.Recipes = TestData.GetInstance.Recipes;//添加测试数据
  109. ThreadManage.GetInstance().StartLong(new Action(() =>
  110. {
  111. ReceviceData();
  112. RecipeInfoToHKPLC();
  113. Thread.Sleep(10);
  114. }), "流程处理", true);
  115. ThreadManage.GetInstance().StartLong(new Action(() =>
  116. {
  117. if (SiemensDevice.IsConnected && HKDevice.IsConnected)
  118. {
  119. /*AgvGetInDelivery();
  120. AgvGetInPickUp();*/
  121. }
  122. Thread.Sleep(10);
  123. }), "AGV进站送取货", true);
  124. ThreadManage.GetInstance().StartLong(new Action(() =>
  125. {
  126. if (HKDevice.IsConnected)
  127. {
  128. ManualOpen();
  129. ManualClose();
  130. }
  131. Thread.Sleep(10);
  132. }), "手动操作", true);
  133. }
  134. private void ManualOpen()
  135. {
  136. ActionManage.GetInstance.Register(new Action<object>((o) =>
  137. {
  138. if (o != null)
  139. {
  140. if (o.ToString().Contains("升降气缸"))
  141. {
  142. int index = Convert.ToInt16(o.ToString().Substring(o.ToString().Length - 1));
  143. switch (index)
  144. {
  145. case 1:
  146. HKDevice.HK_PLC_S7.Write("", true);
  147. break;
  148. case 2:
  149. HKDevice.HK_PLC_S7.Write("", true);
  150. break;
  151. case 3:
  152. HKDevice.HK_PLC_S7.Write("", true);
  153. break;
  154. case 4:
  155. HKDevice.HK_PLC_S7.Write("", true);
  156. break;
  157. case 5:
  158. HKDevice.HK_PLC_S7.Write("", true);
  159. break;
  160. case 6:
  161. HKDevice.HK_PLC_S7.Write("", true);
  162. break;
  163. case 7:
  164. HKDevice.HK_PLC_S7.Write("", true);
  165. break;
  166. case 8:
  167. HKDevice.HK_PLC_S7.Write("", true);
  168. break;
  169. case 9:
  170. HKDevice.HK_PLC_S7.Write("", true);
  171. break;
  172. case 10:
  173. HKDevice.HK_PLC_S7.Write("", true);
  174. break;
  175. case 11:
  176. HKDevice.HK_PLC_S7.Write("", true);
  177. break;
  178. case 12:
  179. HKDevice.HK_PLC_S7.Write("", true);
  180. break;
  181. case 13:
  182. HKDevice.HK_PLC_S7.Write("", true);
  183. break;
  184. case 14:
  185. HKDevice.HK_PLC_S7.Write("", true);
  186. break;
  187. case 15:
  188. HKDevice.HK_PLC_S7.Write("", true);
  189. break;
  190. default:
  191. break;
  192. }
  193. }
  194. else if (o.ToString().Contains("阻挡气缸"))
  195. {
  196. int index = Convert.ToInt16(o.ToString().Substring(o.ToString().Length - 1));
  197. switch (index)
  198. {
  199. case 1:
  200. HKDevice.HK_PLC_S7.Write("", true);
  201. break;
  202. case 2:
  203. HKDevice.HK_PLC_S7.Write("", true);
  204. break;
  205. case 3:
  206. HKDevice.HK_PLC_S7.Write("", true);
  207. break;
  208. case 4:
  209. HKDevice.HK_PLC_S7.Write("", true);
  210. break;
  211. case 5:
  212. HKDevice.HK_PLC_S7.Write("", true);
  213. break;
  214. case 6:
  215. HKDevice.HK_PLC_S7.Write("", true);
  216. break;
  217. case 7:
  218. HKDevice.HK_PLC_S7.Write("", true);
  219. break;
  220. case 8:
  221. HKDevice.HK_PLC_S7.Write("", true);
  222. break;
  223. case 9:
  224. HKDevice.HK_PLC_S7.Write("", true);
  225. break;
  226. case 10:
  227. HKDevice.HK_PLC_S7.Write("", true);
  228. break;
  229. case 11:
  230. HKDevice.HK_PLC_S7.Write("", true);
  231. break;
  232. case 12:
  233. HKDevice.HK_PLC_S7.Write("", true);
  234. break;
  235. case 13:
  236. HKDevice.HK_PLC_S7.Write("", true);
  237. break;
  238. case 14:
  239. HKDevice.HK_PLC_S7.Write("", true);
  240. break;
  241. case 15:
  242. HKDevice.HK_PLC_S7.Write("", true);
  243. break;
  244. default:
  245. break;
  246. }
  247. }
  248. else if (o.ToString().Contains("托盘气缸"))
  249. {
  250. int index = Convert.ToInt16(o.ToString().Substring(o.ToString().Length - 1));
  251. switch (index)
  252. {
  253. case 1:
  254. HKDevice.HK_PLC_S7.Write("", true);
  255. break;
  256. case 2:
  257. HKDevice.HK_PLC_S7.Write("", true);
  258. break;
  259. default:
  260. break;
  261. }
  262. }
  263. }
  264. }), "ManualOpen", true);//根据下发的配方ID将 托盘的位置信息添加到配方中
  265. }
  266. private void ManualClose()
  267. {
  268. ActionManage.GetInstance.Register(new Action<object>((o) =>
  269. {
  270. if (o != null)
  271. {
  272. if (o.ToString().Contains("升降气缸"))
  273. {
  274. int index = Convert.ToInt16(o.ToString().Substring(o.ToString().Length - 1));
  275. switch (index)
  276. {
  277. case 1:
  278. HKDevice.HK_PLC_S7.Write("", false);
  279. break;
  280. case 2:
  281. HKDevice.HK_PLC_S7.Write("", false);
  282. break;
  283. case 3:
  284. HKDevice.HK_PLC_S7.Write("", false);
  285. break;
  286. case 4:
  287. HKDevice.HK_PLC_S7.Write("", false);
  288. break;
  289. case 5:
  290. HKDevice.HK_PLC_S7.Write("", false);
  291. break;
  292. case 6:
  293. HKDevice.HK_PLC_S7.Write("", false);
  294. break;
  295. case 7:
  296. HKDevice.HK_PLC_S7.Write("", false);
  297. break;
  298. case 8:
  299. HKDevice.HK_PLC_S7.Write("", false);
  300. break;
  301. case 9:
  302. HKDevice.HK_PLC_S7.Write("", false);
  303. break;
  304. case 10:
  305. HKDevice.HK_PLC_S7.Write("", false);
  306. break;
  307. case 11:
  308. HKDevice.HK_PLC_S7.Write("", false);
  309. break;
  310. case 12:
  311. HKDevice.HK_PLC_S7.Write("", false);
  312. break;
  313. case 13:
  314. HKDevice.HK_PLC_S7.Write("", false);
  315. break;
  316. case 14:
  317. HKDevice.HK_PLC_S7.Write("", false);
  318. break;
  319. case 15:
  320. HKDevice.HK_PLC_S7.Write("", false);
  321. break;
  322. default:
  323. break;
  324. }
  325. }
  326. else if (o.ToString().Contains("阻挡气缸"))
  327. {
  328. int index = Convert.ToInt16(o.ToString().Substring(o.ToString().Length - 1));
  329. switch (index)
  330. {
  331. case 1:
  332. HKDevice.HK_PLC_S7.Write("", false);
  333. break;
  334. case 2:
  335. HKDevice.HK_PLC_S7.Write("", false);
  336. break;
  337. case 3:
  338. HKDevice.HK_PLC_S7.Write("", false);
  339. break;
  340. case 4:
  341. HKDevice.HK_PLC_S7.Write("", false);
  342. break;
  343. case 5:
  344. HKDevice.HK_PLC_S7.Write("", false);
  345. break;
  346. case 6:
  347. HKDevice.HK_PLC_S7.Write("", false);
  348. break;
  349. case 7:
  350. HKDevice.HK_PLC_S7.Write("", false);
  351. break;
  352. case 8:
  353. HKDevice.HK_PLC_S7.Write("", false);
  354. break;
  355. case 9:
  356. HKDevice.HK_PLC_S7.Write("", false);
  357. break;
  358. case 10:
  359. HKDevice.HK_PLC_S7.Write("", false);
  360. break;
  361. case 11:
  362. HKDevice.HK_PLC_S7.Write("", false);
  363. break;
  364. case 12:
  365. HKDevice.HK_PLC_S7.Write("", false);
  366. break;
  367. case 13:
  368. HKDevice.HK_PLC_S7.Write("", false);
  369. break;
  370. case 14:
  371. HKDevice.HK_PLC_S7.Write("", false);
  372. break;
  373. case 15:
  374. HKDevice.HK_PLC_S7.Write("", false);
  375. break;
  376. default:
  377. break;
  378. }
  379. }
  380. else if (o.ToString().Contains("托盘气缸"))
  381. {
  382. int index = Convert.ToInt16(o.ToString().Substring(o.ToString().Length - 1));
  383. switch (index)
  384. {
  385. case 1:
  386. HKDevice.HK_PLC_S7.Write("", false);
  387. break;
  388. case 2:
  389. HKDevice.HK_PLC_S7.Write("", false);
  390. break;
  391. default:
  392. break;
  393. }
  394. }
  395. }
  396. }), "ManualClose", true);//根据下发的配方ID将 托盘的位置信息添加到配方中
  397. }
  398. /// <summary>
  399. /// AGV进站送货
  400. /// </summary>
  401. private void AgvGetInDelivery()
  402. {
  403. switch (SmallStation.AgvDeliveryPosition)
  404. {
  405. case 0:
  406. if (RTrig.GetInstance("").Start(SiemensDevice.Siemens_PLC_S7.Read<object>(SiemensCommAddress.DeliveryAGVApply) is bool))
  407. {
  408. SmallStation.AgvDeliveryPosition = 1;
  409. HKDevice.HK_PLC_S7.Write(HKPlcCommAddress.DeliveryAGVApply, true);
  410. }
  411. break;
  412. case 1:
  413. if (RTrig.GetInstance("").Start(HKDevice.HK_PLC_S7.Read<bool>(HKPlcCommAddress.DeliveryAGVIsApply)))
  414. {
  415. SmallStation.AgvDeliveryPosition = 2;
  416. SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.DeliveryAGVIsApply, true);
  417. }
  418. break;
  419. case 2:
  420. if (RTrig.GetInstance("").Start(SiemensDevice.Siemens_PLC_S7.Read<object>(SiemensCommAddress.DeliveryAGVApplyJack) is bool))
  421. {
  422. SmallStation.AgvDeliveryPosition = 3;
  423. HKDevice.HK_PLC_S7.Write(HKPlcCommAddress.DeliveryAGVApplyJack, true);
  424. }
  425. break;
  426. case 3:
  427. if (RTrig.GetInstance("").Start(HKDevice.HK_PLC_S7.Read<bool>(HKPlcCommAddress.DeliveryAGVIsApplyJack)))
  428. {
  429. SmallStation.AgvDeliveryPosition = 4;
  430. SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.DeliveryAGVIsApplyJack, true);
  431. }
  432. break;
  433. case 4:
  434. if (RTrig.GetInstance("").Start(SiemensDevice.Siemens_PLC_S7.Read<object>(SiemensCommAddress.DeliveryAGVFinsih) is bool))
  435. {
  436. SmallStation.AgvDeliveryPosition = 5;
  437. HKDevice.HK_PLC_S7.Write(HKPlcCommAddress.DeliveryAGVFinsih, true);
  438. }
  439. break;
  440. case 5:
  441. if (RTrig.GetInstance("").Start(HKDevice.HK_PLC_S7.Read<bool>(HKPlcCommAddress.StationHaveCargo)))
  442. {
  443. SmallStation.AgvDeliveryPosition = 0;
  444. SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.StationHaveCargo, true);
  445. }
  446. break;
  447. default:
  448. break;
  449. }
  450. //获取工位上是否有小车
  451. SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.StationIsExistCar, (bool)
  452. HKDevice.HK_PLC_S7.Read<bool>(HKPlcCommAddress.StationIsExistTray));
  453. }
  454. /// <summary>
  455. /// AGV进站取货
  456. /// </summary>
  457. private void AgvGetInPickUp()
  458. {
  459. switch (SmallStation.AgvPickUpPosition)
  460. {
  461. case 0:
  462. if (RTrig.GetInstance("").Start(SiemensDevice.Siemens_PLC_S7.Read<bool>(SiemensCommAddress.PickAGVApply)))
  463. {
  464. SmallStation.AgvPickUpPosition = 1;
  465. HKDevice.HK_PLC_S7.Write(HKPlcCommAddress.PickAGVApply, true);
  466. }
  467. break;
  468. case 1:
  469. if (RTrig.GetInstance("").Start(HKDevice.HK_PLC_S7.Read<bool>(HKPlcCommAddress.PickAGVIsApply)))
  470. {
  471. SmallStation.AgvPickUpPosition = 2;
  472. SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.PickAGVIsApply, true);
  473. }
  474. break;
  475. case 2:
  476. if (RTrig.GetInstance("").Start(SiemensDevice.Siemens_PLC_S7.Read<object>(SiemensCommAddress.PickCargoAGVFinish) is bool))
  477. {
  478. SmallStation.AgvPickUpPosition = 3;
  479. HKDevice.HK_PLC_S7.Write(HKPlcCommAddress.PickCargoAGVFinish, true);
  480. }
  481. break;
  482. case 3:
  483. if (RTrig.GetInstance("").Start(HKDevice.HK_PLC_S7.Read<bool>(HKPlcCommAddress.PickAGVFinish)))
  484. {
  485. SmallStation.AgvPickUpPosition = 0;
  486. SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.PickAGVFinish, true);
  487. }
  488. break;
  489. default:
  490. break;
  491. }
  492. }
  493. /// <summary>
  494. /// 将配方添加到配方队列中
  495. /// </summary>
  496. private void ReceviceData()
  497. {
  498. RemoteRecipes = Json<RemoteRecipeDataColl>.Data.Recipes;
  499. if (RemoteRecipes.Count > 0)
  500. {
  501. foreach (var data in RemoteRecipes)
  502. {
  503. if (!(RecipeQueue.Contains(data.RecipeCode)))
  504. RecipeQueue.Enqueue(data.RecipeCode);
  505. }
  506. }
  507. }
  508. /// <summary>
  509. /// 执行配方队列中的第一个配方
  510. /// </summary>
  511. private void RecipeInfoToHKPLC()
  512. {
  513. if (RecipeQueue.Count > 0)
  514. {
  515. int index = Array.FindIndex(RemoteRecipes.ToArray(), p => p.RecipeCode == RecipeQueue.ElementAt(0));
  516. if (index >= 0 && index < RemoteRecipes.Count)
  517. {
  518. string code = RemoteRecipes.ElementAt(index).RecipeCode;
  519. int trayCode = RemoteRecipes.ElementAt(index).TrayCode;
  520. string recipeName = RemoteRecipes.ElementAt(index).RecipeName;
  521. //MessageLog.GetInstance.ShowRunLog($"开始执行配方{recipeName}");
  522. if ( true) /*trayCode == 1 &&*/
  523. {
  524. if (HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX1.5") || SmallStation.RecipeStatusID == 0)
  525. {
  526. foreach (var item in RemoteRecipes.ElementAt(index).RawMaterial)
  527. {
  528. HKDevice.StockBinPar((uint)item.RawMaterialBarrelNum, (ushort)item.RawMaterialLocation);
  529. }
  530. HKDevice.HK_PLC_S7.Write("DB3.DBX1.5", false);
  531. HKDevice.HK_PLC_S7.Write("DB4.DBX1.3", true);
  532. SmallStation.RecipeStatusID = 1;
  533. MessageLog.GetInstance.ShowRunLog($"{recipeName}配方下发完成");
  534. HKDevice.HK_PLC_S7.Write("DB3.DBX1.3", true);
  535. }
  536. if (HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX1.3") && SmallStation.RecipeStatusID == 1)
  537. {
  538. HKDevice.HK_PLC_S7.Write("DB3.DBX1.3", false);
  539. SmallStation.RecipeStatusID = 2;
  540. MessageLog.GetInstance.ShowRunLog($"{recipeName}plc端 配方接收完成");
  541. }
  542. if (SmallStation.RecipeStatusID == 2)
  543. {
  544. if (RTrig.GetInstance("DB3.DBX50.0").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX50.0")))
  545. {
  546. var res1= HKDevice.HK_PLC_S7.Read<UInt32>("DB4.DBD26");
  547. var res = HKDevice.HK_PLC_S7.Read<UInt32>("DB3.DBD10");
  548. if (res > 0 && res is UInt32 loc)
  549. {
  550. int loc_index = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == loc);
  551. double weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeight;
  552. if (loc_index >= 1 && loc_index <= 15)
  553. {
  554. DeviceInquire.GetInstance.GetDevice(loc_index)?.Start((uint)weight);//根据料仓编号 启动并写入每个原料重量
  555. SmallStation.StockInIsWork = loc_index;
  556. HKDevice.HK_PLC_S7.Write("DB3.DBX50.0", false);
  557. }
  558. MessageLog.GetInstance.ShowRunLog($"{recipeName}托盘1_1号桶允许配料");
  559. }
  560. }
  561. else if(RTrig.GetInstance("DB3.DBX50.1").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX50.1")))
  562. {
  563. var res = HKDevice.HK_PLC_S7.Read<float>("DB3.DBD14");
  564. if (res > 0 && res is float loc)
  565. {
  566. ushort a = (ushort)loc;
  567. int loc_index = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == loc);
  568. double weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeight;
  569. if (loc_index >= 1 && loc_index <= 15)
  570. {
  571. DeviceInquire.GetInstance.GetDevice(loc_index)?.Start((uint)weight);//启动并写入每个原料重量
  572. SmallStation.StockInIsWork = loc_index;
  573. HKDevice.HK_PLC_S7.Write("DB3.DBX50.1", false);
  574. }
  575. MessageLog.GetInstance.ShowRunLog($"{recipeName}托盘1_2号桶允许配料");
  576. }
  577. }
  578. else if (RTrig.GetInstance("DB3.DBX50.2").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX50.2")))
  579. {
  580. var res = HKDevice.HK_PLC_S7.Read<float>("DB3.DBD18");
  581. if (res > 0 && res is float loc)
  582. {
  583. int loc_index = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == loc);
  584. if (loc_index >= 1 && loc_index <= 15)
  585. {
  586. double weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeight;
  587. if (loc_index >= 1 && loc_index <= 15)
  588. {
  589. DeviceInquire.GetInstance.GetDevice(loc_index)?.Start((uint)weight);//启动并写入每个原料重量
  590. SmallStation.StockInIsWork = loc_index;
  591. HKDevice.HK_PLC_S7.Write("DB3.DBX50.2", false);
  592. }
  593. MessageLog.GetInstance.ShowRunLog($"{recipeName}托盘1_3号桶允许配料");
  594. }
  595. }
  596. }
  597. else if (RTrig.GetInstance("DB3.DBX50.3").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX50.3")))
  598. {
  599. var res = HKDevice.HK_PLC_S7.Read<float>("DB3.DBD22");
  600. if (res > 0 && res is float loc)
  601. {
  602. int loc_index = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == loc);
  603. double weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeight;
  604. if (loc_index >= 1 && loc_index <= 15)
  605. {
  606. DeviceInquire.GetInstance.GetDevice(loc_index)?.Start((uint)weight);//启动并写入每个原料重量
  607. SmallStation.StockInIsWork = loc_index;
  608. HKDevice.HK_PLC_S7.Write("DB3.DBX50.3", false);
  609. }
  610. MessageLog.GetInstance.ShowRunLog($"{recipeName}托盘1_4号桶允许配料");
  611. }
  612. }
  613. for (int i = 1; i < 16; i++)
  614. {
  615. if (RTrig.GetInstance("柔性味魔方配料完成").Start(DeviceInquire.GetInstance.GetDevice(i).deviceStatus.RunStatus == 3))
  616. {
  617. int res = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == i);
  618. RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(res).Laying_Off_Weight = DeviceInquire.GetInstance.GetDevice(i).deviceStatus.CutWeightFeedback;
  619. DeviceInquire.GetInstance.GetDevice(i).StatusReset();
  620. if (i >= 1 && i <= 8)
  621. {
  622. HKDevice.HK_PLC_S7.Write("DB4.DBX30." + (i - 1), true);
  623. }
  624. else if (i >= 9 && i <= 15)
  625. {
  626. HKDevice.HK_PLC_S7.Write("DB4.DBX31." + (i - 9), true);
  627. }
  628. }
  629. }
  630. if (RTrig.GetInstance("配方配料完成").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX1.1")))
  631. {
  632. var res = Json<RemoteRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == code);
  633. MessageLog.GetInstance.ShowRunLog($"配方{res.RecipeName}配料完成");
  634. RecipeFinishInfo.Order_No = RemoteRecipes.ElementAt(index).RecipeCode;
  635. RecipeFinishInfo.Product_Code = RemoteRecipes.ElementAt(index).RecipeName;
  636. for (int i = 0; i < 16; i++)
  637. {
  638. RecipeFinishInfo.Material[i].Material_Name = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialName;
  639. RecipeFinishInfo.Material[i].Material_BarrelNum = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialBarrelNum;
  640. RecipeFinishInfo.Material[i].Material_Laying_Off_Weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).Laying_Off_Weight;
  641. }
  642. SiemensDevice.Siemens_PLC_S7.WriteClass<XL_Finish_DB>(RecipeFinishInfo, 3);
  643. RecipeFinishInfo.Ask_For_Finish = true;
  644. Json<RemoteRecipeDataColl>.Data.Recipes.Remove(res);
  645. RecipeQueue.TryDequeue(out code);
  646. HKDevice.HK_PLC_S7.Write("DB3.DBX1.1", false);
  647. SmallStation.RecipeStatusID = 0;
  648. }
  649. }
  650. }
  651. }
  652. }
  653. }
  654. }
  655. }