ConfigItemBase.cs 6.2 KB
using log4net;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 

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

        public string ConfigStr { get; set; }

        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(ProValue))
            {
                throw new CVSFieldNotMatchingExection(ConfigStr + ",【类型:" + ProType + "】【名称:" + ProName + "】【属性值:" + ProValue + "】必须配置值!");
            }
        }
    }
    /// <summary>
    /// 运动轴配置
    /// </summary>
    public class ConfigMoveAxis : ConfigBase
    {
        /// <summary>
        /// 伺服ON的Do信号
        /// </summary>
        public string ServerOnDO = "";
        /// <summary>
        /// 伺服刹车信号
        /// </summary>
        public string BreakOnDO = "";

        [CSVAttribute("设备名称")]
        public string DeviceName { get; set; }


        [CSVAttribute("目标速度")]
        public int TargetSpeed { get; set; }


        [CSVAttribute("加速时间")]
        public short AddSpeed { get; set; }

        [CSVAttribute("减速时间")]
        public short DelSpeed { get; set; }

        [CSVAttribute("原点低速度")]
        public int HomeLowSpeed { get; set; }
        [CSVAttribute("原点高速")]
        public int HomeHighSpeed { get; set; }
        [CSVAttribute("原点加速度")]
        public int HomeAddSpeed { get; set; }

        [CSVAttribute("脉冲最小误差")]
        public int CanErrorCountMin { get; set; }

        [CSVAttribute("脉冲最大误差")]
        public int CanErrorCountMax { get; set; }

        [CSVAttribute("脉冲最小限位")]
        public int PositionMin { get; set; }

        [CSVAttribute("脉冲最大限位")]
        public int PositionMax { get; set; }

        public int TargetPosition { get; set; }
        public string GetNameStr()
        {
            return DeviceName + "_" + GetAxisValue();
        }
        public bool IsSameAxis(ConfigMoveAxis axis)
        {
            if (DeviceName.Equals(axis.DeviceName) && axis.GetAxisValue().Equals(GetAxisValue()))
            {
                return true;
            }
            return false;
        }


        public string DisplayStr
        {
            get
            {
                return Explain + "(" + ProName + ")";
            }
            set
            {
            }
        }


        public short GetAxisValue()
        {
            if (ProValue.Equals("") || ProValue.Equals("-1"))
            {
                return -1;
            }
            return (short)Convert.ToInt32(ProValue);
        }
        public override void CheckField()
        {
            if (String.IsNullOrEmpty(ProType) || String.IsNullOrEmpty(ProName) || String.IsNullOrEmpty(DeviceName) || String.IsNullOrEmpty(ProValue))
            {
                throw new CVSFieldNotMatchingExection(ConfigStr + ",【类型:ProType】【名称:ProName】【属性值:ProVale】【设备名称:DeviceName】必须配置值!");
            }
        }
    }



    public class ConfigIO : ConfigBase
    {
        public ConfigIO()
        {
         
        }
        private string IP = "";

        public string IO_IP
        {
            get
            {
                if (String.IsNullOrEmpty(IP))
                {
                    if (BaseConfig.ProIOIpMap != null && BaseConfig.ProIOIpMap.ContainsKey(DeviceName))
                    {
                        IP = BaseConfig.ProIOIpMap[DeviceName];
                    }
                    else
                    {
                        return DeviceName;
                    }
                }
                return IP;
            }
        }
        [CSVAttribute("设备名称")]
        public string DeviceName { get; set; }


        [CSVAttribute("电器定义")]
        public string ElectricalDefinition { get; set; }
        
        public string DisplayStr
        {
            get
            {
                return ElectricalDefinition + "-" + Explain + "-" + ProName + "";
            }
            set
            {
            }
        }
        ushort value = 0;
        public ushort GetIOAddr()
        {
            if (value > 0)
            {
                return value;
            }
            try
            {
                value = (ushort)Convert.ToInt32(ProValue);
            }
            catch (Exception ex)
            {
                LogUtil.error("出错:", ex);
            }
            return value;
        }

        public override void CheckField()
        {
            if (String.IsNullOrEmpty(ProType) || String.IsNullOrEmpty(ProName) || String.IsNullOrEmpty(DeviceName) || String.IsNullOrEmpty(ProValue))
            {
                throw new CVSFieldNotMatchingExection(ConfigStr + ",【类型: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";
    }

}