InOutParam.cs 12.0 KB
 
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;

namespace OnlineStore.DeviceLibrary
{
    public class InOutParam
    {
        public MoveType paramType = MoveType.None;
        public InOutParam(MoveType type, string posId, int doorType = 0, string code = "", int plateH = 0, int plateW = 0, int weight = 0,
            string targetPosId = "", string targetCode = "", int targetWeight = 0, int stirSeconds = 0)
        {
            position = null;
            PosCode = code;
            PosId = posId;
            MoveP = null;
            this.Weight = weight;
            this.PlateW = plateW;
            this.PlateH = plateH;
            this.paramType = type;
            this.TarPosId = targetPosId;
            this.TarPosCode = targetCode;
            this.TarWeight = targetWeight;
            this.StirSecsond = stirSeconds;
            this.DoorPosType = doorType;
        }

        public InOutParam(MoveType paramType, string posId, StoreMoveP linePosition, string wareNo = "", int doorType = 0)
        {
            position = null;
            PosCode = wareNo;
            PosId = posId;
            MoveP = linePosition;
            this.paramType = paramType;
            this.DoorPosType = doorType;
        }
        public static InOutParam NewMovePosParam(string posId,   string targetPosId,string code="")
        {
            InOutParam p = new InOutParam(MoveType.MovePos, posId, 0, code, 0, 0, 0, targetPosId, code, 0);
            return p;
        }

        public static InOutParam NewStirParam(string posId1, string code1, int weight1, string targetPosId2, string tcode2 , int tweight2, int stirSeconds)
        {
            InOutParam p = new InOutParam(MoveType.Stirring, posId1, 0, code1, 0, 0, weight1, targetPosId2, tcode2, tweight2, stirSeconds);
            return p;
        }

        public string ToStr()
        {
            string doorT = "中间夹具";
            if (DoorPosType.Equals(1))
            {
                doorT = "左侧锡膏";
            }
            else if (DoorPosType.Equals(1))
            {
                doorT = "右侧锡膏";
            }

            if (paramType.Equals(MoveType.MovePos))
            {
                return "【回温移库:" + PosId + " -> " + TarPosId + ",[" + PosCode + "]】";
            }
            else if (paramType.Equals(MoveType.Stirring))
            {
                return "【搅拌:" + PosId + "([" + Weight + "][" + PosCode + "]) -> " + TarPosId + "([" + TarWeight + "][" + TarPosCode + "]) 】";
            }
            else if (paramType.Equals(MoveType.InStore))
            {
                return "【入库:" + doorT + " -> " + PosId + ",[" + PosCode + "][" + PlateW + "X" + PlateH + "]】";
            }
            else if (paramType.Equals(MoveType.OutStore))
            {
                return "【出库:" + PosId + " -> " + doorT + ",[" + PosCode + "][" + PlateW + "X" + PlateH + "]】";
            }

            return "[" + PosId + "][" + PosCode + "][" + PlateW + "X" + PlateH + "]";
        }
        private TinStorePosition position = null;

        public TinStorePosition Position
        {
            get
            {
                if (position == null)
                {
                    position = CSVPositionReader<TinStorePosition>.GetPositon(PosId);
                }
                return position;
            }
        }

        /// <summary>
        /// 物品二维码信息
        /// </summary>
        public string PosCode = "";
        /// <summary>
        /// 位置坐标名(对应配置表的位置)
        /// </summary>
        public string PosId = "";
        /// <summary>
        /// 门类型,0=中间夹具,1=左侧锡膏,2=右侧锡膏
        /// </summary>
        public int DoorPosType = 0;

        public StoreMoveP MoveP { get; set; }
        /// <summary>
        /// 料盘高度
        /// </summary>
        public int PlateH = 0;
        /// <summary>
        /// 料盘宽度
        /// </summary>
        public int PlateW = 0;

        /// <summary>
        /// 重量 单位  g
        /// </summary>
        public int Weight = 0;


        /// <summary>
        /// 搅拌时间,秒
        /// </summary>
        public int StirSecsond = 600;

        /// <summary>
        /// 目标库位号,回温移库时表示回温区库位
        /// </summary>
        public string TarPosId = "";
        public string TarPosCode = "";
        public int TarWeight = 0;
        private TinStorePosition tarPosition = null;
        public TinStorePosition TarPosition
        {
            get
            {
                if (tarPosition == null)
                {
                    tarPosition = CSVPositionReader<TinStorePosition>.GetPositon(TarPosId);
                }
                return tarPosition;
            }
        }

        public string GetDoorTinCheck()
        {
            if (DoorPosType.Equals(1))
            {
                return IO_Type.TinCheck_DoorLeft;
            }
            else if(DoorPosType.Equals(2))
            {
                return IO_Type.TinCheck_DoorRight;
            }
            else
            {
                return IO_Type.TinCheck_Fixture;
            }
        }

