StoreMoveInfo.cs 10.9 KB
using OnlineStore.Common;
using OnlineStore.DeviceLibrary;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 

namespace OnlineStore.DeviceLibrary
{
    /// <summary>
    /// 料仓当前运动信息类(出入库状态,步骤记录)
    /// </summary>
    public class StoreMoveInfo
    {
        /// <summary>
        /// 超时时间
        /// </summary>
        public int TimeOutSeconds = 60;
        public StoreMoveInfo(int storeId)
        {
            moveType = StoreMoveType.None;
            
            MoveParam = new InOutParam();
            this.storeId = storeId;
            this.moveStep = StoreMoveStep.Wait;
            IsInWait = false;
            MoveNum = 0;
        }

        public int MoveNum { get; set; }

        public DateTime LastSetpTime { get; set; }

        /// <summary>
        /// =true表示满足一个等待条件,就可以完成此步骤的等待
        /// </summary>
        public bool OneWaitCanEndStep = false;
        
        /// <summary>
        /// 操作类型
        /// </summary>
        private StoreMoveType moveType = StoreMoveType.None;

        public StoreMoveType MoveType
        {
            get { return moveType; }
        }
        public TimeSpan StepSpan()
        {
            TimeSpan span = DateTime.Now - LastSetpTime;
            return span;
        }
        public bool IsTimeOut(int timeOutSeconds = 60)
        {
            TimeSpan span = DateTime.Now - LastSetpTime;
            if (span.TotalSeconds > timeOutSeconds)
            {
                return true;
            }
            return false;
        }
        /// <summary>
        ///出入库参数
        /// </summary>
        public InOutParam MoveParam { get; set; }
        /// <summary>
        /// 当前运动是哪个料仓
        /// </summary>
        public int storeId { get; set; }

        /// <summary>
        /// 是否再当前步骤等待中
        /// </summary>
        public bool IsInWait { get; set; }
        /// <summary>
        /// 上一个执行步骤
        /// </summary>
        public StoreMoveStep PreMoveStep { get; set; }
        /// <summary>
        /// 当前执行到的步骤
        /// </summary>
        private StoreMoveStep moveStep;
        /// <summary>
        /// 可以循环运动的次数(轴卡运动才需要)
        /// </summary>
        public int CanWhileCount = 0;
        /// <summary>
        /// 料仓运动步骤记录
        /// </summary>
        public StoreMoveStep MoveStep
        {
            get { return moveStep; }
        }
 
        public void NextMoveStep(StoreMoveStep step)
        {
            PreMoveStep = moveStep;
            moveStep = step;
            LastSetpTime = DateTime.Now; 
            IsInWait = true;
            WaitList = new List<WaitResultInfo>();
            OneWaitCanEndStep = false;
            CanWhileCount = 5;
            TimeOutSeconds = 60;
        }
        /// <summary>
        /// 当前步骤执行完成
        /// </summary>
        public void EndStepWait()
        {
            IsInWait = false;
            WaitList = new List<WaitResultInfo>();
        }
        public void NewMove(StoreMoveType type )
        {
            moveStep = StoreMoveStep.Wait;
            this.moveType = type; 
            LastSetpTime = DateTime.Now;
            WaitList = new List<WaitResultInfo>();
            MoveNum++;
        }
        public void NewMove(StoreMoveType type, InOutParam param)
        {
            moveStep = StoreMoveStep.Wait;
            this.moveType = type;
            this.MoveParam = param;
            LastSetpTime = DateTime.Now;
            WaitList = new List<WaitResultInfo>();
        }
        public void EndMove()
        {
            this.moveType = StoreMoveType.None;
            this.MoveParam = null; 
            moveStep = StoreMoveStep.Wait;
            LastSetpTime = DateTime.Now;
            IsInWait = false;
            WaitList = new List<WaitResultInfo>();
            CanWhileCount = 0;
        }
        public StoreMoveInfo clone()
        {
            return (StoreMoveInfo)this.MemberwiseClone();
        }

        public List<WaitResultInfo> WaitList = new List<WaitResultInfo>();
        /// <summary>
        /// 重置之后继续出入库时,退回上一个步骤执行
        /// </summary>
        public void BackStep()
        {
            moveStep = PreMoveStep;
            IsInWait = false;
        }
    }

    public class WaitResultInfo
    {
        private WaitResultInfo()
        {
        }

