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

487 lines
31 KiB

  1. using BPASmartClient.Helper;
  2. using BPASmartClient.Modbus;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using BPASmartClient.CustomResource.Pages.Model;
  8. using System.Threading.Tasks;
  9. using BPASmartClient.S7Net;
  10. using System.Threading;
  11. namespace BPASmartClient.JXJFoodBigStation.Model.HK_PLC
  12. {
  13. public class HKDeviceStatus
  14. {
  15. public SiemensHelper HK_PLC_S7 = new SiemensHelper();
  16. public bool IsConnected => HK_PLC_S7.IsConnected;
  17. public DB_Write PlcWrite = new DB_Write();
  18. public DB_Read PlcRead = new DB_Read();
  19. public StockBinName StockBinName = new StockBinName();
  20. public void Init()
  21. {
  22. if (IsConnected)
  23. {
  24. ThreadManage.GetInstance().StartLong(new Action(() =>
  25. {
  26. HK_PLC_S7.WriteClass<DB_Write>(PlcWrite, 99);
  27. var res1 = HK_PLC_S7.ReadClass<DB_Read>(98);
  28. var res2 = HK_PLC_S7.ReadClass<StockBinName>(97);
  29. if (res1 != null && res1 is DB_Read data1)
  30. {
  31. PlcRead = data1;
  32. GVL_BigStation.HeartBeatFromPlc = data1.HeartBeat;//读取plc心跳
  33. }
  34. if (res2 != null && res2 is StockBinName data2)
  35. {
  36. StockBinName = data2;
  37. }
  38. Thread.Sleep(10);
  39. }),"信号收发处理");
  40. }
  41. }
  42. /// <summary>
  43. /// 下发配方数据
  44. /// </summary>
  45. public void StockBinPar(RecipeData recipe)
  46. {
  47. if (IsConnected)
  48. {
  49. if (recipe != null)
  50. {
  51. PlcWrite.RecipeCode = Convert.ToInt16(recipe.RecipeCode);
  52. PlcWrite.TrayCode = Convert.ToInt16(recipe.TrayCode);
  53. for (int barrel = 1; barrel < 6; barrel++)
  54. {
  55. if (barrel != 3)//桶的编号不为3 只为1,2,4,5号桶
  56. {
  57. for (int loc = 1; loc < 15; loc++)
  58. {
  59. int index = Array.FindIndex(recipe.RawMaterial.ToArray(), p => p.RawMaterialBarrelNum == barrel && p.RawMaterialLocation == loc);
  60. if (index == -1)
  61. {
  62. switch (barrel)
  63. {
  64. case 1:
  65. switch (loc)
  66. {
  67. case 1:
  68. PlcWrite.Bareel1Bin1SetWeight = 0;
  69. break;
  70. case 2:
  71. PlcWrite.Bareel1Bin2SetWeight = 0;
  72. break;
  73. case 3:
  74. PlcWrite.Bareel1Bin3SetWeight = 0;
  75. break;
  76. case 4:
  77. PlcWrite.Bareel1Bin4SetWeight = 0;
  78. break;
  79. case 5:
  80. PlcWrite.Bareel1Bin5SetWeight = 0;
  81. break;
  82. case 6:
  83. PlcWrite.Bareel1Bin6SetWeight = 0;
  84. break;
  85. case 7:
  86. PlcWrite.Bareel1Bin7SetWeight = 0;
  87. break;
  88. case 8:
  89. PlcWrite.Bareel1Bin8SetWeight = 0;
  90. break;
  91. case 9:
  92. PlcWrite.Bareel1Bin9SetWeight = 0;
  93. break;
  94. case 10:
  95. PlcWrite.Bareel1Bin10SetWeight = 0;
  96. break;
  97. case 11:
  98. PlcWrite.Bareel1Bin11SetWeight = 0;
  99. break;
  100. case 12:
  101. PlcWrite.Bareel1Bin12SetWeight = 0;
  102. break;
  103. case 13:
  104. PlcWrite.Bareel1Bin13SetWeight = 0;
  105. break;
  106. case 14:
  107. PlcWrite.Bareel1Bin14SetWeight = 0;
  108. break;
  109. default:
  110. break;
  111. }
  112. break;
  113. case 2:
  114. switch (loc)
  115. {
  116. case 1:
  117. PlcWrite.Bareel2Bin1SetWeight = 0;
  118. break;
  119. case 2:
  120. PlcWrite.Bareel2Bin2SetWeight = 0;
  121. break;
  122. case 3:
  123. PlcWrite.Bareel2Bin3SetWeight = 0;
  124. break;
  125. case 4:
  126. PlcWrite.Bareel2Bin4SetWeight = 0;
  127. break;
  128. case 5:
  129. PlcWrite.Bareel2Bin5SetWeight = 0;
  130. break;
  131. case 6:
  132. PlcWrite.Bareel2Bin6SetWeight = 0;
  133. break;
  134. case 7:
  135. PlcWrite.Bareel2Bin7SetWeight = 0;
  136. break;
  137. case 8:
  138. PlcWrite.Bareel2Bin8SetWeight = 0;
  139. break;
  140. case 9:
  141. PlcWrite.Bareel2Bin9SetWeight = 0;
  142. break;
  143. case 10:
  144. PlcWrite.Bareel2Bin10SetWeight = 0;
  145. break;
  146. case 11:
  147. PlcWrite.Bareel2Bin11SetWeight = 0;
  148. break;
  149. case 12:
  150. PlcWrite.Bareel2Bin12SetWeight = 0;
  151. break;
  152. case 13:
  153. PlcWrite.Bareel2Bin13SetWeight = 0;
  154. break;
  155. case 14:
  156. PlcWrite.Bareel2Bin14SetWeight = 0;
  157. break;
  158. default:
  159. break;
  160. }
  161. break;
  162. case 4:
  163. switch (loc)
  164. {
  165. case 1:
  166. PlcWrite.Bareel4Bin1SetWeight = 0;
  167. break;
  168. case 2:
  169. PlcWrite.Bareel4Bin2SetWeight = 0;
  170. break;
  171. case 3:
  172. PlcWrite.Bareel4Bin3SetWeight = 0;
  173. break;
  174. case 4:
  175. PlcWrite.Bareel4Bin4SetWeight = 0;
  176. break;
  177. case 5:
  178. PlcWrite.Bareel4Bin5SetWeight = 0;
  179. break;
  180. case 6:
  181. PlcWrite.Bareel4Bin6SetWeight = 0;
  182. break;
  183. case 7:
  184. PlcWrite.Bareel4Bin7SetWeight = 0;
  185. break;
  186. case 8:
  187. PlcWrite.Bareel4Bin8SetWeight = 0;
  188. break;
  189. case 9:
  190. PlcWrite.Bareel4Bin9SetWeight = 0;
  191. break;
  192. case 10:
  193. PlcWrite.Bareel4Bin10SetWeight = 0;
  194. break;
  195. case 11:
  196. PlcWrite.Bareel4Bin11SetWeight = 0;
  197. break;
  198. case 12:
  199. PlcWrite.Bareel4Bin12SetWeight = 0;
  200. break;
  201. case 13:
  202. PlcWrite.Bareel4Bin13SetWeight = 0;
  203. break;
  204. case 14:
  205. PlcWrite.Bareel4Bin14SetWeight = 0;
  206. break;
  207. default:
  208. break;
  209. }
  210. break;
  211. case 5:
  212. switch (loc)
  213. {
  214. case 1:
  215. PlcWrite.Bareel5Bin1SetWeight = 0;
  216. break;
  217. case 2:
  218. PlcWrite.Bareel5Bin2SetWeight = 0;
  219. break;
  220. case 3:
  221. PlcWrite.Bareel5Bin3SetWeight = 0;
  222. break;
  223. case 4:
  224. PlcWrite.Bareel5Bin4SetWeight = 0;
  225. break;
  226. case 5:
  227. PlcWrite.Bareel5Bin5SetWeight = 0;
  228. break;
  229. case 6:
  230. PlcWrite.Bareel5Bin6SetWeight = 0;
  231. break;
  232. case 7:
  233. PlcWrite.Bareel5Bin7SetWeight = 0;
  234. break;
  235. case 8:
  236. PlcWrite.Bareel5Bin8SetWeight = 0;
  237. break;
  238. case 9:
  239. PlcWrite.Bareel5Bin9SetWeight = 0;
  240. break;
  241. case 10:
  242. PlcWrite.Bareel5Bin10SetWeight = 0;
  243. break;
  244. case 11:
  245. PlcWrite.Bareel5Bin11SetWeight = 0;
  246. break;
  247. case 12:
  248. PlcWrite.Bareel5Bin12SetWeight = 0;
  249. break;
  250. case 13:
  251. PlcWrite.Bareel5Bin13SetWeight = 0;
  252. break;
  253. case 14:
  254. PlcWrite.Bareel5Bin14SetWeight = 0;
  255. break;
  256. default:
  257. break;
  258. }
  259. break;
  260. default:
  261. break;
  262. }
  263. }
  264. else
  265. {
  266. MessageNotify.GetInstance.ShowRunLog($"配方编号:{recipe.RecipeCode},托盘编号:{recipe.TrayCode},桶号:{barrel},位置:{loc},重量:{recipe.RawMaterial.ElementAt(index).RawMaterialWeight}");
  267. switch (barrel)
  268. {
  269. case 1:
  270. switch (loc)
  271. {
  272. case 1:
  273. PlcWrite.Bareel1Bin1SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  274. break;
  275. case 2:
  276. PlcWrite.Bareel1Bin2SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  277. break;
  278. case 3:
  279. PlcWrite.Bareel1Bin3SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  280. break;
  281. case 4:
  282. PlcWrite.Bareel1Bin4SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  283. break;
  284. case 5:
  285. PlcWrite.Bareel1Bin5SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  286. break;
  287. case 6:
  288. PlcWrite.Bareel1Bin6SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  289. break;
  290. case 7:
  291. PlcWrite.Bareel1Bin7SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  292. break;
  293. case 8:
  294. PlcWrite.Bareel1Bin8SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  295. break;
  296. case 9:
  297. PlcWrite.Bareel1Bin9SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  298. break;
  299. case 10:
  300. PlcWrite.Bareel1Bin10SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  301. break;
  302. case 11:
  303. PlcWrite.Bareel1Bin11SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  304. break;
  305. case 12:
  306. PlcWrite.Bareel1Bin12SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  307. break;
  308. case 13:
  309. PlcWrite.Bareel1Bin13SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  310. break;
  311. case 14:
  312. PlcWrite.Bareel1Bin14SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  313. break;
  314. default:
  315. break;
  316. }
  317. break;
  318. case 2:
  319. switch (loc)
  320. {
  321. case 1:
  322. PlcWrite.Bareel2Bin1SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  323. break;
  324. case 2:
  325. PlcWrite.Bareel2Bin2SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  326. break;
  327. case 3:
  328. PlcWrite.Bareel2Bin3SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  329. break;
  330. case 4:
  331. PlcWrite.Bareel2Bin4SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  332. break;
  333. case 5:
  334. PlcWrite.Bareel2Bin5SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  335. break;
  336. case 6:
  337. PlcWrite.Bareel2Bin6SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  338. break;
  339. case 7:
  340. PlcWrite.Bareel2Bin7SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  341. break;
  342. case 8:
  343. PlcWrite.Bareel2Bin8SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  344. break;
  345. case 9:
  346. PlcWrite.Bareel2Bin9SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  347. break;
  348. case 10:
  349. PlcWrite.Bareel2Bin10SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  350. break;
  351. case 11:
  352. PlcWrite.Bareel2Bin11SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  353. break;
  354. case 12:
  355. PlcWrite.Bareel2Bin12SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  356. break;
  357. case 13:
  358. PlcWrite.Bareel2Bin13SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  359. break;
  360. case 14:
  361. PlcWrite.Bareel2Bin14SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  362. break;
  363. default:
  364. break;
  365. }
  366. break;
  367. case 4:
  368. switch (loc)
  369. {
  370. case 1:
  371. PlcWrite.Bareel4Bin1SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  372. break;
  373. case 2:
  374. PlcWrite.Bareel4Bin2SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  375. break;
  376. case 3:
  377. PlcWrite.Bareel4Bin3SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  378. break;
  379. case 4:
  380. PlcWrite.Bareel4Bin4SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  381. break;
  382. case 5:
  383. PlcWrite.Bareel4Bin5SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  384. break;
  385. case 6:
  386. PlcWrite.Bareel4Bin6SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  387. break;
  388. case 7:
  389. PlcWrite.Bareel4Bin7SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  390. break;
  391. case 8:
  392. PlcWrite.Bareel4Bin8SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  393. break;
  394. case 9:
  395. PlcWrite.Bareel4Bin9SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  396. break;
  397. case 10:
  398. PlcWrite.Bareel4Bin10SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  399. break;
  400. case 11:
  401. PlcWrite.Bareel4Bin11SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  402. break;
  403. case 12:
  404. PlcWrite.Bareel4Bin12SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  405. break;
  406. case 13:
  407. PlcWrite.Bareel4Bin13SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  408. break;
  409. case 14:
  410. PlcWrite.Bareel4Bin14SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  411. break;
  412. default:
  413. break;
  414. }
  415. break;
  416. case 5:
  417. switch (loc)
  418. {
  419. case 1:
  420. PlcWrite.Bareel5Bin1SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  421. break;
  422. case 2:
  423. PlcWrite.Bareel5Bin2SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  424. break;
  425. case 3:
  426. PlcWrite.Bareel5Bin3SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  427. break;
  428. case 4:
  429. PlcWrite.Bareel5Bin4SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  430. break;
  431. case 5:
  432. PlcWrite.Bareel5Bin5SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  433. break;
  434. case 6:
  435. PlcWrite.Bareel5Bin6SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  436. break;
  437. case 7:
  438. PlcWrite.Bareel5Bin7SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  439. break;
  440. case 8:
  441. PlcWrite.Bareel5Bin8SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  442. break;
  443. case 9:
  444. PlcWrite.Bareel5Bin9SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  445. break;
  446. case 10:
  447. PlcWrite.Bareel5Bin10SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  448. break;
  449. case 11:
  450. PlcWrite.Bareel5Bin11SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  451. break;
  452. case 12:
  453. PlcWrite.Bareel5Bin12SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  454. break;
  455. case 13:
  456. PlcWrite.Bareel5Bin13SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  457. break;
  458. case 14:
  459. PlcWrite.Bareel5Bin14SetWeight = recipe.RawMaterial.ElementAt(index).RawMaterialWeight;
  460. break;
  461. default:
  462. break;
  463. }
  464. break;
  465. default:
  466. break;
  467. }
  468. }
  469. }
  470. }
  471. }
  472. }
  473. }
  474. }
  475. }
  476. }