예제 #1
0
        private bool Process4012(string palletID, ref Int16 re, ref string reStr)
        {
            //1 先解绑
            int step = 0;

            if (!MesAcc.GetStep(this.rfidUID, out step, ref reStr))
            {
                currentTaskDescribe = "查询MES工步失败:" + reStr;
                return(false);
            }
            step = 0;
            if (!MesAcc.UpdateStep(step, this.rfidUID, ref reStr))
            {
                currentTaskDescribe = "更新MES工步失败:" + reStr;
                return(false);
            }

            //2 再分流
            return(Process4010(palletID, ref re, ref reStr));
        }
예제 #2
0
        private bool Switch4003()
        {
            string reStr = "";

            if (!MesAcc.UpdateStep(1, this.rfidUID, ref reStr))
            {
                Console.WriteLine("{0} 更新步号错误,{1}", nodeName, reStr);
                return(false);
            }
            int switchRe = 0;

            FlowPathModel switchPath = FindFirstValidPath(this.rfidUID, ref reStr);

            if (switchPath == null)
            {
                switchRe             = this.flowPathList.Count() + 2; //无可用路径,等待
                this.db1ValsToSnd[0] = 3;
                return(false);
            }
            else
            {
                //string strCata = this.rfidUID.Substring(10, 1).ToUpper();

                string strCataName = "正极材料";
                if (!RecordPalletInfo(this.rfidUID, ref strCataName, ref reStr))
                {
                    return(false);
                }

                switchRe = switchPath.PathSeq + 1;
                CtlNodeBaseModel node = switchPath.NodeList[0];
                if (node.GetType().ToString() == "AsrsControl.AsrsPortalModel")
                {
                    (node as AsrsControl.AsrsPortalModel).PushPalletID(this.rfidUID);
                }
                this.db1ValsToSnd[0] = (short)switchRe;
                logRecorder.AddDebugLog(nodeName, string.Format("{0}分流,进入{1}", this.rfidUID, switchPath.NodeList[0].NodeName));
                return(true);
            }
        }
예제 #3
0
        /// <summary>
        /// 化成后修改工步为3
        /// </summary>

        private bool Process4008(string palletID, ref Int16 re, ref string reStr)
        {
            try
            {
                re = 0;
                int updateStep = 3;
                if (!MesAcc.UpdateStep(updateStep, palletID, ref reStr))
                {
                    return(false);
                }
                re = 2;
                string logStr = string.Format("{0},{1}更新工步{2}", this.nodeName, palletID, updateStep);
                logRecorder.AddDebugLog(nodeName, logStr);
                AddProduceRecord(palletID, logStr);
                return(true);
            }
            catch (Exception ex)
            {
                reStr = ex.ToString();
                return(false);
            }
        }
예제 #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);
        }
