WorkStart.cs 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299
  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<IStation523>(, 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, 523, 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>(){ 1736, 1741}), //库三南
  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<ISRM537>(0, 537, $"10.30.37.{ip}");
  352. //增加巷道
  353. var tunnel = new Device($"TY{i + 1}");
  354. tunnel.AddFlag(DeviceFlags.巷道);
  355. }
  356. #endregion 初始化堆垛机相关信息
  357. //var toao = 100;
  358. //Task.Run(() =>
  359. //{
  360. // while (true)
  361. // {
  362. // //var sw = new Stopwatch();
  363. // //sw.Start();
  364. // //var sw1 = new Stopwatch();
  365. // //sw1.Start();
  366. // //try
  367. // //{
  368. // // var db = new SqlSugarHelper().PLC;
  369. // // var pack = RedisHub.Monitor.BLPop<DeviceDataPack>("DataCollectionpacks", 0); ;
  370. // // var sw4 = new Stopwatch();
  371. // // sw4.Start();
  372. // // Parallel.ForEach(pack.GetType().GetProperties().OrderBy(x => x.Name), ps =>
  373. // // {
  374. // // var sw10 = new Stopwatch();
  375. // // sw10.Start();
  376. // // var typeName = "";
  377. // // try
  378. // // {
  379. // // if (ps.PropertyType == typeof(ProtocolData<WCS_BCR80>[]))
  380. // // {
  381. // // if (pack.BCR80.Any())
  382. // // {
  383. // // var value = pack.BCR80.Select(x =>
  384. // // {
  385. // // var data = x.Data;
  386. // // data.Frame = x.Frame;
  387. // // data.Code = x.Code;
  388. // // return data;
  389. // // }).ToList();
  390. // // db.Insertable(value).ExecuteCommand();
  391. // // typeName = typeof(WCS_BCR80).Name;
  392. // // }
  393. // // }
  394. // // else if (ps.PropertyType == typeof(ProtocolData<WCS_BCR81>[]))
  395. // // {
  396. // // if (pack.BCR81.Any())
  397. // // {
  398. // // var value = pack.BCR81.Select(x =>
  399. // // {
  400. // // var data = x.Data;
  401. // // data.Frame = x.Frame;
  402. // // data.Code = x.Code;
  403. // // return data;
  404. // // }).ToList();
  405. // // db.Insertable(value).ExecuteCommand();
  406. // // typeName = typeof(WCS_BCR81).Name;
  407. // // }
  408. // // }
  409. // // else if (ps.PropertyType == typeof(ProtocolData<WCS_BCR83>[]))
  410. // // {
  411. // // if (pack.BCR83.Any())
  412. // // {
  413. // // var value = pack.BCR83.Select(x =>
  414. // // {
  415. // // var data = x.Data;
  416. // // data.Frame = x.Frame;
  417. // // data.Code = x.Code;
  418. // // return data;
  419. // // }).ToList();
  420. // // db.Insertable(value).ExecuteCommand();
  421. // // typeName = typeof(WCS_BCR83).Name;
  422. // // }
  423. // // }
  424. // // else if (ps.PropertyType == typeof(ProtocolData<WCS_RGV520>[]))
  425. // // {
  426. // // if (pack.RGV520.Any())
  427. // // {
  428. // // var value = pack.RGV520.Select(x =>
  429. // // {
  430. // // var data = x.Data;
  431. // // data.Frame = x.Frame;
  432. // // data.Code = x.Code;
  433. // // return data;
  434. // // }).ToList();
  435. // // db.Insertable(value).ExecuteCommand();
  436. // // typeName = typeof(WCS_RGV520).Name;
  437. // // }
  438. // // }
  439. // // else if (ps.PropertyType == typeof(ProtocolData<WCS_RGV521>[]))
  440. // // {
  441. // // if (pack.RGV521.Any())
  442. // // {
  443. // // var value = pack.RGV521.Select(x =>
  444. // // {
  445. // // var data = x.Data;
  446. // // data.Frame = x.Frame;
  447. // // data.Code = x.Code;
  448. // // return data;
  449. // // }).ToList();
  450. // // db.Insertable(value).ExecuteCommand();
  451. // // typeName = typeof(WCS_RGV521).Name;
  452. // // }
  453. // // }
  454. // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot520>[]))
  455. // // {
  456. // // if (pack.Robot520.Any())
  457. // // {
  458. // // var value = pack.Robot520.Select(x =>
  459. // // {
  460. // // var data = x.Data;
  461. // // data.Frame = x.Frame;
  462. // // data.Code = x.Code;
  463. // // return data;
  464. // // }).ToList();
  465. // // db.Insertable(value).ExecuteCommand();
  466. // // typeName = typeof(WCS_Robot520).Name;
  467. // // }
  468. // // }
  469. // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot521>[]))
  470. // // {
  471. // // if (pack.Robot521.Any())
  472. // // {
  473. // // var value = pack.Robot521.Select(x =>
  474. // // {
  475. // // var data = x.Data;
  476. // // data.Frame = x.Frame;
  477. // // data.Code = x.Code;
  478. // // return data;
  479. // // }).ToList();
  480. // // db.Insertable(value).ExecuteCommand();
  481. // // typeName = typeof(WCS_Robot521).Name;
  482. // // }
  483. // // }
  484. // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot522>[]))
  485. // // {
  486. // // if (pack.Robot522.Any())
  487. // // {
  488. // // var value = pack.Robot522.Select(x =>
  489. // // {
  490. // // var data = x.Data;
  491. // // data.Frame = x.Frame;
  492. // // data.Code = x.Code;
  493. // // return data;
  494. // // }).ToList();
  495. // // var sql = db.Insertable(value).ToSqlString();
  496. // // db.Ado.ExecuteCommand(sql);
  497. // // typeName = typeof(WCS_Robot522).Name;
  498. // // }
  499. // // }
  500. // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot530>[]))
  501. // // {
  502. // // if (pack.Robot530.Any())
  503. // // {
  504. // // var value = pack.Robot530.Select(x =>
  505. // // {
  506. // // var data = x.Data;
  507. // // data.Frame = x.Frame;
  508. // // data.Code = x.Code;
  509. // // return data;
  510. // // }).ToList();
  511. // // db.Insertable(value).ExecuteCommand();
  512. // // typeName = typeof(WCS_Robot530).Name;
  513. // // }
  514. // // }
  515. // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot531>[]))
  516. // // {
  517. // // if (pack.Robot531.Any())
  518. // // {
  519. // // var value = pack.Robot531.Select(x =>
  520. // // {
  521. // // var data = x.Data;
  522. // // data.Frame = x.Frame;
  523. // // data.Code = x.Code;
  524. // // return data;
  525. // // }).ToList();
  526. // // db.Insertable(value).ExecuteCommand();
  527. // // typeName = typeof(WCS_Robot531).Name;
  528. // // }
  529. // // }
  530. // // else if (ps.PropertyType == typeof(ProtocolData<WCS_SRM520>[]))
  531. // // {
  532. // // if (pack.SRM520.Any())
  533. // // {
  534. // // var value = pack.SRM520.Select(x =>
  535. // // {
  536. // // var data = x.Data;
  537. // // data.Frame = x.Frame;
  538. // // data.Code = x.Code;
  539. // // return data;
  540. // // }).ToList();
  541. // // db.Insertable(value).ExecuteCommand();
  542. // // typeName = typeof(WCS_SRM520).Name;
  543. // // }
  544. // // }
  545. // // else if (ps.PropertyType == typeof(ProtocolData<WCS_SRM521>[]))
  546. // // {
  547. // // if (pack.SRM521.Any())
  548. // // {
  549. // // var value = pack.SRM521.Select(x =>
  550. // // {
  551. // // var data = x.Data;
  552. // // data.Frame = x.Frame;
  553. // // data.Code = x.Code;
  554. // // return data;
  555. // // }).ToList();
  556. // // db.Insertable(value).ExecuteCommand();
  557. // // typeName = typeof(WCS_SRM521).Name;
  558. // // }
  559. // // }
  560. // // else if (ps.PropertyType == typeof(ProtocolData<WCS_SRM537>[]))
  561. // // {
  562. // // if (pack.SRM537.Any())
  563. // // {
  564. // // var value = pack.SRM537.Select(x =>
  565. // // {
  566. // // var data = x.Data;
  567. // // data.Frame = x.Frame;
  568. // // data.Code = x.Code;
  569. // // return data;
  570. // // }).ToList();
  571. // // var sql = db.Insertable(value).ToSqlString();
  572. // // db.Ado.ExecuteCommand(sql);
  573. // // typeName = typeof(WCS_SRM537).Name;
  574. // // }
  575. // // }
  576. // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Station520>[]))
  577. // // {
  578. // // if (pack.Station520.Any())
  579. // // {
  580. // // var value = pack.Station520.Select(x =>
  581. // // {
  582. // // var data = x.Data;
  583. // // data.Frame = x.Frame;
  584. // // data.Code = x.Code;
  585. // // return data;
  586. // // }).ToList();
  587. // // db.Insertable(value).ExecuteCommand();
  588. // // typeName = typeof(WCS_Station520).Name;
  589. // // }
  590. // // }
  591. // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Station521>[]))
  592. // // {
  593. // // if (pack.Station521.Any())
  594. // // {
  595. // // var value = pack.Station521.Select(x =>
  596. // // {
  597. // // var data = x.Data;
  598. // // data.Frame = x.Frame;
  599. // // data.Code = x.Code;
  600. // // return data;
  601. // // }).ToList();
  602. // // db.Insertable(value).ExecuteCommand();
  603. // // typeName = typeof(WCS_Station521).Name;
  604. // // }
  605. // // }
  606. // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Station523>[]))
  607. // // {
  608. // // if (pack.Station523.Any())
  609. // // {
  610. // // var value = pack.Station523.Select(x =>
  611. // // {
  612. // // var data = x.Data;
  613. // // data.Frame = x.Frame;
  614. // // data.Code = x.Code;
  615. // // return data;
  616. // // }).ToList();
  617. // // db.Insertable(value).ExecuteCommand();
  618. // // typeName = typeof(WCS_Station523).Name;
  619. // // }
  620. // // }
  621. // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Station524>[]))
  622. // // {
  623. // // if (pack.Station524.Any())
  624. // // {
  625. // // var value = pack.Station524.Select(x =>
  626. // // {
  627. // // var data = x.Data;
  628. // // data.Frame = x.Frame;
  629. // // data.Code = x.Code;
  630. // // return data;
  631. // // }).ToList();
  632. // // db.Insertable(value).ExecuteCommand();
  633. // // typeName = typeof(WCS_Station524).Name;
  634. // // }
  635. // // }
  636. // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Station525>[]))
  637. // // {
  638. // // if (pack.Station525.Any())
  639. // // {
  640. // // var value = pack.Station525.Select(x =>
  641. // // {
  642. // // var data = x.Data;
  643. // // data.Frame = x.Frame;
  644. // // data.Code = x.Code;
  645. // // return data;
  646. // // }).ToList();
  647. // // db.Insertable(value).ExecuteCommand();
  648. // // typeName = typeof(WCS_Station525).Name;
  649. // // }
  650. // // }
  651. // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Station90>[]))
  652. // // {
  653. // // if (pack.Station90.Any())
  654. // // {
  655. // // var value = pack.Station90.Select(x =>
  656. // // {
  657. // // var data = x.Data;
  658. // // data.Frame = x.Frame;
  659. // // data.Code = x.Code;
  660. // // return data;
  661. // // }).ToList();
  662. // // db.Insertable(value).ExecuteCommand();
  663. // // typeName = typeof(WCS_Station90).Name;
  664. // // }
  665. // // }
  666. // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Station91>[]))
  667. // // {
  668. // // if (pack.Station91.Any())
  669. // // {
  670. // // var value = pack.Station91.Select(x =>
  671. // // {
  672. // // var data = x.Data;
  673. // // data.Frame = x.Frame;
  674. // // data.Code = x.Code;
  675. // // return data;
  676. // // }).ToList();
  677. // // db.Insertable(value).ExecuteCommand();
  678. // // typeName = typeof(WCS_Station91).Name;
  679. // // }
  680. // // }
  681. // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss520>[]))
  682. // // {
  683. // // if (pack.Truss520.Any())
  684. // // {
  685. // // var value = pack.Truss520.Select(x =>
  686. // // {
  687. // // var data = x.Data;
  688. // // data.Frame = x.Frame;
  689. // // data.Code = x.Code;
  690. // // return data;
  691. // // }).ToList();
  692. // // db.Insertable(value).ExecuteCommand();
  693. // // typeName = typeof(WCS_Truss520).Name;
  694. // // }
  695. // // }
  696. // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss521>[]))
  697. // // {
  698. // // if (pack.Truss521.Any())
  699. // // {
  700. // // var value = pack.Truss521.Select(x =>
  701. // // {
  702. // // var data = x.Data;
  703. // // data.Frame = x.Frame;
  704. // // data.Code = x.Code;
  705. // // return data;
  706. // // }).ToList();
  707. // // db.Insertable(value).ExecuteCommand();
  708. // // typeName = typeof(WCS_Truss521).Name;
  709. // // }
  710. // // }
  711. // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss523>[]))
  712. // // {
  713. // // if (pack.Truss523.Any())
  714. // // {
  715. // // var value = pack.Truss523.Select(x =>
  716. // // {
  717. // // var data = x.Data;
  718. // // data.Frame = x.Frame;
  719. // // data.Code = x.Code;
  720. // // return data;
  721. // // }).ToList();
  722. // // db.Insertable(value).ExecuteCommand();
  723. // // typeName = typeof(WCS_Truss523).Name;
  724. // // }
  725. // // }
  726. // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss530>[]))
  727. // // {
  728. // // if (pack.Truss530.Any())
  729. // // {
  730. // // var value = pack.Truss530.Select(x =>
  731. // // {
  732. // // var data = x.Data;
  733. // // data.Frame = x.Frame;
  734. // // data.Code = x.Code;
  735. // // return data;
  736. // // }).ToList();
  737. // // db.Insertable(value).ExecuteCommand();
  738. // // typeName = typeof(WCS_Truss530).Name;
  739. // // }
  740. // // }
  741. // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss531>[]))
  742. // // {
  743. // // if (pack.Truss531.Any())
  744. // // {
  745. // // var value = pack.Truss531.Select(x =>
  746. // // {
  747. // // var data = x.Data;
  748. // // data.Frame = x.Frame;
  749. // // data.Code = x.Code;
  750. // // return data;
  751. // // }).ToList();
  752. // // db.Insertable(value).ExecuteCommand();
  753. // // typeName = typeof(WCS_Truss531).Name;
  754. // // }
  755. // // }
  756. // // }
  757. // // catch (Exception e)
  758. // // {
  759. // // LogHub.InterfacePublish(e.Message, e.StackTrace);
  760. // // }
  761. // // finally
  762. // // {
  763. // // sw10.Stop();
  764. // // LogHub.InterfacePublish("执行耗时", $"执行耗时:{typeName}:{sw10.ElapsedMilliseconds}");
  765. // // }
  766. // // });
  767. // // sw4.Stop();
  768. // // LogHub.InterfacePublish("执行SQL耗时", $"执行SQL耗时:{sw4.ElapsedMilliseconds}");
  769. // //}
  770. // //catch (Exception e)
  771. // //{
  772. // // LogHub.InterfacePublish("错误内容", $"错误内容:{e.Message}");
  773. // //}
  774. // //sw.Stop();
  775. // //if (sw.ElapsedMilliseconds >= toao)
  776. // //{
  777. // // Console.WriteLine($"数据处理耗时:{sw.ElapsedMilliseconds}");
  778. // // LogHub.InterfacePublish("数据处理耗时", $"数据处理耗时:{sw.ElapsedMilliseconds}");
  779. // // continue;
  780. // //}
  781. // //var time = toao - sw.ElapsedMilliseconds.ToInt();
  782. // //Thread.Sleep(time);
  783. // //sw1.Stop();
  784. // //Console.ForegroundColor = ConsoleColor.Red;
  785. // //Console.WriteLine($"数据处理耗时:{sw1.ElapsedMilliseconds}");
  786. // //Console.ResetColor();
  787. // //LogHub.InterfacePublish("数据处理耗时", $"数据处理耗时:{sw1.ElapsedMilliseconds}");
  788. // var sw = new Stopwatch();
  789. // sw.Start();
  790. // var sw1 = new Stopwatch();
  791. // sw1.Start();
  792. // try
  793. // {
  794. // var db = new SqlSugarHelper().PLC;
  795. // var pack = RedisHub.Monitor.BLPop<DeviceDataPack>("DataCollectionpacks", 0); ;
  796. // var sw4 = new Stopwatch();
  797. // sw4.Start();
  798. // Parallel.ForEach(pack.GetType().GetProperties().OrderBy(x => x.Name), ps =>
  799. // {
  800. // var sw10 = new Stopwatch();
  801. // sw10.Start();
  802. // var typeName = "";
  803. // try
  804. // {
  805. // if (ps.PropertyType == typeof(ProtocolData<WCS_BCR80>[]))
  806. // {
  807. // if (pack.BCR80.Any())
  808. // {
  809. // var value = pack.BCR80.Select(x => x.Data).ToList();
  810. // var sql = db.Insertable(value).ToSqlString();
  811. // db.Ado.ExecuteCommand(sql);
  812. // typeName = typeof(WCS_BCR80).Name;
  813. // }
  814. // }
  815. // else if (ps.PropertyType == typeof(ProtocolData<WCS_BCR81>[]))
  816. // {
  817. // if (pack.BCR81.Any())
  818. // {
  819. // var value = pack.BCR81.Select(x => x.Data).ToList();
  820. // var sql = db.Insertable(value).ToSqlString();
  821. // db.Ado.ExecuteCommand(sql);
  822. // typeName = typeof(WCS_BCR81).Name;
  823. // }
  824. // }
  825. // else if (ps.PropertyType == typeof(ProtocolData<WCS_BCR83>[]))
  826. // {
  827. // if (pack.BCR83.Any())
  828. // {
  829. // var value = pack.BCR83.Select(x => x.Data).ToList();
  830. // var sql = db.Insertable(value).ToSqlString();
  831. // db.Ado.ExecuteCommand(sql);
  832. // typeName = typeof(WCS_BCR83).Name;
  833. // }
  834. // }
  835. // else if (ps.PropertyType == typeof(ProtocolData<WCS_RGV520>[]))
  836. // {
  837. // if (pack.RGV520.Any())
  838. // {
  839. // var value = pack.RGV520.Select(x => x.Data).ToList();
  840. // var sql = db.Insertable(value).ToSqlString();
  841. // db.Ado.ExecuteCommand(sql);
  842. // typeName = typeof(WCS_RGV520).Name;
  843. // }
  844. // }
  845. // else if (ps.PropertyType == typeof(ProtocolData<WCS_RGV521>[]))
  846. // {
  847. // if (pack.RGV521.Any())
  848. // {
  849. // var value = pack.RGV521.Select(x => x.Data).ToList();
  850. // var sql = db.Insertable(value).ToSqlString();
  851. // db.Ado.ExecuteCommand(sql);
  852. // typeName = typeof(WCS_RGV521).Name;
  853. // }
  854. // }
  855. // else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot520>[]))
  856. // {
  857. // if (pack.Robot520.Any())
  858. // {
  859. // var value = pack.Robot520.Select(x => x.Data).ToList();
  860. // var sql = db.Insertable(value).ToSqlString();
  861. // db.Ado.ExecuteCommand(sql);
  862. // typeName = typeof(WCS_Robot520).Name;
  863. // }
  864. // }
  865. // else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot521>[]))
  866. // {
  867. // if (pack.Robot521.Any())
  868. // {
  869. // var value = pack.Robot521.Select(x => x.Data).ToList();
  870. // var sql = db.Insertable(value).ToSqlString();
  871. // db.Ado.ExecuteCommand(sql);
  872. // typeName = typeof(WCS_Robot521).Name;
  873. // }
  874. // }
  875. // else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot522>[]))
  876. // {
  877. // if (pack.Robot522.Any())
  878. // {
  879. // var value = pack.Robot522.Select(x => x.Data).ToList();
  880. // var sql = db.Insertable(value).ToSqlString();
  881. // db.Ado.ExecuteCommand(sql);
  882. // typeName = typeof(WCS_Robot522).Name;
  883. // }
  884. // }
  885. // else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot530>[]))
  886. // {
  887. // if (pack.Robot530.Any())
  888. // {
  889. // var value = pack.Robot530.Select(x => x.Data).ToList();
  890. // var sql = db.Insertable(value).ToSqlString();
  891. // db.Ado.ExecuteCommand(sql);
  892. // typeName = typeof(WCS_Robot530).Name;
  893. // }
  894. // }
  895. // else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot531>[]))
  896. // {
  897. // if (pack.Robot531.Any())
  898. // {
  899. // var value = pack.Robot531.Select(x => x.Data).ToList();
  900. // var sql = db.Insertable(value).ToSqlString();
  901. // db.Ado.ExecuteCommand(sql);
  902. // typeName = typeof(WCS_Robot531).Name;
  903. // }
  904. // }
  905. // else if (ps.PropertyType == typeof(ProtocolData<WCS_SRM520>[]))
  906. // {
  907. // if (pack.SRM520.Any())
  908. // {
  909. // var value = pack.SRM520.Select(x => x.Data).ToList();
  910. // var sql = db.Insertable(value).ToSqlString();
  911. // db.Ado.ExecuteCommand(sql);
  912. // typeName = typeof(WCS_SRM520).Name;
  913. // }
  914. // }
  915. // else if (ps.PropertyType == typeof(ProtocolData<WCS_SRM521>[]))
  916. // {
  917. // if (pack.SRM521.Any())
  918. // {
  919. // var value = pack.SRM521.Select(x => x.Data).ToList();
  920. // var sql = db.Insertable(value).ToSqlString();
  921. // db.Ado.ExecuteCommand(sql);
  922. // typeName = typeof(WCS_SRM521).Name;
  923. // }
  924. // }
  925. // else if (ps.PropertyType == typeof(ProtocolData<WCS_SRM537>[]))
  926. // {
  927. // if (pack.SRM537.Any())
  928. // {
  929. // var value = pack.SRM537.Select(x => x.Data).ToList();
  930. // var sql = db.Insertable(value).ToSqlString();
  931. // db.Ado.ExecuteCommand(sql);
  932. // typeName = typeof(WCS_SRM537).Name;
  933. // }
  934. // }
  935. // else if (ps.PropertyType == typeof(ProtocolData<WCS_Station520>[]))
  936. // {
  937. // if (pack.Station520.Any())
  938. // {
  939. // var value = pack.Station520.Select(x => x.Data).ToList();
  940. // var sql = db.Insertable(value).ToSqlString();
  941. // db.Ado.ExecuteCommand(sql);
  942. // typeName = typeof(WCS_Station520).Name;
  943. // }
  944. // }
  945. // else if (ps.PropertyType == typeof(ProtocolData<WCS_Station521>[]))
  946. // {
  947. // if (pack.Station521.Any())
  948. // {
  949. // var value = pack.Station521.Select(x => x.Data).ToList();
  950. // var sql = db.Insertable(value).ToSqlString();
  951. // db.Ado.ExecuteCommand(sql);
  952. // typeName = typeof(WCS_Station521).Name;
  953. // }
  954. // }
  955. // else if (ps.PropertyType == typeof(ProtocolData<WCS_Station523>[]))
  956. // {
  957. // if (pack.Station523.Any())
  958. // {
  959. // var value = pack.Station523.Select(x => x.Data).ToList();
  960. // var sql = db.Insertable(value).ToSqlString();
  961. // db.Ado.ExecuteCommand(sql);
  962. // typeName = typeof(WCS_Station523).Name;
  963. // }
  964. // }
  965. // else if (ps.PropertyType == typeof(ProtocolData<WCS_Station524>[]))
  966. // {
  967. // if (pack.Station524.Any())
  968. // {
  969. // var value = pack.Station524.Select(x => x.Data).ToList();
  970. // var sql = db.Insertable(value).ToSqlString();
  971. // db.Ado.ExecuteCommand(sql);
  972. // typeName = typeof(WCS_Station524).Name;
  973. // }
  974. // }
  975. // else if (ps.PropertyType == typeof(ProtocolData<WCS_Station525>[]))
  976. // {
  977. // if (pack.Station525.Any())
  978. // {
  979. // var value = pack.Station525.Select(x => x.Data).ToList();
  980. // var sql = db.Insertable(value).ToSqlString();
  981. // db.Ado.ExecuteCommand(sql);
  982. // typeName = typeof(WCS_Station525).Name;
  983. // }
  984. // }
  985. // else if (ps.PropertyType == typeof(ProtocolData<WCS_Station90>[]))
  986. // {
  987. // if (pack.Station90.Any())
  988. // {
  989. // var value = pack.Station90.Select(x => x.Data).ToList();
  990. // var sql = db.Insertable(value).ToSqlString();
  991. // db.Ado.ExecuteCommand(sql);
  992. // typeName = typeof(WCS_Station90).Name;
  993. // }
  994. // }
  995. // else if (ps.PropertyType == typeof(ProtocolData<WCS_Station91>[]))
  996. // {
  997. // if (pack.Station91.Any())
  998. // {
  999. // var value = pack.Station91.Select(x => x.Data).ToList();
  1000. // var sql = db.Insertable(value).ToSqlString();
  1001. // db.Ado.ExecuteCommand(sql);
  1002. // typeName = typeof(WCS_Station91).Name;
  1003. // }
  1004. // }
  1005. // else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss520>[]))
  1006. // {
  1007. // if (pack.Truss520.Any())
  1008. // {
  1009. // var value = pack.Truss520.Select(x => x.Data).ToList();
  1010. // var sql = db.Insertable(value).ToSqlString();
  1011. // db.Ado.ExecuteCommand(sql);
  1012. // typeName = typeof(WCS_Truss520).Name;
  1013. // }
  1014. // }
  1015. // else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss521>[]))
  1016. // {
  1017. // if (pack.Truss521.Any())
  1018. // {
  1019. // var value = pack.Truss521.Select(x => x.Data).ToList();
  1020. // var sql = db.Insertable(value).ToSqlString();
  1021. // db.Ado.ExecuteCommand(sql);
  1022. // typeName = typeof(WCS_Truss521).Name;
  1023. // }
  1024. // }
  1025. // else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss523>[]))
  1026. // {
  1027. // if (pack.Truss523.Any())
  1028. // {
  1029. // var value = pack.Truss523.Select(x => x.Data).ToList();
  1030. // var sql = db.Insertable(value).ToSqlString();
  1031. // db.Ado.ExecuteCommand(sql);
  1032. // typeName = typeof(WCS_Truss523).Name;
  1033. // }
  1034. // }
  1035. // else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss530>[]))
  1036. // {
  1037. // if (pack.Truss530.Any())
  1038. // {
  1039. // var value = pack.Truss530.Select(x => x.Data).ToList();
  1040. // var sql = db.Insertable(value).ToSqlString();
  1041. // db.Ado.ExecuteCommand(sql);
  1042. // typeName = typeof(WCS_Truss530).Name;
  1043. // }
  1044. // }
  1045. // else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss531>[]))
  1046. // {
  1047. // if (pack.Truss531.Any())
  1048. // {
  1049. // var value = pack.Truss531.Select(x => x.Data).ToList();
  1050. // var sql = db.Insertable(value).ToSqlString();
  1051. // db.Ado.ExecuteCommand(sql);
  1052. // typeName = typeof(WCS_Truss531).Name;
  1053. // }
  1054. // }
  1055. // }
  1056. // catch (Exception e)
  1057. // {
  1058. // LogHub.InterfacePublish(e.Message, e.StackTrace);
  1059. // }
  1060. // finally
  1061. // {
  1062. // sw10.Stop();
  1063. // LogHub.InterfacePublish("执行耗时", $"执行耗时:{typeName}:{sw10.ElapsedMilliseconds}");
  1064. // }
  1065. // });
  1066. // sw4.Stop();
  1067. // LogHub.InterfacePublish("执行SQL耗时", $"执行SQL耗时:{sw4.ElapsedMilliseconds}");
  1068. // }
  1069. // catch (Exception e)
  1070. // {
  1071. // LogHub.InterfacePublish("错误内容", $"错误内容:{e.Message}");
  1072. // }
  1073. // sw.Stop();
  1074. // if (sw.ElapsedMilliseconds >= toao)
  1075. // {
  1076. // Console.WriteLine($"数据处理耗时:{sw.ElapsedMilliseconds}");
  1077. // LogHub.InterfacePublish("数据处理耗时", $"数据处理耗时:{sw.ElapsedMilliseconds}");
  1078. // continue;
  1079. // }
  1080. // var time = toao - sw.ElapsedMilliseconds.ToInt();
  1081. // Thread.Sleep(time);
  1082. // sw1.Stop();
  1083. // Console.ForegroundColor = ConsoleColor.Red;
  1084. // Console.WriteLine($"数据处理耗时:{sw1.ElapsedMilliseconds}");
  1085. // Console.ResetColor();
  1086. // LogHub.InterfacePublish("数据处理耗时", $"数据处理耗时:{sw1.ElapsedMilliseconds}");
  1087. // }
  1088. //});
  1089. }
  1090. /// <summary>
  1091. /// 初始化数据库连接
  1092. /// </summary>
  1093. /// <param name="datas"></param>
  1094. public static void InitDB(this List<DataBaseConnectionString> datas)
  1095. {
  1096. //初始化数据库
  1097. SqlSugarHelper.Do(db =>
  1098. {
  1099. foreach (var connectionString in datas!)
  1100. {
  1101. var _db = db.Connect.GetConnectionScope(connectionString.Key);
  1102. switch (connectionString.Key)
  1103. {
  1104. case "WCSDB"://WCS基本数据库
  1105. //SqlSugarHelper.SetDefault(connectionString.Key);
  1106. //_db.CodeFirst.InitTables(typeof(WCS_PlcData));
  1107. //_db.CodeFirst.InitTables(typeof(WCS_TaskInfo));
  1108. //_db.CodeFirst.InitTables(typeof(WCS_TaskDtl));
  1109. //_db.CodeFirst.InitTables(typeof(WCS_TaskOld));
  1110. //_db.CodeFirst.InitTables(typeof(WCS_AgvTaskInfo));
  1111. //_db.CodeFirst.InitTables(typeof(WCS_Palletizing));
  1112. //_db.CodeFirst.InitTables(typeof(WCS_PalletizingLayer));
  1113. //_db.CodeFirst.InitTables(typeof(WCS_PalletizingRow));
  1114. //_db.CodeFirst.InitTables(typeof(WCS_PalletizingLoc));
  1115. //_db.CodeFirst.InitTables(typeof(WCS_CacheLine));
  1116. //_db.CodeFirst.InitTables(typeof(WCS_CacheLineLoc));
  1117. break;
  1118. case "WCSDlog"://WCS日志数据库
  1119. break;
  1120. case "PLC"://PLC
  1121. SqlSugarHelper.SetPLC(connectionString.Key);
  1122. //_db.DbMaintenance.CreateDatabase();
  1123. //_db.CodeFirst.InitTables<WCS_Log>();
  1124. //_db.CodeFirst.InitTables<DevRunInfo>();
  1125. //_db.CodeFirst.InitTables<WCS_SRM520>();
  1126. //_db.CodeFirst.InitTables<WCS_SRM521>();
  1127. //_db.CodeFirst.InitTables<WCS_SRM537>();
  1128. //_db.CodeFirst.InitTables<WCS_RGV520>();
  1129. //_db.CodeFirst.InitTables<WCS_RGV521>();
  1130. //_db.CodeFirst.InitTables<WCS_BCR80>();
  1131. //_db.CodeFirst.InitTables<WCS_BCR81>();
  1132. //_db.CodeFirst.InitTables<WCS_BCR83>();
  1133. //_db.CodeFirst.InitTables<WCS_Station520>();
  1134. //_db.CodeFirst.InitTables<WCS_Station521>();
  1135. //_db.CodeFirst.InitTables<WCS_Station523>();
  1136. //_db.CodeFirst.InitTables<WCS_Station524>();
  1137. //_db.CodeFirst.InitTables<WCS_Station525>();
  1138. //_db.CodeFirst.InitTables<WCS_Station90>();
  1139. //_db.CodeFirst.InitTables<WCS_Station91>();
  1140. //_db.CodeFirst.InitTables<WCS_Truss520>();
  1141. //_db.CodeFirst.InitTables<WCS_Truss521>();
  1142. //_db.CodeFirst.InitTables<WCS_Truss523>();
  1143. //_db.CodeFirst.InitTables<WCS_Truss530>();
  1144. //_db.CodeFirst.InitTables<WCS_Truss531>();
  1145. //_db.CodeFirst.InitTables<WCS_Robot520>();
  1146. //_db.CodeFirst.InitTables<WCS_Robot521>();
  1147. //_db.CodeFirst.InitTables<WCS_Robot522>();
  1148. //_db.CodeFirst.InitTables<WCS_Robot530>();
  1149. //_db.CodeFirst.InitTables<WCS_Robot531>();
  1150. var a = false;
  1151. break;
  1152. default: //其他库
  1153. break;
  1154. };
  1155. };
  1156. });
  1157. }
  1158. }
  1159. public class DevDbConfig<T>
  1160. {
  1161. public DevDbConfig()
  1162. {
  1163. }
  1164. public DevDbConfig(string ip, T code)
  1165. {
  1166. IP = ip;
  1167. Code = code;
  1168. }
  1169. public DevDbConfig(string ip, List<DevInterval<T>> devIntervalList)
  1170. {
  1171. IP = ip;
  1172. DevIntervalList = devIntervalList;
  1173. }
  1174. public DevDbConfig(string ip, List<T> devCodeList)
  1175. {
  1176. IP = ip;
  1177. DevCodeList = devCodeList;
  1178. }
  1179. public string IP { get; set; }
  1180. public T Code { get; set; }
  1181. public T StartCode { get; set; }
  1182. public T EndCode { get; set; }
  1183. public List<T> DevCodeList { get; set; }
  1184. public List<DevInterval<T>> DevIntervalList { get; set; }
  1185. }
  1186. public class DevInterval<T>
  1187. {
  1188. public DevInterval(T s, T e)
  1189. {
  1190. StartCode = s;
  1191. EndCode = e;
  1192. }
  1193. public T StartCode { get; set; }
  1194. public T EndCode { get; set; }
  1195. }
  1196. }