DeviceWriteSystem.cs 3.4 KB

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