Пример #1
0
 public ANCStepResult GetStep(string TrayNO)
 {
     try
     {
         return(MesAcc.GetStep(TrayNO));
     }
     catch (Exception ex)
     {
         ANCStepResult re = new ANCStepResult();
         re.ResultCode = -1;
         re.ResultMsg  = "MES网络异常:" + ex.Message;
         return(re);
     }
 }
Пример #2
0
        private bool MESBatteryFill(int fillSeq, string palletID, List <string> batteryList, ref string reStr)
        {
            try
            {
                ANCStepResult stepRe = MesAcc.GetStep(palletID);
                if (stepRe.ResultCode != 0)
                {
                    reStr = stepRe.ResultMsg;
                    return(false);
                }

                int     channelMax = 36;
                JObject jsonObj    = new JObject(new JProperty("Type", "One"), new JProperty("TrayNO", palletID));
                if (fillSeq > 1)
                {
                    jsonObj["Type"] = "Two";
                }
                for (int i = 0; i < Math.Min(channelMax, batteryList.Count()); i++)
                {
                    jsonObj.Add("Cell" + (i + 1).ToString(), batteryList[i]);
                }
                VMResult re = MesAcc.UploadTrayCellInfo(jsonObj.ToString());
                if (re.ResultCode != 0)
                {
                    reStr = re.ResultMsg;
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                reStr = ex.ToString();
                return(false);
            }
        }
Пример #3
0
        private int GetSwitchDecision(string palletID, ref string reStr)
        {
            int re = 0;

            #region 查询本地应该进入哪个分区

            /*
             * string nextMesStepID = targetPorts[0].AsrsCtl.GetNextStepID(this.rfidUID);
             * string currentMesStepID = GetCurrentStepID(this.rfidUID);
             * int curSeq = SysCfg.SysCfgModel.stepSeqs.IndexOf(currentMesStepID);
             * int nextSeq = SysCfg.SysCfgModel.stepSeqs.IndexOf(nextMesStepID);
             * string storeAreaZone = AsrsModel.EnumLogicArea.常温区.ToString();
             * int seq1 = SysCfg.SysCfgModel.stepSeqs.IndexOf("PS-60");
             * //int seq2 = SysCfg.SysCfgModel.stepSeqs.IndexOf("PS-100");
             * if (nextSeq <= seq1)
             * {
             *  storeAreaZone = AsrsModel.EnumLogicArea.冷却区.ToString();
             * }
             * else
             * {
             *
             *  storeAreaZone = AsrsModel.EnumLogicArea.常温区.ToString();
             * }*/
            #endregion
            #region 查询MES 下一步应该进哪个库区
            string        storeAreaZone = AsrsModel.EnumLogicArea.常温区.ToString();
            ANCStepResult stepRe        = MesAcc.GetStep(palletID);
            if (stepRe.ResultCode != 0)
            {
                reStr = string.Format("查询MES托盘{0}步次失败:{1}", palletID, stepRe.ResultMsg);
                return(-1);
            }
            if (stepRe.Step < 12)
            {
                storeAreaZone = AsrsModel.EnumLogicArea.冷却区.ToString();
            }
            else
            {
                storeAreaZone = AsrsModel.EnumLogicArea.常温区.ToString();
            }
            #endregion
            if (targetPorts[0].PalletBuffer.Count() == 0 && targetPorts[1].PalletBuffer.Count() == 0)
            {
                //查询C1,C2库剩余货位数量

                int cellEmptCounts1 = 0, cellEmptCounts2 = 0;

                this.asrsResManage.GetHouseAreaLeftGs("C1库房", storeAreaZone, ref cellEmptCounts1, reStr);
                this.asrsResManage.GetHouseAreaLeftGs("C2库房", storeAreaZone, ref cellEmptCounts2, reStr);
                if (cellEmptCounts1 >= cellEmptCounts2 && cellEmptCounts1 > 0 && targetPorts[0].Db2Vals[0] != 2 && targetPorts[0].Db2Vals[1] != 2)
                {
                    re = 1;//流向C1,  this.db1ValsToSnd[0] = 1;
                }
                else if (cellEmptCounts1 < cellEmptCounts2 && cellEmptCounts2 > 0 && targetPorts[1].Db2Vals[0] != 2 && targetPorts[1].Db2Vals[1] != 2)
                {
                    re = 2;//流向C2,  this.db1ValsToSnd[0] = 2;
                }
                else
                {
                    re = 3;//等待 this.db1ValsToSnd[0] = 3;
                }
            }
            else
            {
                bool switchStat = false;
                for (int i = 0; i < targetPorts.Count(); i++)
                {
                    if (targetPorts[i].PalletBuffer.Count() > 0 && targetPorts[i].PalletBuffer.Count() < targetPorts[i].PortinBufCapacity)
                    {
                        string lastPalletID = targetPorts[i].PalletBuffer[targetPorts[i].PalletBuffer.Count() - 1];

                        #region 查询MES应该进入那个分区,及批次
                        string storeAreaZoneLast = AsrsModel.EnumLogicArea.冷却区.ToString();
                        stepRe = MesAcc.GetStep(lastPalletID);
                        if (stepRe.ResultCode != 0)
                        {
                            reStr = "查询MES托盘步次失败:" + stepRe.ResultMsg;
                            return(-1);
                        }
                        if (stepRe.Step < 12)
                        {
                            storeAreaZoneLast = AsrsModel.EnumLogicArea.冷却区.ToString();
                        }
                        else
                        {
                            storeAreaZoneLast = AsrsModel.EnumLogicArea.常温区.ToString();
                        }


                        VMResultLot reLast = MesAcc.GetTrayCellLotNO(lastPalletID);
                        VMResultLot reCur  = MesAcc.GetTrayCellLotNO(this.rfidUID);
                        if (reLast.ResultCode != 0)
                        {
                            reStr = string.Format("查询MES 托盘号{0}的批次失败,{1}", lastPalletID, reLast.ResultMsg);
                            break;
                        }
                        if (reCur.ResultCode != 0)
                        {
                            reStr = string.Format("查询MES 托盘号{0}的批次失败,{1}", this.rfidUID, reCur.ResultMsg);
                            break;
                        }
                        string preBatch = reLast.LotNO; //productOnlineBll.GetBatchNameofPallet(lastPalletID);
                        string curBatch = reCur.LotNO;  //productOnlineBll.GetBatchNameofPallet(this.rfidUID);
                        #endregion
                        #region 查询MES应该进入那个分区,本地批次信息

                        /*
                         * string preBatch = productOnlineBll.GetBatchNameofPallet(lastPalletID);
                         * string curBatch = productOnlineBll.GetBatchNameofPallet(this.rfidUID);
                         * string nextMesStepIDLast = targetPorts[0].AsrsCtl.GetNextStepID(lastPalletID);
                         * string currentMesStepIDLast = GetCurrentStepID(lastPalletID);
                         * int curSeqLast = SysCfg.SysCfgModel.stepSeqs.IndexOf(currentMesStepIDLast);
                         * int nextSeqLast = SysCfg.SysCfgModel.stepSeqs.IndexOf(nextMesStepIDLast);
                         * string storeAreaZoneLast = AsrsModel.EnumLogicArea.冷却区.ToString();
                         * int seq1Last = SysCfg.SysCfgModel.stepSeqs.IndexOf("PS-60");
                         * //int seq2 = SysCfg.SysCfgModel.stepSeqs.IndexOf("PS-100");
                         * if (nextSeqLast <= seq1Last)
                         * {
                         * storeAreaZoneLast = AsrsModel.EnumLogicArea.冷却区.ToString();
                         * }
                         * else
                         * {
                         *
                         * storeAreaZoneLast = AsrsModel.EnumLogicArea.常温区.ToString();
                         * }*/
                        #endregion
                        if (preBatch == curBatch && (storeAreaZone == storeAreaZoneLast))
                        {
                            re = (Int16)(i + 1);//this.db1ValsToSnd[0] =
                            //targetPorts[i].PushPalletID(this.rfidUID);
                            switchStat = true;
                            break;
                        }
                    }
                }
                if (!switchStat) //遍历各入口未能满足2筐入库规则,则选择缓存为空的入口
                {
                    for (int i = 0; i < targetPorts.Count(); i++)
                    {
                        //if (targetPorts[i].PalletBuffer.Count() == 0 && ((targetPorts[i].AsrsCtl.StackDevice.Db2Vals[1] < 3) || (targetPorts[i].AsrsCtl.StackDevice.Db2Vals[0] > 0)))
                        if ((targetPorts[i].PalletBuffer.Count() == 0) && (targetPorts[i].Db2Vals[0] < 2))//入口缓存数据为空,并且入口处无板(光眼信号判断)。
                        {
                            int cellEmptCounts = 0;

                            if (!this.asrsResManage.GetHouseAreaLeftGs(targetPorts[i].AsrsCtl.HouseName, storeAreaZone, ref cellEmptCounts, reStr))
                            {
                                continue;
                            }
                            if (cellEmptCounts <= 0)
                            {
                                continue;
                            }
                            re = (Int16)(i + 1);//this.db1ValsToSnd[0] =
                            // targetPorts[i].PushPalletID(this.rfidUID);
                            switchStat = true;
                            break;
                        }
                    }
                }

                if (!switchStat)
                {
                    re = 3;// this.db1ValsToSnd[0] = 3;
                    //this.currentTaskDescribe = "等待分流";
                    //break;
                }
            }
            return(re);
        }
Пример #4
0
        private void AsrsCheckinRequire()
        {
            //foreach(AsrsControl.AsrsPortalModel port in targetPorts)
            for (int i = 0; i < targetPorts.Count(); i++)
            {
                AsrsControl.AsrsPortalModel port = targetPorts[i];
                if (port.AsrsCtl.StackDevice.Db2Vals[0] > 0 || port.AsrsCtl.StackDevice.Db2Vals[1] > 2)
                {
                    continue;
                }
                if (port.PalletBuffer.Count() < 1)
                {
                    continue;
                }

                bool checkInRequire = false;
                if (port.PalletBuffer.Count() >= port.PortinBufCapacity)
                {
                    checkInRequire = true;
                }
                else
                {
                    if (db1ValsToSnd[0] == 3 && port.Db2Vals[0] == 2)
                    {
                        checkInRequire = true;
                    }
                }
                for (int j = 0; j < Math.Min(port.PalletBuffer.Count(), port.PortinBufCapacity); j++)
                {
                    if (port.Db2Vals[j] != 2)
                    {
                        checkInRequire = false;
                        break;
                    }
                }
                if (port.Db2Vals[2] == 2) //手动入库按钮请求
                {
                    checkInRequire = true;
                }
                if (!checkInRequire)
                {
                    continue;
                }
                string palletID = port.PalletBuffer[0];
                #region 查询本地应该进入哪个分区

                /*
                 * string nextProcessID = port.AsrsCtl.GetNextStepID(palletID);
                 * int nextProcessSeq = SysCfg.SysCfgModel.stepSeqs.IndexOf(nextProcessID);
                 * int curSeq = SysCfg.SysCfgModel.stepSeqs.IndexOf(port.AsrsCtl.MesProcessStepID[0]);
                 * AsrsModel.EnumLogicArea logicArea = AsrsModel.EnumLogicArea.冷却区;
                 * if (nextProcessSeq > curSeq)
                 * {
                 *  logicArea = AsrsModel.EnumLogicArea.常温区;
                 * }*/
                #endregion
                #region 查询MES应该进入哪个库区

                //在MES中查询入口处的第一个托盘当前工步,判断应该进入哪个库区
                ANCStepResult stepRe = MesAcc.GetStep(palletID);
                if (stepRe.ResultCode != 0)
                {
                    port.CurrentTaskDescribe = "查询MES托盘步次失败:" + stepRe.ResultMsg;
                    continue;
                }

                AsrsModel.EnumLogicArea logicArea = AsrsModel.EnumLogicArea.冷却区;
                if (stepRe.Step < 12)
                {
                    logicArea = AsrsModel.EnumLogicArea.冷却区;
                }
                else
                {
                    logicArea = AsrsModel.EnumLogicArea.常温区;
                }
                #endregion

                string reStr = "";
                SysCfg.EnumAsrsTaskType taskType = SysCfg.EnumAsrsTaskType.产品入库;
                if (port.AsrsCtl.AsrsCheckinTaskRequire(port, logicArea, taskType, port.PalletBuffer.ToArray(), ref reStr))
                {
                    //port.PalletBuffer.Clear();
                    if (!port.ClearBufPallets(ref reStr))
                    {
                        logRecorder.AddDebugLog(port.NodeName, "清理入口缓存数据失败" + reStr);
                    }
                }
                else
                {
                    string logStr = string.Format("{0}申请失败,因为:{1}", taskType.ToString(), reStr);
                    logRecorder.AddDebugLog(port.NodeName, logStr);
                }
            }
        }
Пример #5
0
        public override bool ExeBusiness(ref string reStr)
        {
            if (this.nodeID == "4001")
            {
                if (this.db2Vals[1] != SysCfg.SysCfgModel.ZhuyeMode)
                {
                    logRecorder.AddDebugLog(nodeName, string.Format("一次注液模式切换到{0}步模式", this.db2Vals[1]));
                }
                SysCfg.SysCfgModel.ZhuyeMode = this.db2Vals[1];
            }
            if (this.nodeID == "4001" || this.nodeID == "4002")
            {
                barcodeFailedStat = 4;
            }
            else
            {
                barcodeFailedStat = 3;
            }
            if (db2Vals[0] == 1)
            {
                currentTaskPhase = 0;
                DevCmdReset();
                db1ValsToSnd[0] = 0;

                rfidUID             = string.Empty;
                currentTaskDescribe = "等待新的任务";
                return(true);
            }
            if (db2Vals[0] == 2)
            {
                if (currentTaskPhase == 0)
                {
                    currentTaskPhase = 1;
                }
            }
            switch (this.currentTaskPhase)
            {
            case 1:
            {
                currentTaskDescribe = "开始读RFID";
                this.rfidUID        = "";
                if (SysCfg.SysCfgModel.SimMode || SysCfg.SysCfgModel.RfidSimMode)
                {
                    this.rfidUID = this.SimRfidUID;
                }
                else
                {
                    if (this.barcodeRW != null)
                    {
                        this.rfidUID = this.barcodeRW.ReadBarcode();
                    }
                    else
                    {
                        this.rfidUID = rfidRW.ReadStrData();        // rfidRW.ReadUID();
                    }
                }
                if (string.IsNullOrWhiteSpace(this.rfidUID))
                {
                    if (this.db1ValsToSnd[0] != barcodeFailedStat)
                    {
                        logRecorder.AddDebugLog(nodeName, "读RFID失败");
                    }
                    this.db1ValsToSnd[0] = barcodeFailedStat;
                    currentTaskDescribe  = "读RFID失败";
                    break;
                }
                this.rfidUID = this.rfidUID.Trim(new char[] { '\0', '\r', '\n', '\t', ' ' });
                string pattern = @"^[a-zA-Z0-9]*$";         //匹配所有字符都在字母和数字之间
                if (!System.Text.RegularExpressions.Regex.IsMatch(this.rfidUID, pattern))
                {
                    if (this.db1ValsToSnd[0] != barcodeFailedStat)
                    {
                        logRecorder.AddDebugLog(nodeName, "读料框ID错误,含有非法字符 !" + this.rfidUID);
                    }
                    this.db1ValsToSnd[0] = barcodeFailedStat;
                    return(true);
                }

                if (this.rfidUID.Length < 9)
                {
                    if (this.db1ValsToSnd[0] != barcodeFailedStat)
                    {
                        logRecorder.AddDebugLog(nodeName, "读料框RFID错误,长度不足9字符!");
                    }
                    this.db1ValsToSnd[0] = barcodeFailedStat;
                    break;
                }

                if (this.rfidUID.Length > 9)
                {
                    this.rfidUID = this.rfidUID.Substring(0, 9);
                }
                logRecorder.AddDebugLog(this.nodeName, "读到托盘号:" + this.rfidUID);
                currentTaskDescribe = "开始执行分流";
                string        logStr = "";
                ANCStepResult stepRe = MesAcc.GetStep(this.rfidUID);
                if (stepRe.ResultCode != 0)
                {
                    this.currentTaskDescribe = "查询MES托盘步次失败:" + stepRe.ResultMsg;
                    break;
                }
                int palletStat = MESPalletStat(this.rfidUID, ref reStr);
                if (this.nodeID == "4001")
                {
                    if (stepRe.Step == 0)
                    {
                        this.db1ValsToSnd[0] = 1;
                        logRecorder.AddDebugLog(nodeName, string.Format("托盘{0}分流:空筐", this.rfidUID));
                    }
                    else if (stepRe.Step >= 4)
                    {
                        this.db1ValsToSnd[0] = 3;
                        logRecorder.AddDebugLog(nodeName, string.Format("托盘{0}分流,MES工步:{1},已经完成一次注液第二步", this.rfidUID, stepRe.Step));
                    }
                    else
                    {
                        this.db1ValsToSnd[0] = 2;
                        logRecorder.AddDebugLog(nodeName, string.Format("托盘{0}分流,MES工步:{1},已经完成一次注液第一步", this.rfidUID, stepRe.Step));
                    }
                }
                #region 二次注液前分流点

                else if (this.nodeID == "4002")
                {
                    if (palletStat == 0)
                    {
                        this.db1ValsToSnd[0] = 1;
                        logRecorder.AddDebugLog(nodeName, string.Format("托盘{0}分流:空筐", this.rfidUID));
                    }
                    else
                    {
                        if (!MesAcc.UnbindTrayCell(this.rfidUID))
                        {
                            this.db1ValsToSnd[0] = 3;
                            logStr = string.Format("托盘{0}MES解绑失败", this.rfidUID);
                            logRecorder.AddDebugLog(nodeName, logStr);
                        }
                        else
                        {
                            this.db1ValsToSnd[0] = 2;
                            logStr = string.Format("托盘{0}分流:满筐,调用MES解绑成功", this.rfidUID);
                            logRecorder.AddDebugLog(nodeName, logStr);
                        }

                        /*
                         * if(stepRe.Step<6)
                         * {
                         *  this.db1ValsToSnd[0] = 3;
                         *  logStr = string.Format("托盘{0}工序流程错误,化成未完成,MES工步{1}", this.rfidUID,stepRe.Step);
                         *  logRecorder.AddDebugLog(nodeName, logStr);
                         * }
                         * else
                         * {
                         *  //调用MES接口解绑
                         *  if (!MesAcc.UnbindTrayCell(this.rfidUID))
                         *  {
                         *      this.db1ValsToSnd[0] = 3;
                         *      logStr = string.Format("托盘{0}MES解绑失败", this.rfidUID);
                         *      logRecorder.AddDebugLog(nodeName, logStr);
                         *  }
                         *  else
                         *  {
                         *      this.db1ValsToSnd[0] = 2;
                         *      logStr = string.Format("托盘{0}MES解绑成功", this.rfidUID);
                         *      logRecorder.AddDebugLog(nodeName, string.Format("托盘{0}分流:满筐", this.rfidUID));
                         *  }
                         *
                         *
                         * }*/
                    }
                }
                #endregion
                else
                {
                    if (stepRe.Step < 20)
                    {
                        currentTaskDescribe  = "OCV2";
                        this.db1ValsToSnd[0] = 1;         //OCV2
                        logStr = string.Format("{0},MES工步:{1},分流信息:OCV2分拣后料框", this.rfidUID, stepRe.Step);
                        logRecorder.AddDebugLog(nodeName, logStr);
                    }
                    else
                    {
                        currentTaskDescribe  = "OCV4";
                        this.db1ValsToSnd[0] = 2;         //OCV4
                        logStr = string.Format("{0},MES工步:{1},分流信息:OCV4分拣后料框", this.rfidUID, stepRe.Step);
                        logRecorder.AddDebugLog(nodeName, logStr);
                    }
                    #region 本地工艺流程查询

                    /*
                     * string curMesProcessID = this.productOnlineBll.GetProcessIDOfPallet(this.rfidUID);
                     * if (string.IsNullOrWhiteSpace(curMesProcessID))
                     * {
                     *  currentTaskDescribe = "OCV2";
                     *  this.db1ValsToSnd[0] = 1; //OCV2
                     *  logStr = "分流信息:OCV2分拣后料框";
                     * }
                     * else
                     * {
                     *  int curSeq = SysCfg.SysCfgModel.stepSeqs.IndexOf(curMesProcessID);
                     *  int ocv2Seq = SysCfg.SysCfgModel.stepSeqs.IndexOf("PS-70");
                     *  if (curSeq <= ocv2Seq)
                     *  {
                     *      currentTaskDescribe = "OCV2";
                     *      this.db1ValsToSnd[0] = 1; //OCV2
                     *      logStr = "分流信息:OCV2分拣后料框";
                     *  }
                     *  else
                     *  {
                     *      currentTaskDescribe = "OCV4";
                     *      this.db1ValsToSnd[0] = 2; //OCV4
                     *      logStr = "分流信息:OCV4分拣后料框";
                     *  }
                     * }*/
                    #endregion
                }

                this.currentTaskPhase++;
                break;
            }

            case 2:
            {
                currentTaskDescribe = "流程完成";
                break;
            }
            }
            return(true);
        }
Пример #6
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);
        }
Пример #7
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 = "开始执行分拣任务";


                // 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);
        }