Beispiel #1
0
        private string AsrsAreaToCheckin(string palletID, AsrsControl.AsrsCtlModel asrsCtl, int step)
        {
            string area = "";

            if (step == 0)
            {
                area = "空筐区";
                //if (asrsCtl.HouseName == "C1库房" || asrsCtl.HouseName == "C2库房" || asrsCtl.HouseName == "C3库房")
                //{
                //    area = "空筐区";
                //}
                //else
                //{
                //    area = SysCfg.SysCfgModel.asrsStepCfg.AsrsAreaSwitch(step);
                //}
            }
            else
            {
                if (asrsCtl.HouseName == "B1库房")
                {
                    string batteryCata = "";
                    if (palletID.Length >= 11)
                    {
                        batteryCata = palletID.Substring(0, 4);
                    }
                    else
                    {
                        //return area;
                        batteryCata = "F33A";
                    }
                    MesDBAccess.BLL.BatteryFenrongCfgBll batteryFenrongBll = new MesDBAccess.BLL.BatteryFenrongCfgBll();
                    string strWhere = string.Format("batteryCataCode = '{0}'", batteryCata);
                    List <MesDBAccess.Model.BatteryFenrongCfgModel> batteryFenrongList = batteryFenrongBll.GetModelList(strWhere, "fenrongZone");
                    foreach (MesDBAccess.Model.BatteryFenrongCfgModel cfgM in batteryFenrongList)
                    {
                        string areaCheckin = cfgM.fenrongZone;
                        int    validCells  = 0;
                        string reStr       = "";
                        if (!asrsResManage.GetHouseAreaLeftGs(asrsCtl.HouseName, areaCheckin, ref validCells, reStr))
                        {
                            Console.WriteLine("{0}获取 {1} 剩余货位数量失败", asrsCtl.HouseName, areaCheckin);
                            continue;
                        }
                        if (validCells > 0)
                        {
                            area = areaCheckin;
                            break;
                        }
                    }
                }
                else
                {
                    area = SysCfg.SysCfgModel.asrsStepCfg.AsrsAreaSwitch(step);
                }
            }
            return(area);
        }
Beispiel #2
0
        //A1库出库任务委托
        public CtlDBAccess.Model.ControlTaskModel GetCheckoutOfA1(AsrsControl.AsrsCtlModel asrsCtl, IAsrsManageToCtl asrsResManage, IList <CtlDBAccess.Model.ControlTaskModel> taskList, SysCfg.EnumAsrsTaskType taskType)
        {
            if (asrsCtl.HouseName != AsrsModel.EnumStoreHouse.A1库房.ToString())
            {
                return(null);
            }
            if (taskList == null)
            {
                return(null);
            }
            NodeVirStation nodeStation = GetNodeByID("4001") as NodeVirStation;
            //AsrsModel.EnumLogicArea requireCheckoutArea = AsrsModel.EnumLogicArea.一次高温A区;
            List <AsrsModel.EnumLogicArea> areaList = new List <AsrsModel.EnumLogicArea>();

            if (nodeStation.Db2Vals[2] == 1)
            {
                //requireCheckoutArea = AsrsModel.EnumLogicArea.一次高温A区;
                areaList.Add(AsrsModel.EnumLogicArea.一次高温A区);
                areaList.Add(AsrsModel.EnumLogicArea.一次高温B区);
            }
            else if (nodeStation.Db2Vals[2] == 2)
            {
                areaList.Add(AsrsModel.EnumLogicArea.一次高温B区);
                areaList.Add(AsrsModel.EnumLogicArea.一次高温A区);
            }
            else
            {
                return(null);
            }
            string           houseName = asrsCtl.HouseName;
            ControlTaskModel task      = null;

            foreach (AsrsModel.EnumLogicArea requireCheckoutArea in areaList)
            {
                task = GetCheckoutOfArea(asrsCtl, asrsResManage, taskType, taskList, requireCheckoutArea);
                if (task != null)
                {
                    break;
                }
            }

            return(task);
        }