        internal bool LoadParam(TieStoreConfig Config)
        {
           
            //加载位置
            if (MoveP == null)
            {
                StoreMoveP p = new StoreMoveP();
                TinStorePosition position = Position;
                if (position == null)
                {
                    LogUtil.error("出入库时发现param中取到的Position=null,没有库位不能执行出入库");
                    return false;
                }

                p.InOut_P1 = Config.InOutAxis_P1;
                p.Middle_P1 = Config.MiddleAxis_P1;
                p.InOut_P2 = Config.InOutAxis_P20;

                p.UpDown_P1 = Config.UpDownAxis_OL_P1;
                p.UpDown_P8 = Config.UpDownAxis_IL_P8;
                p.UpDown_P2 = Config.UpDownAxis_IH_P2;
                p.UpDown_P7 = Config.UpDownAxis_OH_P7;

                if (this.DoorPosType.Equals(1) || this.DoorPosType.Equals(2))
                {
                    p.UpDown_P1 = Config.UpDownAxis_OL_P11;
                    p.UpDown_P8 = Config.UpDownAxis_IL_P81;
                    p.UpDown_P2 = Config.UpDownAxis_IH_P21;
                    p.UpDown_P7 = Config.UpDownAxis_OH_P71;
                }

                if (this.DoorPosType.Equals(1))
                {
                    p.Middle_P1 = Config.MiddleAxis_P11;
                    p.InOut_P2 = Config.InOutAxis_P21;

                }
                else if (this.DoorPosType.Equals(2))
                {
                    p.Middle_P1 = Config.MiddleAxis_P12;
                    p.InOut_P2 = Config.InOutAxis_P22;
                }

                p.Warm_P2 = position.WarmAxis_P2;
                p.Cold_P2 = position.ColdAxis_P2;
                p.InOut_P3 = position.InOutAxis_P3;
                p.Middle_P2 = position.MiddleAxis_P2;
                p.UpDown_P3 = position.UpDownAxis_IH_P3;
                p.UpDown_P4 = position.UpDownAxis_IL_P4;
                p.UpDown_P5 = position.UpDownAxis_OH_P5;
                p.UpDown_P6 = position.UpDownAxis_OL_P6;
                this.MoveP = p;
                return true;
            }
            return true;
        }

        public string LogName
        {
            get
            {
                string doorT = "中间夹具";
                if (DoorPosType.Equals(1))
                {
                    doorT = "左侧锡膏";
                }
                else if (DoorPosType.Equals(1))
                {
                    doorT = "右侧锡膏";
                }

                if (paramType.Equals(MoveType.MovePos))
                {
                    return "【回温移库:" + PosId + " -> " + TarPosId + "】";
                }
                else if (paramType.Equals(MoveType.Stirring))
                {
                    return "【搅拌:" + PosId + " -> " + TarPosId + "】";
                }
                else if (paramType.Equals(MoveType.InStore))
                {
                    return "【入库:" + doorT + " -> " + PosId + "】";
                }
                else if (paramType.Equals(MoveType.OutStore))
                {
                    return "【出库:" + PosId + " -> " + doorT + "】";
                }
                else
                {
                    return PosId;
                }
            }
        }
      
        internal bool UpdateFama()
        {
            TinStorePosition wPostion = GetStriWeightPos(Weight);
            if (wPostion == null)
            {
                LogUtil.error("" + LogName + "失败,未找到匹配的砝码");
                return false;
            }

            TarPosCode = "weight-" + wPostion.PosType + "G";
            TarPosId = wPostion.PositionNum;
            TarWeight = wPostion.PosType;

            LogUtil.info(LogName + "搅拌前,找到匹配砝码:[" + TarPosId + "][" + TarWeight + "]G");
            return true;
        }
        private TinStorePosition GetStriWeightPos(int weight)
        {
            //根据重量获取砝码库位
            List<TinStorePosition> allList = new List<TinStorePosition>(CSVPositionReader<TinStorePosition>.allPositionMap.Values);
            List<TinStorePosition> weightList = (from m in allList where m.PosType >= 100 orderby m.PosType descending select m).ToList<TinStorePosition>();

            foreach (TinStorePosition p in weightList)
            {
                int cha = weight - p.PosType;
                if ((Math.Abs(cha) < 50))
                {
                    return p;
                }
                if (weight >= p.PosType)
                {
                    return p;
                } 
            }
            if (weightList != null)
            {
                return weightList[weightList.Count - 1];
            }
            return null;
        }
    }

    public class StirInfo
    {
        public StirInfo()
        {
            InStirWork = false;
            StartTime = DateTime.Now;
            StopTime = DateTime.Now;
            StirParam = new InOutParam(MoveType.None, "",0, "");
        }

        /// <summary>
        /// 是否在搅拌中
        /// </summary>
        public bool InStirWork = false;
        /// <summary>
        /// 搅拌区状态:1=物料1已放入,2=物料2已放入,3=搅拌中,4=搅拌完成,等待取出物料,5=物料1已取出,6=物料2已取出,7=全部完成
        /// </summary>
        public int MoveStatus = 0;

        /// <summary>
        /// 开始搅拌信息
        /// </summary>
        public DateTime StartTime = DateTime.Now;
        /// <summary>
        /// 需要停止搅拌的时间
        /// </summary>
        public DateTime StopTime = DateTime.Now;
        /// <summary>
        /// 搅拌参数
        /// </summary>
        public InOutParam StirParam = null;

        public string toStr()
        {
            if (MoveStatus.Equals(0) && InStirWork.Equals(false))
            {
                return "暂无搅拌信息";
            }

            string str = "等待物料放入搅拌区";
            if (MoveStatus.Equals(1))
            {
                str = "物料1已放入";
            }
            else if (MoveStatus.Equals(2))
            {
                str = "物料2已放入";
            }
            else if (MoveStatus.Equals(3))
            {
                str = "搅拌中,结束时间:"+StopTime.ToLongTimeString();
            }
            else if (MoveStatus.Equals(4))
            {
                str = "搅拌完成,等待物料回库 ";
            }
            else if (MoveStatus.Equals(5))
            {
                str = "物料1已回库";
            }
            else if (MoveStatus.Equals(6))
            {
                str = "物料2已回库";
            }

            return "[" + str + "]" + StirParam.ToStr();
        }
    }
}