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

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