Beispiel #3
0
        private CtlDBAccess.Model.ControlTaskModel GetCheckoutOfArea(AsrsControl.AsrsCtlModel asrsCtl, IAsrsManageToCtl asrsResManage, SysCfg.EnumAsrsTaskType taskType, IList <CtlDBAccess.Model.ControlTaskModel> taskList, AsrsModel.EnumLogicArea checkOutArea)
        {
            string           houseName = asrsCtl.HouseName;
            ControlTaskModel task      = null;

            if (taskList == null)
            {
                return(null);
            }
            foreach (ControlTaskModel t in taskList)
            {
                string             reStr      = "";
                AsrsTaskParamModel paramModel = new AsrsTaskParamModel();
                if (!paramModel.ParseParam(taskType, t.TaskParam, ref reStr))
                {
                    continue;
                }
                AsrsModel.EnumGSEnabledStatus cellEnabledStatus = AsrsModel.EnumGSEnabledStatus.启用;
                if (!asrsResManage.GetCellEnabledStatus(houseName, paramModel.CellPos1, ref cellEnabledStatus))
                {
                    // reStr = "获取货位启用状态失败";
                    continue;
                }
                if (cellEnabledStatus == AsrsModel.EnumGSEnabledStatus.禁用)
                {
                    continue;
                }
                AsrsModel.EnumLogicArea curLogicArea = AsrsModel.EnumLogicArea.一次高温A区;
                if (!asrsResManage.GetLogicAreaName(houseName, paramModel.CellPos1, ref curLogicArea))
                {
                    continue;
                }
                if (curLogicArea == checkOutArea)
                {
                    task = t;
                    break;
                }
            }
            return(task);
        }
