DeviceWriteSystem.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using WCS.Core;
  2. using WCS.Entity.Protocol.RGV;
  3. using WCS.Entity.Protocol.SRM;
  4. using WCS.Entity.Protocol.Station;
  5. using WCS.WorkEngineering.Extensions;
  6. using WCS.WorkEngineering.Worlds;
  7. using DeviceFlags = WCS.WorkEngineering.Extensions.DeviceFlags;
  8. namespace WCS.WorkEngineering.Systems
  9. {
  10. /// <summary>
  11. /// 设备信息写入接口
  12. /// </summary>
  13. [BelongTo(typeof(MainWorld))]
  14. public class DeviceWriteSystem : ServiceSystem<DeviceWriteInfo>
  15. {
  16. /// <summary>
  17. /// 所有的站台
  18. /// </summary>
  19. private Dictionary<string, Station> Convs;
  20. private Dictionary<string, SRM> Srms;
  21. private Dictionary<string, RGV> Rgvs;
  22. /// <summary>
  23. /// 构造函数
  24. /// </summary>
  25. public DeviceWriteSystem()
  26. {
  27. Convs = Device.All.Where(v => v.HasFlag(DeviceFlags.拆盘机, DeviceFlags.桁架码垛位, DeviceFlags.环形库码垛工位)).Select(v => new Station(v, this.World)).ToDictionary(v => v.Entity.Code, v => v);
  28. //Srms = Device.All.Where(v => v.HasProtocol<ISRM520>()).Select(v => new SRM(v, this.World)).ToDictionary(v => v.Entity.Code, v => v);
  29. Rgvs = Device.All.Where(v => v.Code.Contains("RGV")).Select(v => new RGV(v, this.World)).ToDictionary(v => v.Entity.Code, v => v);
  30. }
  31. protected override void Do(DeviceWriteInfo info)
  32. {
  33. Type? type = null;
  34. object? obj = null;
  35. switch (info.DeviceType)
  36. {
  37. case DeviceTypeEnum.SRM:
  38. var srm = Srms[info.Code];
  39. type = typeof(ISRM520).Assembly.GetTypes().Where(v => v.Name == info.Protocol).First();
  40. obj = srm.Entity.Protocol(type, this.World);
  41. break;
  42. case DeviceTypeEnum.DEV:
  43. var conv = Convs[info.Code];
  44. type = typeof(IStation523).Assembly.GetTypes().Where(v => v.Name == info.Protocol).First();
  45. obj = conv.Entity.Protocol(type, this.World);
  46. break;
  47. case DeviceTypeEnum.BCR:
  48. break;
  49. case DeviceTypeEnum.RGV:
  50. var rgv = Rgvs[info.Code];
  51. type = typeof(IRGV520).Assembly.GetTypes().Where(v => v.Name == info.Protocol).First();
  52. obj = rgv.Entity.Protocol(type, this.World);
  53. break;
  54. }
  55. var p = type.GetProperty(info.Property);
  56. if (p.PropertyType.IsEnum)
  57. {
  58. var value = Enum.Parse(p.PropertyType, info.Value);
  59. p.SetValue(obj, value);
  60. }
  61. else
  62. {
  63. var value = Convert.ChangeType(info.Value, p.PropertyType);
  64. p.SetValue(obj, value);
  65. }
  66. }
  67. }
  68. /// <summary>
  69. /// 设备写入信息
  70. /// </summary>
  71. public class DeviceWriteInfo
  72. {
  73. /// <summary>
  74. /// 设备类型
  75. /// </summary>
  76. public DeviceTypeEnum DeviceType { get; set; }
  77. /// <summary>
  78. /// 设备号
  79. /// </summary>
  80. public string Code { get; set; }
  81. /// <summary>
  82. /// 协议
  83. /// </summary>
  84. public string Protocol { get; set; }
  85. /// <summary>
  86. /// 字段明
  87. /// </summary>
  88. public string Property { get; set; }
  89. /// <summary>
  90. /// 值
  91. /// </summary>
  92. public string Value { get; set; }
  93. }
  94. /// <summary>
  95. /// 设备类型接口
  96. /// </summary>
  97. public enum DeviceTypeEnum
  98. {
  99. /// <summary>
  100. /// 堆垛机
  101. /// </summary>
  102. SRM = 1,
  103. /// <summary>
  104. /// 输送线
  105. /// </summary>
  106. DEV = 2,
  107. /// <summary>
  108. /// 扫码器
  109. /// </summary>
  110. BCR = 3,
  111. /// <summary>
  112. /// RGV小车
  113. /// </summary>
  114. RGV = 4,
  115. }
  116. }