BoxBean_Partial.cs 11.1 KB
using Asa;
using DeviceLib;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace OnlineStore.DeviceLibrary
{
    partial class BoxBean
    {

        public ConcurrentQueue<InOutParam> waitOutStoreList = new ConcurrentQueue<InOutParam>();
        #region 出入库结果验证 
        private void CheckWait()
        {
            List<WaitResultInfo> list = MoveInfo.WaitList;
            //当等待超过一分钟时,需要打印提示 
            TimeSpan span = DateTime.Now - MoveInfo.LastSetpTime;
            string NotOkMsg = "";
            if (list.Count <= 0)
            {
                MoveInfo.EndStepWait();
                return;
            }
            bool isOk = true;
            if (MoveInfo.OneWaitCanEndStep)
            {
                isOk = false;
            }
            foreach (WaitResultInfo wait in list)
            {
                if (wait.IsEnd)
                {
                    continue;
                }
                NotOkMsg = wait.ToStr();
                if (wait.WaitType.Equals(WaitEnum.W001_AxisMove))
                {
                    string msg = "";
                    if (wait.IsHomeMove)
                    {
                        wait.IsEnd = AxisBean.HomeMoveIsEnd(MoveInfo, wait.AxisInfo, out msg);
                    }
                    else
                    {
                        wait.IsEnd = AxisBean.ACAxisMoveIsEnd(MoveInfo, wait.AxisInfo, wait.TargetPosition, wait.TargetSpeed, out msg);
                    }
                    if (!msg.Equals(""))
                    {
                        isOk = false;
                        WarnMsg = msg;
                        Alarm(AlarmType.AxisMoveError, GetAlarmCodeByAxis(wait.AxisInfo).ToString(), WarnMsg, MoveInfo.MoveType);
                        break;
                    }
                }
                else if (wait.WaitType.Equals(WaitEnum.W002_IOValue))
                {
                    wait.IsEnd = IOValue(wait.IoType).Equals(wait.IoValue);
                    int timeOutMs = StoreManager.Config.IOSingle_TimerOut;

                    if (MoveInfo.MoveStep.Equals(StoreMoveStep.BS_08_WaitLineIn) ||
                        MoveInfo.MoveStep.Equals(StoreMoveStep.BI_04_WaitTakeSingle))
                    {
                        timeOutMs = 30000;
                    }
                    else if (MoveInfo.MoveStep.Equals(StoreMoveStep.BI_03_LineRun))
                    {
                        timeOutMs = 40000;
                    }
                    if ((!wait.IsEnd) && span.TotalMilliseconds > timeOutMs && NoAlarm())
                    {
                        ConfigIO io = Config.getWaitIO(wait.IoType);
                        WarnMsg = Name + "[" + MoveInfo.MoveType + "][" + MoveInfo.MoveStep + "] 等待(" + io.DisplayStr + "=" + wait.IoValue + ") 超时";
                        Alarm(AlarmType.IoSingleTimeOut, io.ElectricalDefinition, WarnMsg, MoveInfo.MoveType);
                        LogUtil.error(Name + "[" + MoveInfo.MoveType + "][" + MoveInfo.MoveStep + "] 等待(" + io.DisplayStr + "=" + wait.IoValue + ") 超时", logType + 14);
                        if (!MoveInfo.OneWaitCanEndStep)
                        {
                            isOk = false;
                            break;
                        }
                    }
                }
                else if (wait.WaitType.Equals(WaitEnum.W003_Time))
                {
                    wait.IsEnd = (span.TotalMilliseconds >= wait.TimeMSeconds);
                } 
                if (wait.IsEnd)
                {
                    if (MoveInfo.OneWaitCanEndStep)
                    {
                        isOk = true;
                        break;
                    }
                }
                else
                {
                    if (!MoveInfo.OneWaitCanEndStep)
                    {
                        isOk = false;
                        break;
                    }
                }
            }
            if (isOk)
            {
                MoveInfo.EndStepWait();
            }
            else if (span.TotalSeconds > MoveInfo.TimeOutSeconds)
            {
                WarnMsg = Name + "[" + MoveInfo.MoveType + "][" + MoveInfo.MoveStep + "]等待" + NotOkMsg
                + "超时[" + Math.Round(span.TotalSeconds, 1) + "]秒";
                int second = 10;

                second = (int)(MoveInfo.TimeOutSeconds / span.TotalSeconds) * 10;
                if (second > 120)
                {
                    second = 120;
                }
                else if (second < 10)
                {
                    second = 10;
                }
                LogUtil.error(WarnMsg, logType + 100, second);
                Alarm(AlarmType.IoSingleTimeOut, "", WarnMsg, MoveInfo.MoveType);
            }
        }
        private bool AcInPosition(ConfigMoveAxis axis,int p)
        {
            return ACServerManager.isInPosition(axis.DeviceName, axis.GetAxisValue(), p, axis.CanErrorCountMax);

        }
        private static DateTime lastComRHomeTime = DateTime.Now;
        private void InOutBackToP1(int InOut_P1)
        {
            //判断是否在P1,如果是,不需要运行  
            if (AcInPosition(Config.InOut_Axis, InOut_P1))
            {
                LogUtil.debug(Name + "进出轴当前已经在P1,不需要再回P1");
            }
            else
            {
                InoutAxis.AbsMove(MoveInfo, InOut_P1, Config.InOutAxis_P1_Speed);
            } 
        }
        #endregion

    

        #region 入库
     
        private DateTime startInStoreTime = DateTime.Now;
      
        public override void StartInStoreMove(InOutParam param)
        {
            startInStoreTime = DateTime.Now;
            string posId = param != null ? param.PosID : "";
            if (isInSuddenDown || isNoAirCheck ||
           (!storeRunStatus.Equals(StoreRunStatus.Runing))
           || (!MoveInfo.MoveType.Equals(MoveType.None)))
            {
                LogUtil.error(Name + " 启动出库出错,忙碌或报警中 ,storeStatus=" + storeRunStatus + ",MoveType=" + MoveInfo.MoveType + ",isInSuddenDown=" + isInSuddenDown + ",isNoAirCheck" + isNoAirCheck);
                return;
            }

            if (!StoreManager.LoadInoutParam(param, true, this))
            {
                LogUtil.error(Name + " 启动入库【" + param.ToStr() + "】出错,找不到库位信息");
                return;
            }
            LogInfo(" 启动入库【" + param.ToStr() + "】,压紧点P2【" + param.MoveP.ComPress_P2 + "】压紧前点P3【" + param.MoveP.ComPress_P3 + "】");
            storeRunStatus = StoreRunStatus.Busy;
            storeStatus = StoreStatus.InStoreExecute;
            MoveInfo.NewMove(MoveType.InStore, param);

            //新的料架库位
            MoveInfo.NextMoveStep(StoreMoveStep.BI_11_InoutToP1);
            MoveInfo.SingleInstore = true;
            InOutStoreLog("料架取料:" + MoveInfo.SLog + " 叉子后退到待机点P1, 重置盘信息");
            InoutAxis.AbsMove(MoveInfo, Config.InOutAxis_P1, Config.InOutAxis_P1_Speed); 
        }
          
        protected override void InStoreProcess()
        {
            LineMoveP moveP = MoveInfo.MoveParam.MoveP;
            if (MoveInfo.IsInWait)
            {
                CheckWait();
            }
            if (MoveInfo.IsInWait)
            {
                return;
            }
              
            else
            {
                LogInfo(" 入库,MoveInfo.MoveStep=" + MoveInfo.MoveStep + ",没有对应的处理!");
            }
        }

        #endregion

         

        #region 出库
        private DateTime startOutStoreTime = DateTime.Now;
        public bool IsIgnoreComSig = false; //忽略料叉压紧信号
        private void StartExecuctOut(InOutParam param)
        {

            bool result = StartOutStoreMove(param);
            if (!result)
            {
                LogInfo(" 执行出库【" + param.ToStr() + "】失败,加入等待队列");
                waitOutStoreList.Enqueue(param);
            }
        } 
        public override bool StartOutStoreMove(InOutParam param)
        {
            startOutStoreTime = DateTime.Now;
            string posId = param != null ? param.PosID : "";

            if (isInSuddenDown || isNoAirCheck ||
            (!storeRunStatus.Equals(StoreRunStatus.Runing))
            || (!MoveInfo.MoveType.Equals(MoveType.None)))
            {
                LogUtil.error(Name + " 启动出库【" + param.ToStr() + "】失败,忙碌或报警中 ,storeStatus:" + storeRunStatus + ",MoveType:" + MoveInfo.MoveType + ",isInSuddenDown:" + isInSuddenDown + ",isNoAirCheck:" + isNoAirCheck);
                return false;
            }
          
            if (!StoreManager.LoadInoutParam(param, false, this))
            {
                LogUtil.error(Name + " 启动出库【" + param.ToStr() + "】出错,找不到库位信息");
                return false;
            }
             
            storeStatus = StoreStatus.OutStoreExecute;
            storeRunStatus = StoreRunStatus.Busy;
            MoveInfo.NewMove(MoveType.OutStore, param);
            LogInfo("启动出库【" + param.ToStr() + "】  ");
            //出库前shelfPosID需要固定,出库时根据rfid判断是否需要出入料架
            MoveInfo.NextMoveStep(StoreMoveStep.SO_01_InoutBack);
            InOutStoreLog("出库 " + MoveInfo.SLog + ":进出轴到P1  开始");
            InOutBackToP1(MoveInfo.MoveParam.MoveP.InOut_P1);
            return true;
        }
        private void SO_03_ToBagPosition()
        {
            MoveInfo.NextMoveStep(StoreMoveStep.SO_03_ToPosition);
            InOutStoreLog("出库 " + MoveInfo.SLog + ":走到库位,压紧轴至P3(压紧前点) ,旋转轴至P2(库位点),升降轴至P5(库位出库前点) ,顶升上升");
            ComAxis.AbsMove(MoveInfo, MoveInfo.MoveParam.MoveP.ComPress_P3, Config.CompAxis_P3_Speed);
            MiddleAxis.AbsMove(MoveInfo, MoveInfo.MoveParam.MoveP.Middle_P2, Config.MiddleAxis_P2_Speed);
            UpdownAxis.AbsMove(MoveInfo, MoveInfo.MoveParam.MoveP.UpDown_P5, Config.UpDownAxis_P5_Speed);
            CylinderMove(MoveInfo, IO_Type.TopCylinder_Down, IO_Type.TopCylinder_Up);
        }
        protected override void OutStoreProcess()
        {
            LineMoveP moveP = MoveInfo.MoveParam.MoveP;
            if (MoveInfo.IsInWait)
            {
                CheckWait();
            }
            if (MoveInfo.IsInWait)
            {
                return;
            }
             
            else if (MoveInfo.MoveStep <= StoreMoveStep.SO_01_InoutBack)
            {
                 
            }
            else if (MoveInfo.MoveStep >= StoreMoveStep.BS_01_TopDown)
            { 
            }
            else
            {
                LogUtil.error(Name + " 出库处理,MoveInfo.MoveStep=" + MoveInfo.MoveStep + ",没有对应的处理!");
            }
        }


        #endregion


    }
}