Beispiel #4
0
        public override bool ExeBusiness(ref string reStr)
        {
            if (!devStatusRestore)
            {
                devStatusRestore = DevStatusRestore();
            }
            if (db2Vals[0] == 1)
            {
                currentTaskPhase = 0;
                Array.Clear(this.db1ValsToSnd, 0, this.db1ValsToSnd.Count());
                rfidUID             = string.Empty;
                currentTaskDescribe = "等待新的任务";
                //return true;
            }
            //if(db1ValsToSnd[0] >1) //分流完成后
            //{
            //    return true;
            //}
            if (db2Vals[0] == 2)
            {
                if (currentTaskPhase == 0)
                {
                    currentTaskPhase = 1;
                }
            }
            switch (this.currentTaskPhase)
            {
            case 1:
            {
                currentTaskDescribe = "开始读RFID";
                this.rfidUID        = "";
                if (SysCfg.SysCfgModel.UnbindMode)
                {
                    this.rfidUID = System.Guid.NewGuid().ToString();
                }
                else
                {
                    if (SysCfg.SysCfgModel.SimMode || SysCfg.SysCfgModel.RfidSimMode)
                    {
                        this.rfidUID = this.SimRfidUID;
                    }
                    else
                    {
                        this.rfidUID = this.barcodeRW.ReadBarcode();
                    }
                }

                if (string.IsNullOrWhiteSpace(this.rfidUID))
                {
                    if (this.db1ValsToSnd[0] != barcodeFailedStat)
                    {
                        logRecorder.AddDebugLog(nodeName, "读料框条码失败");
                    }
                    this.db1ValsToSnd[0] = barcodeFailedStat;
                    break;
                }
                this.rfidUID = this.rfidUID.Trim(new char[] { '\0', '\r', '\n', '\t', ' ' });

                string palletPattern = @"^[a-z|A-Z|0-9]{4}TP[0-9]{4,}";
                if (!Regex.IsMatch(this.rfidUID, palletPattern))
                {
                    if (this.db1ValsToSnd[0] != barcodeFailedStat)
                    {
                        logRecorder.AddDebugLog(nodeName, "读料框条码不符合规则," + this.rfidUID);
                        this.currentTaskDescribe = "读料框条码不符合规则," + this.rfidUID;
                    }
                    this.db1ValsToSnd[0] = barcodeFailedStat;
                    break;
                }

                /*
                 * //检测是否跟库里有重码
                 * string[] houseNames = new string[] { AsrsModel.EnumStoreHouse.A1库房.ToString(), AsrsModel.EnumStoreHouse.A2库房.ToString(),
                 *  AsrsModel.EnumStoreHouse.B1库房.ToString(), AsrsModel.EnumStoreHouse.C1库房.ToString(),AsrsModel.EnumStoreHouse.C2库房.ToString(),AsrsModel.EnumStoreHouse.C3库房.ToString() };
                 * foreach (string houseName in houseNames)
                 * {
                 *  string cellIn = AsrsResManage.IsProductCodeInStore(houseName, this.rfidUID, ref reStr);
                 *  if (!string.IsNullOrWhiteSpace(cellIn))
                 *  {
                 *      if (this.db1ValsToSnd[0] != 3)
                 *      {
                 *          currentTaskDescribe = string.Format("条码异常,条码{0}已经在库房{1},库位{2}", this.rfidUID.Length.ToString(), houseName, cellIn);
                 *          logRecorder.AddDebugLog(nodeName, currentTaskDescribe);
                 *      }
                 *      this.db1ValsToSnd[0] = 3;
                 *      return true;
                 *  }
                 * }*/

                logRecorder.AddDebugLog(this.nodeName, "读到托盘号:" + this.rfidUID);
                this.currentTaskPhase++;
                break;
            }

            case 2:
            {
                //分流
                currentTaskDescribe = "等待分流";
                int switchRe = 0;
                int step     = 0;
                if (!MesAcc.GetStep(this.rfidUID, out step, ref reStr))
                {
                    currentTaskDescribe = "查询MES工步失败:" + reStr;
                    break;
                }
                if (this.nodeID == "4001")
                {
                    if (step == 0)
                    {
                        currentTaskDescribe = string.Format("{0} 入库分流失败,步号为0,禁止入库", this.rfidUID);
                        if (this.db1ValsToSnd[0] != 4)
                        {
                            logRecorder.AddDebugLog(nodeName, string.Format("{0} 入库分流失败,步号为0,禁止入库", this.rfidUID));
                        }
                        this.db1ValsToSnd[0] = 4;         //

                        break;
                    }
                }
                if (this.nodeID == "4004")
                {
                    step = 5;
                    if (!MesAcc.UpdateStep(step, this.rfidUID, ref reStr))
                    {
                        currentTaskDescribe = "更新MES工步失败:" + reStr;
                        break;
                    }
                }
                if (this.nodeID == "4005")
                {
                    step = 6;
                    if (!MesAcc.UpdateStep(step, this.rfidUID, ref reStr))
                    {
                        currentTaskDescribe = "更新MES工步失败:" + reStr;
                        break;
                    }
                }
                if (this.nodeID == "4006")
                {
                    if (step > 0)
                    {
                        if (step >= 11)
                        {
                            step = 0;
                            if (!MesAcc.UpdateStep(step, this.rfidUID, ref reStr))
                            {
                                currentTaskDescribe = "更新MES工步失败:" + reStr;
                                break;
                            }
                        }
                        else if (step != 10)
                        {
                            step = 10;
                            if (!MesAcc.UpdateStep(step, this.rfidUID, ref reStr))
                            {
                                currentTaskDescribe = "更新MES工步失败:" + reStr;
                                break;
                            }
                        }
                    }
                }
                FlowPathModel switchPath = FindFirstValidPath(this.rfidUID, ref reStr);
                if (switchPath == null)
                {
                    switchRe                 = 0; //无可用路径,等待
                    this.db1ValsToSnd[0]     = (short)switchRe;
                    this.currentTaskDescribe = reStr;
                    break;
                }
                else
                {
                    CtlNodeBaseModel node = switchPath.NodeList[0];

                    if (this.nodeID == "4004")
                    {
                        AsrsControl.AsrsPortalModel port = (node as AsrsControl.AsrsPortalModel);
                        if (port == null)
                        {
                            break;
                        }
                        AsrsModel.CellCoordModel       requireCell   = null;
                        AsrsControl.AsrsCtlModel       asrsCtl       = port.AsrsCtl;
                        AsrsInterface.IAsrsManageToCtl asrsResManage = port.AsrsCtl.AsrsResManage;
                        string logicArea = "通用分区";
                        if (dlgtGetLogicArea != null)
                        {
                            logicArea = dlgtGetLogicArea(this.rfidUID, asrsCtl, step);
                        }
                        if (string.IsNullOrWhiteSpace(logicArea))
                        {
                            this.currentTaskDescribe = string.Format("{0} 检索货区失败,未配置", this.rfidUID);
                            break;
                        }
                        // AsrsModel.EnumLogicArea logicArea = (AsrsModel.EnumLogicArea)Enum.Parse(typeof(AsrsModel.EnumLogicArea), SysCfg.SysCfgModel.asrsStepCfg.AsrsAreaSwitch(step));
                        if (!asrsResManage.CellRequire(asrsCtl.HouseName, logicArea, ref requireCell, ref reStr))
                        {
                            Console.WriteLine("{0}申请库位失败,{1}", nodeName, reStr);
                            break;
                        }
                        if (requireCell.Row == 1)
                        {
                            switchRe = 2;
                            asrsCtl.SetAsrsCheckinRow(requireCell.Row);
                        }
                        else if (requireCell.Row == 2)
                        {
                            switchRe = 3;
                            asrsCtl.SetAsrsCheckinRow(requireCell.Row);
                        }
                        else
                        {
                            break;
                        }
                        logRecorder.AddDebugLog(nodeName, string.Format("{0}锁定分容库位第{1}排", this.rfidUID, requireCell.Row));
                    }
                    else
                    {
                        switchRe = switchPath.PathSeq + 1;
                    }

                    this.db1ValsToSnd[0] = (short)switchRe;

                    /*
                     * if(this.nodeID=="4006") //OCV后入库分流时,把条码后4位以整形发给PLC
                     * {
                     *  this.db1ValsToSnd[1] = short.Parse(this.rfidUID.Substring(this.rfidUID.Length - 4, 4));
                     * }*/
                    if (node.GetType().ToString() == "AsrsControl.AsrsPortalModel")
                    {
                        (node as AsrsControl.AsrsPortalModel).PushPalletID(this.rfidUID);
                    }
                    string logStr = string.Format("{0}分流,进入{1}", this.rfidUID, switchPath.NodeList[0].NodeName);
                    logRecorder.AddDebugLog(nodeName, logStr);
                    AddProduceRecord(this.rfidUID, logStr);

                    if (this.nodeID == "4001")
                    {
                        if (step >= 4)
                        {
                            step = 0;
                            if (!MesAcc.UpdateStep(step, this.rfidUID, ref reStr))
                            {
                                currentTaskDescribe = "更新MES工步失败:" + reStr;
                                break;
                            }
                        }
                    }
                }

                this.currentTaskPhase++;
                break;
            }

            case 3:
            {
                currentTaskDescribe = "分流完成";
                break;
            }

            default:
                break;
            }
            return(true);
        }
