Exemple #1
0
 /// <summary>
 /// 贴标队列处理,周期执行
 /// </summary>
 public void PrinterListProcess()
 {
     lock (lockPrintbuf)
     {
         if (!PLProcessModel.SysCfgModel.PrienterEnable)
         {
             this.printList.Clear();
             return;
         }
         if (this.printList.Count() == 0)
         {
             return;
         }
         string productBarcode = this.printList[0];
         int    mesRe          = 0;
         string reStr          = "";
         if (!SysCfgModel.MesOfflineMode && PLProcessModel.SysCfgModel.MesCheckEnable)
         {
             mesRe = mesDA.MesAssemDown(new string[] { productBarcode, LineMonitorPresenter.mesLineID }, ref reStr);
         }
         if (0 == mesRe)
         {
             if (!PLProcessModel.SysCfgModel.PrienterEnable)
             {
                 this.printList.Clear();
                 return;
             }
             bool re = prienterRW.SndBarcode(productBarcode, ref reStr);
             if (!re)
             {
                 string failInfo = string.Format("给贴标机发送条码{0} 失败,错误信息:{1}", productBarcode, reStr);
                 logRecorder.AddDebugLog(nodeName, failInfo);
             }
             else
             {
                 this.printList.Remove(productBarcode);
                 logRecorder.AddDebugLog(nodeName, "成功发送贴标条码:" + productBarcode + "," + reStr);
             }
         }
         else
         {
             MesStatRecord mesStat = NodePack.GetMequeryStat(productBarcode);
             if (mesStat != null)
             {
                 if (3 == mesStat.StatVal)
                 {
                     logRecorder.AddDebugLog(this.nodeName, productBarcode + ":MES禁止下线:" + reStr);
                     this.printList.Remove(productBarcode);
                     return;
                 }
             }
         }
     }
 }
Exemple #2
0
 public static void SetMesQueryStat(string productBarcode, int val)
 {
     lock (mesQueryStat)
     {
         if (NodePack.mesQueryStat.Keys.Contains(productBarcode))
         {
             NodePack.mesQueryStat[productBarcode].StatVal        = val;
             NodePack.mesQueryStat[productBarcode].ProductBarcode = productBarcode;
             NodePack.mesQueryStat[productBarcode].StatModifyTime = System.DateTime.Now;
         }
         else
         {
             MesStatRecord stat = new MesStatRecord();
             stat.StatVal        = val;
             stat.StatModifyTime = System.DateTime.Now;
             stat.ProductBarcode = productBarcode;
             NodePack.mesQueryStat[productBarcode] = stat;
         }
     }
 }
