HYEquip_Config.cs 12.0 KB
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace OnlineStore.LoadCSVLibrary
{
   
    public class HYEquip_Config : DeviceConfig
    {
        public HYEquip_Config()
            : base()
        {
        }
        public HYEquip_Config(int id, string cid, string type, string filepath)
            : base(id, cid, LoadCSVLibrary.DeviceType.HYEquip, filepath)
        {
            IsOutLineOut = false ;
            IsOutLineIn = false;
            IsSideWayIn = false;
            IsOutLineOut = false;
            UpDownUseAxis = 0;
            IsDebug = 0;
        }
        public void LoadParam()
        {
            IsOutLineOut = false;
            IsOutLineIn = false;
            IsSideWayIn = false;
            IsOutLineOut = false;
            if (Id.Equals(202))
            {
                WorkDeviceId = 102;
            }
            else if (Id.Equals(201))
            {
                WorkDeviceId = 101;
            }
            else if (Id.Equals(220))
            {
                WorkDeviceId = 104;
            }
            else if (Id.Equals(221))
            {
                WorkDeviceId = 105;
            }

            int[] sideIns = new int[] { 202, 204, 209, 215, 218, 220 };
            int[] sideOuts = new int[] { 201, 203, 208, 216, 219, 221 };
            int[] outIns = new int[] { 204, 206, 213, 216 };
            int[] outOuts = new int[] { 209, 211 };
            if (sideIns.Contains(Id))
            {
                IsSideWayIn = true ;
            }
            else if (sideOuts.Contains(Id))
            {
                IsSideWayOut = true ;
            }
            if (outIns.Contains(Id))
            {
                IsOutLineIn = true ;
            }
            else if (outOuts.Contains(Id))
            {
                IsOutLineOut = true ;
            }
            LineName = "C1";
            if (Id.Equals(205))
            {
                LineName = "C2-C8";
            }
            else if (Id.Equals(207))
            {
                LineName = "C3-C8";
            }
            else if (Id.Equals(210))
            {
                LineName = "C8-C4";
            }
            else if (Id.Equals(217))
            {
                LineName = "C7-C9";
            }
            else if (Id.Equals(214))
            {
                LineName = "C6-C9";
            }
            else if (Id.Equals(212))
            {
                LineName = "C9-C5";
            }
        }


        /// <summary>
        /// 设备是否处于调试状态(1=调试,0=正常)
        /// </summary>
        [ConfigProAttribute("IsDebug", false)]
        public int IsDebug { get; set; }

        /// <summary>
        ///  PRO,0,HY所在流水线,LineName,C1,,
        /// </summary>
        [ConfigProAttribute("LineName", false)]
        public string  LineName { get; set; }
        /// <summary>
        ///  PRO,0,HY工位对应的取放料设备,WorkDevice,105,,
        /// </summary>
        [ConfigProAttribute("WorkDeviceId", false)]
        public int  WorkDeviceId { get; set; }
        /// <summary>
        ///  PRO,0,HY是否是托盘横移入口,IsSideWayIn,0,,
        /// </summary>
        [ConfigProAttribute("IsSideWayIn", false)]
        public bool IsSideWayIn { get; set; }
        /// <summary>
        ///  PRO,0,HY是否是托盘横移出口,IsSideWayOut,1,,
        /// </summary>
        [ConfigProAttribute("IsSideWayOut", false)]
        public bool IsSideWayOut { get; set; }
        /// <summary>
        ///  PRO,0,HY是否是托盘进入出料线入口,IsOutLineIn,0,,
        /// </summary>
        [ConfigProAttribute("IsOutLineIn", false)]
        public bool IsOutLineIn { get; set; }
        /// <summary>
        ///  PRO,0,HY是否是托盘离开出料线出口,IsOutLineOut,0,,
        /// </summary>
        [ConfigProAttribute("IsOutLineOut", false)]
        public bool IsOutLineOut { get; set; }


        /// <summary>
        ///   PRO	0	移栽上下运动是否使用伺服 UpDownUseAxis	1
        /// </summary>
        [ConfigProAttribute("UpDownUseAxis", false)]
        public int UpDownUseAxis { get; set; }
        /// <summary>
        ///  PRO	0	移栽上下轴在移栽上下降的位置 UpDownP2List	0=180000
        /// </summary>
        [ConfigProAttribute("UpDownP2List", false)]
        public string UpDownP2List { get; set; }
        /// <summary>
        ///  PRO	0	移栽上下轴在出料线下降的位置 UpDownP3List	0=116000
        /// </summary>
        [ConfigProAttribute("UpDownP3List", false)]
        public string UpDownP3List { get; set; }
        /// <summary>
        ///  AXIS	0	移栽上下轴 UpDown_Axis	2
        /// </summary>
        [ConfigProAttribute("UpDown_Axis", false)]
        public ConfigMoveAxis UpDown_Axis { get; set; }
        /// <summary>
        ///  PRO	0	移栽上下轴待机点 P1 UpDownAxisP1	403000
        /// </summary>
        [ConfigProAttribute("UpDownAxisP1", false)]
        public int UpDownAxisP1 { get; set; } 

        /// <summary>
        ///   PRO,0,移栽上下轴走到待机点速度,UpdownAxis_P1Speed,400,,,,,
        /// </summary>
        [ConfigProAttribute("UpdownAxis_P1Speed", false)]
        public int UpdownAxis_P1Speed { get; set; }

        /// <summary>
        ///   PRO,0,移栽上下轴P2速度,UpdownAxis_P2Speed,500,,,,,  
        /// </summary>
        [ConfigProAttribute("UpdownAxis_P2Speed", false)]
        public int UpdownAxis_P2Speed { get; set; }
        /// <summary>
        ///   PRO,0,移栽上下轴P3速度,UpdownAxis_P3Speed,500,,,,,
        /// </summary>
        [ConfigProAttribute("UpdownAxis_P3Speed", false)]
        public int UpdownAxis_P3Speed { get; set; }



        /// <summary>
        ///   PRO,0,移栽上下轴流水线取放料详细位置P2,UpDownP2DetialList,7*16=80000;,,,,,
        /// </summary>
        [ConfigProAttribute("UpDownP2DetialList", false)]
        public string UpDownP2DetialList { get; set; }

        private Dictionary<string, int> UpdownP2DetialMap = null;

        public Dictionary<string, int> LoadP2DetialMap()
        {
            try
            {
                if (UpdownP2DetialMap == null)
                {
                    UpdownP2DetialMap = new Dictionary<string, int>();
                    string[] arrayList = UpDownP2DetialList.Split(';');
                    foreach (string str in arrayList)
                    {
                        string[] arrStr = str.Split('=');
                        if (arrStr.Length == 2)
                        {
                            string key = arrStr[0].Trim().ToUpper();
                            if (key.Equals("0X0"))
                            {
                                continue;
                            }
                            int length = Convert.ToInt32(arrStr[1].Trim());
                            UpdownP2DetialMap.Add(key, length);
                        }
                    }
                }
            }
            catch (Exception ex)
            {

            }
            return UpdownP2DetialMap;
        }

        public int GetUpdownP2Detial(int trayHeight, int traySize)
        {
            LoadP2DetialMap();
            string fkey = traySize + "X" + trayHeight;
            if (UpdownP2DetialMap.ContainsKey(fkey))
            {
                return UpdownP2DetialMap[fkey];
            }
            else
            {
                return GetUpdownP2(trayHeight);
            }
            return -1;
        }


        public void UpdateUpdownP2Detial(int size, int height, int sizePosition)
        {
            string fkey = size + "X" + height;
            string newPositionStr = "";
            if (UpdownP2DetialMap.ContainsKey(fkey))
            {
                UpdownP2DetialMap[fkey] = sizePosition;
            }
            else
            {

                UpdownP2DetialMap.Add(fkey, sizePosition);
            }
            foreach (string key in UpdownP2DetialMap.Keys)
            {
                newPositionStr += key + "=" + UpdownP2DetialMap[key] + ";";
            }
            newPositionStr = newPositionStr.Substring(0, newPositionStr.Length - 1);
            UpDownP2DetialList = newPositionStr;
        }


        ///// <summary>s
        ///// PRO,0,移栽上下轴下降速度,UpdownAxis_DownSpeed,500,,,,,
        ///// </summary>
        //[ConfigProAttribute("UpdownAxis_DownSpeed", false)]
        //public int UpdownAxis_DownSpeed { get; set; }
        private Dictionary<int, int> UpDownP2Map = null;
        public int GetUpdownP2(int trayHeight)
        {
            try
            {
                if (UpDownP2Map == null)
                {
                    UpDownP2Map = new Dictionary<int, int>();
                    string[] arrayList = UpDownP2List.Split(';');
                    foreach (string str in arrayList)
                    {
                        string[] arrStr = str.Split('=');
                        if (arrStr.Length == 2)
                        {
                            int height = Convert.ToInt32(arrStr[0].Trim());
                            int length = Convert.ToInt32(arrStr[1].Trim());
                            UpDownP2Map.Add(height, length);
                        }
                    }
                }
            }
            catch (Exception ex)
            {

            }
            if (UpDownP2Map.ContainsKey(trayHeight))
            {
                return UpDownP2Map[trayHeight];
            }
            else if (UpDownP2Map.ContainsKey(0))
            {
                return UpDownP2Map[0];
            }
            return -1;
        }


        public void UpdateUpdownP2(int size, int sizePosition)
        {
            string newPositionStr = "";
            if (UpDownP2Map.ContainsKey(size))
            {
                UpDownP2Map[size] = sizePosition;
            }
            else
            {

                UpDownP2Map.Add(size, sizePosition);
            }
            foreach (int key in UpDownP2Map.Keys)
            {
                newPositionStr += key + "=" + UpDownP2Map[key] + ";";
            }
            newPositionStr = newPositionStr.Substring(0, newPositionStr.Length - 1);
            UpDownP2List = newPositionStr;
        }

        private Dictionary<int, int> UpDownP3Map = null;
        public int GetUpdownP3(int trayHeight)
        {
            try
            {
                if (UpDownP3Map == null)
                {
                    UpDownP3Map = new Dictionary<int, int>();
                    string[] arrayList = UpDownP3List.Split(';');
                    foreach (string str in arrayList)
                    {
                        string[] arrStr = str.Split('=');
                        if (arrStr.Length == 2)
                        {
                            int height = Convert.ToInt32(arrStr[0].Trim());
                            int length = Convert.ToInt32(arrStr[1].Trim());
                            UpDownP3Map.Add(height, length);
                        }
                    }
                }
            }
            catch (Exception ex)
            {

            }
            if (UpDownP3Map.ContainsKey(trayHeight))
            {
                return UpDownP3Map[trayHeight];
            }
            else if (UpDownP3Map.ContainsKey(0))
            {
                return UpDownP3Map[0];
            }
            return -1;
        }

        public void UpdateUpdownP3(int size, int sizePosition)
        {
            string newPositionStr = "";
            if (UpDownP3Map.ContainsKey(size))
            {
                UpDownP3Map[size] = sizePosition;
            }
            else
            {

                UpDownP3Map.Add(size, sizePosition);
            }
            foreach (int key in UpDownP3Map.Keys)
            {
                newPositionStr += key + "=" + UpDownP3Map[key] + ";";
            }
            newPositionStr = newPositionStr.Substring(0, newPositionStr.Length - 1);
            UpDownP3List = newPositionStr;
        }
    }
}