Beispiel #5
0
        /// <summary>
        /// 控制出库任务的生成,包括产品出库,空筐出库
        /// </summary>
        /// <param name="asrsCtl"></param>
        /// <param name="reStr"></param>
        /// <returns></returns>
        private bool AsrsCheckoutLoop(AsrsControl.AsrsCtlModel asrsCtl, SysCfg.EnumAsrsTaskType taskType, ref string reStr)
        {
            try
            {
                CtlDBAccess.BLL.ControlTaskBll ctlTaskBll = new CtlDBAccess.BLL.ControlTaskBll();
                //  SysCfg.EnumAsrsTaskType taskType = SysCfg.EnumAsrsTaskType.产品出库;
                // 1产品出库
                List <AsrsPortalModel> ports = asrsCtl.GetOutPortsOfBindedtask(taskType);
                string houseName             = asrsCtl.HouseName;
                AsrsModel.EnumCellStatus targetStoreStatus = EnumCellStatus.满位;
                if (taskType == SysCfg.EnumAsrsTaskType.空筐出库)
                {
                    targetStoreStatus = EnumCellStatus.空料框;
                }
                foreach (AsrsPortalModel port in ports)
                {
                    if (taskType == SysCfg.EnumAsrsTaskType.空筐出库)
                    {
                        if (port.Db2Vals[0] != 2 || port.Db2Vals[2] != 1)  //禁止出库
                        {
                            continue;
                        }
                    }
                    else  //禁止出库
                    {
                        if (port.Db2Vals[0] != 2 || port.Db2Vals[1] != 1)
                        {
                            continue;
                        }
                    }
                    //查询是否有待执行或者执行中的任务
                    string str = string.Format("DeviceID='{0}' and EndDevice='{1}' and TaskType={2} and (TaskStatus='待执行' or TaskStatus='执行中')", asrsCtl.StackDevice.NodeID, port.NodeID, (int)taskType);
                    List <CtlDBAccess.Model.ControlTaskModel> taskList = ctlTaskBll.GetModelList(str);
                    if (taskList != null && taskList.Count() > 0)
                    {
                        continue;
                    }
                    //遍历所有库位,判断材料类别,按照先入先出规则,匹配出库的货位。
                    Dictionary <string, AsrsModel.GSMemTempModel> asrsStatDic = new Dictionary <string, AsrsModel.GSMemTempModel>();
                    if (!asrsResManage.GetAllGsModel(ref asrsStatDic, ref reStr))
                    {
                        Console.WriteLine(string.Format("{0} 获取货位状态失败", houseName));
                        return(false);
                    }
                    List <AsrsModel.GSMemTempModel> validCells = new List <AsrsModel.GSMemTempModel>();

                    int r = 1, c = 1, L = 1;
                    //先查询所有可出库货位
                    for (r = 1; r < asrsCtl.AsrsRow + 1; r++)
                    {
                        for (c = 1; c < asrsCtl.AsrsCol + 1; c++)
                        {
                            for (L = 1; L < asrsCtl.AsrsLayer + 1; L++)
                            {
                                string strKey = string.Format("{0}:{1}-{2}-{3}", houseName, r, c, L);
                                AsrsModel.GSMemTempModel cellStat = null;
                                if (!asrsStatDic.Keys.Contains(strKey))
                                {
                                    continue;
                                }
                                cellStat = asrsStatDic[strKey];
                                if ((!cellStat.GSEnabled) || (cellStat.GSTaskStatus == AsrsModel.EnumGSTaskStatus.锁定.ToString()) || (cellStat.GSStatus != targetStoreStatus.ToString()))
                                {
                                    // reStr = string.Format("货位{0}-{1}-{2}禁用,无法生成出库任务", cell.Row, cell.Col, cell.Layer);
                                    continue;
                                }
                                AsrsModel.CellCoordModel cell = new AsrsModel.CellCoordModel(r, c, L);
                                validCells.Add(cellStat);
                            }
                        }
                    }
                    //再按照先入先出原则生成出库任务
                    if (validCells.Count() > 0)
                    {
                        //排序,按照先入先出
                        AsrsModel.GSMemTempModel firstGS = validCells[0];
                        if (validCells.Count() > 1)
                        {
                            for (int i = 1; i < validCells.Count(); i++)
                            {
                                AsrsModel.GSMemTempModel tempGS = validCells[i];
                                if (tempGS.InHouseDate < firstGS.InHouseDate)
                                {
                                    firstGS = tempGS;
                                }
                            }
                        }
                        //生成出库任务
                        string[] strCellArray              = firstGS.GSPos.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries);
                        int      row                       = int.Parse(strCellArray[0]);
                        int      col                       = int.Parse(strCellArray[1]);
                        int      layer                     = int.Parse(strCellArray[2]);
                        AsrsModel.CellCoordModel cell      = new AsrsModel.CellCoordModel(row, col, layer);
                        List <string>            storGoods = new List <string>();
                        if (!asrsResManage.GetStockDetail(houseName, cell, ref storGoods))
                        {
                            return(false);
                        }
                        string palletIDStr = "";
                        for (int i = 0; i < storGoods.Count(); i++)
                        {
                            if (storGoods.Count() > 1 && (i == storGoods.Count() - 1))
                            {
                                palletIDStr = palletIDStr + storGoods[i];
                            }
                            else
                            {
                                palletIDStr = palletIDStr + storGoods[i] + ",";
                            }
                        }

                        return(asrsCtl.CreateStackerTask(port, taskType, cell, palletIDStr, ref reStr));


                        //if (asrsCtl.GenerateOutputTask(cell, port.BindedTaskOutput, true, port.PortSeq, ref reStr, new List<short> { palletCata }))
                        //{
                        //    port.Db1ValsToSnd[0] = 2;
                        //}
                        //else
                        //{
                        //    Console.WriteLine("生成任务{0}失败,{1}", port.BindedTaskOutput.ToString(), reStr);
                        //}
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                reStr = ex.ToString();
                return(false);
            }
        }
        /// <summary>
        /// 判断物流线是否堵塞,选择出库任务
        /// </summary>
        /// <param name="asrsCtl"></param>
        /// <param name="asrsResManage"></param>
        /// <param name="taskList"></param>
        /// <param name="taskType"></param>
        /// <returns></returns>
        public CtlDBAccess.Model.ControlTaskModel AsrsCheckoutTaskTorun(AsrsControl.AsrsCtlModel asrsCtl, IAsrsManageToCtl asrsResManage, IList <CtlDBAccess.Model.ControlTaskModel> taskList, SysCfg.EnumAsrsTaskType taskType)
        {
            try
            {
                if (taskList == null)
                {
                    return(null);
                }

                string houseName = asrsCtl.HouseName;
                CtlDBAccess.Model.ControlTaskModel task = null;
                foreach (CtlDBAccess.Model.ControlTaskModel t in taskList)
                {
                    if (t.TaskStatus != "待执行")
                    {
                        continue;
                    }
                    string             reStr      = "";
                    AsrsTaskParamModel paramModel = new AsrsTaskParamModel();
                    if (!paramModel.ParseParam(taskType, t.TaskParam, ref reStr))
                    {
                        continue;
                    }
                    AsrsPortalModel port          = asrsCtl.Ports[paramModel.OutputPort - 1];
                    int             switchPathSeq = 1;
                    CellCoordModel  cell          = paramModel.CellPos1;
                    if (asrsCtl.NodeName == "A1库房" || asrsCtl.HouseName == "A2库房")
                    {
                        string area = "注液高温区";
                        if (!this.asrsResManage.GetLogicAreaName(houseName, cell, ref area))
                        {
                            continue;
                        }
                        if (area == "注液高温区")
                        {
                            switchPathSeq = 1;
                        }
                        else if (area == "化成高温区")
                        {
                            switchPathSeq = 2;
                        }
                        else
                        {
                            continue;
                        }
                        if (port.Db2Vals[switchPathSeq] != 1)
                        {
                            continue;
                        }
                    }
                    else if (asrsCtl.HouseName == "C1库房" || asrsCtl.HouseName == "C2库房" || asrsCtl.HouseName == "C3库房")
                    {
                        if (taskType == SysCfg.EnumAsrsTaskType.空筐出库)
                        {
                            if (port.Db2Vals[switchPathSeq] != 1)
                            {
                                continue;
                            }
                        }
                    }

                    AsrsModel.EnumGSEnabledStatus cellEnabledStatus = AsrsModel.EnumGSEnabledStatus.启用;
                    if (!asrsResManage.GetCellEnabledStatus(houseName, paramModel.CellPos1, ref cellEnabledStatus))
                    {
                        // reStr = "获取货位启用状态失败";
                        continue;
                    }
                    if (cellEnabledStatus == AsrsModel.EnumGSEnabledStatus.禁用)
                    {
                        continue;
                    }
                    task = t;
                    break;
                }
                return(task);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return(null);
            }
        }