WorkStart.cs 20 KB

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