예제 #5
0
        public override bool ExeBusiness(ref string reStr)
        {
            if (!nodeEnabled)
            {
                return(true);
            }
            if (!devStatusRestore)
            {
                devStatusRestore = DevStatusRestore();
            }
            if (!devStatusRestore)
            {
                return(false);
            }
            if (db2Vals[0] != 2)
            {
                db1ValsToSnd[0] = 1;
            }

            //任务撤销
            if (db2Vals[1] == 3 && db1ValsToSnd[1] != 3)
            {
                if (this.currentTask != null && this.currentTaskPhase > 0)
                {
                    this.currentTask.TaskStatus = SysCfg.EnumTaskStatus.任务撤销.ToString();
                    this.currentTask.FinishTime = System.DateTime.Now;
                    ctlTaskBll.Update(this.currentTask);

                    logRecorder.AddDebugLog(this.nodeName, string.Format("分拣任务{0}撤销,托盘号:{1}", this.currentTask.TaskID, this.rfidUID));
                    currentTaskDescribe   = "分拣任务撤销,等待任务撤销信号复位";
                    this.currentTask      = null;
                    this.currentTaskPhase = 0;
                }
                Array.Clear(this.db1ValsToSnd, 0, this.db1ValsToSnd.Count());
                db1ValsToSnd[1] = 3;//

                return(true);
            }
            if (db1ValsToSnd[1] == 3 && db2Vals[1] != 2)
            {
                //任务撤销命令复位,应答也复位
                db1ValsToSnd[1] = 1;
            }

            if (!GraspTaskRequire(ref reStr))
            {
                return(false);
            }
            if (this.currentTask == null)
            {
                return(true);
            }

            switch (this.currentTaskPhase)
            {
            case 1:
            {
                currentTaskDescribe = "开始执行分拣任务";

                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] != 3)
                    {
                        logRecorder.AddDebugLog(nodeName, "读料框条码失败");
                    }
                    this.db1ValsToSnd[0] = 3;
                    break;
                }

                // int ocvProcessID = 1;//zwx,临时



                this.currentTaskPhase++;
                this.currentTask.TaskPhase = this.currentTaskPhase;
                this.ctlTaskBll.Update(this.currentTask);
                break;
            }

            case 2:
            {
                //查询MES 不良电芯数据

                //写入PLC


                db1ValsToSnd[0]     = 2;
                currentTaskDescribe = "分拣参数发送完成";

                this.currentTaskPhase++;
                this.currentTask.TaskPhase = this.currentTaskPhase;
                this.ctlTaskBll.Update(this.currentTask);

                break;
            }

            case 3:
            {
                //等待任务完成
                currentTaskDescribe = "等待分拣完成";
                if (this.db2Vals[1] != 2 && this.db2Vals[1] != 4)
                {
                    break;
                }

                //更新MES步号

                int stepUp = 0;
                if (this.nodeID == "6001")
                {
                    stepUp = 7;
                }
                else if (this.nodeID == "6002")
                {
                    stepUp = 10;
                }
                else
                {
                    stepUp = 13;
                }
                if (!MesAcc.UpdateStep(stepUp, this.rfidUID, ref reStr))
                {
                    currentTaskDescribe = "更新MES工步失败:" + reStr;
                    break;
                }
                db1ValsToSnd[1] = 2;
                string grasp = "";

                AddProduceRecord(this.rfidUID, string.Format("正常分拣:{0}", nodeName));
                logRecorder.AddDebugLog(nodeName, string.Format("{0},分拣完成,{1}", this.rfidUID, grasp));

                this.currentTaskPhase++;

                this.currentTask.TaskPhase = this.currentTaskPhase;
                this.ctlTaskBll.Update(this.currentTask);


                break;
            }

            case 4:
            {
                currentTaskDescribe = "分拣流程完成,等待分拣完成信号复位";
                if (this.db2Vals[1] != 1)
                {
                    break;
                }
                DevCmdReset();
                this.currentTask.TaskStatus = SysCfg.EnumTaskStatus.已完成.ToString();
                this.ctlTaskBll.Update(this.currentTask);

                this.currentTask    = null;
                currentTaskPhase    = 0;
                currentTaskDescribe = "等待执行下一个任务";
                break;
            }

            default:
                break;
            }
            return(true);
        }
