| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 | using WCS.Core;using WCS.Entity.Protocol.SRM;using WCS.Entity.Protocol.Station;using WCS.WorkEngineering.Extensions;using WCS.WorkEngineering.Worlds;namespace WCS.WorkEngineering.Systems{    /// <summary>    ///  设备信息写入接口    /// </summary>    [BelongTo(typeof(MainWorld))]    public class DeviceWriteSystem : ServiceSystem<DeviceWriteInfo>    {        /// <summary>        /// 所有的站台        /// </summary>        private Dictionary<string, Station> Convs;        private Dictionary<string, SRM> Srms;        /// <summary>        ///  构造函数        /// </summary>        public DeviceWriteSystem()        {            Convs = Device.All.Where(v => v.HasProtocol<IStation523>()).Select(v => new Station(v, this.World)).ToDictionary(v => v.Entity.Code, v => v);            Srms = Device.All.Where(v => v.HasProtocol<ISRM520>()).Select(v => new SRM(v, this.World)).ToDictionary(v => v.Entity.Code, v => v);        }        protected override void Do(DeviceWriteInfo info)        {            Type? type = null;            object? obj = null;            switch (info.DeviceType)            {                case DeviceTypeEnum.SRM:                    var srm = Srms[info.Code];                    type = typeof(ISRM520).Assembly.GetTypes().Where(v => v.Name == info.Protocol).First();                    obj = srm.Entity.Protocol(type, this.World);                    break;                case DeviceTypeEnum.DEV:                    var conv = Convs[info.Code];                    type = typeof(IStation523).Assembly.GetTypes().Where(v => v.Name == info.Protocol).First();                    obj = conv.Entity.Protocol(type, this.World);                    break;                case DeviceTypeEnum.BCR:                    break;                case DeviceTypeEnum.RGV:                    break;            }            var p = type.GetProperty(info.Property);            if (p.PropertyType.IsEnum)            {                var value = Enum.Parse(p.PropertyType, info.Value);                p.SetValue(obj, value);            }            else            {                var value = Convert.ChangeType(info.Value, p.PropertyType);                p.SetValue(obj, value);            }        }    }    /// <summary>    /// 设备写入信息    /// </summary>    public class DeviceWriteInfo    {        /// <summary>        ///  设备类型        /// </summary>        public DeviceTypeEnum DeviceType { get; set; }        /// <summary>        /// 设备号        /// </summary>        public string Code { get; set; }        /// <summary>        ///  协议        /// </summary>        public string Protocol { get; set; }        /// <summary>        /// 字段明        /// </summary>        public string Property { get; set; }        /// <summary>        ///  值        /// </summary>        public string Value { get; set; }    }    /// <summary>    ///  设备类型接口    /// </summary>    public enum DeviceTypeEnum    {        /// <summary>        ///  堆垛机        /// </summary>        SRM = 1,        /// <summary>        ///  输送线        /// </summary>        DEV = 2,        /// <summary>        ///  扫码器        /// </summary>        BCR = 3,        /// <summary>        /// RGV小车        /// </summary>        RGV = 4,    }}
 |