BoxBean_Inventory.cs 8.3 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;

namespace OnlineStore.DeviceLibrary
{
    public partial class BoxBean
    {

        bool reelIsExist = false;
        protected override void InventoryProcess()
        {
            LineMoveP moveP = MoveInfo.MoveParam.MoveP;
            if (MoveInfo.IsInWait)
            {
                CheckWait();
            }
            if (MoveInfo.IsInWait)
            {
                return;
            }
            if (MoveInfo.MoveStep == StoreMoveStep.SC_01_InOutAxisHome)
            {
                MoveInfo.NextMoveStep(StoreMoveStep.SC_04_Inventory);//直接跑到库位点,不使用盘点信号
                 //StoreMove.NextMoveStep(StoreMoveStep.SC_02_MoveToLBag);
                 ACAxisMove(Config.Middle_Axis, moveP.Middle_P2, Config.MiddleAxis_P2_Speed);
                int outCount = ACServerManager.GetActualtPosition(Config.UpDown_Axis.DeviceName, Config.UpDown_Axis.GetAxisValue());
                int disCount = Math.Abs(outCount - moveP.UpDown_P5);
                if (disCount > 150000)
                {
                    ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P5, Config.UpDownAxis_P5_Speed);
                    CheckPositionLog(" 旋转轴至P2升降轴到P5(库位低点) UpDownAxis_P5_Speed=" + Config.UpDownAxis_P5_Speed.ToString());
                }
                else
                {
                    ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P5, Config.UpDownAxis_P6_Speed);
                    CheckPositionLog(" 旋转轴至P2升降轴到P5(库位低点) UpDownAxis_P6_Speed=" + Config.UpDownAxis_P6_Speed.ToString());
                }
                //}
                //else if (StoreMove.MoveStep == StoreMoveStep.SC_02_MoveToLBag)
                //{
                //    StoreMove.NextMoveStep(StoreMoveStep.SC_03_MoveToHBag);
                //    CheckPositionLog(" 升降轴到库位高点P9, UpDownAxis_P9_Speed=" + Config.UpDownAxis_P9_Speed.ToString());
                //    ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P9, Config.UpDownAxis_P9_Speed);
            }
            else if (MoveInfo.MoveStep == StoreMoveStep.SC_03_MoveToHBag)
            {
                MoveInfo.NextMoveStep(StoreMoveStep.SC_04_Inventory);
                CheckPositionLog(" 升降轴到目标位置, 当前位置=" + ACServerManager.GetActualtPosition(Config.UpDown_Axis) + " 目标位置=" + ACServerManager.GetTargetPosition(Config.UpDown_Axis.DeviceName, Config.UpDown_Axis.GetAxisValue()));
                //ACServerManager.SuddenStop(Config.UpDown_Axis.DeviceName, Config.UpDown_Axis.GetAxisValue());

                //int outCount = ACServerManager.GetActualtPosition(Config.UpDown_Axis);
                //int errorCount = Math.Abs(outCount - moveP.UpDown_P9);
                //if (errorCount <= Config.UpDown_Axis.CanErrorCountMax)
                //{
                //    CheckPositionLog(" 升降轴到目标位置, 当前位置=" + ACServerManager.GetActualtPosition(Config.UpDown_Axis)+" 目标位置="+ moveP.UpDown_P9 + " errorCount="+ errorCount);
                //}
                //else
                //{
                //    CheckPositionLog(" 升降轴运动过程中检测到料盘, 当前位置=" + ACServerManager.GetActualtPosition(Config.UpDown_Axis) + " 目标位置=" + moveP.UpDown_P9 + " errorCount=" + errorCount+ " Config.UpDown_Axis.CanErrorCountMax=" + Config.UpDown_Axis.CanErrorCountMax);
                //}
                Dictionary<string, string> paramMap = new Dictionary<string, string>();
                paramMap.Add("cid", CID);//cid = 料仓CID
                paramMap.Add("pos", MoveInfo.MoveParam.PosInfo.PosId);   // 库位
                paramMap.Add("hasReel", reelIsExist.ToString());  // 是否有料
                string server = StoreManager.GetAddr(StoreManager.Addr_posReelCheck, paramMap);
                //bool timeOut = false;
                string resultStr = HttpHelper.Post(server, "" );
                CheckPositionLog("盘点仓位: [CID=" + CID + "] [" + MoveInfo.MoveParam.PosInfo.PosId + "] [IO_Type.reelIsExist=" + reelIsExist.ToString() + "] [resultStr=" + resultStr + "]");
                reelIsExist = false;
            }
            else if (MoveInfo.MoveStep == StoreMoveStep.SC_04_Inventory)
            {
                MoveInfo.EndMove();
                storeRunStatus = StoreRunStatus.Runing;
                //设备连接,盘点后,BOX恢复原始状态 
                storeStatus = StoreStatus.StoreOnline;
                InventoryEndProcess(StoreMoveType.CheckPosition);
            }
        }


        /// <summary>
        /// 自动盘点是否结束
        /// </summary>
        /// <param name="storeMoveType"></param>
        private void InventoryEndProcess(StoreMoveType storeMoveType)
        {
            try
            {
                //是否自动状态
                if (!autoNext)
                {
                    readDITimer.Enabled = false;
                    return;
                }
                if (storeMoveType.Equals(StoreMoveType.CheckPosition))
                {
                    int newIndex = autoPositionIndex - 1;
                    if (newIndex < 0)
                    {
                        if (AutoStartIndex >= 0 && AutoStartIndex < PositionNumList.Count)
                        {
                            newIndex = AutoStartIndex;
                            LogUtil.info(  Name + "下一个索引不存在,重新开始自动盘点,索引【" + AutoStartIndex + "】");
                        }
                        else
                        {
                            autoNext = false;
                            readDITimer.Enabled = false;
                            autoMsg = "自动盘点结束!";
                            LogUtil.info(  Name + "下一个索引不存在,自动盘点结束!");
                            //回待机位
                            MoveToP1();
                        }
                    }
                    else
                    {
                        autoPositionIndex = newIndex;
                        string posid = PositionNumList[autoPositionIndex];
                        InOutPosInfo inoutinfo = new InOutPosInfo(autoInoutCode, posid);
                        LogUtil.info(  Name + "自动进入下一个仓位:posid=" + posid);
                        autoMsg = "自动盘点:" + posid;
                        StartInventoryMove(new InOutParam(inoutinfo));

                    }
                }
            }
            catch (Exception ex)
            {
                LogUtil.error(  ex.ToString());
            }
        }


        /// <summary>
        /// 开始库位盘点
        /// </summary> 
        public void StartInventoryMove(InOutParam param)
        {
            readDITimer.Enabled = true;
            startInStoreTime = DateTime.Now;
            string posId = param != null ? param.PosInfo.PosId : "";
            if (storeRunStatus == StoreRunStatus.Runing)
            {
                if (!LoadParamPosition(param))
                {
                    LogUtil.error(  Name + " 启动盘点库位【" + posId + "】出错,找不到库位信息");
                    return;
                }
                LogUtil.info(  Name + " 启动盘点库位【" + posId + "】");
                storeRunStatus = StoreRunStatus.Busy;
                storeStatus = StoreStatus.CheckPosMove;
                MoveInfo.NewMove(StoreMoveType.CheckPosition, param);
                SC_01_Move(param.MoveP);

            }
            else
            {
                LogUtil.error(  Name + " 启动盘点库位【" + posId + "】出错,当前状态,storeStatus=" + storeRunStatus);
            }
        }

        private void SC_01_Move(LineMoveP moveP)
        {
            MoveInfo.NextMoveStep(StoreMoveStep.SC_01_InOutAxisHome);
            CheckPositionLog("盘点:SC_01_InOutAxisHome  进出轴(叉子)动作至P1");
            InOutBackToP1(moveP.InOut_P1);
        }
        private void CheckPositionLog(string msg)
        {
            string posId = MoveInfo.MoveParam != null ? "【" + MoveInfo.MoveParam.PosInfo.PosId + "】" : " ";
            LogUtil.info(  posId + MoveInfo.MoveStep + "  " + msg);
        }
    }
}