예제 #6
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;
                }

                /*
                 * //检测是否跟库里有重码
                 * 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")
                {
                    step = 14;
                    if (!MesAcc.UpdateStep(step, this.rfidUID, ref reStr))
                    {
                        currentTaskDescribe = "更新MES工步失败:" + reStr;
                        break;
                    }
                }
                else if (this.nodeID == "4002")
                {
                    step = 0;
                    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;
                    break;
                }
                else
                {
                    CtlNodeBaseModel node = switchPath.NodeList[0];
                    switchRe = switchPath.PathSeq + 1;
                    if (node.GetType().ToString() == "AsrsControl.AsrsPortalModel")
                    {
                        (node as AsrsControl.AsrsPortalModel).PushPalletID(this.rfidUID);
                    }
                    this.db1ValsToSnd[0] = (short)switchRe;
                    string logStr = string.Format("{0}分流,进入{1}", this.rfidUID, switchPath.NodeList[0].NodeName);
                    logRecorder.AddDebugLog(nodeName, logStr);
                    AddProduceRecord(this.rfidUID, logStr);
                }

                this.currentTaskPhase++;
                break;
            }

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

            default:
                break;
            }
            return(true);
        }
예제 #7
0
        public override bool ExeBusiness(ref string reStr)
        {
            //Console.WriteLine("TES P1");
            if (!nodeEnabled)
            {
                return(true);
            }
            if (!devStatusRestore)
            {
                devStatusRestore = DevStatusRestore();
            }
            if (!devStatusRestore)
            {
                return(false);
            }
            if (db2Vals[0] != 2)
            {
                db1ValsToSnd[1] = 1;
            }
            //任务撤销
            if (db2Vals[1] == 3 && db1ValsToSnd[0] != 3)
            {
                if (this.currentTask != null && this.currentTaskPhase > 0)
                {
                    this.currentTask.TaskStatus = SysCfg.EnumTaskStatus.任务撤销.ToString();
                    this.currentTask.FinishTime = System.DateTime.Now;
                    ctlTaskBll.Update(this.currentTask);

                    logRecorder.AddDebugLog(this.nodeName, string.Format("装载任务{0}撤销,托盘号:{1}", this.currentTask.TaskID, this.rfidUID));
                    currentTaskDescribe   = "装载任务撤销";
                    this.currentTask      = null;
                    this.currentTaskPhase = 0;
                }
                Array.Clear(this.db1ValsToSnd, 0, this.db1ValsToSnd.Count());
                db1ValsToSnd[0] = 3;//

                return(true);
            }
            if (db1ValsToSnd[0] == 3 && db2Vals[1] == 1)
            {
                //任务撤销命令复位,应答也复位
                db1ValsToSnd[0] = 1;
            }

            if (!FillTaskRequire(ref reStr))
            {
                return(false);
            }
            //  Console.WriteLine("TES P2");
            //if(this.currentTask == null)
            //{
            //    return true;
            //}
            switch (this.currentTaskPhase)
            {
            case 1:
            {
                currentTaskDescribe  = "开始执行装载任务";
                this.db1ValsToSnd[1] = 2;

                //如果是一次装载,判断是否第一步
                if (this.nodeID == "3001")
                {
                    //如果是第1步,则上传MES步次,直接放行。通知PLC不用扫条码

                    ANCStepResult stepRe = MesAcc.GetStep(this.rfidUID);
                    if (stepRe.ResultCode != 0)
                    {
                        this.currentTaskDescribe = "查询MES托盘步次失败:" + stepRe.ResultMsg;
                        break;
                    }

                    if (SysCfg.SysCfgModel.ZhuyeMode == 1)        //一步模式
                    {
                        #region 一步模式
                        this.db1ValsToSnd[2] = 2;
                        logRecorder.AddDebugLog(nodeName, string.Format("一次注液一步模式下,托盘{0}当前步次{1},等待装载 ", this.rfidUID, stepRe.Step));
                        #endregion
                    }
                    else if (SysCfg.SysCfgModel.ZhuyeMode == 2)       //两步模式
                    {
                        #region 两步模式
                        if (stepRe.Step < 3)
                        {
                            this.currentTaskDescribe = string.Format("{0}一次注液第1步,将跳过装载", this.rfidUID);
                            int updateStep = 2;
                            logRecorder.AddDebugLog(nodeName, string.Format("托盘{0}当前步次{1},完成一次注液第1步后过站,不装载 ", this.rfidUID, stepRe.Step));
                            VMResult re = MesAcc.UpdateStep(updateStep, this.rfidUID);
                            if (re.ResultCode != 0)
                            {
                                this.currentTaskDescribe = "更新MES步次失败," + re.ResultMsg;
                                logRecorder.AddDebugLog(nodeName, this.currentTaskDescribe);
                                break;         //zwx ,11-16
                            }
                            this.db1ValsToSnd[2] = 1;

                            this.db1ValsToSnd[0]       = 2;
                            this.currentTaskPhase      = 3;
                            this.currentTask.TaskPhase = this.currentTaskPhase;
                            this.ctlTaskBll.Update(this.currentTask);
                            break;
                        }
                        else if (stepRe.Step == 3)
                        {
                            this.db1ValsToSnd[2] = 2;
                            logRecorder.AddDebugLog(nodeName, string.Format("一次注液两步模式下,托盘{0}当前步次{1},完成一次注液第2步后装载 ", this.rfidUID, stepRe.Step));
                        }
                        else
                        {
                            if (this.db1ValsToSnd[2] != 3)
                            {
                                logRecorder.AddDebugLog(nodeName, string.Format("托盘{0}步次错误,当前步次:{1} ", this.rfidUID, stepRe.Step));
                            }

                            this.db1ValsToSnd[2] = 3;
                            break;
                        }
                        #endregion
                    }
                    else
                    {
                        if (this.db1ValsToSnd[2] != 3)
                        {
                            logRecorder.AddDebugLog(nodeName, string.Format("一次注液模式错误,实际为{0}", SysCfg.SysCfgModel.ZhuyeMode));
                        }

                        this.db1ValsToSnd[2] = 3;
                        break;
                    }
                }

                this.currentTaskPhase++;
                this.currentTask.TaskPhase = this.currentTaskPhase;
                this.ctlTaskBll.Update(this.currentTask);
                break;
            }

            case 2:
            {
                if (this.db1ValsToSnd[0] == 4)
                {
                    //装载错误状态
                    break;
                }
                //等待扫码完成
                currentTaskDescribe = "RFID读取完成,等待电池条码数据";
                if (db2Vals[1] != 2)
                {
                    break;
                }
                if (SysCfg.SysCfgModel.SimMode)
                {
                    //生成模拟数据
                    GenerateSimBatterys();
                }
                //取电池条码数据
                List <string> batteryList = new List <string>();
                int           validBatNum = 0;
                for (int i = 0; i < PalletCapacity; i++)
                {
                    List <byte> batteryBytes = new List <byte>();
                    for (int j = 0; j < 20; j++)
                    {
                        int indexSt = 2 + i * 20 + j;
                        batteryBytes.Add((byte)(this.db2Vals[indexSt] & 0xff));
                        batteryBytes.Add((byte)((this.db2Vals[indexSt] >> 8) & 0xff));
                    }

                    //字节流转换成字符串
                    string batteryID = System.Text.ASCIIEncoding.UTF8.GetString(batteryBytes.ToArray());
                    batteryID = batteryID.Trim(new char[] { '\0', '\r', '\n', '\t', ' ' }).ToUpper();
                    if (batteryID.Contains("ERROR"))
                    {
                        batteryID = "";
                    }

                    if (batteryID.Length > 22)
                    {
                        validBatNum++;
                        if (batteryID.Length < 35 && batteryID.Substring(16, 6).ToUpper() == "17K03C")
                        {
                            batteryID = batteryID.Insert(22, "1");
                        }
                    }
                    batteryList.Add(batteryID);
                }
                if (validBatNum < 1)
                {
                    if (this.db1ValsToSnd[0] != 5)
                    {
                        logRecorder.AddDebugLog(nodeName, string.Format("{0}电池数据为空", rfidUID));
                    }
                    this.db1ValsToSnd[0] = 5;
                    break;
                }


                #region 调用MES接口上传绑定数据,更新步次
                int fillSeq = 1;
                if (this.nodeID == "3002")
                {
                    fillSeq = 2;
                }
                logRecorder.AddDebugLog(nodeName, string.Format("{0}开始上传MES", rfidUID));
                if (!MESBatteryFill(fillSeq, rfidUID, batteryList, ref reStr))
                {
                    logRecorder.AddDebugLog(nodeName, string.Format(" {0}MES装载错误:{1}", rfidUID, reStr));
                    this.db1ValsToSnd[0] = 4;        //装载错误
                    currentTaskDescribe  = string.Format(" 装载错误{0}", reStr);
                    logRecorder.AddDebugLog(nodeName, currentTaskDescribe);
                    break;         //zwx,11-16
                }
                else
                {
                    logRecorder.AddDebugLog(nodeName, string.Format("{0}MES装载成功", rfidUID));
                }

                ANCStepResult stepRe = MesAcc.GetStep(this.rfidUID);
                if (stepRe.ResultCode != 0)
                {
                    this.currentTaskDescribe = "查询MES托盘步次失败:" + stepRe.ResultMsg;
                    logRecorder.AddDebugLog(nodeName, this.currentTaskDescribe);
                    break;         //zwx,11-16
                }
                int updateStep = 0;
                if (this.nodeID == "3001")
                {
                    updateStep = 4;
                }
                else
                {
                    updateStep = 8;
                }
                VMResult re = MesAcc.UpdateStep(updateStep, this.rfidUID);
                if (re.ResultCode != 0)
                {
                    this.currentTaskDescribe = "更新MES步次失败," + re.ResultMsg;
                    logRecorder.AddDebugLog(nodeName, this.currentTaskDescribe);
                    break;         //zwx ,11-16
                }
                #endregion


                //自动装载都是1次装载
                #region   杭可
                //string sndStr = "";
                //if (!hkAccess.BatteryFill(0, this.rfidUID, batteryList, ref sndStr, ref reStr))
                //{

                //    logRecorder.AddDebugLog(nodeName, string.Format(" 装载错误:{0},发送数据:{1}", reStr, sndStr));
                //    this.db1ValsToSnd[0] = 4;//装载错误
                //    currentTaskDescribe = string.Format(" 装载错误{0}", reStr);
                //    break;
                //}
                #endregion
                #region 本地数据装载
                for (int i = 0; i < batteryList.Count(); i++)
                {
                    string batteryID = batteryList[i];
                    if (string.IsNullOrWhiteSpace(batteryID) || (batteryID.Length < 23))
                    {
                        continue;
                    }
                    MesDBAccess.Model.ProductOnlineModel productModel = null;
                    if (productOnlineBll.Exists(batteryID))
                    {
                        productModel               = productOnlineBll.GetModel(batteryID);
                        productModel.productID     = batteryID;
                        productModel.palletID      = this.rfidUID;
                        productModel.modifyTime    = System.DateTime.Now;
                        productModel.processStepID = this.mesProcessStepID[0].ToString();
                        productModel.productCata   = SysCfg.EnumProductCata.电芯.ToString();
                        productModel.palletBinded  = true;
                        productModel.stationID     = this.nodeID;
                        productModel.checkResult   = "0";
                        if (batteryID.Length > 22)
                        {
                            productModel.batchName = batteryID.Substring(16, 6);
                        }

                        int seq = i + 1;
                        productModel.tag1 = seq.ToString();
                        int rowIndex = i / 12 + 1;
                        productModel.tag2 = rowIndex.ToString();
                        int colIndex = i - (rowIndex - 1) * 12 + 1;
                        productModel.tag3 = colIndex.ToString();
                        productModel.tag5 = "0";
                        if (!productOnlineBll.Update(productModel))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        productModel               = new MesDBAccess.Model.ProductOnlineModel();
                        productModel.onlineTime    = System.DateTime.Now;
                        productModel.modifyTime    = System.DateTime.Now;
                        productModel.productID     = batteryID;
                        productModel.palletID      = this.rfidUID;
                        productModel.processStepID = this.mesProcessStepID[0].ToString();
                        productModel.productCata   = SysCfg.EnumProductCata.电芯.ToString();
                        productModel.palletBinded  = true;
                        productModel.stationID     = this.nodeID;
                        productModel.checkResult   = "0";
                        productModel.tag5          = "0";
                        if (batteryID.Length > 22)
                        {
                            productModel.batchName = batteryID.Substring(16, 6);
                        }
                        int seq = i + 1;
                        productModel.tag1 = seq.ToString();
                        int rowIndex = i / 12 + 1;
                        productModel.tag2 = rowIndex.ToString();
                        int colIndex = i - (rowIndex - 1) * 12 + 1;
                        productModel.tag3 = colIndex.ToString();
                        if (!productOnlineBll.Add(productModel))
                        {
                            return(false);
                        }
                    }
                }
                #endregion

                logRecorder.AddDebugLog(nodeName, string.Format(" 装载成功{0},更新MES工步:{1}", rfidUID, updateStep));
                AddProduceRecord(this.rfidUID, string.Format("装载:{0},更新MES步次{1}", nodeName, updateStep));
                this.currentTaskPhase++;
                this.currentTask.TaskPhase = this.currentTaskPhase;
                this.ctlTaskBll.Update(this.currentTask);
                this.db1ValsToSnd[0] = 2;
                break;
            }

            case 3:
            {
                currentTaskDescribe = "托盘跟电池条码数据绑定完成,等待扫码完成信号复位";
                if (this.db2Vals[1] != 1)
                {
                    break;
                }
                DevCmdReset();
                this.currentTask.TaskStatus = SysCfg.EnumTaskStatus.已完成.ToString();
                this.ctlTaskBll.Update(this.currentTask);
                this.currentTask    = null;
                currentTaskPhase    = 0;
                currentTaskDescribe = "等待执行下一个任务";
                //等待扫码完成
                break;
            }

            default:
                break;
            }
            //Console.WriteLine("TES P3");
            return(true);
        }
예제 #8
0
파일: NodeGrasp.cs 프로젝트: radtek/ANCHI
        public override bool ExeBusiness(ref string reStr)
        {
            if (!nodeEnabled)
            {
                return(true);
            }
            if (!devStatusRestore)
            {
                devStatusRestore = DevStatusRestore();
            }
            if (!devStatusRestore)
            {
                return(false);
            }
            if (db2Vals[0] != 2)
            {
                db1ValsToSnd[0] = 1;
            }

            //任务撤销
            if (db2Vals[1] == 3 && db1ValsToSnd[1] != 3)
            {
                if (this.currentTask != null && this.currentTaskPhase > 0)
                {
                    this.currentTask.TaskStatus = SysCfg.EnumTaskStatus.任务撤销.ToString();
                    this.currentTask.FinishTime = System.DateTime.Now;
                    ctlTaskBll.Update(this.currentTask);

                    logRecorder.AddDebugLog(this.nodeName, string.Format("分拣任务{0}撤销,托盘号:{1}", this.currentTask.TaskID, this.rfidUID));
                    currentTaskDescribe   = "分拣任务撤销,等待任务撤销信号复位";
                    this.currentTask      = null;
                    this.currentTaskPhase = 0;
                }
                Array.Clear(this.db1ValsToSnd, 0, this.db1ValsToSnd.Count());
                db1ValsToSnd[1] = 3;//

                return(true);
            }
            if (db1ValsToSnd[1] == 3 && db2Vals[1] != 2)
            {
                //任务撤销命令复位,应答也复位
                db1ValsToSnd[1] = 1;
            }

            if (!GraspTaskRequire(ref reStr))
            {
                return(false);
            }
            if (this.currentTask == null)
            {
                return(true);
            }
            switch (this.currentTaskPhase)
            {
            case 1:
            {
                currentTaskDescribe = "开始执行分拣任务";


                // int ocvProcessID = 1;//zwx,临时
                List <int> ocvTestSeqIDS  = new List <int>();
                int        testValStIndex = 2;

                ANCStepResult stepRe = MesAcc.GetStep(this.rfidUID);
                if (stepRe.ResultCode != 0)
                {
                    this.currentTaskDescribe = "查询MES托盘步次失败:" + stepRe.ResultMsg;
                    break;
                }

                if (this.nodeID == "6002")
                {
                    //查询MES,当前步次,是OCV2还是OCV4分拣
                    testValStIndex = 3;
                    if (stepRe.Step < 19)
                    {
                        this.db1ValsToSnd[2] = 1;        //OCV2
                    }
                    else
                    {
                        this.db1ValsToSnd[2] = 2;         //OCV4
                    }
                    #region 判断本地工艺步号

                    /*
                     *
                     * testValStIndex = 3;
                     * string curMesProcessID = this.productOnlineBll.GetProcessIDOfPallet(this.rfidUID);
                     * if (string.IsNullOrWhiteSpace(curMesProcessID))
                     * {
                     *
                     *  this.db1ValsToSnd[2] = 1; //OCV2
                     * }
                     * else
                     * {
                     *  int curSeq = SysCfg.SysCfgModel.stepSeqs.IndexOf(curMesProcessID);
                     *  int ocv2Seq = SysCfg.SysCfgModel.stepSeqs.IndexOf("PS-70");
                     *  if (curSeq <= ocv2Seq)
                     *  {
                     *
                     *      this.db1ValsToSnd[2] = 1; //OCV2
                     *  }
                     *  else
                     *  {
                     *
                     *      this.db1ValsToSnd[2] = 2; //OCV4
                     *  }
                     * }*/
                    #endregion
                }
                #region 从杭可查询检测数据

                /*
                 * if (this.nodeID == "6001")
                 * {
                 *   //检测OCV1数据
                 *   ocvTestSeqIDS.Add(1);
                 * }
                 * else if (this.nodeID == "6002")
                 * {
                 *    if(this.db1ValsToSnd[2] ==1)
                 *    {
                 *        ocvTestSeqIDS.Add(2); //检测OCV2数据
                 *    }
                 *    else
                 *    {
                 *        ocvTestSeqIDS.Add(5);//检测OCV4数据
                 *    }
                 * }
                 * else
                 * {
                 *   //检测分容,OCV3数据
                 *   ocvTestSeqIDS.Add(3);
                 *   ocvTestSeqIDS.Add(4);
                 * }
                 * //查询杭可测试结果
                 * vals = new List<int>();
                 * if(SysCfg.SysCfgModel.SimMode)
                 * {
                 *   for(int i=0;i<36;i++)
                 *   {
                 *       vals.Add(1);
                 *   }
                 * }
                 * else
                 * {
                 *   //List<int> ocvTestSeqIDS = new List<int>();
                 *
                 *   if (!ocvAccess.GetCheckResult(this.rfidUID, ocvTestSeqIDS, ref vals, ref reStr))
                 *   {
                 *       if(db1ValsToSnd[0] != 4)
                 *       {
                 *           logRecorder.AddDebugLog(nodeName,string.Format("查询OCV测试结果失败,{0},{1}",this.rfidUID,reStr));
                 *       }
                 *       db1ValsToSnd[0] = 4;
                 *       break;
                 *   }
                 * }
                 */
                #endregion


                //查询MES分拣数据
                vals = new List <int>();
                if (SysCfg.SysCfgModel.SimMode)
                {
                    for (int i = 0; i < 36; i++)
                    {
                        vals.Add(1);
                    }
                }
                else
                {
                    int step = 0;
                    if (this.nodeID == "6001")
                    {
                        step = 9;
                    }
                    else if (this.nodeID == "6002")
                    {
                        if (stepRe.Step < 14)
                        {
                            step = 13;
                        }
                        else
                        {
                            step = 19;
                        }
                    }
                    else
                    {
                        step = 16;
                    }

                    if (!MESGetGraspVals(step, this.rfidUID, ref vals, ref reStr))
                    {
                        this.currentTaskDescribe = reStr;
                        break;
                    }
                }

                //发送分拣参数
                for (int i = 0; i < Math.Max(channelSum, vals.Count()); i++)
                {
                    Int16 re = (short)vals[i];
                    db1ValsToSnd[testValStIndex + i] = re;
                }
                db1ValsToSnd[0] = 2;
                AddGraspRecord(this.rfidUID, vals);         //记录分拣发送详细
                currentTaskDescribe = "分拣参数发送完成";
                this.currentTaskPhase++;
                this.currentTask.TaskPhase = this.currentTaskPhase;
                this.ctlTaskBll.Update(this.currentTask);
                break;
            }

            case 2:
            {
                //等待任务完成
                currentTaskDescribe = "等待分拣完成";
                if (this.db2Vals[1] != 2 && this.db2Vals[1] != 4)
                {
                    break;
                }
                if (this.db2Vals[1] == 4)
                {
                    AddProduceRecord(this.rfidUID, string.Format("无需分拣模式:{0}", nodeName));
                    logRecorder.AddDebugLog(nodeName, string.Format("由人工处理,{0}无需挑选放行", this.rfidUID));
                }

                //if (db2Vals[1] == 2)
                //{
                //    ANCStepResult stepRe = MesAcc.GetStep(this.rfidUID);
                //    if (stepRe.ResultCode != 0)
                //    {
                //        this.currentTaskDescribe = "查询MES托盘步次失败:" + stepRe.ResultMsg;
                //        logRecorder.AddDebugLog(nodeName, this.currentTaskDescribe);
                //        break; //zwx,11-16
                //    }

                //}

                UpdateOnlineProductInfo(this.rfidUID);

                this.currentTaskPhase++;

                this.currentTask.TaskPhase = this.currentTaskPhase;
                this.ctlTaskBll.Update(this.currentTask);

                break;
            }

            case 3:
            {
                //更新MES步号

                ANCStepResult stepRe = MesAcc.GetStep(this.rfidUID);
                if (stepRe.ResultCode != 0)
                {
                    this.currentTaskDescribe = "查询MES托盘步次失败:" + stepRe.ResultMsg;
                    logRecorder.AddDebugLog(nodeName, this.currentTaskDescribe);
                    break;         //zwx,11-16
                }

                int stepUp = 0;
                if (this.nodeID == "6001")
                {
                    stepUp = 10;
                }
                else if (this.nodeID == "6002")
                {
                    if (stepRe.Step <= 14)
                    {
                        stepUp = 14;
                    }
                    else
                    {
                        stepUp = 20;
                    }
                }
                else
                {
                    stepUp = 17;
                }
                VMResult re = MesAcc.UpdateStep(stepUp, this.rfidUID);
                if (re.ResultCode != 0)
                {
                    this.currentTaskDescribe = "更新MES步号失败," + re.ResultMsg;
                    logRecorder.AddDebugLog(nodeName, this.currentTaskDescribe);
                    break;         //zwx,11-16
                }


                db1ValsToSnd[1] = 2;
                string grasp = "";
                if (this.nodeID == "6002")
                {
                    if (stepRe.Step < 20)
                    {
                        grasp = string.Format("OCV2 分拣完成,更新步次{0}", stepUp);
                    }
                    else
                    {
                        grasp = string.Format("OCV4 分拣完成,更新步次{0}", stepUp);
                    }
                }
                else
                {
                    grasp = string.Format("{0} 分拣完成,更新步次{1}", nodeName, stepUp);
                }
                AddProduceRecord(this.rfidUID, string.Format("正常分拣:{0}", grasp));
                logRecorder.AddDebugLog(nodeName, string.Format("{0},分拣完成,{1}", this.rfidUID, grasp));

                this.currentTaskPhase++;

                this.currentTask.TaskPhase = this.currentTaskPhase;
                this.ctlTaskBll.Update(this.currentTask);


                break;
            }

            case 4:
            {
                currentTaskDescribe = "分拣流程完成,等待分拣完成信号复位";
                if (this.db2Vals[1] != 1)
                {
                    break;
                }
                DevCmdReset();
                this.currentTask.TaskStatus = SysCfg.EnumTaskStatus.已完成.ToString();
                this.ctlTaskBll.Update(this.currentTask);

                this.currentTask    = null;
                currentTaskPhase    = 0;
                currentTaskDescribe = "等待执行下一个任务";
                break;
            }

            default:
                break;
            }
            return(true);
        }