DeviceWriteSystem.cs 3.3 KB

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