ConfigItemBase.cs 9.5 KB
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace URSoldering.LoadCSVLibrary
{
    /// <summary>
    /// 基础的属性配置
    /// </summary>
    public class ConfigBase
    {
        protected static readonly ILog LOGGER = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        /// <summary>
        /// DI=输入IO,DO=输出IO,PRO=属性,AXIS=轴
        /// </summary>
        [CSVAttribute("类型")]
        public string ProType { get; set; }
        /// <summary>
        /// 说明
        /// </summary>
        [CSVAttribute("说明")]
        public string Explain { get; set; }
        /// <summary>
        /// 名称
        /// </summary>
        [CSVAttribute("名称")]
        public string ProName { get; set; }
        /// <summary>
        /// 属性值
        /// </summary>
        [CSVAttribute("属性值")]
        public string ProVale { get; set; }

        public ushort GetIOAddr()
        {
            ushort value = 0;
            try
            {
                value = (ushort)Convert.ToInt32(ProVale);
            }
            catch (Exception ex)
            {
                LOGGER.Error("出错:", ex);
            }
            return value;
        }
        public virtual int GetValue()
        {
            if (ProVale.Equals(""))
            {
                return -1;
            }
            return Convert.ToInt32(ProVale);
        }
        public override string ToString()
        {
            return   "ConfigBase。" + "类型:" + ProType + ",说明:" + Explain + ",名称:" + ProName + ",属性值:" + ProVale;
        }

        public virtual void CheckField()
        {
            if (String.IsNullOrEmpty(ProType) || String.IsNullOrEmpty(ProName) ||   String.IsNullOrEmpty(ProVale))
            {
                throw new CVSFieldNotMatchingExection(ToString() + ",【类型:ProType】【名称:ProName】【属性值:ProVale】必须配置值!");
            }
        }
    }
    /// <summary>
    /// 运动轴配置
    /// </summary>
    public class ConfigMoveAxis : ConfigBase
    {
        [CSVAttribute("设备名称")]
        public string DeviceName { get; set; }
        /// <summary>
        /// 待机位置
        /// </summary>
        //[CSVAttribute("默认值")]
        public int DefaultPosition { get; set; }
        /// <summary>
        /// 目标速度
        /// </summary>
        //[CSVAttribute("目标速度")]
        public int TargetSpeed { get; set; }
        /// <summary>
        /// 开始速度
        /// </summary>
        //[CSVAttribute("开始速度")]
        public int StartSpeed { get; set; }
        /// <summary>
        /// 加速时间
        /// </summary>
        //[CSVAttribute("加速时间")]
        public short AccelTime { get; set; }
        /// <summary>
        /// 减速时间
        /// </summary>
        //[CSVAttribute("减速时间")]
        public short DecelTime { get; set; }
        /// <summary>
        /// 可以误差的脉冲范围的最小值
        /// </summary>
        public int CanErrorCountMin { get; set; }
        /// <summary>
        /// 可以误差的脉冲范围的最大值
        /// </summary>
        public int CanErrorCountMax { get; set; }

        /// <summary>
        /// 出入库目标值(只有出入库过程中才会有效)
        /// </summary>
        public int TargetPosition { get; set; }
        /// <summary>
        ///  速度倍率 
        /// </summary> 
        public int  ResolveSpeed { get; set; }
        /// <summary>
        /// 最小位置
        /// </summary>
        public int PositionMin { get; set; }
       /// <summary>
       /// 最大位置
       /// </summary>
        public int PositionMax { get; set; }

        public bool PositionIsHasLimit(){
            if (PositionMin.Equals(PositionMax))
            {
                return false;
            } return true;
        }
        /// <summary>
        /// 下拉列表显示
        /// </summary>
        public string DisplayStr
        {
            get {
                return  Explain + "(" + ProName + ")"; 
            }
            set
            {
            }
        }
        public override int GetValue()
        {
            return GetAxisValue();
        }

        public short GetAxisValue()
        { 
            if (ProVale.Equals("") || ProVale.Equals("-1"))
            { 
                return -1;
            }
            return (short)Convert.ToInt32(ProVale);
        }

        public override string ToString()
        {
            return "ConfigMoveAxis。" + "类型:" + ProType + ",说明:" + Explain + ",名称:" + ProName + ",属性值:" + ProVale + ",设备名称:" + DeviceName;
        }
        public override void CheckField()
        {
            if (String.IsNullOrEmpty( ProType) || String.IsNullOrEmpty( ProName ) || String.IsNullOrEmpty( DeviceName ) || String.IsNullOrEmpty( ProVale ))
            {
                throw new CVSFieldNotMatchingExection(ToString() + ",【类型:ProType】【名称:ProName】【属性值:ProVale】【设备名称:DeviceName】必须配置值!");
            }
        }

        public bool IsMyAxis(string DeviceName, int AxisNo)
        {
            int AxisValue = GetAxisValue();
            if (DeviceName.Equals(DeviceName) && AxisValue.Equals(AxisNo))
            {
                return true;
            }
            return false;
        }
    }
    /// <summary>
    /// io配置
    /// </summary>
    public class ConfigIO : ConfigBase
    {
        public ConfigIO()
        {
            SlaveID = 0;
        }

        public ConfigIO(string type, string ip, byte slaveId, ushort index, string name, string explain)
        {
            this.SlaveID = slaveId;
            this.ProType = type;
            this.DeviceName = ip;
            this.ProVale = index.ToString();
            this.ProName = name;
            this.Explain = explain;
        }
        /// <summary>
        /// 设备名称
        /// </summary>
        [CSVAttribute("设备名称")]
        public string DeviceName { get; set; }
        /// <summary>
        /// 描述
        /// </summary>
        [CSVAttribute("描述")]
        public string Describe { get; set; }
        /// <summary>
        /// 电器定义
        /// </summary>
        [CSVAttribute("电器定义")]
        public string ElectricalDefinition { get; set; }
        /// <summary>
        /// 代码定义
        /// </summary>
        [CSVAttribute("代码定义")]
        public string CodeDefinition { get; set; }
        /// <summary>
        /// 默认值
        /// </summary>
        [CSVAttribute("默认值")]
        public int DefaultValue { get; set; }
        /// <summary>
        /// SlaveID
        /// </summary>
         [CSVAttribute("SlaveID") ] 
        public byte SlaveID { get; set; }
        private int IoValue = -10;
        public string DisplayStr
        {
            get
            {
                return ElectricalDefinition + "_" + Explain + "(" + ProName+")";
            }
            set
            {
            }
        }
        public override int GetValue()
        {
            return GetIOValue();
        }

        public ushort GetIOValue()
        {
              ushort value = 0;
            try
            {
                value = (ushort)Convert.ToInt32(ProVale);
            }
            catch (Exception ex)
            {
                LOGGER.Error("出错:", ex);
            }
            return value; 
           
        }

        public override string ToString()
        {
            return "ConfigIO。" + ProType + "," + Explain + "," + ProName + ",属性值:" + ProVale + ",设备名称:" + DeviceName + ",描述:" + Describe + ",电器定义:" + ElectricalDefinition + ",代码定义:" + CodeDefinition + "";
        }
        public override void CheckField()
        {
            if (String.IsNullOrEmpty(ProType) || String.IsNullOrEmpty(ProName) || String.IsNullOrEmpty(DeviceName) || String.IsNullOrEmpty(ProVale))
            {
                throw new CVSFieldNotMatchingExection(ToString() + ",【类型:ProType】【名称:ProName】【属性值:ProVale】【设备名称:DeviceName】必须配置值!");
            }
        }
    }

    public static class ConfigItemType
    {
        public static string DI = "DI";
        public static string DO = "DO";
        public static string AXIS = "AXIS";
        public static string PRO = "PRO";
    }

    public static class ConfigItemName
    {
        /// <summary>
        /// 上下转动轴
        /// </summary>
        public static string UpDown_Axis = "UpDown_Axis";
        /// <summary>
        /// 中转伝动轴	Middle_Axis
        /// </summary>
        public static string Middle_Axis = "Middle_Axis";
        /// <summary>
        /// 中轴移动速度	MiddleAxis_Move_Speed
        /// </summary>
        public static string MiddleAxis_Move_Speed = "MiddleAxis_Move_Speed";
        /// <summary>
        /// 上下轴普通速度	Updown_Move_Speed
        /// </summary>
        public static string Updown_Move_Speed = "Updown_Move_Speed";
        /// <summary>
        /// 上下轴慢速度	Updown_Move_Speed_Low
        /// </summary>
        public static string Updown_Move_Speed_Low = "Updown_Move_Speed_Low";
        /// <summary>
        /// 温湿度传感器地址	Temperate_ServerAddress
        /// </summary>
        public static string Temperate_ServerAddress = "Temperate_ServerAddress";

    }
}