ProtocolProxy.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. using ServiceCenter.SqlSugars;
  2. using WCS.Core;
  3. using WCS.Entity.Protocol;
  4. using WCS.Entity.Protocol.BCR;
  5. using WCS.Entity.Protocol.DataStructure;
  6. using WCS.Entity.Protocol.Protocol.DataStructure;
  7. using WCS.Entity.Protocol.RGV;
  8. using WCS.Entity.Protocol.Robot;
  9. using WCS.Entity.Protocol.SRM;
  10. using WCS.Entity.Protocol.Station;
  11. using WCS.Entity.Protocol.Truss;
  12. using WCS.WorkEngineering.Systems;
  13. namespace WCS.WorkEngineering
  14. {
  15. public class ProtocolProxy : ProtocolProxyBase
  16. {
  17. public static DeviceDataPack DataPack { get; set; } = new DeviceDataPack();
  18. public ProtocolProxy(Device dev, ProtocolInfo info, Type protocolType, World world) : base(dev, info, protocolType, world)
  19. {
  20. }
  21. protected override void DataChanged()
  22. {
  23. //if (Device.Code == "RGV1" && Info.DBInfo.No == 520)
  24. //{
  25. // var a = Items;
  26. // //var dev=Device.Protocol(ProtocolType)
  27. // var b = a;
  28. //}
  29. //try
  30. //{
  31. // var datas = DataCollectionSysyem.AllDatas;
  32. // if (Device.Code.All(char.IsNumber))
  33. // {
  34. // if (!datas.ContainsKey(Device.Code)) datas[Device.Code] = new StationData { Code = Device.Code };
  35. // }
  36. // else if (Device.Code.Contains("SRM"))
  37. // {
  38. // if (!datas.ContainsKey(Device.Code)) datas[Device.Code] = new SRMData { Code = Device.Code };
  39. // }
  40. // else if (Device.Code.Contains("Truss"))
  41. // {
  42. // if (!datas.ContainsKey(Device.Code)) datas[Device.Code] = new TrussData() { Code = Device.Code };
  43. // }
  44. // else if (Device.Code.Contains("Robot"))
  45. // {
  46. // if (!datas.ContainsKey(Device.Code)) datas[Device.Code] = new RobotData() { Code = Device.Code };
  47. // }
  48. // else if (Device.Code.Contains("RGV"))
  49. // {
  50. // if (!datas.ContainsKey(Device.Code)) datas[Device.Code] = new RGVData { Code = Device.Code };
  51. // }
  52. // if (!datas.TryGetValue(Device.Code, out var data)) return;
  53. // data.Frame = DateTime.Now;
  54. // var p = data.GetType().GetProperties().FirstOrDefault(v => v.PropertyType == ProtocolDataType);
  55. // //var ty90 = WCS_Station90;
  56. // //if (p.getty is ty90 or)
  57. // //{
  58. // //}
  59. // if (p == null) return;
  60. // p.SetValue(data, DictionaryToEntity(ProtocolDataType, Items, data));
  61. //}
  62. //catch (Exception ex)
  63. //{
  64. // Console.WriteLine(ex.Message);
  65. //}
  66. }
  67. public void DictionaryToEntity(Type type, Dictionary<string, PlcItem> plcItems, DeviceData data)
  68. {
  69. //var entity = Activator.CreateInstance(type);
  70. ////采集量
  71. //Parallel.ForEach(type.GetProperties(), ty =>
  72. //{
  73. // if (plcItems.Any(x => x.Key == ty.Name))
  74. // {
  75. // var item = plcItems.First(x => ty.Name == x.Key);
  76. // ty.SetValue(entity, item.Value.Value);
  77. // }
  78. //});
  79. //Parallel.ForEach(type.GetProperties(), ty =>
  80. //{
  81. // var items = data.GetType().GetProperties();
  82. // if (items.Any(x => x.Name == ty.Name))
  83. // {
  84. // var item = items.First(x => ty.Name == x.Name);
  85. // ty.SetValue(entity, item.GetValue(data));
  86. // }
  87. //});
  88. //foreach (var ty in type.GetProperties().Where(x => x.Name == nameof(TDengineBaseEntity.CreateSql)))
  89. //{
  90. // var db = new SqlSugarHelper().PLC;
  91. // switch (type.Name)
  92. // {
  93. // case nameof(WCS_SRM520):
  94. // var item = entity as WCS_SRM520;
  95. // ty.SetValue(entity, GetString(db.Insertable(item).ToSqlString()));
  96. // break;
  97. // case nameof(WCS_SRM521):
  98. // var item1 = entity as WCS_SRM521;
  99. // ty.SetValue(entity, GetString(db.Insertable(item1).ToSqlString()));
  100. // break;
  101. // case nameof(WCS_SRM537):
  102. // var item2 = entity as WCS_SRM537;
  103. // ty.SetValue(entity, GetString(db.Insertable(item2).ToSqlString()));
  104. // break;
  105. // case nameof(WCS_RGV520):
  106. // var item3 = entity as WCS_RGV520;
  107. // ty.SetValue(entity, GetString(db.Insertable(item3).ToSqlString()));
  108. // break;
  109. // case nameof(WCS_RGV521):
  110. // var item4 = entity as WCS_RGV521;
  111. // ty.SetValue(entity, GetString(db.Insertable(item4).ToSqlString()));
  112. // break;
  113. // case nameof(WCS_BCR80):
  114. // var item5 = entity as WCS_BCR80;
  115. // ty.SetValue(entity, GetString(db.Insertable(item5).ToSqlString()));
  116. // break;
  117. // case nameof(WCS_BCR81):
  118. // var item6 = entity as WCS_BCR81;
  119. // ty.SetValue(entity, GetString(db.Insertable(item6).ToSqlString()));
  120. // break;
  121. // case nameof(WCS_BCR83):
  122. // var item7 = entity as WCS_BCR83;
  123. // ty.SetValue(entity, GetString(db.Insertable(item7).ToSqlString()));
  124. // break;
  125. // case nameof(WCS_Station520):
  126. // var item8 = entity as WCS_Station520;
  127. // ty.SetValue(entity, GetString(db.Insertable(item8).ToSqlString()));
  128. // break;
  129. // case nameof(WCS_Station521):
  130. // var item9 = entity as WCS_Station521;
  131. // ty.SetValue(entity, GetString(db.Insertable(item9).ToSqlString()));
  132. // break;
  133. // case nameof(WCS_Station523):
  134. // var item10 = entity as WCS_Station523;
  135. // ty.SetValue(entity, GetString(db.Insertable(item10).ToSqlString()));
  136. // break;
  137. // case nameof(WCS_Station524):
  138. // var item11 = entity as WCS_Station524;
  139. // ty.SetValue(entity, GetString(db.Insertable(item11).ToSqlString()));
  140. // break;
  141. // case nameof(WCS_Station525):
  142. // var item12 = entity as WCS_Station525;
  143. // ty.SetValue(entity, GetString(db.Insertable(item12).ToSqlString()));
  144. // break;
  145. // case nameof(WCS_Station90):
  146. // var item13 = entity as WCS_Station90;
  147. // ty.SetValue(entity, GetString(db.Insertable(item13).ToSqlString()));
  148. // break;
  149. // case nameof(WCS_Station91):
  150. // var item14 = entity as WCS_Station91;
  151. // ty.SetValue(entity, GetString(db.Insertable(item14).ToSqlString()));
  152. // break;
  153. // case nameof(WCS_Truss520):
  154. // var item15 = entity as WCS_Truss520;
  155. // ty.SetValue(entity, GetString(db.Insertable(item15).ToSqlString()));
  156. // break;
  157. // case nameof(WCS_Truss521):
  158. // var item16 = entity as WCS_Truss521;
  159. // ty.SetValue(entity, GetString(db.Insertable(item16).ToSqlString()));
  160. // break;
  161. // case nameof(WCS_Truss523):
  162. // var item17 = entity as WCS_Truss523;
  163. // ty.SetValue(entity, GetString(db.Insertable(item17).ToSqlString()));
  164. // break;
  165. // case nameof(WCS_Truss530):
  166. // var item18 = entity as WCS_Truss530;
  167. // ty.SetValue(entity, GetString(db.Insertable(item18).ToSqlString()));
  168. // break;
  169. // case nameof(WCS_Truss531):
  170. // var item19 = entity as WCS_Truss531;
  171. // ty.SetValue(entity, GetString(db.Insertable(item19).ToSqlString()));
  172. // break;
  173. // case nameof(WCS_Robot520):
  174. // var item20 = entity as WCS_Robot520;
  175. // ty.SetValue(entity, GetString(db.Insertable(item20).ToSqlString()));
  176. // break;
  177. // case nameof(WCS_Robot521):
  178. // var item21 = entity as WCS_Robot521;
  179. // ty.SetValue(entity, GetString(db.Insertable(item21).ToSqlString()));
  180. // break;
  181. // case nameof(WCS_Robot522):
  182. // var item22 = entity as WCS_Robot522;
  183. // ty.SetValue(entity, GetString(db.Insertable(item22).ToSqlString()));
  184. // break;
  185. // case nameof(WCS_Robot530):
  186. // var item23 = entity as WCS_Robot530;
  187. // ty.SetValue(entity, GetString(db.Insertable(item23).ToSqlString()));
  188. // break;
  189. // case nameof(WCS_Robot531):
  190. // var item24 = entity as WCS_Robot531;
  191. // ty.SetValue(entity, GetString(db.Insertable(item24).ToSqlString()));
  192. // break;
  193. // }
  194. //}
  195. //return entity;
  196. }
  197. public string GetString(string value)
  198. {
  199. return value.Replace("INSERT INTO ", "")
  200. .Replace(",N'", ",'")
  201. .Replace("\0", "")
  202. .Replace("wcs_", "")
  203. .Replace("(N'", "('") + "\r";
  204. }
  205. }
  206. }