123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- using ServiceCenter.SqlSugars;
- using WCS.Core;
- using WCS.Entity.Protocol;
- using WCS.Entity.Protocol.BCR;
- using WCS.Entity.Protocol.DataStructure;
- using WCS.Entity.Protocol.Protocol.DataStructure;
- 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.Systems;
- namespace WCS.WorkEngineering
- {
- public class ProtocolProxy : ProtocolProxyBase
- {
- public static DeviceDataPack DataPack { get; set; } = new DeviceDataPack();
- public ProtocolProxy(Device dev, ProtocolInfo info, Type protocolType, World world) : base(dev, info, protocolType, world)
- {
- }
- protected override void DataChanged()
- {
- //if (Device.Code == "RGV1" && Info.DBInfo.No == 520)
- //{
- // var a = Items;
- // //var dev=Device.Protocol(ProtocolType)
- // var b = a;
- //}
- //try
- //{
- // var datas = DataCollectionSysyem.AllDatas;
- // if (Device.Code.All(char.IsNumber))
- // {
- // if (!datas.ContainsKey(Device.Code)) datas[Device.Code] = new StationData { Code = Device.Code };
- // }
- // else if (Device.Code.Contains("SRM"))
- // {
- // if (!datas.ContainsKey(Device.Code)) datas[Device.Code] = new SRMData { Code = Device.Code };
- // }
- // else if (Device.Code.Contains("Truss"))
- // {
- // if (!datas.ContainsKey(Device.Code)) datas[Device.Code] = new TrussData() { Code = Device.Code };
- // }
- // else if (Device.Code.Contains("Robot"))
- // {
- // if (!datas.ContainsKey(Device.Code)) datas[Device.Code] = new RobotData() { Code = Device.Code };
- // }
- // else if (Device.Code.Contains("RGV"))
- // {
- // if (!datas.ContainsKey(Device.Code)) datas[Device.Code] = new RGVData { Code = Device.Code };
- // }
- // if (!datas.TryGetValue(Device.Code, out var data)) return;
- // data.Frame = DateTime.Now;
- // var p = data.GetType().GetProperties().FirstOrDefault(v => v.PropertyType == ProtocolDataType);
- // //var ty90 = WCS_Station90;
- // //if (p.getty is ty90 or)
- // //{
- // //}
- // if (p == null) return;
- // p.SetValue(data, DictionaryToEntity(ProtocolDataType, Items, data));
- //}
- //catch (Exception ex)
- //{
- // Console.WriteLine(ex.Message);
- //}
- }
- public void DictionaryToEntity(Type type, Dictionary<string, PlcItem> plcItems, DeviceData data)
- {
- //var entity = Activator.CreateInstance(type);
- ////采集量
- //Parallel.ForEach(type.GetProperties(), ty =>
- //{
- // if (plcItems.Any(x => x.Key == ty.Name))
- // {
- // var item = plcItems.First(x => ty.Name == x.Key);
- // ty.SetValue(entity, item.Value.Value);
- // }
- //});
- //Parallel.ForEach(type.GetProperties(), ty =>
- //{
- // var items = data.GetType().GetProperties();
- // if (items.Any(x => x.Name == ty.Name))
- // {
- // var item = items.First(x => ty.Name == x.Name);
- // ty.SetValue(entity, item.GetValue(data));
- // }
- //});
- //foreach (var ty in type.GetProperties().Where(x => x.Name == nameof(TDengineBaseEntity.CreateSql)))
- //{
- // var db = new SqlSugarHelper().PLC;
- // switch (type.Name)
- // {
- // case nameof(WCS_SRM520):
- // var item = entity as WCS_SRM520;
- // ty.SetValue(entity, GetString(db.Insertable(item).ToSqlString()));
- // break;
- // case nameof(WCS_SRM521):
- // var item1 = entity as WCS_SRM521;
- // ty.SetValue(entity, GetString(db.Insertable(item1).ToSqlString()));
- // break;
- // case nameof(WCS_SRM537):
- // var item2 = entity as WCS_SRM537;
- // ty.SetValue(entity, GetString(db.Insertable(item2).ToSqlString()));
- // break;
- // case nameof(WCS_RGV520):
- // var item3 = entity as WCS_RGV520;
- // ty.SetValue(entity, GetString(db.Insertable(item3).ToSqlString()));
- // break;
- // case nameof(WCS_RGV521):
- // var item4 = entity as WCS_RGV521;
- // ty.SetValue(entity, GetString(db.Insertable(item4).ToSqlString()));
- // break;
- // case nameof(WCS_BCR80):
- // var item5 = entity as WCS_BCR80;
- // ty.SetValue(entity, GetString(db.Insertable(item5).ToSqlString()));
- // break;
- // case nameof(WCS_BCR81):
- // var item6 = entity as WCS_BCR81;
- // ty.SetValue(entity, GetString(db.Insertable(item6).ToSqlString()));
- // break;
- // case nameof(WCS_BCR83):
- // var item7 = entity as WCS_BCR83;
- // ty.SetValue(entity, GetString(db.Insertable(item7).ToSqlString()));
- // break;
- // case nameof(WCS_Station520):
- // var item8 = entity as WCS_Station520;
- // ty.SetValue(entity, GetString(db.Insertable(item8).ToSqlString()));
- // break;
- // case nameof(WCS_Station521):
- // var item9 = entity as WCS_Station521;
- // ty.SetValue(entity, GetString(db.Insertable(item9).ToSqlString()));
- // break;
- // case nameof(WCS_Station523):
- // var item10 = entity as WCS_Station523;
- // ty.SetValue(entity, GetString(db.Insertable(item10).ToSqlString()));
- // break;
- // case nameof(WCS_Station524):
- // var item11 = entity as WCS_Station524;
- // ty.SetValue(entity, GetString(db.Insertable(item11).ToSqlString()));
- // break;
- // case nameof(WCS_Station525):
- // var item12 = entity as WCS_Station525;
- // ty.SetValue(entity, GetString(db.Insertable(item12).ToSqlString()));
- // break;
- // case nameof(WCS_Station90):
- // var item13 = entity as WCS_Station90;
- // ty.SetValue(entity, GetString(db.Insertable(item13).ToSqlString()));
- // break;
- // case nameof(WCS_Station91):
- // var item14 = entity as WCS_Station91;
- // ty.SetValue(entity, GetString(db.Insertable(item14).ToSqlString()));
- // break;
- // case nameof(WCS_Truss520):
- // var item15 = entity as WCS_Truss520;
- // ty.SetValue(entity, GetString(db.Insertable(item15).ToSqlString()));
- // break;
- // case nameof(WCS_Truss521):
- // var item16 = entity as WCS_Truss521;
- // ty.SetValue(entity, GetString(db.Insertable(item16).ToSqlString()));
- // break;
- // case nameof(WCS_Truss523):
- // var item17 = entity as WCS_Truss523;
- // ty.SetValue(entity, GetString(db.Insertable(item17).ToSqlString()));
- // break;
- // case nameof(WCS_Truss530):
- // var item18 = entity as WCS_Truss530;
- // ty.SetValue(entity, GetString(db.Insertable(item18).ToSqlString()));
- // break;
- // case nameof(WCS_Truss531):
- // var item19 = entity as WCS_Truss531;
- // ty.SetValue(entity, GetString(db.Insertable(item19).ToSqlString()));
- // break;
- // case nameof(WCS_Robot520):
- // var item20 = entity as WCS_Robot520;
- // ty.SetValue(entity, GetString(db.Insertable(item20).ToSqlString()));
- // break;
- // case nameof(WCS_Robot521):
- // var item21 = entity as WCS_Robot521;
- // ty.SetValue(entity, GetString(db.Insertable(item21).ToSqlString()));
- // break;
- // case nameof(WCS_Robot522):
- // var item22 = entity as WCS_Robot522;
- // ty.SetValue(entity, GetString(db.Insertable(item22).ToSqlString()));
- // break;
- // case nameof(WCS_Robot530):
- // var item23 = entity as WCS_Robot530;
- // ty.SetValue(entity, GetString(db.Insertable(item23).ToSqlString()));
- // break;
- // case nameof(WCS_Robot531):
- // var item24 = entity as WCS_Robot531;
- // ty.SetValue(entity, GetString(db.Insertable(item24).ToSqlString()));
- // break;
- // }
- //}
- //return entity;
- }
- public string GetString(string value)
- {
- return value.Replace("INSERT INTO ", "")
- .Replace(",N'", ",'")
- .Replace("\0", "")
- .Replace("wcs_", "")
- .Replace("(N'", "('") + "\r";
- }
- }
- }
|