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

namespace OnlineStore.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; }
        /// <summary>
        /// 分类编号
        /// </summary>
        [CSVAttribute("分类编号")]
        public int SubType { get; set; }

        public string ConfigStr { get; set; }
        ushort value = 0;
        public ushort GetIOAddr()
        {
            if (value > 0)
            {
                return value;
            }
            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;
            return ConfigStr;
        }

        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
    {
        /// <summary>
        /// 伺服ON的Do信号
        /// </summary>
        public string ServerOnDO ="" ;
        /// <summary>
        /// 伺服刹车信号
        /// </summary>
        public string BreakOnDO = "";
        /// <summary>
        /// 使用AC伺服时表示串口号,使用康泰克运动版表示板卡名称
        /// </summary>
        [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 short AddSpeed { get; set; }
        /// <summary>
        /// 减速度
        /// </summary>
        //[CSVAttribute("减速时间")]
        public short DelSpeed { get; set; }

        public int HomeLowSpeed { get; set; }
        public int HomeHighSpeed { get; set; }
        public int HomeAddSpeed { get; set; }
        /// <summary>
        /// 可以误差的脉冲范围的最小值
        /// </summary>
        public int CanErrorCountMin = 10;
        /// <summary>
        /// 可以误差的脉冲范围的最大值
        /// </summary>
        public int CanErrorCountMax = 100;

        /// <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 string GetNameStr()
        {
            return DeviceName + "_" + GetAxisValue();
        }
        public bool IsSameAxis(string portName, int slv)
        {
            if (DeviceName.Equals(portName) && slv.Equals(GetAxisValue()))
            {
                return true;
            }
            return false;
        }
        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();
        }
        /// <summary>
        /// 使用康泰克板卡表示轴编号,使用Ac伺服电机表示伺服地址
        /// </summary>
        /// <returns></returns>
        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;
        }
        /// <summary>
        /// 设备IP
        /// </summary> 
        public string IO_IP
        {
            get
            { 
                if (DeviceConfig.ProIpMap != null && DeviceConfig.ProIpMap.ContainsKey(DeviceName))
                {
                    return DeviceConfig.ProIpMap[DeviceName];
                }
                return DeviceName;
            }
        }
        /// <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; } 
        public string DisplayStr
        {
            get
            {
                return ElectricalDefinition + "-" + Explain + "-" + ProName+"";
            }
            set
            {
            }
        } 

        //public override string ToString()
        //{
        //    return "[" + 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";
    }
     
}