PLCGroup.cs 1.96 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
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);
        }
    }
}