using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;

namespace FLY.Modbus
{
    /// <summary>
    /// 加载通讯列表用
    /// </summary>
    public class PLCGroup
    {
        public class PLCDevice
        {
            public IPEndPoint EP { get; set; }
        }

        public class PLCVariable
        {
            /// <summary>
            /// 设备序号
            /// </summary>
            public int DeviceIndex { get; set; }
            /// <summary>
            /// 值为 0,1,3,4 ;对应modbus寄存器的区号
            /// </summary>
            public string Mode { get; set; }
            /// <summary>
            /// 区号的地址
            /// </summary>
            public int Addr { get; set; }
            /// <summary>
            /// 类型 只有 bool 才对应 bool， 其它数值类型 都转为 float
            /// </summary>
            public string Type { get; set; }
            /// <summary>
            /// 放大倍数
            /// </summary>
            public double Scale { get; set; }
            /// <summary>
            /// 属性拥有者名称
            /// </summary>
            public string OwnerName { get; set; }
            /// <summary>
            /// 属性名称
            /// </summary>
            public string PropertyName { get; set; }

            public override string ToString()
            {
                return OwnerName + "." + PropertyName + " dev" + DeviceIndex + " [" + Mode + "](" + Addr + ")";
            }
        }


        public List<PLCDevice> Devices = new List<PLCDevice>();
        public List<PLCVariable> Variables = new List<PLCVariable>();

        static PLCGroup()
        {
            Misc.SaveToXmlHepler.Regist(typeof(PLCDevice));
            Misc.SaveToXmlHepler.Regist(typeof(PLCVariable));
        }
        public void Load(string filepath)
        {
            Misc.SaveToXmlHepler.Load(filepath, this);
        }
    }
}