Exemple #3
0
        /// <summary>
        /// 贴标队列处理,周期执行
        /// </summary>
        public void PrinterListProcess()
        {
            string productBarcode = "";

            lock (lockPrintbuf)
            {
                if (!PLProcessModel.SysCfgModel.PrienterEnable)
                {
                    this.printList.Clear();
                    return;
                }
                if (this.printList.Count() == 0)
                {
                    return;
                }
                productBarcode = this.printList[0];
            }
            int      mesRe = 0;
            string   reStr = "";//!NodeFactory.SimMode &&
            DateTime mesSt = DateTime.Now;

            try
            {
                if (!SysCfgModel.MesOfflineMode && PLProcessModel.SysCfgModel.MesCheckEnable)
                {
                    mesRe = mesDA.MesAssemDown(new string[] { productBarcode, LineMonitorPresenter.mesLineID }, ref reStr);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            int queryInterval = 100;

            while (mesRe != 0)
            {
                MesStatRecord mesStat = NodePack.GetMequeryStat(productBarcode);
                if (mesStat != null)
                {
                    if (3 == mesStat.StatVal)
                    {
                        logRecorder.AddDebugLog(this.nodeName, productBarcode + ":MES禁止下线:" + reStr);
                        break;
                    }
                }
                TimeSpan timeElapse = System.DateTime.Now - mesSt;
                if (timeElapse.TotalSeconds > (SysCfgModel.MesTimeout + 10))
                {
                    break;
                }
                Thread.Sleep(queryInterval);
                mesRe = mesDA.MesAssemDown(new string[] { productBarcode, LineMonitorPresenter.mesLineID }, ref reStr);
            }
            if (0 == mesRe)
            {
                bool re = prienterRW.SndBarcode(productBarcode, ref reStr);
                if (!re)
                {
                    string failInfo = string.Format("给贴标机发送条码{0} 失败,错误信息:{1}", productBarcode, reStr);
                    logRecorder.AddDebugLog(nodeName, failInfo);
                }
                else
                {
                    lock (lockPrintbuf)
                    {
                        this.printList.Remove(productBarcode);
                    }

                    logRecorder.AddDebugLog(nodeName, "成功发送贴标条码:" + productBarcode + "," + reStr);
                }
            }
            else
            {
                logRecorder.AddDebugLog(this.nodeName, productBarcode + ":MES下线查询超时," + reStr);
                lock (lockPrintbuf)
                {
                    this.printList.Remove(productBarcode);
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// 异步发送条码给贴标机
        /// </summary>
        /// <param name="productBarcode"></param>
        /// <param name="reStr"></param>
        /// <returns></returns>
        private bool AsySndPrinterinfo(string productBarcode, ref string reStr)
        {
            if (!PLProcessModel.SysCfgModel.PrienterEnable)
            {
                reStr = "贴标机已经禁用";
                return(true);
            }
            int mesRe = 0;

            if (!SysCfgModel.MesOfflineMode && PLProcessModel.SysCfgModel.MesCheckEnable)
            {
                mesRe = mesDA.MesAssemDown(new string[] { productBarcode, LineMonitorPresenter.mesLineID }, ref reStr);
            }

            int      delayTimeOut  = 600;//
            int      queryInterval = 100;
            DateTime mesSt         = DateTime.Now;

            while (0 != mesRe)
            {
                //this.currentStat.StatDescribe = productBarcode + ":MES禁止下线:" + reStr;
                // logRecorder.AddDebugLog(this.nodeName, this.currentStat.StatDescribe);
                MesStatRecord mesStat = NodePack.GetMequeryStat(productBarcode);
                if (mesStat != null)
                {
                    if (3 == mesStat.StatVal)
                    {
                        logRecorder.AddDebugLog(this.nodeName, productBarcode + ":MES禁止下线:" + reStr);
                        return(false);
                    }
                }
                TimeSpan timeElapse = System.DateTime.Now - mesSt;
                if (timeElapse.TotalMilliseconds > delayTimeOut * 1000)
                {
                    break;
                }
                Thread.Sleep(queryInterval);
                mesRe = mesDA.MesAssemDown(new string[] { productBarcode, LineMonitorPresenter.mesLineID }, ref reStr);
            }
            if (0 == mesRe)
            {
                //PushBarcodeToBuf(productBarcode);
                bool re         = prienterRW.SndBarcode(productBarcode, ref reStr);
                int  reTryMax   = 20;
                int  tryCounter = 0;
                while (!re)
                {
                    tryCounter++;
                    string failInfo = string.Format("给贴标机发送条码{0} 失败,错误信息:{1}", productBarcode, reStr);
                    logRecorder.AddDebugLog(nodeName, failInfo);
                    if (tryCounter > reTryMax)
                    {
                        break;
                    }
                    Thread.Sleep(1000);
                    re = prienterRW.SndBarcode(productBarcode, ref reStr);
                }
                if (re)
                {
                    logRecorder.AddDebugLog(nodeName, "成功发送贴标条码:" + productBarcode + "," + reStr);
                    return(true);
                }
                else
                {
                    string failInfo = string.Format("给贴标机发送条码失败:{0},错误信息:{1}", productBarcode, reStr);
                    logRecorder.AddDebugLog(nodeName, failInfo);
                    return(false);
                }
            }
            else
            {
                string logStr = productBarcode + ":MES禁止下线:" + reStr;
                logRecorder.AddDebugLog(this.nodeName, logStr);
                return(false);
            }
        }
Exemple #5
0
        public override bool ExeBusiness(ref string reStr)
        {
            DateTime commSt = System.DateTime.Now;

            // Console.WriteLine("P1");
            MessLossCheck();
            //  Console.WriteLine("P2");
            DateTime commEd = System.DateTime.Now;
            TimeSpan ts     = commEd - commSt;

            if (ts.TotalMilliseconds > 1000)
            {
                // node.LogRecorder.AddDebugLog(node.NodeName, dispCommInfo);
                CurrentStat.StatDescribe = string.Format("漏项检查周期:{0}毫秒", (int)ts.TotalMilliseconds);
            }
            if (this.db2Vals[1] == 1) //纸箱到位
            {
                boxPrepareOK = true;
            }
            if (!NodeStatParse(ref reStr))
            {
                return(false);
            }
            // Console.WriteLine("P3");
            if ((this.db2Vals[1] == 0) && (currentTaskPhase > 1) && boxPrepareOK)
            {
                //抓取完毕后,纸箱复位(主要是非正常流程下人工取走纸箱)
                DevCmdReset();
                this.currentStat.StatDescribe = "流程复位";
                currentTaskDescribe           = "流程复位";
                graspBegin       = false;//准备新的流程
                currentTaskPhase = 1;
            }

            //清理MES查询记录字典
            List <string> removeList = new List <string>();

            foreach (string key in NodePack.mesQueryStat.Keys)
            {
                MesStatRecord mesStat = NodePack.mesQueryStat[key];
                TimeSpan      tmSpan  = System.DateTime.Now - mesStat.StatModifyTime;
                if (tmSpan.TotalSeconds > 60)
                {
                    removeList.Add(key);
                }
            }
            //   Console.WriteLine("P4");
            foreach (string key in removeList)
            {
                NodePack.mesQueryStat.Remove(key);
            }
            // Console.WriteLine("P5");
            if (!checkEnable)
            {
                return(true);
            }

            switch (currentTaskPhase)
            {
            case 1:
            {
                DevCmdReset();
                rfidUID = string.Empty;
                this.currentStat.Status         = EnumNodeStatus.设备空闲;
                this.currentStat.ProductBarcode = "";
                this.currentStat.StatDescribe   = "设备空闲";
                checkFinished       = false;
                boxPrepareOK        = false;
                graspBegin          = false;
                currentTaskDescribe = "等待有板信号";
                break;
            }

            case 2:
            {
                db1ValsToSnd[32] = 1;        //流程锁定
                if (this.currentStat.Status == EnumNodeStatus.设备故障)
                {
                    break;
                }
                this.currentStat.Status         = EnumNodeStatus.设备使用中;
                this.currentStat.ProductBarcode = "";
                this.currentStat.StatDescribe   = "设备使用中";
                //开始读卡
                DateTime dtSt = System.DateTime.Now;
                if (!SimMode)
                {
                    rfidUID = rfidRW.ReadUID();
                }
                else
                {
                    rfidUID = SimRfidUID;
                }
                currentTaskDescribe = "开始读RFID";
                if (!string.IsNullOrWhiteSpace(rfidUID))
                {
                    db1ValsToSnd[0] = 0;
                    this.currentStat.StatDescribe = "RFID识别完成";
                    //根据绑定,查询条码,赋条码
                    OnlineProductsModel productBind = productBindBll.GetModelByrfid(rfidUID);
                    if (productBind == null)
                    {
                        db1ValsToSnd[0] = db1StatNG;
                        this.currentStat.StatDescribe = "未投产";
                        currentTaskDescribe           = "未投产";
                        //mesQueryStat[this.currentStat.ProductBarcode] = 3;//MES禁止下线
                        SetMesQueryStat(this.currentStat.ProductBarcode, 3);
                        checkEnable = false;
                        break;
                    }
                    productBind.currentNode = this.nodeName;
                    productBindBll.Update(productBind);

                    //状态赋条码,
                    this.currentStat.ProductBarcode = productBind.productBarcode;
                    BarcodeFillDB1(productBind.productBarcode, 2);
                    SetMesQueryStat(this.currentStat.ProductBarcode, 1);

                    //检查是否已经下线,MES离线模式下不判断
                    logRecorder.AddDebugLog(nodeName, "查询MES是否已经下线:" + this.currentStat.ProductBarcode);
                    if (!SysCfgModel.MesOfflineMode)
                    {
                        int mesDown = mesDA.MesDowned(this.currentStat.ProductBarcode, mesNodeID, ref reStr);
                        if (mesDown == 1)
                        {
                            string logInfo = string.Format("条码重复,{0} 已经下线,请检查", this.currentStat.ProductBarcode);
                            logRecorder.AddDebugLog(nodeName, logInfo);
                            db1ValsToSnd[0] = mesDownedFlag;
                            checkEnable     = false;
                            break;
                        }
                        else if (mesDown == 3)
                        {
                            string logInfo = string.Format("MES数据库访问失败,无法查询是否已经下线,{0},{1}", this.currentStat.ProductBarcode, reStr);
                            logRecorder.AddDebugLog(nodeName, logInfo);
                        }
                    }

                    if (!PreDetectCheck(productBind.productBarcode))
                    {
                        if (db1ValsToSnd[0] != db1StatNG)
                        {
                            logRecorder.AddDebugLog(this.nodeName, string.Format("{0} 在前面工位有检测NG项", productBind.productBarcode));
                        }
                        db1ValsToSnd[0]     = db1StatNG;
                        currentTaskDescribe = string.Format("{0} 在前面工位有检测NG项", productBind.productBarcode);
                        SetMesQueryStat(this.currentStat.ProductBarcode, 3);        //MES禁止下线
                        //  mesQueryStat.Remove(this.currentStat.ProductBarcode);
                        checkEnable = false;
                        break;
                    }
                    if (!LossCheck(productBind.productBarcode, ref reStr))
                    {
                        if (db1ValsToSnd[0] != db1StatNG)
                        {
                            logRecorder.AddDebugLog(this.nodeName, string.Format("{0} 检测漏项,{1}", productBind.productBarcode, reStr));
                        }
                        currentTaskDescribe = string.Format("{0} 检测漏项,{1}", productBind.productBarcode, reStr);
                        db1ValsToSnd[0]     = db1StatNG;
                        SetMesQueryStat(this.currentStat.ProductBarcode, 3);        //MES禁止下线
                        //mesQueryStat.Remove(this.currentStat.ProductBarcode);
                        checkEnable = false;
                        break;
                    }
                    this.detectStartTime = System.DateTime.Now;
                    logRecorder.AddDebugLog(nodeName, "MES下线查询开始:" + this.currentStat.ProductBarcode);
                    currentTaskDescribe = "MES下线查询开始:" + this.currentStat.ProductBarcode;
                    currentTaskPhase++;
                }
                else
                {
                    currentTaskDescribe = "读RFID卡失败";
                    if (!SysCfgModel.SimMode)
                    {
                        DateTime dtEnd   = DateTime.Now;
                        string   recvStr = (rfidRW as SgrfidRW).GetRecvBufStr();
                        string   logStr  = string.Format("读RFID失败,发送读卡命令:{0},接收判断时间:{1},接收数据:{2}", dtSt.ToString("HH:mm:ss"), dtEnd.ToString("HH:mm:ss"), recvStr);
                        logRecorder.AddDebugLog(nodeName, logStr);
                    }

                    //if (db1ValsToSnd[0] != db1StatRfidFailed)
                    //{
                    //    logRecorder.AddDebugLog(nodeName, "读RFID卡失败");
                    //}
                    db1ValsToSnd[0]               = db1StatRfidFailed;
                    this.currentStat.Status       = EnumNodeStatus.无法识别;
                    this.currentStat.StatDescribe = "读RFID卡失败";

                    break;
                }

                break;
            }

            case 3:
            {
                currentTaskDescribe = "开始查询MES下线是否允许";
                int mesRe = 0;
                if (!SysCfgModel.MesOfflineMode && PLProcessModel.SysCfgModel.MesCheckEnable)
                {
                    mesRe = mesDA.MesAssemDown(new string[] { this.currentStat.ProductBarcode, LineMonitorPresenter.mesLineID }, ref reStr);
                }
                //int mesRe = mesDA.MesAssemDown(new string[] { this.currentStat.ProductBarcode, LineMonitorPresenter.mesLineID }, ref reStr);
                if (0 != mesRe)
                {
                    int      delayTimeOut = SysCfgModel.MesTimeout;   //20;//最多允许延迟10秒
                    TimeSpan timeElapse   = System.DateTime.Now - detectStartTime;
                    if (timeElapse.TotalMilliseconds > delayTimeOut * 1000)
                    {
                        SetMesQueryStat(this.currentStat.ProductBarcode, 3);        //MES禁止下线
                        this.currentStat.StatDescribe = string.Format("{0} :MES预下线查询超时({1}秒),{2}", this.currentStat.ProductBarcode, delayTimeOut, reStr);
                        logRecorder.AddDebugLog(this.nodeName, currentStat.StatDescribe);
                        currentTaskDescribe = "MES下线允许超时";
                        //超时,通知外观检测工位
                        db1ValsToSnd[0] = db1StatNG;
                        checkEnable     = false;
                        break;
                    }
                }
                else
                {
                    logRecorder.AddDebugLog(this.nodeName, string.Format("{0} 下线允许", this.currentStat.ProductBarcode));
                    currentTaskDescribe = "MES下线允许";
                    SetMesQueryStat(this.currentStat.ProductBarcode, 2);

                    //下线,高度配方发完,MES入库
                    if (!MesDatalocalSave(this.currentStat.ProductBarcode, 0, "", "", 1))
                    {
                        logRecorder.AddLog(new LogModel(this.nodeName, "保存检测数据到本地数据库失败", EnumLoglevel.警告));
                        break;
                    }
                    string[] mesProcessSeq = new string[] { "RQ-ZA280" };
                    if (!UploadMesdata(true, this.currentStat.ProductBarcode, mesProcessSeq, ref reStr))
                    {
                        this.currentStat.StatDescribe = "上传MES失败";
                        logRecorder.AddDebugLog(this.nodeName, this.currentStat.StatDescribe);
                        currentTaskDescribe = "上传MES失败";
                        break;
                    }

                    //查询产品高度参数
                    string productTypeCode = "";

                    if (this.currentStat.ProductBarcode.Count() == 26)
                    {
                        productTypeCode = this.currentStat.ProductBarcode.Substring(0, 13);
                    }
                    else
                    {
                        productTypeCode = "";
                    }
                    ProductSizeCfgModel cfg = productCfgBll.GetModel(productTypeCode);
                    if (cfg == null)
                    {
                        db1ValsToSnd[0]               = 32;
                        currentTaskDescribe           = string.Format("产品未配置,物料码{0}", productTypeCode);
                        this.currentStat.StatDescribe = currentTaskDescribe;
                        this.currentStat.Status       = EnumNodeStatus.设备故障;
                        checkEnable = false;

                        break;
                    }
                    //产品高度信息
                    //  ProductHeightDefModel heightDef = productHeightBll.GetModel(cfg.productHeight);
                    if (cfg.baseSizeLevel == null)
                    {
                        cfg.baseSizeLevel = 0;
                    }
                    db1ValsToSnd[33] = (short)cfg.baseSizeLevel;
                    db1ValsToSnd[1]  = short.Parse(cfg.tag1);       //(short)heightDef.heightSeq;
                    graspBegin       = true;
                    currentTaskPhase++;
                }
                break;
            }

            case 4:
            {
                currentTaskDescribe = "等待有板信号复位";
                if (db2Vals[0] != 0)
                {
                    //等待抓起
                    break;
                }
                //解绑
                TryUnbind(this.rfidUID, this.currentStat.ProductBarcode);

                DevCmdReset();         //

                currentTaskDescribe = "等待纸箱信号";
                currentTaskPhase++;
                break;
            }

            case 5:
            {
                //读条码,做校验

                if (db2Vals[1] != 1)         //纸箱到位后才启动条码枪
                {
                    break;
                }
                boxPrepareOK = true;
                //启用自动贴标功能
                if (PLProcessModel.SysCfgModel.PrienterEnable)
                {
                    string boxBarcode = "";
                    if (SysCfgModel.SimMode)
                    {
                        boxBarcode = SimBarcode;
                    }
                    else
                    {
                        boxBarcode = barcodeRW.ReadBarcode();
                    }

                    if (boxBarcode == string.Empty || boxBarcode.Length < 26)
                    {
                        db1ValsToSnd[0] = barcodeCompareFailed;
                        this.currentStat.StatDescribe = "无效的条码,位数不足26位!";
                        currentTaskDescribe           = string.Format("纸箱条码校验错误,无效的条码,位数不足26位{0}", boxBarcode);
                        break;
                    }
                    //校验纸箱条码跟主机条码是否一致
                    if (boxBarcode != this.currentStat.ProductBarcode)
                    {
                        this.currentStat.StatDescribe = "纸箱跟主机条码不同";
                        currentTaskDescribe           = string.Format("纸箱条码校验错误,主机:{0},纸箱{1}", this.currentStat.ProductBarcode, boxBarcode);
                        if (db1ValsToSnd[0] != barcodeCompareFailed)
                        {
                            logRecorder.AddDebugLog(nodeName, currentTaskDescribe);
                        }
                        db1ValsToSnd[0] = barcodeCompareFailed;

                        break;
                    }
                    logRecorder.AddDebugLog(nodeName, "纸箱条码验证通过:" + boxBarcode);
                    currentTaskDescribe = "纸箱条码验证通过:" + boxBarcode;
                }

                currentTaskPhase++;
                break;
            }

            case 6:
            {
                db1ValsToSnd[0] = db1StatCheckOK;         //核对正确,允许搬运
                this.currentStat.StatDescribe = "装箱核对检测完成";
                currentTaskDescribe           = "装箱核对检测完成";
                checkFinished = true;
                currentTaskPhase++;
                break;
            }

            case 7:
            {
                currentTaskDescribe = "等待纸箱信号复位";
                if (db2Vals[1] != 0)
                {
                    break;
                }
                logRecorder.AddDebugLog(nodeName, "入箱完成:" + this.currentStat.ProductBarcode);
                DevCmdReset();
                this.currentStat.StatDescribe = "流程完成";
                currentTaskDescribe           = "入箱完成";
                graspBegin       = false;  //准备新的流程
                boxPrepareOK     = false;
                currentTaskPhase = 1;
                break;
            }

            default:
                break;
            }
            return(true);
        }