        public static  WaitResultInfo WaitIO(string ioType, IO_VALUE ioValue)
        {
            WaitResultInfo wait = new WaitResultInfo();
            wait.CanWhileMoveCount = 0;
            wait.WaitType = 2;
            wait.IoType = ioType;
            wait.IoValue = ioValue;
            wait.IsEnd = false;
            return wait;
        }
        public static WaitResultInfo WaitAxis(ConfigMoveAxis axis,int targetPosition,int targetSpeed )
        {
            WaitResultInfo wait = new WaitResultInfo();
            wait.CanWhileMoveCount = 0;
            wait.WaitType = 1;
            wait.AxisInfo = axis;
            wait.IsHomeMove = false;
            wait.TargetPosition = targetPosition;
            wait.TargetSpeed = targetSpeed;
            wait.IsEnd = false;
            return wait;
        }
        public static WaitResultInfo WaitAxisHome(ConfigMoveAxis axis, int AxisOrgValue)
        {
            WaitResultInfo wait = new WaitResultInfo();
            wait.CanWhileMoveCount = 0;
            wait.WaitType = 1;
            wait.AxisInfo = axis;
            wait.IsHomeMove = true;
            wait.IsEnd = false;
            wait.AxisOrgValue = AxisOrgValue;
            wait.LastHasOrgTime = DateTime.Now;
            return wait;
        } 
        public static WaitResultInfo WaitTime(int MScends)
        {
            WaitResultInfo wait = new WaitResultInfo();
            wait.CanWhileMoveCount = 0;
            wait.WaitType = 3;
            wait.TimeMSeconds = MScends;
            wait.IsEnd = false;
            return wait;
        }
        public static WaitResultInfo WaitAxisOrg(ConfigMoveAxis axis,IO_VALUE value )
        {
            WaitResultInfo wait = new WaitResultInfo();
            wait.CanWhileMoveCount = 0;
            wait.WaitType = 6;
            wait.AxisInfo = axis;
            wait.IsHomeMove = true;
            wait.IoValue = value;
            wait.IsEnd = false;
            return wait;
        }
        //public  static WaitResultInfo WaitVisionComp()
        //{
        //    WaitResultInfo wait = new WaitResultInfo();
        //    wait.CanWhileMoveCount = 0;
        //    wait.WaitType = 8;
        //    wait.IsEnd = false;
        //    return wait;
        //}
        //public static WaitResultInfo WaitHeight(int height)
        //{
        //    WaitResultInfo wait = new WaitResultInfo(); 
        //    wait.WaitType = 7;
        //    wait.HeightValue = height;
        //    wait.IsEnd = false;
        //    return wait;
        //}
        public string ToStr()
        {
            if (WaitType == 1)
            {
                if (IsHomeMove)
                {
                    return "轴【" + AxisInfo.DisplayStr  + "】原点返回";
                }
                else
                {
                    return "轴【" + AxisInfo.DisplayStr + "】绝对运动,目标位置【" + TargetPosition + "】";
                }
            }
            else if (WaitType == 2)
            {
                return "IO信号等待,IO类型【" + IoType + "】,等待值【" + IoValue + "】";
            }
            else if (WaitType == 3)
            {
                return "时间等待:【" + TimeMSeconds + "】毫秒";
            }
            else if (WaitType == 4)
            {
                return "电钢目标位置:【" + TargetPosition + "】 ";
            }
            else if (WaitType == 5)
            {
                return "硕科电机目标位置:【" + TargetPosition + "】 ";
            }
            else if (WaitType == 6)
            {
                return "轴【" + AxisInfo.DisplayStr  + "】ORG信号:【" + IoValue + "】 ";
            }else if (WaitType == 7)
            {
                return "料盘高度【" + HeightValue + "】  ";
            }else if (WaitType == 8)
            {
                return "视觉识别门口有料";
            }
            else 
            {
                return "Wait位置类型:WaitType=【" + WaitType + "】";
            }
        }
        /// <summary>
        /// 当未结束时可以重复运动的次数
        /// </summary>
        public int CanWhileMoveCount { get; set; }
        /// <summary>
        /// 等待结果,1=轴运动,2=IO运动,3=时间,4=电钢,5=硕科电机,6=等待轴原点信号
        /// </summary>
        public int WaitType { get; set; }
        /// <summary>
        /// 轴运动时表示轴信息
        /// </summary>
        public ConfigMoveAxis AxisInfo { get; set; }
        /// <summary>
        /// 电钢地址
        /// </summary>
        public byte SlvAddr { get; set; }
        /// <summary>
        /// IO类型
        /// </summary>
        public String  IoType { get; set; }
        /// <summary>
        /// IO值
        /// </summary>
        public IO_VALUE  IoValue { get; set; }
        /// <summary>
        /// 等待的毫秒
        /// </summary>
        public int TimeMSeconds { get; set; }
        /// <summary>
        /// 是否是原点返回
        /// </summary>
        public bool IsHomeMove = false;

        /// <summary>
        /// 轴目标位置
        /// </summary>
        public int TargetPosition { get; set; }
        /// <summary>
        /// 轴目标速度
        /// </summary>
        public int TargetSpeed { get; set; }
        /// <summary>
        /// 是否已经结束
        /// </summary>
        public bool IsEnd{ get; set; }
        /// <summary>
        /// 高度
        /// </summary>
        public int HeightValue { get; set; }


        public int AxisOrgValue = 0;

        public DateTime LastHasOrgTime = DateTime.Now;

     
    }
    public enum StoreMoveType
    {
        /// <summary>
        /// 没有任何操作
        /// </summary>
        None = 0,
        /// <summary>
        /// 入库
        /// </summary>
        InStore = 1,
        /// <summary>
        /// 出库
        /// </summary>
        OutStore = 2,
        /// <summary>
        /// 原点返回
        /// </summary>
        ReturnHome = 3,
        /// <summary>
        /// 重置
        /// </summary>
        StoreReset = 4,
        ///// <summary>
        ///// 移栽装置的停止,需要先远点返回,然后停止
        ///// </summary>
        //StopMove=5,
        ///// <summary>
        ///// 移栽检测托盘
        ///// </summary>
        //CheckFixture=6,
        /// <summary>
        /// 盘点
        /// </summary>
        CheckPosition,
    }
}