WorkStart.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. using PlcSiemens.Core.Extension;
  2. using ServiceCenter;
  3. using ServiceCenter.Logs;
  4. using ServiceCenter.Redis;
  5. using ServiceCenter.SqlSugars;
  6. using System.Diagnostics;
  7. using WCS.Core;
  8. using WCS.Entity.Protocol;
  9. using WCS.Entity.Protocol.BCR;
  10. using WCS.Entity.Protocol.DataStructure;
  11. using WCS.Entity.Protocol.HUB;
  12. using WCS.Entity.Protocol.RGV;
  13. using WCS.Entity.Protocol.Robot;
  14. using WCS.Entity.Protocol.SRM;
  15. using WCS.Entity.Protocol.Station;
  16. using WCS.Entity.Protocol.Truss;
  17. using WCS.WorkEngineering.Extensions;
  18. using DeviceFlags = WCS.WorkEngineering.Extensions.DeviceFlags;
  19. namespace WCS.WorkEngineering
  20. {
  21. /// <summary>
  22. /// 业务工程配置信息
  23. /// </summary>
  24. public static class WorkStart
  25. {
  26. /// <summary>
  27. /// 初始化 设备信息
  28. /// </summary>
  29. public static void InitializeDeviceInfo()
  30. {
  31. #region 初始化RGV相关信息
  32. List<RgvSegmentInfo> RgvInfo = new List<RgvSegmentInfo>
  33. {
  34. new RgvSegmentInfo( 1, "10.30.37.113"), //库一北
  35. new RgvSegmentInfo( 2, "10.30.37.118"), //库一南
  36. new RgvSegmentInfo( 3, "10.30.37.123"), //库二北
  37. new RgvSegmentInfo( 4, "10.30.37.128"), //库二南
  38. new RgvSegmentInfo( 5, "10.30.37.133"), //库三北
  39. new RgvSegmentInfo( 6, "10.30.37.138"), //库三南
  40. };
  41. foreach (var item in RgvInfo)
  42. {
  43. var conv = new Device($"RGV{item.Code}");
  44. conv.AddFlag(DeviceFlags.RGV);
  45. conv.AddProtocol<IRGV520>(0, 520, item.Ip);
  46. conv.AddProtocol<IRGV521>(0, 521, item.Ip);
  47. conv.AddProtocol<IRGV523>(0, 523, item.Ip);
  48. }
  49. #endregion 初始化RGV相关信息
  50. #region 初始化输送机相关信息
  51. #region 基本信息
  52. #region 托盘线输送线
  53. var tuples = new List<Tuple<string, List<Tuple<int, int>>>>
  54. {
  55. //分拣库一
  56. new("10.30.37.89",new List<Tuple<int, int>>()
  57. {
  58. new(1601, 1620),
  59. new(2501, 2540),
  60. new(2701, 2740),
  61. new(1661, 1690),
  62. }),
  63. //分拣库二
  64. new("10.30.37.97",new List<Tuple<int, int>>()
  65. {
  66. new(1621, 1640),
  67. new(2901, 2940),
  68. new(3101, 3140),
  69. new(1691, 1720),
  70. }),
  71. //分拣库三
  72. new("10.30.37.105",new List<Tuple<int, int>>()
  73. {
  74. new(1641, 1660),
  75. new(3301, 3340),
  76. new(3501, 3540),
  77. new(1721, 1750)
  78. })
  79. };
  80. foreach (var item in tuples)
  81. {
  82. var db520 = 0;
  83. var db521 = 0;
  84. var db523 = 0;
  85. foreach (var item1 in item.Item2)
  86. {
  87. for (var i = item1.Item1; i <= item1.Item2; i++)
  88. {
  89. var conv = new Device(i.ToString());
  90. conv.AddFlag(DeviceFlags.输送机);
  91. conv.AddProtocol<IStation520>(db520, 520, item.Item1);
  92. conv.AddProtocol<IStation521>(db521, 521, item.Item1);
  93. conv.AddProtocol<IStation523>(db523, 523, item.Item1);
  94. db520 += 14;
  95. db521 += 16;
  96. db523 += 12;
  97. }
  98. }
  99. }
  100. #endregion 托盘线输送线
  101. #region 满轮输送线
  102. #region DB523,所有线体都会有DB523
  103. var mLtuples523 = new List<Tuple<string, List<Tuple<int, int>>>>()
  104. {
  105. new("10.30.37.166",new List<Tuple<int, int>>() //北侧满轮主线
  106. {
  107. new(1, 100),
  108. new(9001, 9010),//暂用,无意义
  109. new(401, 599),
  110. new(801,999),
  111. new(1201,1399),
  112. }),
  113. new("10.30.37.198",new List<Tuple<int, int>>() //南侧满轮主线
  114. {
  115. new(101, 210),
  116. new(601, 799),
  117. new(1001, 1199),
  118. new(1401,1599),
  119. new(341,379),
  120. })
  121. };
  122. foreach (var item in mLtuples523)
  123. {
  124. var db523 = 0;
  125. var db524 = 0;
  126. foreach (var item1 in item.Item2)
  127. {
  128. for (var i = item1.Item1; i <= item1.Item2; i++)
  129. {
  130. var conv = new Device(i.ToString());
  131. conv.AddFlag(DeviceFlags.输送机);
  132. conv.AddProtocol<IStation523>(db523, 523, item.Item1);
  133. conv.AddProtocol<IStation524>(db524, 524, item.Item1);
  134. db523 += 12;
  135. db524 += 16;
  136. }
  137. }
  138. }
  139. #endregion DB523,所有线体都会有DB523
  140. #region 520、521 交互线体会有520、521
  141. //Item2表示线体号集合,Item1表示IP
  142. var mLTuples520 = new List<Tuple<string, List<int>>>()
  143. {
  144. //北侧
  145. new("10.30.37.166",new List<int>() {1,22,41,61,418,426,435,444,455,466,480,494,508,522,536,550,564,578,591,818,826,835,844,855,866,880,894,908,922,936,950,964,978,991,1218,1226,1235,1244,1255,1266,1280,1294,1308,1322,1336,1350,1364,1378,1391}),
  146. //南侧
  147. new("10.30.37.198",new List<int>(){101,122,141,161,618,626,635,644,655,666,680,694,708,722,736,750,764,778,791,1018,1026,1035,1044,1055,1066,1080,1094,1108,1122,1136,1150,1164,1178,1191,1418,1426,1435,1444,1455,1466,1480,1494,1508,1522,1536,1550,1564,1578,1591})
  148. };
  149. foreach (var item in mLTuples520)
  150. {
  151. var db520 = 0;
  152. var db521 = 0;
  153. foreach (var device in item.Item2.Select(item1 => Device.All.FirstOrDefault(v => v.Code == item1.ToString())))
  154. {
  155. if (device != null)
  156. {
  157. device.AddProtocol<IStation520>(db520, 520, item.Item1);
  158. device.AddProtocol<IStation521>(db521, 521, item.Item1);
  159. }
  160. db520 += 14;
  161. db521 += 16;
  162. }
  163. }
  164. #endregion 520、521 交互线体会有520、521
  165. #region 满轮扫码器
  166. //Item2表示线体号集合,Item1表示IP
  167. var mLTuples83 = new List<Tuple<string, List<int>>>()
  168. {
  169. new("10.30.37.166",new List<int>(){3,14,18,22,38,323,41,58,61}) ,
  170. new("10.30.37.198",new List<int>(){101,114,118,122,138,363,141,158,161})
  171. };
  172. foreach (var item in mLTuples83)
  173. {
  174. var db83 = 0;
  175. foreach (var device in item.Item2.Select(item1 => Device.All.FirstOrDefault(v => v.Code == item1.ToString())))
  176. {
  177. device?.AddProtocol<IBCR83>(db83, 83, item.Item1);
  178. db83 += 604;
  179. }
  180. }
  181. #endregion 满轮扫码器
  182. #region 满轮线告诉分拣预分配
  183. //Item2表示线体号集合,Item1表示IP
  184. var mLTuples525 = new List<Tuple<string, List<int>>>()
  185. {
  186. new("10.30.37.166",new List<int>(){18,38,58}),
  187. new("10.30.37.198",new List<int>(){118,138,158}),
  188. };
  189. foreach (var item in mLTuples525)
  190. {
  191. var db525 = 0;
  192. foreach (var device in item.Item2.Select(item1 => Device.All.FirstOrDefault(v => v.Code == item1.ToString())))
  193. {
  194. device?.AddProtocol<IStation525>(db525, 525, item.Item1);
  195. db525 += 3266;
  196. }
  197. }
  198. #endregion 满轮线告诉分拣预分配
  199. #region 外检信息
  200. //Item2表示线体号集合,Item1表示IP
  201. var mLTuples91 = new List<Tuple<string, List<int>>>()
  202. {
  203. new("10.30.37.166",new List<int>(){418,818,1218}),
  204. new("10.30.37.198",new List<int>(){618,1018,1418})
  205. };
  206. foreach (var item in mLTuples91)
  207. {
  208. var db91 = 0;
  209. foreach (var device in item.Item2.Select(item2 => Device.All.FirstOrDefault(v => v.Code == item2.ToString())))
  210. {
  211. device?.AddProtocol<IStation91>(db91, 91, item.Item1);
  212. db91 += 14;
  213. }
  214. }
  215. #endregion 外检信息
  216. #endregion 满轮输送线
  217. #endregion 基本信息
  218. #region 托盘线扫码器
  219. var bcrInfo = new List<BcrInfo>
  220. {
  221. new(new [] { "2532", "2732" }, "10.30.37.89"),
  222. new(new [] { "2932", "3132" }, "10.30.37.97"),
  223. //new(new [] { "2532", "2732" }, "10.30.37.105"),
  224. new(new [] {"RGV1"},"10.30.37.113"),
  225. new(new [] {"RGV2"},"10.30.37.118"),
  226. new(new [] {"RGV3"},"10.30.37.123"),
  227. new(new [] {"RGV4"},"10.30.37.128"),
  228. new(new [] {"RGV5"},"10.30.37.133"),
  229. new(new [] {"RGV6"},"10.30.37.138")
  230. };
  231. foreach (var item in bcrInfo)
  232. {
  233. for (var i = 0; i < item.DeviceNo.Length; i++)
  234. {
  235. var device = Device.All.FirstOrDefault(v => v.Code == item.DeviceNo[i]);
  236. device.AddFlag(DeviceFlags.扫码);
  237. var pos = i * 20;
  238. device.AddProtocol<IBCR81>(pos, 81, item.Ip);
  239. }
  240. }
  241. #endregion 托盘线扫码器
  242. #region 外检信息
  243. List<ShapeInfo> shapeInfo = new List<ShapeInfo>
  244. {
  245. new ShapeInfo(new int[] { 2732,2532 }, "10.30.37.89"),
  246. new ShapeInfo(new int[] { 2932, 3132 }, "10.30.37.97"),
  247. //new ShapeInfo(new int[] { 2732,2532 }, "10.30.37.105")
  248. };
  249. foreach (var item in shapeInfo)
  250. {
  251. for (int i = 0; i < item.DeviceNo.Length; i++)
  252. {
  253. var conv = Device.All.FirstOrDefault(x => x.Code == item.DeviceNo[i].ToString());
  254. conv.AddFlag(DeviceFlags.外检);
  255. int pos = i * 14;
  256. conv.AddProtocol<IStation91>(pos, 91, item.Ip);
  257. }
  258. }
  259. #endregion 外检信息
  260. #endregion 初始化输送机相关信息
  261. #region 初始化桁架相关信息
  262. List<TrussSegmentInfo> TrussInfo = new List<TrussSegmentInfo>
  263. {
  264. new TrussSegmentInfo( 1, "10.30.37.211"),
  265. new TrussSegmentInfo( 2, "10.30.37.217"),
  266. new TrussSegmentInfo( 3, "10.30.37.223")
  267. };
  268. foreach (var item in TrussInfo)
  269. {
  270. var conv = new Device($"Truss{item.Code}");
  271. conv.AddFlag(DeviceFlags.桁架);
  272. conv.AddProtocol<ITruss520>(0, 520, item.Ip);
  273. conv.AddProtocol<ITruss521>(0, 521, item.Ip);
  274. conv.AddProtocol<ITruss523>(0, 522, item.Ip);
  275. }
  276. var tuples1 = new List<Tuple<string, List<int>>>
  277. {
  278. //桁架
  279. new("10.30.37.211",new List<int>(){1685,1686,1687,1688,1689,1690,1675,1674,1673,1672,1671,1670,1677,1678,1679,1680,1665,1664,1663,1662}), //分拣库一
  280. new("10.30.37.217",new List<int>(){1715,1716,1717,1718,1719,1720,1705,1704,1703,1702,1701,1700,1707,1708,1709,1710,1695,1694,1693,1692}), //分拣库二
  281. new("10.30.37.223",new List<int>(){1745,1746,1747,1748,1749,1750,1735,1734,1733,1732,1731,1730,1737,1738,1739,1740,1725,1724,1723,1722}), //分拣库三
  282. };
  283. foreach (var item in tuples1)
  284. {
  285. var db530 = 0;
  286. var db531 = 0;
  287. foreach (var conv in item.Item2.Select(item1 => Device.All.FirstOrDefault(x => x.Code == item1.ToString())))
  288. {
  289. conv!.AddProtocol<ITruss530>(db530, 530, item.Item1);
  290. conv!.AddProtocol<ITruss531>(db531, 531, item.Item1);
  291. db530 += 18;
  292. db531 += 250;
  293. if (conv.Code == "1662")
  294. {
  295. var a = 0;
  296. }
  297. }
  298. }
  299. var tuples21 = new List<Tuple<string, List<int>>>
  300. {
  301. //机械臂
  302. new("10.30.37.230",new List<int>(){ 1666, 1661}), //库一北
  303. new("10.30.37.232",new List<int>(){ 1681, 1676}), //库一南
  304. new("10.30.37.234",new List<int>(){ 1696, 1691}), //库二北
  305. new("10.30.37.236",new List<int>(){ 1711, 1706}), //库二南
  306. new("10.30.37.238",new List<int>(){ 1726, 1721}), //库三北
  307. new("10.30.37.240",new List<int>(){ 1741, 1736 }), //库三南
  308. };
  309. foreach (var item in tuples21)
  310. {
  311. var db530 = 0;
  312. var db531 = 0;
  313. foreach (var conv in item.Item2.Select(item1 => Device.All.FirstOrDefault(x => x.Code == item1.ToString())))
  314. {
  315. conv!.AddProtocol<IRobot530>(db530, 530, item.Item1);
  316. conv!.AddProtocol<IRobot531>(db531, 531, item.Item1);
  317. db530 += 8;
  318. db531 += 130;
  319. }
  320. }
  321. #endregion 初始化桁架相关信息
  322. #region 初始化机械臂相关信息
  323. List<TrussSegmentInfo> TrussInfo1 = new List<TrussSegmentInfo>
  324. {
  325. new( 1, "10.30.37.230"),
  326. new( 2, "10.30.37.232"),
  327. new( 3, "10.30.37.234"),
  328. new( 4, "10.30.37.236"),
  329. new( 5, "10.30.37.238"),
  330. new( 6, "10.30.37.240"),
  331. };
  332. foreach (var item in TrussInfo1)
  333. {
  334. var conv = new Device($"Robot{item.Code}");
  335. conv.AddFlag(DeviceFlags.Robot);
  336. conv.AddProtocol<IRobot520>(0, 520, item.Ip);
  337. conv.AddProtocol<IRobot521>(0, 521, item.Ip);
  338. conv.AddProtocol<IRobot522>(0, 522, item.Ip);
  339. }
  340. #endregion 初始化机械臂相关信息
  341. #region 初始化堆垛机相关信息
  342. int ip = 41;
  343. for (int i = 0; i <= 5; i++)
  344. {
  345. var srm = new Device($"SRM{i + 1}");
  346. srm.AddFlag(DeviceFlags.堆垛机);
  347. ip = i == 0 ? ip : ip + 8;
  348. //三台堆垛机IP主机位分别是 41、49、57、65、73、81
  349. srm.AddProtocol<ISRM520>(0, 520, $"10.30.37.{ip}");
  350. srm.AddProtocol<ISRM521>(0, 521, $"10.30.37.{ip}");
  351. srm.AddProtocol<ISRM523>(0, 523, $"10.30.37.{ip}");
  352. //增加巷道
  353. var tunnel = new Device($"TY{i + 1}");
  354. tunnel.AddFlag(DeviceFlags.巷道);
  355. }
  356. #endregion 初始化堆垛机相关信息
  357. }
  358. /// <summary>
  359. /// 初始化数据库连接
  360. /// </summary>
  361. /// <param name="datas"></param>
  362. public static void InitDB(this List<DataBaseConnectionString> datas)
  363. {
  364. //初始化数据库
  365. SqlSugarHelper.Do(db =>
  366. {
  367. foreach (var connectionString in datas!)
  368. {
  369. var _db = db.Connect.GetConnectionScope(connectionString.Key);
  370. switch (connectionString.Key)
  371. {
  372. case "WCSDB"://WCS基本数据库
  373. break;
  374. case "WCSDlog"://WCS日志数据库
  375. break;
  376. case "PLC"://PLC
  377. SqlSugarHelper.SetPLC(connectionString.Key);
  378. _db.CodeFirst.InitTables<WCS_SRM520>();
  379. _db.CodeFirst.InitTables<WCS_SRM521>();
  380. _db.CodeFirst.InitTables<QuestDb_SRM523>();
  381. _db.CodeFirst.InitTables<WCS_RGV520>();
  382. _db.CodeFirst.InitTables<WCS_RGV521>();
  383. _db.CodeFirst.InitTables<QuestDb_RGV523>();
  384. _db.CodeFirst.InitTables<WCS_BCR80>();
  385. _db.CodeFirst.InitTables<WCS_BCR81>();
  386. _db.CodeFirst.InitTables<WCS_Station520>();
  387. _db.CodeFirst.InitTables<WCS_Station521>();
  388. _db.CodeFirst.InitTables<WCS_Station523>();
  389. _db.CodeFirst.InitTables<WCS_Station524>();
  390. _db.CodeFirst.InitTables<WCS_Station91>();
  391. _db.CodeFirst.InitTables<WCS_Truss520>();
  392. _db.CodeFirst.InitTables<WCS_Truss521>();
  393. _db.CodeFirst.InitTables<QuestDb_Truss523>();
  394. _db.CodeFirst.InitTables<WCS_Robot520>();
  395. _db.CodeFirst.InitTables<WCS_Robot521>();
  396. _db.CodeFirst.InitTables<QuestDb_Robot522>();
  397. break;
  398. default: //其他库
  399. break;
  400. };
  401. };
  402. });
  403. }
  404. }
  405. public class DevDbConfig<T>
  406. {
  407. public DevDbConfig()
  408. {
  409. }
  410. public DevDbConfig(string ip, T code)
  411. {
  412. IP = ip;
  413. Code = code;
  414. }
  415. public DevDbConfig(string ip, List<DevInterval<T>> devIntervalList)
  416. {
  417. IP = ip;
  418. DevIntervalList = devIntervalList;
  419. }
  420. public DevDbConfig(string ip, List<T> devCodeList)
  421. {
  422. IP = ip;
  423. DevCodeList = devCodeList;
  424. }
  425. public string IP { get; set; }
  426. public T Code { get; set; }
  427. public T StartCode { get; set; }
  428. public T EndCode { get; set; }
  429. public List<T> DevCodeList { get; set; }
  430. public List<DevInterval<T>> DevIntervalList { get; set; }
  431. }
  432. public class DevInterval<T>
  433. {
  434. public DevInterval(T s, T e)
  435. {
  436. StartCode = s;
  437. EndCode = e;
  438. }
  439. public T StartCode { get; set; }
  440. public T EndCode { get; set; }
  441. }
  442. }