123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299 |
- using PlcSiemens.Core.Extension;
- using ServiceCenter;
- using ServiceCenter.Logs;
- using ServiceCenter.Redis;
- using ServiceCenter.SqlSugars;
- using System.Diagnostics;
- using WCS.Core;
- using WCS.Entity.Protocol;
- using WCS.Entity.Protocol.BCR;
- using WCS.Entity.Protocol.DataStructure;
- using WCS.Entity.Protocol.HUB;
- using WCS.Entity.Protocol.RGV;
- using WCS.Entity.Protocol.Robot;
- using WCS.Entity.Protocol.SRM;
- using WCS.Entity.Protocol.Station;
- using WCS.Entity.Protocol.Truss;
- using WCS.WorkEngineering.Extensions;
- using DeviceFlags = WCS.WorkEngineering.Extensions.DeviceFlags;
- namespace WCS.WorkEngineering
- {
- /// <summary>
- /// 业务工程配置信息
- /// </summary>
- public static class WorkStart
- {
- /// <summary>
- /// 初始化 设备信息
- /// </summary>
- public static void InitializeDeviceInfo()
- {
- #region 初始化RGV相关信息
- List<RgvSegmentInfo> RgvInfo = new List<RgvSegmentInfo>
- {
- new RgvSegmentInfo( 1, "10.30.37.113"), //库一北
- new RgvSegmentInfo( 2, "10.30.37.118"), //库一南
- new RgvSegmentInfo( 3, "10.30.37.123"), //库二北
- new RgvSegmentInfo( 4, "10.30.37.128"), //库二南
- new RgvSegmentInfo( 5, "10.30.37.133"), //库三北
- new RgvSegmentInfo( 6, "10.30.37.138"), //库三南
- };
- foreach (var item in RgvInfo)
- {
- var conv = new Device($"RGV{item.Code}");
- conv.AddFlag(DeviceFlags.RGV);
- conv.AddProtocol<IRGV520>(0, 520, item.Ip);
- conv.AddProtocol<IRGV521>(0, 521, item.Ip);
- //conv.AddProtocol<IStation523>(, 523, item.IP);
- }
- #endregion 初始化RGV相关信息
- #region 初始化输送机相关信息
- #region 基本信息
- #region 托盘线输送线
- var tuples = new List<Tuple<string, List<Tuple<int, int>>>>
- {
- //分拣库一
- new("10.30.37.89",new List<Tuple<int, int>>()
- {
- new(1601, 1620),
- new(2501, 2540),
- new(2701, 2740),
- new(1661, 1690),
- }),
- //分拣库二
- new("10.30.37.97",new List<Tuple<int, int>>()
- {
- new(1621, 1640),
- new(2901, 2940),
- new(3101, 3140),
- new(1691, 1720),
- }),
- //分拣库三
- new("10.30.37.105",new List<Tuple<int, int>>()
- {
- new(1641, 1660),
- new(3301, 3340),
- new(3501, 3540),
- new(1721, 1750)
- })
- };
- foreach (var item in tuples)
- {
- var db520 = 0;
- var db521 = 0;
- var db523 = 0;
- foreach (var item1 in item.Item2)
- {
- for (var i = item1.Item1; i <= item1.Item2; i++)
- {
- var conv = new Device(i.ToString());
- conv.AddFlag(DeviceFlags.输送机);
- conv.AddProtocol<IStation520>(db520, 520, item.Item1);
- conv.AddProtocol<IStation521>(db521, 521, item.Item1);
- conv.AddProtocol<IStation523>(db523, 523, item.Item1);
- db520 += 14;
- db521 += 16;
- db523 += 12;
- }
- }
- }
- #endregion 托盘线输送线
- #region 满轮输送线
- #region DB523,所有线体都会有DB523
- var mLtuples523 = new List<Tuple<string, List<Tuple<int, int>>>>()
- {
- new("10.30.37.166",new List<Tuple<int, int>>() //北侧满轮主线
- {
- new(1, 100),
- new(9001, 9010),//暂用,无意义
- new(401, 599),
- new(801,999),
- new(1201,1399),
- }),
- new("10.30.37.198",new List<Tuple<int, int>>() //南侧满轮主线
- {
- new(101, 210),
- new(601, 799),
- new(1001, 1199),
- new(1401,1599),
- new(341,379),
- })
- };
- foreach (var item in mLtuples523)
- {
- var db523 = 0;
- var db524 = 0;
- foreach (var item1 in item.Item2)
- {
- for (var i = item1.Item1; i <= item1.Item2; i++)
- {
- var conv = new Device(i.ToString());
- conv.AddFlag(DeviceFlags.输送机);
- conv.AddProtocol<IStation523>(db523, 523, item.Item1);
- conv.AddProtocol<IStation524>(db524, 524, item.Item1);
- db523 += 12;
- db524 += 16;
- }
- }
- }
- #endregion DB523,所有线体都会有DB523
- #region 520、521 交互线体会有520、521
- //Item2表示线体号集合,Item1表示IP
- var mLTuples520 = new List<Tuple<string, List<int>>>()
- {
- //北侧
- 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}),
- //南侧
- 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})
- };
- foreach (var item in mLTuples520)
- {
- var db520 = 0;
- var db521 = 0;
- foreach (var device in item.Item2.Select(item1 => Device.All.FirstOrDefault(v => v.Code == item1.ToString())))
- {
- if (device != null)
- {
- device.AddProtocol<IStation520>(db520, 520, item.Item1);
- device.AddProtocol<IStation521>(db521, 521, item.Item1);
- }
- db520 += 14;
- db521 += 16;
- }
- }
- #endregion 520、521 交互线体会有520、521
- #region 满轮扫码器
- //Item2表示线体号集合,Item1表示IP
- var mLTuples83 = new List<Tuple<string, List<int>>>()
- {
- new("10.30.37.166",new List<int>(){3,14,18,22,38,323,41,58,61}) ,
- new("10.30.37.198",new List<int>(){101,114,118,122,138,363,141,158,161})
- };
- foreach (var item in mLTuples83)
- {
- var db83 = 0;
- foreach (var device in item.Item2.Select(item1 => Device.All.FirstOrDefault(v => v.Code == item1.ToString())))
- {
- device?.AddProtocol<IBCR83>(db83, 83, item.Item1);
- db83 += 604;
- }
- }
- #endregion 满轮扫码器
- #region 满轮线告诉分拣预分配
- //Item2表示线体号集合,Item1表示IP
- var mLTuples525 = new List<Tuple<string, List<int>>>()
- {
- new("10.30.37.166",new List<int>(){18,38,58}),
- new("10.30.37.198",new List<int>(){118,138,158}),
- };
- foreach (var item in mLTuples525)
- {
- var db525 = 0;
- foreach (var device in item.Item2.Select(item1 => Device.All.FirstOrDefault(v => v.Code == item1.ToString())))
- {
- device?.AddProtocol<IStation525>(db525, 525, item.Item1);
- db525 += 3266;
- }
- }
- #endregion 满轮线告诉分拣预分配
- #region 外检信息
- //Item2表示线体号集合,Item1表示IP
- var mLTuples91 = new List<Tuple<string, List<int>>>()
- {
- new("10.30.37.166",new List<int>(){418,818,1218}),
- new("10.30.37.198",new List<int>(){618,1018,1418})
- };
- foreach (var item in mLTuples91)
- {
- var db91 = 0;
- foreach (var device in item.Item2.Select(item2 => Device.All.FirstOrDefault(v => v.Code == item2.ToString())))
- {
- device?.AddProtocol<IStation91>(db91, 91, item.Item1);
- db91 += 14;
- }
- }
- #endregion 外检信息
- #endregion 满轮输送线
- #endregion 基本信息
- #region 托盘线扫码器
- var bcrInfo = new List<BcrInfo>
- {
- new(new [] { "2532", "2732" }, "10.30.37.89"),
- new(new [] { "2932", "3132" }, "10.30.37.97"),
- //new(new [] { "2532", "2732" }, "10.30.37.105"),
- new(new [] {"RGV1"},"10.30.37.113"),
- new(new [] {"RGV2"},"10.30.37.118"),
- new(new [] {"RGV3"},"10.30.37.123"),
- new(new [] {"RGV4"},"10.30.37.128"),
- new(new [] {"RGV5"},"10.30.37.133"),
- new(new [] {"RGV6"},"10.30.37.138")
- };
- foreach (var item in bcrInfo)
- {
- for (var i = 0; i < item.DeviceNo.Length; i++)
- {
- var device = Device.All.FirstOrDefault(v => v.Code == item.DeviceNo[i]);
- device.AddFlag(DeviceFlags.扫码);
- var pos = i * 20;
- device.AddProtocol<IBCR81>(pos, 81, item.Ip);
- }
- }
- #endregion 托盘线扫码器
- #region 外检信息
- List<ShapeInfo> shapeInfo = new List<ShapeInfo>
- {
- new ShapeInfo(new int[] { 2732,2532 }, "10.30.37.89"),
- new ShapeInfo(new int[] { 2932, 3132 }, "10.30.37.97"),
- //new ShapeInfo(new int[] { 2732,2532 }, "10.30.37.105")
- };
- foreach (var item in shapeInfo)
- {
- for (int i = 0; i < item.DeviceNo.Length; i++)
- {
- var conv = Device.All.FirstOrDefault(x => x.Code == item.DeviceNo[i].ToString());
- conv.AddFlag(DeviceFlags.外检);
- int pos = i * 14;
- conv.AddProtocol<IStation91>(pos, 91, item.Ip);
- }
- }
- #endregion 外检信息
- #endregion 初始化输送机相关信息
- #region 初始化桁架相关信息
- List<TrussSegmentInfo> TrussInfo = new List<TrussSegmentInfo>
- {
- new TrussSegmentInfo( 1, "10.30.37.211"),
- new TrussSegmentInfo( 2, "10.30.37.217"),
- new TrussSegmentInfo( 3, "10.30.37.223")
- };
- foreach (var item in TrussInfo)
- {
- var conv = new Device($"Truss{item.Code}");
- conv.AddFlag(DeviceFlags.桁架);
- conv.AddProtocol<ITruss520>(0, 520, item.Ip);
- conv.AddProtocol<ITruss521>(0, 521, item.Ip);
- conv.AddProtocol<ITruss523>(0, 523, item.Ip);
- }
- var tuples1 = new List<Tuple<string, List<int>>>
- {
- //桁架
- 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}), //分拣库一
- 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}), //分拣库二
- 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}), //分拣库三
- };
- foreach (var item in tuples1)
- {
- var db530 = 0;
- var db531 = 0;
- foreach (var conv in item.Item2.Select(item1 => Device.All.FirstOrDefault(x => x.Code == item1.ToString())))
- {
- conv!.AddProtocol<ITruss530>(db530, 530, item.Item1);
- conv!.AddProtocol<ITruss531>(db531, 531, item.Item1);
- db530 += 18;
- db531 += 250;
- if (conv.Code == "1662")
- {
- var a = 0;
- }
- }
- }
- var tuples21 = new List<Tuple<string, List<int>>>
- {
- //机械臂
- new("10.30.37.230",new List<int>(){ 1666, 1661}), //库一北
- new("10.30.37.232",new List<int>(){ 1681, 1676}), //库一南
- new("10.30.37.234",new List<int>(){ 1696, 1691}), //库二北
- new("10.30.37.236",new List<int>(){ 1711, 1706}), //库二南
- new("10.30.37.238",new List<int>(){ 1726, 1721}), //库三北
- new("10.30.37.240",new List<int>(){ 1736, 1741}), //库三南
- };
- foreach (var item in tuples21)
- {
- var db530 = 0;
- var db531 = 0;
- foreach (var conv in item.Item2.Select(item1 => Device.All.FirstOrDefault(x => x.Code == item1.ToString())))
- {
- conv!.AddProtocol<IRobot530>(db530, 530, item.Item1);
- conv!.AddProtocol<IRobot531>(db531, 531, item.Item1);
- db530 += 8;
- db531 += 130;
- }
- }
- #endregion 初始化桁架相关信息
- #region 初始化机械臂相关信息
- List<TrussSegmentInfo> TrussInfo1 = new List<TrussSegmentInfo>
- {
- new( 1, "10.30.37.230"),
- new( 2, "10.30.37.232"),
- new( 3, "10.30.37.234"),
- new( 4, "10.30.37.236"),
- new( 5, "10.30.37.238"),
- new( 6, "10.30.37.240"),
- };
- foreach (var item in TrussInfo1)
- {
- var conv = new Device($"Robot{item.Code}");
- conv.AddFlag(DeviceFlags.Robot);
- conv.AddProtocol<IRobot520>(0, 520, item.Ip);
- conv.AddProtocol<IRobot521>(0, 521, item.Ip);
- conv.AddProtocol<IRobot522>(0, 522, item.Ip);
- }
- #endregion 初始化机械臂相关信息
- #region 初始化堆垛机相关信息
- int ip = 41;
- for (int i = 0; i <= 5; i++)
- {
- var srm = new Device($"SRM{i + 1}");
- srm.AddFlag(DeviceFlags.堆垛机);
- ip = i == 0 ? ip : ip + 8;
- //三台堆垛机IP主机位分别是 41、49、57、65、73、81
- srm.AddProtocol<ISRM520>(0, 520, $"10.30.37.{ip}");
- srm.AddProtocol<ISRM521>(0, 521, $"10.30.37.{ip}");
- srm.AddProtocol<ISRM537>(0, 537, $"10.30.37.{ip}");
- //增加巷道
- var tunnel = new Device($"TY{i + 1}");
- tunnel.AddFlag(DeviceFlags.巷道);
- }
- #endregion 初始化堆垛机相关信息
- //var toao = 100;
- //Task.Run(() =>
- //{
- // while (true)
- // {
- // //var sw = new Stopwatch();
- // //sw.Start();
- // //var sw1 = new Stopwatch();
- // //sw1.Start();
- // //try
- // //{
- // // var db = new SqlSugarHelper().PLC;
- // // var pack = RedisHub.Monitor.BLPop<DeviceDataPack>("DataCollectionpacks", 0); ;
- // // var sw4 = new Stopwatch();
- // // sw4.Start();
- // // Parallel.ForEach(pack.GetType().GetProperties().OrderBy(x => x.Name), ps =>
- // // {
- // // var sw10 = new Stopwatch();
- // // sw10.Start();
- // // var typeName = "";
- // // try
- // // {
- // // if (ps.PropertyType == typeof(ProtocolData<WCS_BCR80>[]))
- // // {
- // // if (pack.BCR80.Any())
- // // {
- // // var value = pack.BCR80.Select(x =>
- // // {
- // // var data = x.Data;
- // // data.Frame = x.Frame;
- // // data.Code = x.Code;
- // // return data;
- // // }).ToList();
- // // db.Insertable(value).ExecuteCommand();
- // // typeName = typeof(WCS_BCR80).Name;
- // // }
- // // }
- // // else if (ps.PropertyType == typeof(ProtocolData<WCS_BCR81>[]))
- // // {
- // // if (pack.BCR81.Any())
- // // {
- // // var value = pack.BCR81.Select(x =>
- // // {
- // // var data = x.Data;
- // // data.Frame = x.Frame;
- // // data.Code = x.Code;
- // // return data;
- // // }).ToList();
- // // db.Insertable(value).ExecuteCommand();
- // // typeName = typeof(WCS_BCR81).Name;
- // // }
- // // }
- // // else if (ps.PropertyType == typeof(ProtocolData<WCS_BCR83>[]))
- // // {
- // // if (pack.BCR83.Any())
- // // {
- // // var value = pack.BCR83.Select(x =>
- // // {
- // // var data = x.Data;
- // // data.Frame = x.Frame;
- // // data.Code = x.Code;
- // // return data;
- // // }).ToList();
- // // db.Insertable(value).ExecuteCommand();
- // // typeName = typeof(WCS_BCR83).Name;
- // // }
- // // }
- // // else if (ps.PropertyType == typeof(ProtocolData<WCS_RGV520>[]))
- // // {
- // // if (pack.RGV520.Any())
- // // {
- // // var value = pack.RGV520.Select(x =>
- // // {
- // // var data = x.Data;
- // // data.Frame = x.Frame;
- // // data.Code = x.Code;
- // // return data;
- // // }).ToList();
- // // db.Insertable(value).ExecuteCommand();
- // // typeName = typeof(WCS_RGV520).Name;
- // // }
- // // }
- // // else if (ps.PropertyType == typeof(ProtocolData<WCS_RGV521>[]))
- // // {
- // // if (pack.RGV521.Any())
- // // {
- // // var value = pack.RGV521.Select(x =>
- // // {
- // // var data = x.Data;
- // // data.Frame = x.Frame;
- // // data.Code = x.Code;
- // // return data;
- // // }).ToList();
- // // db.Insertable(value).ExecuteCommand();
- // // typeName = typeof(WCS_RGV521).Name;
- // // }
- // // }
- // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot520>[]))
- // // {
- // // if (pack.Robot520.Any())
- // // {
- // // var value = pack.Robot520.Select(x =>
- // // {
- // // var data = x.Data;
- // // data.Frame = x.Frame;
- // // data.Code = x.Code;
- // // return data;
- // // }).ToList();
- // // db.Insertable(value).ExecuteCommand();
- // // typeName = typeof(WCS_Robot520).Name;
- // // }
- // // }
- // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot521>[]))
- // // {
- // // if (pack.Robot521.Any())
- // // {
- // // var value = pack.Robot521.Select(x =>
- // // {
- // // var data = x.Data;
- // // data.Frame = x.Frame;
- // // data.Code = x.Code;
- // // return data;
- // // }).ToList();
- // // db.Insertable(value).ExecuteCommand();
- // // typeName = typeof(WCS_Robot521).Name;
- // // }
- // // }
- // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot522>[]))
- // // {
- // // if (pack.Robot522.Any())
- // // {
- // // var value = pack.Robot522.Select(x =>
- // // {
- // // var data = x.Data;
- // // data.Frame = x.Frame;
- // // data.Code = x.Code;
- // // return data;
- // // }).ToList();
- // // var sql = db.Insertable(value).ToSqlString();
- // // db.Ado.ExecuteCommand(sql);
- // // typeName = typeof(WCS_Robot522).Name;
- // // }
- // // }
- // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot530>[]))
- // // {
- // // if (pack.Robot530.Any())
- // // {
- // // var value = pack.Robot530.Select(x =>
- // // {
- // // var data = x.Data;
- // // data.Frame = x.Frame;
- // // data.Code = x.Code;
- // // return data;
- // // }).ToList();
- // // db.Insertable(value).ExecuteCommand();
- // // typeName = typeof(WCS_Robot530).Name;
- // // }
- // // }
- // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot531>[]))
- // // {
- // // if (pack.Robot531.Any())
- // // {
- // // var value = pack.Robot531.Select(x =>
- // // {
- // // var data = x.Data;
- // // data.Frame = x.Frame;
- // // data.Code = x.Code;
- // // return data;
- // // }).ToList();
- // // db.Insertable(value).ExecuteCommand();
- // // typeName = typeof(WCS_Robot531).Name;
- // // }
- // // }
- // // else if (ps.PropertyType == typeof(ProtocolData<WCS_SRM520>[]))
- // // {
- // // if (pack.SRM520.Any())
- // // {
- // // var value = pack.SRM520.Select(x =>
- // // {
- // // var data = x.Data;
- // // data.Frame = x.Frame;
- // // data.Code = x.Code;
- // // return data;
- // // }).ToList();
- // // db.Insertable(value).ExecuteCommand();
- // // typeName = typeof(WCS_SRM520).Name;
- // // }
- // // }
- // // else if (ps.PropertyType == typeof(ProtocolData<WCS_SRM521>[]))
- // // {
- // // if (pack.SRM521.Any())
- // // {
- // // var value = pack.SRM521.Select(x =>
- // // {
- // // var data = x.Data;
- // // data.Frame = x.Frame;
- // // data.Code = x.Code;
- // // return data;
- // // }).ToList();
- // // db.Insertable(value).ExecuteCommand();
- // // typeName = typeof(WCS_SRM521).Name;
- // // }
- // // }
- // // else if (ps.PropertyType == typeof(ProtocolData<WCS_SRM537>[]))
- // // {
- // // if (pack.SRM537.Any())
- // // {
- // // var value = pack.SRM537.Select(x =>
- // // {
- // // var data = x.Data;
- // // data.Frame = x.Frame;
- // // data.Code = x.Code;
- // // return data;
- // // }).ToList();
- // // var sql = db.Insertable(value).ToSqlString();
- // // db.Ado.ExecuteCommand(sql);
- // // typeName = typeof(WCS_SRM537).Name;
- // // }
- // // }
- // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Station520>[]))
- // // {
- // // if (pack.Station520.Any())
- // // {
- // // var value = pack.Station520.Select(x =>
- // // {
- // // var data = x.Data;
- // // data.Frame = x.Frame;
- // // data.Code = x.Code;
- // // return data;
- // // }).ToList();
- // // db.Insertable(value).ExecuteCommand();
- // // typeName = typeof(WCS_Station520).Name;
- // // }
- // // }
- // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Station521>[]))
- // // {
- // // if (pack.Station521.Any())
- // // {
- // // var value = pack.Station521.Select(x =>
- // // {
- // // var data = x.Data;
- // // data.Frame = x.Frame;
- // // data.Code = x.Code;
- // // return data;
- // // }).ToList();
- // // db.Insertable(value).ExecuteCommand();
- // // typeName = typeof(WCS_Station521).Name;
- // // }
- // // }
- // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Station523>[]))
- // // {
- // // if (pack.Station523.Any())
- // // {
- // // var value = pack.Station523.Select(x =>
- // // {
- // // var data = x.Data;
- // // data.Frame = x.Frame;
- // // data.Code = x.Code;
- // // return data;
- // // }).ToList();
- // // db.Insertable(value).ExecuteCommand();
- // // typeName = typeof(WCS_Station523).Name;
- // // }
- // // }
- // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Station524>[]))
- // // {
- // // if (pack.Station524.Any())
- // // {
- // // var value = pack.Station524.Select(x =>
- // // {
- // // var data = x.Data;
- // // data.Frame = x.Frame;
- // // data.Code = x.Code;
- // // return data;
- // // }).ToList();
- // // db.Insertable(value).ExecuteCommand();
- // // typeName = typeof(WCS_Station524).Name;
- // // }
- // // }
- // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Station525>[]))
- // // {
- // // if (pack.Station525.Any())
- // // {
- // // var value = pack.Station525.Select(x =>
- // // {
- // // var data = x.Data;
- // // data.Frame = x.Frame;
- // // data.Code = x.Code;
- // // return data;
- // // }).ToList();
- // // db.Insertable(value).ExecuteCommand();
- // // typeName = typeof(WCS_Station525).Name;
- // // }
- // // }
- // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Station90>[]))
- // // {
- // // if (pack.Station90.Any())
- // // {
- // // var value = pack.Station90.Select(x =>
- // // {
- // // var data = x.Data;
- // // data.Frame = x.Frame;
- // // data.Code = x.Code;
- // // return data;
- // // }).ToList();
- // // db.Insertable(value).ExecuteCommand();
- // // typeName = typeof(WCS_Station90).Name;
- // // }
- // // }
- // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Station91>[]))
- // // {
- // // if (pack.Station91.Any())
- // // {
- // // var value = pack.Station91.Select(x =>
- // // {
- // // var data = x.Data;
- // // data.Frame = x.Frame;
- // // data.Code = x.Code;
- // // return data;
- // // }).ToList();
- // // db.Insertable(value).ExecuteCommand();
- // // typeName = typeof(WCS_Station91).Name;
- // // }
- // // }
- // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss520>[]))
- // // {
- // // if (pack.Truss520.Any())
- // // {
- // // var value = pack.Truss520.Select(x =>
- // // {
- // // var data = x.Data;
- // // data.Frame = x.Frame;
- // // data.Code = x.Code;
- // // return data;
- // // }).ToList();
- // // db.Insertable(value).ExecuteCommand();
- // // typeName = typeof(WCS_Truss520).Name;
- // // }
- // // }
- // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss521>[]))
- // // {
- // // if (pack.Truss521.Any())
- // // {
- // // var value = pack.Truss521.Select(x =>
- // // {
- // // var data = x.Data;
- // // data.Frame = x.Frame;
- // // data.Code = x.Code;
- // // return data;
- // // }).ToList();
- // // db.Insertable(value).ExecuteCommand();
- // // typeName = typeof(WCS_Truss521).Name;
- // // }
- // // }
- // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss523>[]))
- // // {
- // // if (pack.Truss523.Any())
- // // {
- // // var value = pack.Truss523.Select(x =>
- // // {
- // // var data = x.Data;
- // // data.Frame = x.Frame;
- // // data.Code = x.Code;
- // // return data;
- // // }).ToList();
- // // db.Insertable(value).ExecuteCommand();
- // // typeName = typeof(WCS_Truss523).Name;
- // // }
- // // }
- // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss530>[]))
- // // {
- // // if (pack.Truss530.Any())
- // // {
- // // var value = pack.Truss530.Select(x =>
- // // {
- // // var data = x.Data;
- // // data.Frame = x.Frame;
- // // data.Code = x.Code;
- // // return data;
- // // }).ToList();
- // // db.Insertable(value).ExecuteCommand();
- // // typeName = typeof(WCS_Truss530).Name;
- // // }
- // // }
- // // else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss531>[]))
- // // {
- // // if (pack.Truss531.Any())
- // // {
- // // var value = pack.Truss531.Select(x =>
- // // {
- // // var data = x.Data;
- // // data.Frame = x.Frame;
- // // data.Code = x.Code;
- // // return data;
- // // }).ToList();
- // // db.Insertable(value).ExecuteCommand();
- // // typeName = typeof(WCS_Truss531).Name;
- // // }
- // // }
- // // }
- // // catch (Exception e)
- // // {
- // // LogHub.InterfacePublish(e.Message, e.StackTrace);
- // // }
- // // finally
- // // {
- // // sw10.Stop();
- // // LogHub.InterfacePublish("执行耗时", $"执行耗时:{typeName}:{sw10.ElapsedMilliseconds}");
- // // }
- // // });
- // // sw4.Stop();
- // // LogHub.InterfacePublish("执行SQL耗时", $"执行SQL耗时:{sw4.ElapsedMilliseconds}");
- // //}
- // //catch (Exception e)
- // //{
- // // LogHub.InterfacePublish("错误内容", $"错误内容:{e.Message}");
- // //}
- // //sw.Stop();
- // //if (sw.ElapsedMilliseconds >= toao)
- // //{
- // // Console.WriteLine($"数据处理耗时:{sw.ElapsedMilliseconds}");
- // // LogHub.InterfacePublish("数据处理耗时", $"数据处理耗时:{sw.ElapsedMilliseconds}");
- // // continue;
- // //}
- // //var time = toao - sw.ElapsedMilliseconds.ToInt();
- // //Thread.Sleep(time);
- // //sw1.Stop();
- // //Console.ForegroundColor = ConsoleColor.Red;
- // //Console.WriteLine($"数据处理耗时:{sw1.ElapsedMilliseconds}");
- // //Console.ResetColor();
- // //LogHub.InterfacePublish("数据处理耗时", $"数据处理耗时:{sw1.ElapsedMilliseconds}");
- // var sw = new Stopwatch();
- // sw.Start();
- // var sw1 = new Stopwatch();
- // sw1.Start();
- // try
- // {
- // var db = new SqlSugarHelper().PLC;
- // var pack = RedisHub.Monitor.BLPop<DeviceDataPack>("DataCollectionpacks", 0); ;
- // var sw4 = new Stopwatch();
- // sw4.Start();
- // Parallel.ForEach(pack.GetType().GetProperties().OrderBy(x => x.Name), ps =>
- // {
- // var sw10 = new Stopwatch();
- // sw10.Start();
- // var typeName = "";
- // try
- // {
- // if (ps.PropertyType == typeof(ProtocolData<WCS_BCR80>[]))
- // {
- // if (pack.BCR80.Any())
- // {
- // var value = pack.BCR80.Select(x => x.Data).ToList();
- // var sql = db.Insertable(value).ToSqlString();
- // db.Ado.ExecuteCommand(sql);
- // typeName = typeof(WCS_BCR80).Name;
- // }
- // }
- // else if (ps.PropertyType == typeof(ProtocolData<WCS_BCR81>[]))
- // {
- // if (pack.BCR81.Any())
- // {
- // var value = pack.BCR81.Select(x => x.Data).ToList();
- // var sql = db.Insertable(value).ToSqlString();
- // db.Ado.ExecuteCommand(sql);
- // typeName = typeof(WCS_BCR81).Name;
- // }
- // }
- // else if (ps.PropertyType == typeof(ProtocolData<WCS_BCR83>[]))
- // {
- // if (pack.BCR83.Any())
- // {
- // var value = pack.BCR83.Select(x => x.Data).ToList();
- // var sql = db.Insertable(value).ToSqlString();
- // db.Ado.ExecuteCommand(sql);
- // typeName = typeof(WCS_BCR83).Name;
- // }
- // }
- // else if (ps.PropertyType == typeof(ProtocolData<WCS_RGV520>[]))
- // {
- // if (pack.RGV520.Any())
- // {
- // var value = pack.RGV520.Select(x => x.Data).ToList();
- // var sql = db.Insertable(value).ToSqlString();
- // db.Ado.ExecuteCommand(sql);
- // typeName = typeof(WCS_RGV520).Name;
- // }
- // }
- // else if (ps.PropertyType == typeof(ProtocolData<WCS_RGV521>[]))
- // {
- // if (pack.RGV521.Any())
- // {
- // var value = pack.RGV521.Select(x => x.Data).ToList();
- // var sql = db.Insertable(value).ToSqlString();
- // db.Ado.ExecuteCommand(sql);
- // typeName = typeof(WCS_RGV521).Name;
- // }
- // }
- // else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot520>[]))
- // {
- // if (pack.Robot520.Any())
- // {
- // var value = pack.Robot520.Select(x => x.Data).ToList();
- // var sql = db.Insertable(value).ToSqlString();
- // db.Ado.ExecuteCommand(sql);
- // typeName = typeof(WCS_Robot520).Name;
- // }
- // }
- // else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot521>[]))
- // {
- // if (pack.Robot521.Any())
- // {
- // var value = pack.Robot521.Select(x => x.Data).ToList();
- // var sql = db.Insertable(value).ToSqlString();
- // db.Ado.ExecuteCommand(sql);
- // typeName = typeof(WCS_Robot521).Name;
- // }
- // }
- // else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot522>[]))
- // {
- // if (pack.Robot522.Any())
- // {
- // var value = pack.Robot522.Select(x => x.Data).ToList();
- // var sql = db.Insertable(value).ToSqlString();
- // db.Ado.ExecuteCommand(sql);
- // typeName = typeof(WCS_Robot522).Name;
- // }
- // }
- // else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot530>[]))
- // {
- // if (pack.Robot530.Any())
- // {
- // var value = pack.Robot530.Select(x => x.Data).ToList();
- // var sql = db.Insertable(value).ToSqlString();
- // db.Ado.ExecuteCommand(sql);
- // typeName = typeof(WCS_Robot530).Name;
- // }
- // }
- // else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot531>[]))
- // {
- // if (pack.Robot531.Any())
- // {
- // var value = pack.Robot531.Select(x => x.Data).ToList();
- // var sql = db.Insertable(value).ToSqlString();
- // db.Ado.ExecuteCommand(sql);
- // typeName = typeof(WCS_Robot531).Name;
- // }
- // }
- // else if (ps.PropertyType == typeof(ProtocolData<WCS_SRM520>[]))
- // {
- // if (pack.SRM520.Any())
- // {
- // var value = pack.SRM520.Select(x => x.Data).ToList();
- // var sql = db.Insertable(value).ToSqlString();
- // db.Ado.ExecuteCommand(sql);
- // typeName = typeof(WCS_SRM520).Name;
- // }
- // }
- // else if (ps.PropertyType == typeof(ProtocolData<WCS_SRM521>[]))
- // {
- // if (pack.SRM521.Any())
- // {
- // var value = pack.SRM521.Select(x => x.Data).ToList();
- // var sql = db.Insertable(value).ToSqlString();
- // db.Ado.ExecuteCommand(sql);
- // typeName = typeof(WCS_SRM521).Name;
- // }
- // }
- // else if (ps.PropertyType == typeof(ProtocolData<WCS_SRM537>[]))
- // {
- // if (pack.SRM537.Any())
- // {
- // var value = pack.SRM537.Select(x => x.Data).ToList();
- // var sql = db.Insertable(value).ToSqlString();
- // db.Ado.ExecuteCommand(sql);
- // typeName = typeof(WCS_SRM537).Name;
- // }
- // }
- // else if (ps.PropertyType == typeof(ProtocolData<WCS_Station520>[]))
- // {
- // if (pack.Station520.Any())
- // {
- // var value = pack.Station520.Select(x => x.Data).ToList();
- // var sql = db.Insertable(value).ToSqlString();
- // db.Ado.ExecuteCommand(sql);
- // typeName = typeof(WCS_Station520).Name;
- // }
- // }
- // else if (ps.PropertyType == typeof(ProtocolData<WCS_Station521>[]))
- // {
- // if (pack.Station521.Any())
- // {
- // var value = pack.Station521.Select(x => x.Data).ToList();
- // var sql = db.Insertable(value).ToSqlString();
- // db.Ado.ExecuteCommand(sql);
- // typeName = typeof(WCS_Station521).Name;
- // }
- // }
- // else if (ps.PropertyType == typeof(ProtocolData<WCS_Station523>[]))
- // {
- // if (pack.Station523.Any())
- // {
- // var value = pack.Station523.Select(x => x.Data).ToList();
- // var sql = db.Insertable(value).ToSqlString();
- // db.Ado.ExecuteCommand(sql);
- // typeName = typeof(WCS_Station523).Name;
- // }
- // }
- // else if (ps.PropertyType == typeof(ProtocolData<WCS_Station524>[]))
- // {
- // if (pack.Station524.Any())
- // {
- // var value = pack.Station524.Select(x => x.Data).ToList();
- // var sql = db.Insertable(value).ToSqlString();
- // db.Ado.ExecuteCommand(sql);
- // typeName = typeof(WCS_Station524).Name;
- // }
- // }
- // else if (ps.PropertyType == typeof(ProtocolData<WCS_Station525>[]))
- // {
- // if (pack.Station525.Any())
- // {
- // var value = pack.Station525.Select(x => x.Data).ToList();
- // var sql = db.Insertable(value).ToSqlString();
- // db.Ado.ExecuteCommand(sql);
- // typeName = typeof(WCS_Station525).Name;
- // }
- // }
- // else if (ps.PropertyType == typeof(ProtocolData<WCS_Station90>[]))
- // {
- // if (pack.Station90.Any())
- // {
- // var value = pack.Station90.Select(x => x.Data).ToList();
- // var sql = db.Insertable(value).ToSqlString();
- // db.Ado.ExecuteCommand(sql);
- // typeName = typeof(WCS_Station90).Name;
- // }
- // }
- // else if (ps.PropertyType == typeof(ProtocolData<WCS_Station91>[]))
- // {
- // if (pack.Station91.Any())
- // {
- // var value = pack.Station91.Select(x => x.Data).ToList();
- // var sql = db.Insertable(value).ToSqlString();
- // db.Ado.ExecuteCommand(sql);
- // typeName = typeof(WCS_Station91).Name;
- // }
- // }
- // else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss520>[]))
- // {
- // if (pack.Truss520.Any())
- // {
- // var value = pack.Truss520.Select(x => x.Data).ToList();
- // var sql = db.Insertable(value).ToSqlString();
- // db.Ado.ExecuteCommand(sql);
- // typeName = typeof(WCS_Truss520).Name;
- // }
- // }
- // else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss521>[]))
- // {
- // if (pack.Truss521.Any())
- // {
- // var value = pack.Truss521.Select(x => x.Data).ToList();
- // var sql = db.Insertable(value).ToSqlString();
- // db.Ado.ExecuteCommand(sql);
- // typeName = typeof(WCS_Truss521).Name;
- // }
- // }
- // else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss523>[]))
- // {
- // if (pack.Truss523.Any())
- // {
- // var value = pack.Truss523.Select(x => x.Data).ToList();
- // var sql = db.Insertable(value).ToSqlString();
- // db.Ado.ExecuteCommand(sql);
- // typeName = typeof(WCS_Truss523).Name;
- // }
- // }
- // else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss530>[]))
- // {
- // if (pack.Truss530.Any())
- // {
- // var value = pack.Truss530.Select(x => x.Data).ToList();
- // var sql = db.Insertable(value).ToSqlString();
- // db.Ado.ExecuteCommand(sql);
- // typeName = typeof(WCS_Truss530).Name;
- // }
- // }
- // else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss531>[]))
- // {
- // if (pack.Truss531.Any())
- // {
- // var value = pack.Truss531.Select(x => x.Data).ToList();
- // var sql = db.Insertable(value).ToSqlString();
- // db.Ado.ExecuteCommand(sql);
- // typeName = typeof(WCS_Truss531).Name;
- // }
- // }
- // }
- // catch (Exception e)
- // {
- // LogHub.InterfacePublish(e.Message, e.StackTrace);
- // }
- // finally
- // {
- // sw10.Stop();
- // LogHub.InterfacePublish("执行耗时", $"执行耗时:{typeName}:{sw10.ElapsedMilliseconds}");
- // }
- // });
- // sw4.Stop();
- // LogHub.InterfacePublish("执行SQL耗时", $"执行SQL耗时:{sw4.ElapsedMilliseconds}");
- // }
- // catch (Exception e)
- // {
- // LogHub.InterfacePublish("错误内容", $"错误内容:{e.Message}");
- // }
- // sw.Stop();
- // if (sw.ElapsedMilliseconds >= toao)
- // {
- // Console.WriteLine($"数据处理耗时:{sw.ElapsedMilliseconds}");
- // LogHub.InterfacePublish("数据处理耗时", $"数据处理耗时:{sw.ElapsedMilliseconds}");
- // continue;
- // }
- // var time = toao - sw.ElapsedMilliseconds.ToInt();
- // Thread.Sleep(time);
- // sw1.Stop();
- // Console.ForegroundColor = ConsoleColor.Red;
- // Console.WriteLine($"数据处理耗时:{sw1.ElapsedMilliseconds}");
- // Console.ResetColor();
- // LogHub.InterfacePublish("数据处理耗时", $"数据处理耗时:{sw1.ElapsedMilliseconds}");
- // }
- //});
- }
- /// <summary>
- /// 初始化数据库连接
- /// </summary>
- /// <param name="datas"></param>
- public static void InitDB(this List<DataBaseConnectionString> datas)
- {
- //初始化数据库
- SqlSugarHelper.Do(db =>
- {
- foreach (var connectionString in datas!)
- {
- var _db = db.Connect.GetConnectionScope(connectionString.Key);
- switch (connectionString.Key)
- {
- case "WCSDB"://WCS基本数据库
- //SqlSugarHelper.SetDefault(connectionString.Key);
- //_db.CodeFirst.InitTables(typeof(WCS_PlcData));
- //_db.CodeFirst.InitTables(typeof(WCS_TaskInfo));
- //_db.CodeFirst.InitTables(typeof(WCS_TaskDtl));
- //_db.CodeFirst.InitTables(typeof(WCS_TaskOld));
- //_db.CodeFirst.InitTables(typeof(WCS_AgvTaskInfo));
- //_db.CodeFirst.InitTables(typeof(WCS_Palletizing));
- //_db.CodeFirst.InitTables(typeof(WCS_PalletizingLayer));
- //_db.CodeFirst.InitTables(typeof(WCS_PalletizingRow));
- //_db.CodeFirst.InitTables(typeof(WCS_PalletizingLoc));
- //_db.CodeFirst.InitTables(typeof(WCS_CacheLine));
- //_db.CodeFirst.InitTables(typeof(WCS_CacheLineLoc));
- break;
- case "WCSDlog"://WCS日志数据库
- break;
- case "PLC"://PLC
- SqlSugarHelper.SetPLC(connectionString.Key);
- //_db.DbMaintenance.CreateDatabase();
- //_db.CodeFirst.InitTables<WCS_Log>();
- //_db.CodeFirst.InitTables<DevRunInfo>();
- //_db.CodeFirst.InitTables<WCS_SRM520>();
- //_db.CodeFirst.InitTables<WCS_SRM521>();
- //_db.CodeFirst.InitTables<WCS_SRM537>();
- //_db.CodeFirst.InitTables<WCS_RGV520>();
- //_db.CodeFirst.InitTables<WCS_RGV521>();
- //_db.CodeFirst.InitTables<WCS_BCR80>();
- //_db.CodeFirst.InitTables<WCS_BCR81>();
- //_db.CodeFirst.InitTables<WCS_BCR83>();
- //_db.CodeFirst.InitTables<WCS_Station520>();
- //_db.CodeFirst.InitTables<WCS_Station521>();
- //_db.CodeFirst.InitTables<WCS_Station523>();
- //_db.CodeFirst.InitTables<WCS_Station524>();
- //_db.CodeFirst.InitTables<WCS_Station525>();
- //_db.CodeFirst.InitTables<WCS_Station90>();
- //_db.CodeFirst.InitTables<WCS_Station91>();
- //_db.CodeFirst.InitTables<WCS_Truss520>();
- //_db.CodeFirst.InitTables<WCS_Truss521>();
- //_db.CodeFirst.InitTables<WCS_Truss523>();
- //_db.CodeFirst.InitTables<WCS_Truss530>();
- //_db.CodeFirst.InitTables<WCS_Truss531>();
- //_db.CodeFirst.InitTables<WCS_Robot520>();
- //_db.CodeFirst.InitTables<WCS_Robot521>();
- //_db.CodeFirst.InitTables<WCS_Robot522>();
- //_db.CodeFirst.InitTables<WCS_Robot530>();
- //_db.CodeFirst.InitTables<WCS_Robot531>();
- var a = false;
- break;
- default: //其他库
- break;
- };
- };
- });
- }
- }
- public class DevDbConfig<T>
- {
- public DevDbConfig()
- {
- }
- public DevDbConfig(string ip, T code)
- {
- IP = ip;
- Code = code;
- }
- public DevDbConfig(string ip, List<DevInterval<T>> devIntervalList)
- {
- IP = ip;
- DevIntervalList = devIntervalList;
- }
- public DevDbConfig(string ip, List<T> devCodeList)
- {
- IP = ip;
- DevCodeList = devCodeList;
- }
- public string IP { get; set; }
- public T Code { get; set; }
- public T StartCode { get; set; }
- public T EndCode { get; set; }
- public List<T> DevCodeList { get; set; }
- public List<DevInterval<T>> DevIntervalList { get; set; }
- }
- public class DevInterval<T>
- {
- public DevInterval(T s, T e)
- {
- StartCode = s;
- EndCode = e;
- }
- public T StartCode { get; set; }
- public T EndCode { get; set; }
- }
- }
|