コード例 #1
0
 //private ProductHeightDefBll heightDefBll = null;
 //private ProductPacsizeDefBll packsizeDefBll = null;
 //private ProductSizeCfgBll productCfgBll = null;
 #endregion
 #region 公共接口
 // public string CaptionText { get { return captionText; } set { captionText = value; this.Text = captionText; } }
 public ProductDatasheetView(string captionText) : base(captionText)
 {
     InitializeComponent();
     this.Text = captionText;
     //this.captionText = captionText;
     productCfgBll = new ProductSizeCfgBll();
 }
コード例 #2
0
 public ProductDataPresenter(IProductDataSheetView view)
 {
     this.view      = view;
     heightDefBll   = new ProductHeightDefBll();
     packsizeDefBll = new ProductPacsizeDefBll();
     productCfgBll  = new ProductSizeCfgBll();
     gasCfgBll      = new GasConfigBll();
 }
コード例 #3
0
        public override bool ExeBusiness(ref string reStr)
        {
            if (!base.ExeBusiness(ref reStr))
            {
                return(false);
            }
            if (db2Vals[0] == 0)
            {
                if (currentTaskPhase > 2)
                {
                    if (!SysCfgModel.SimMode)
                    {
                        if (!AipuObj.CloseDev(ref reStr))
                        {
                            logRecorder.AddDebugLog(nodeName, "关闭艾普检测设备失败," + reStr);
                        }
                    }
                }
            }
            if (!NodeStatParse(ref reStr))
            {
                return(false);
            }
            //SendPrintcodeFromBuf();

            if (!checkEnable)
            {
                return(true);
            }
            switch (currentTaskPhase)
            {
            case 1:
            {
                checkRe = 0;
                if (!ProcessStartCheck(3, !SysCfgModel.DebugMode))
                {
                    break;
                }

                //发送机器人配方
                ProductSizeCfgBll productCfg = new ProductSizeCfgBll();
                string            cataCode   = this.currentStat.ProductBarcode.Substring(0, 13);
                cfgModel = productCfg.GetModel(cataCode);

                if (cfgModel == null)
                {
                    if (this.db1ValsToSnd[0] != 6)
                    {
                        ThrowErrorStat(string.Format("{0}产品配置信息不存在", this.currentStat.ProductBarcode), EnumNodeStatus.设备故障);
                        // logRecorder.AddDebugLog(nodeName, string.Format("{0}产品配置信息不存在", this.currentStat.ProductBarcode));
                    }
                    this.currentStat.StatDescribe = "配置不存在";
                    checkEnable          = false;
                    this.db1ValsToSnd[0] = 6;
                    return(true);
                }
                this.db1ValsToSnd[2] = (short)cfgModel.robotProg;
                this.currentTaskPhase++;
                break;
            }

            case 2:
            {
                if (!SysCfgModel.SimMode)
                {
                    float frequenze = 50.0f;    // (float)cfgModel.frequency1;
                    float volt      = 233.0f;   // (float)cfgModel.volt1;
                    if (!AipuObj.SetRunningParam(frequenze, volt, ref reStr))
                    {
                        logRecorder.AddDebugLog(nodeName, "设置艾普强档检测参数失败," + reStr);
                        break;
                    }
                    logRecorder.AddDebugLog(nodeName, string.Format("设置艾普强档电压/频率参数,{0}V,{1}HZ", volt, frequenze));
                    //if(!AipuObj.OpenDev(ref reStr))
                    //{
                    //    logRecorder.AddDebugLog(nodeName, "设置艾普强档检测参数失败," + reStr);
                    //    break;
                    //}
                    detectStartTime = System.DateTime.Now;
                }
                logRecorder.AddDebugLog(this.nodeName, this.currentStat.ProductBarcode + "开始检测,启动艾普检测仪");
                this.currentTaskPhase++;
                break;
            }

            case 3:
            {
                float frequenze = 50.0f;    //(float)cfgModel.frequency1;
                float volt      = 220.0f;   //(float)cfgModel.volt2;
                if (!SysCfgModel.SimMode)
                {
                    TimeSpan ts = System.DateTime.Now - detectStartTime;
                    if (ts.TotalSeconds > 10)
                    {
                        //开始切换到弱档参数
                        logRecorder.AddDebugLog(nodeName, string.Format("设置艾普弱档电压/频率参数,{0}V,{1}HZ", volt, frequenze));
                        if (!AipuObj.SetRunningParam(frequenze, volt, ref reStr))
                        {
                            logRecorder.AddDebugLog(nodeName, "设置艾普弱档检测参数失败," + reStr);
                            break;
                        }

                        this.currentTaskPhase++;
                    }
                }
                else
                {
                    logRecorder.AddDebugLog(nodeName, string.Format("设置艾普弱档电压/频率参数,{0}V,{1}HZ", volt, frequenze));
                    this.currentTaskPhase++;
                }

                break;
            }

            case 4:
            {
                currentTaskDescribe = "等待检测结果";
                if (db2Vals[2] == 0)
                {
                    break;
                }

                string detectCodes = "";
                if (db2Vals[2] == 1)
                {
                    //合格
                    checkRe = 0;
                }
                else
                {
                    checkRe     = 1;
                    detectCodes = GetDetectCodeStr();
                    if (string.IsNullOrWhiteSpace(detectCodes))
                    {
                        break;
                    }
                    OutputRecord(this.currentStat.ProductBarcode);
                }
                currentTaskDescribe = "开始保存结果到本地";
                if (!MesDatalocalSave(this.currentStat.ProductBarcode, checkRe, detectCodes, "", 0))
                {
                    logRecorder.AddLog(new LogModel(this.nodeName, "保存检测数据到本地数据库失败", EnumLoglevel.警告));
                    break;
                }

                currentTaskPhase++;
                break;
            }

            case 5:
            {
                currentTaskDescribe = "开始上传结果到MES";
                if (checkRe == 1)
                {
                    if (!UploadMesdata(true, this.currentStat.ProductBarcode, mesProcessSeq, ref reStr))
                    {
                        this.currentStat.StatDescribe = "上传MES失败";
                        logRecorder.AddDebugLog(this.nodeName, this.currentStat.StatDescribe);
                        break;
                    }
                }

                currentTaskPhase++;
                break;
            }

            case 6:
            {
                currentTaskDescribe           = "放行";
                this.currentStat.StatDescribe = "检测完成";
                string checkreStr = "OK";
                if (checkRe == 1)
                {
                    checkreStr      = "NG";
                    db1ValsToSnd[0] = db1StatNG;
                }
                else
                {
                    db1ValsToSnd[0] = db1StatCheckOK;        //允许下线
                }
                logRecorder.AddDebugLog(this.nodeName, this.currentStat.ProductBarcode + "检测完成," + checkreStr);
                this.currentStat.StatDescribe = "下线";
                checkFinished = true;
                currentTaskPhase++;
                break;
            }

            case 7:
            {
                this.currentStat.StatDescribe = "流程完成";
                currentTaskDescribe           = "流程结束";
                break;
            }
            }
            return(true);
        }
コード例 #4
0
        public bool ManualExeBusiness(ref string reStr)
        {
            switch (currentTaskPhase)
            {
            case 1:
            {
                detectCode = "";
                cfgModel   = null;

                if (!ProcessStartCheck(3, !SysCfgModel.DebugMode))
                {
                    break;
                }
                this.currentTask.TaskPhase = this.currentTaskPhase;
                this.currentTask.TaskParam = rfidUID;
                this.ctlTaskBll.Update(this.currentTask);
                ProductSizeCfgBll productCfg = new ProductSizeCfgBll();
                string            cataCode   = this.currentStat.ProductBarcode.Substring(0, 13);
                cfgModel = productCfg.GetModel(cataCode);
                if (cfgModel == null)
                {
                    if (this.db1ValsToSnd[0] != 6)
                    {
                        ThrowErrorStat(string.Format("{0}产品配置信息不存在", this.currentStat.ProductBarcode), EnumNodeStatus.设备故障);
                        // logRecorder.AddDebugLog(nodeName, string.Format("{0}产品配置信息不存在", this.currentStat.ProductBarcode));
                    }
                    this.currentStat.StatDescribe = "配置不存在";
                    checkEnable          = false;
                    this.db1ValsToSnd[0] = 6;
                    return(true);
                }
                logRecorder.AddDebugLog(this.nodeName, this.currentStat.ProductBarcode + "开始检测");
                this.db1ValsToSnd[2] = (short)cfgModel.robotProg;
                this.currentTaskPhase++;
                this.currentTask.TaskPhase = this.currentTaskPhase;
                this.ctlTaskBll.Update(this.currentTask);
                break;
            }

            case 2:
            {
                //等待人工检测完毕,
                this.currentStat.StatDescribe = "等待人工检测完成";
                this.currentTaskDescribe      = "等待人工检测完成";
                if (this.db2Vals[2] != 1)
                {
                    break;
                }
                currentTaskDescribe = "开始查询安规结果";
                DevAccess.AinuoDetectModel detectModel = null;
                string strDetectVal = "";
                if (SysCfgModel.SimMode)
                {
                    detectModel = GenerateSimDetect();
                    //currentTaskDescribe = "开始保存本地检测结果";
                    //checkRe = 0;
                    //if (!MesDatalocalSave(this.currentStat.ProductBarcode, checkRe, detectCode, "", 0))
                    //{
                    //    Console.WriteLine(string.Format("{0}保存检测数据到本地数据库失败", nodeName));
                    //    break;
                    //}
                }
                else
                {
                    detectModel = AinuoObj.GetDetectResult(ref reStr);
                    //if (detectModel == null)
                    //{
                    //    TimeSpan timeElapse = System.DateTime.Now - detectStartTime;
                    //    if (timeElapse.TotalMilliseconds < detectTimeout)
                    //    {
                    //        break;
                    //    }
                    //    else
                    //    {
                    //        detectStartTime = System.DateTime.Now;
                    //        logRecorder.AddDebugLog(this.nodeName, string.Format("检测超时,{0}毫秒,重新检测", detectTimeout));
                    //        currentStat.StatDescribe = string.Format("检测超时");
                    //    }
                    //}
                }
                if (detectModel == null)
                {
                    logRecorder.AddDebugLog(nodeName, this.currentStat.ProductBarcode + "检测超时,无数据," + reStr);
                    ThreadBaseModel.Sleep(1000);
                    break;
                }
                float designPower = float.Parse(cfgModel.power1);
                if (!GetDetectResult(this.currentStat.ProductBarcode, detectModel, designPower, ref detectCode, ref strDetectVal, ref checkRe))
                {
                    ThreadBaseModel.Sleep(1000);
                    break;
                }
                //if (!SysCfgModel.SimMode)
                //{
                //    if (!AinuoObj.CloseDev(ref reStr))
                //    {
                //        logRecorder.AddDebugLog(nodeName, this.currentStat.ProductBarcode + "关闭艾诺检测设备失败," + reStr);
                //        break;
                //    }
                //}

                currentTaskDescribe = "开始保存本地检测结果";
                if (!string.IsNullOrWhiteSpace(detectCode))
                {
                    if (detectCode.Substring(detectCode.Length - 1, 1) == ",")
                    {
                        detectCode = detectCode.Remove(detectCode.Length - 1, 1);
                    }
                    logRecorder.AddDebugLog(nodeName, this.currentStat.ProductBarcode + "故障码:" + detectCode);
                }
                if (checkRe > 0)
                {
                    OutputRecord(this.currentStat.ProductBarcode);
                }
                if (!MesDatalocalSave(this.currentStat.ProductBarcode, checkRe, detectCode, strDetectVal, 0))
                {
                    Console.WriteLine(string.Format("{0}保存检测数据到本地数据库失败", nodeName));
                    break;
                }
                this.currentTaskPhase++;
                this.currentTask.TaskPhase = this.currentTaskPhase;
                this.ctlTaskBll.Update(this.currentTask);
                break;
            }

            case 3:
            {
                string checkReStr = "OK";
                if (this.nodeID == "2001")
                {
                    if (checkRe == 1)
                    {
                        //安规1检测完成NG后上传数据
                        if (!UploadMesdata(true, this.currentStat.ProductBarcode, mesProcessSeq, ref reStr))
                        {
                            this.currentStat.StatDescribe = "上传MES失败";
                            logRecorder.AddDebugLog(this.nodeName, this.currentStat.StatDescribe);
                            break;
                        }
                    }
                }
                else
                {
                    //安规1检测完成若合格后不上传数据
                    if (!UploadMesdata(true, this.currentStat.ProductBarcode, mesProcessSeq, ref reStr))
                    {
                        this.currentStat.StatDescribe = "上传MES失败";
                        logRecorder.AddDebugLog(this.nodeName, this.currentStat.StatDescribe);
                        break;
                    }
                }

                currentTaskDescribe = "放行";
                if (checkRe == 1)
                {
                    db1ValsToSnd[0] = db1StatNG;
                    checkReStr      = "NG";
                }
                else
                {
                    db1ValsToSnd[0] = db1StatCheckOK;
                }
                logRecorder.AddDebugLog(this.nodeName, this.currentStat.ProductBarcode + "检测完成," + checkReStr);
                this.currentStat.StatDescribe = "安规检测完成," + checkReStr;
                checkFinished = true;
                currentTaskPhase++;
                this.currentTask.TaskPhase = this.currentTaskPhase;
                this.ctlTaskBll.Update(this.currentTask);
                break;
            }

            case 4:
            {
                //流程结束
                this.currentStat.StatDescribe = "流程完成";
                currentTaskDescribe           = "流程结束";
                // this.currentTaskPhase++;
                break;
            }
            }
            return(true);
        }
コード例 #5
0
        // int tempCounter = 0;
        public override bool ExeBusiness(ref string reStr)
        {
            try
            {
                if (!base.ExeBusiness(ref reStr))
                {
                    return(false);
                }
                if (!NodeStatParse(ref reStr))
                {
                    return(false);
                }
                if (!checkEnable)
                {
                    return(true);
                }
                if (this.currentTask == null)
                {
                    return(true);
                }
                switch (this.currentTaskPhase)
                {
                case 1:
                {
                    db1ValsToSnd[1] = 1;        //流程锁定
                    if (this.currentStat.Status == EnumNodeStatus.设备故障)
                    {
                        break;
                    }

                    this.currentStat.Status         = EnumNodeStatus.设备使用中;
                    this.currentStat.ProductBarcode = "";
                    this.currentStat.StatDescribe   = "设备使用中";

                    //读条码,rfid,绑定

                    currentTaskDescribe = "开始读RFID";
                    DateTime dtSt = System.DateTime.Now;
                    if (string.IsNullOrWhiteSpace(rfidUID))
                    {
                        if (SysCfgModel.SimMode)
                        {
                            rfidUID = this.SimRfidUID;
                        }
                        else
                        {
                            rfidUID = rfidRW.ReadUID();
                        }
                    }

                    if (string.IsNullOrEmpty(rfidUID))
                    {
                        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 (!rfidTimeCounterBegin)
                        {
                            //logRecorder.AddDebugLog(nodeName, "读RFID卡失败");
                            rfidFailSt = System.DateTime.Now;
                        }
                        rfidTimeCounterBegin = true;
                        TimeSpan ts = System.DateTime.Now - rfidFailSt;
                        if (ts.TotalSeconds > 5)
                        {
                            if (db1ValsToSnd[0] != db1StatRfidFailed)
                            {
                                logRecorder.AddDebugLog(nodeName, "读RFID卡失败");
                            }
                            db1ValsToSnd[0] = db1StatRfidFailed;
                        }
                        this.currentStat.StatDescribe = "读RFID卡失败!";
                        break;
                    }
                    else
                    {
                        rfidTimeCounterBegin = false;
                    }
                    this.currentTaskPhase++;
                    this.currentTask.TaskPhase = this.currentTaskPhase;
                    this.currentTask.TaskParam = rfidUID;
                    this.barcodeRW.ClearBarcodesBuf();         //清空条码枪缓存
                    this.ctlTaskBll.Update(this.currentTask);
                    break;
                }

                case 2:
                {
                    currentTaskDescribe = "开始读条码";
                    string barcode = barcodeRW.ReadBarcode().Trim();
                    if (string.IsNullOrWhiteSpace(barcode) || barcode.Length != 26)
                    {
                        if (!rfidTimeCounterBegin)
                        {
                            //logRecorder.AddDebugLog(nodeName, "读RFID卡失败");
                            rfidFailSt = System.DateTime.Now;
                        }
                        rfidTimeCounterBegin = true;
                        TimeSpan ts = System.DateTime.Now - rfidFailSt;
                        if (ts.TotalSeconds > 5)
                        {
                            if (db1ValsToSnd[0] != 3)
                            {
                                logRecorder.AddDebugLog(nodeName, "读条码失败:" + barcode);
                            }
                            db1ValsToSnd[0] = 3;
                            if (!string.IsNullOrWhiteSpace(barcode))
                            {
                                this.currentStat.StatDescribe   = "无效的条码,位数不足26位!";
                                this.currentStat.ProductBarcode = this.currentStat.StatDescribe;
                                currentTaskDescribe             = this.currentStat.StatDescribe;
                            }
                            else
                            {
                                this.currentStat.StatDescribe   = "读条码失败!";
                                this.currentStat.ProductBarcode = "读条码失败!";
                                currentTaskDescribe             = "读条码失败!";
                            }
                        }
                        break;
                    }

                    //db1赋条码
                    BarcodeFillDB1(barcode, 2);
                    currentStat.ProductBarcode = barcode;
                    ProductSizeCfgBll   productCfg = new ProductSizeCfgBll();
                    string              cataCode   = barcode.Substring(0, 13);
                    ProductSizeCfgModel cfgModel   = productCfg.GetModel(cataCode);
                    if (cfgModel == null)
                    {
                        if (this.db1ValsToSnd[0] != 4)
                        {
                            // ThrowErrorStat(string.Format("{0}产品配置信息不存在", this.currentStat.ProductBarcode), EnumNodeStatus.设备故障);
                            logRecorder.AddDebugLog(nodeName, string.Format("{0}产品配置信息不存在", this.currentStat.ProductBarcode));
                        }
                        this.currentStat.StatDescribe = "配置不存在";
                        //  checkEnable = false;
                        this.db1ValsToSnd[0] = 4;
                        break;
                        //return true;
                    }

                    // 若已经存在,则解绑
                    if (!TryUnbind(rfidUID, barcode))
                    {
                        string strLog = string.Format("解绑错误,RFID:{0},主机条码:{1}", rfidUID, barcode);
                        logRecorder.AddDebugLog(this.nodeName, strLog);
                        currentTaskDescribe = strLog;
                        break;
                    }
                    ClearLoacalMesData(barcode);

                    //数据库绑定
                    if (onlineProductBll.Exists(barcode))
                    {
                        logRecorder.AddDebugLog(nodeName, "已经存在:" + barcode + ",删除");
                        onlineProductBll.Delete(barcode);
                    }

                    OnlineProductsModel productBind = new OnlineProductsModel();
                    productBind.rfidCode       = rfidUID;
                    productBind.productBarcode = barcode;
                    productBind.currentNode    = this.nodeName;
                    productBind.inputTime      = System.DateTime.Now;
                    onlineProductBll.Add(productBind);
                    string logStr = string.Format("产品绑定完成,RFID UID:{0},整机条码:{1}", rfidUID, barcode);
                    logRecorder.AddDebugLog(nodeName, logStr);

                    //先存本地,再MES投产
                    if (SysCfgModel.MesAutodownEnabled)
                    {
                        if (!MesDatalocalSave(barcode, 0, "", "", 0))
                        {
                            return(false);
                        }
                    }
                    AddInputRecord(barcode);
                    currentTaskDescribe = "产品绑定完成,等待MES投产";


                    this.currentTaskPhase++;
                    this.currentTask.TaskParam = this.rfidUID + "," + barcode;
                    this.currentTask.TaskPhase = this.currentTaskPhase;
                    this.ctlTaskBll.Update(this.currentTask);
                    break;
                }

                case 3:
                {
                    //MES投产
                    if (SysCfgModel.MesAutodownEnabled)
                    {
                        if (!UploadMesdata(true, this.currentStat.ProductBarcode, new string[] { this.mesNodeID }, ref reStr))
                        {
                            this.currentStat.StatDescribe = "MES投产失败";
                            logRecorder.AddDebugLog(this.nodeName, this.currentStat.StatDescribe);
                            break;
                        }
                        currentTaskDescribe = "MES投产完成";
                    }

                    this.currentTaskPhase++;
                    this.currentTask.TaskPhase = this.currentTaskPhase;
                    this.ctlTaskBll.Update(this.currentTask);
                    db1ValsToSnd[0] = db1StatCheckOK;
                    break;
                }

                case 4:
                {
                    //流程完成
                    this.currentStat.StatDescribe = "流程完成";
                    currentTaskDescribe           = "流程完成";
                    this.currentTask.TaskStatus   = EnumTaskStatus.已完成.ToString();
                    this.currentTask.TaskPhase    = this.currentTaskPhase;
                    this.ctlTaskBll.Update(this.currentTask);
                    this.currentTask = null;
                    break;
                }

                default:
                    break;
                }
                //     this.currentStat.StatDescribe = "流程步号:" + currentTaskPhase.ToString();
                return(true);
            }
            catch (Exception ex)
            {
                ThrowErrorStat(ex.ToString(), EnumNodeStatus.设备故障);
                return(false);
            }
        }
コード例 #6
0
ファイル: LineMonitorPresenter.cs プロジェクト: zwxscu/ZAOJU3
        public bool Init(ref string reStr)
        {
            try
            {
                localMesBasebll   = new LOCAL_MES_STEP_INFOBll();
                localMesDetailbll = new LOCAL_MES_STEP_INFO_DETAILBll();
                productCfgBll     = new ProductSizeCfgBll();
                LineNodes.NodeFactory nodeFactory = new LineNodes.NodeFactory();


                if (!nodeFactory.ConfigInit(ref reStr))
                {
                    return(false);
                }
                this.plcRWs       = nodeFactory.PlcRWList;
                this.rfidRWs      = nodeFactory.RfidRWList;
                this.barcodeRWs   = nodeFactory.BarcodeRWList;
                this.airDetectRWs = nodeFactory.AirDetectRWList;
                this.printerRWs   = nodeFactory.PrinterRWList;
                this.nodeList     = nodeFactory.GetNodes(ref reStr);
                this.threadList   = nodeFactory.GetThreadAlloc(ref reStr);
                foreach (ThreadBaseModel threadObj in this.threadList)
                {
                    threadObj.LogRecorder = logRecorder;
                }
                //  this.threadList = new List<ThreadRunModel>();

                ////线程1
                //ThreadRunModel threadObj = new ThreadRunModel(1, "线程1:" );
                //threadObj.LoopInterval = 100;
                //threadObj.LogRecorder = logRecorder;
                //threadObj.AddNode(node);
                //if (!threadObj.TaskInit(ref reStr))
                //{
                //    Console.WriteLine(reStr);
                //}
                //this.threadList.Add(threadObj);

                //线程2

                //for (int i = 0; i < nodeList.Count(); i++)
                //{
                //    CtlNodeBaseModel node = nodeList[i];

                //    ThreadRunModel threadObj = new ThreadRunModel(i + 1, "线程:" + node.NodeName);
                //    threadObj.LoopInterval = 100;

                //    threadObj.LogRecorder = logRecorder;
                //    threadObj.AddNode(node);
                //    if (!threadObj.TaskInit(ref reStr))
                //    {
                //        Console.WriteLine(reStr);
                //    }
                //    this.threadList.Add(threadObj);
                //}

                //for (int i = 0; i < nodeList.Count(); i++)
                //{
                //    CtlNodeBaseModel node = nodeList[i];
                //    node.PlcRW = this.plcRWs[0];
                //    node.SimMode = NodeFactory.SimMode;
                //}

                if (!NodeFactory.SimMode)
                {
                    CommDevConnect();//通信设备连接
                }

                this.nodeStatusList = new List <CtlNodeStatus>();
                svcNodeStatusList   = new List <MonitorSvcNodeStatus>();
                foreach (CtlNodeBaseModel node in this.nodeList)
                {
                    this.nodeStatusList.Add(node.CurrentStat);
                    node.LogRecorder = logRecorder;
                    MonitorSvcNodeStatus svcStat = new MonitorSvcNodeStatus();
                    svcStat.NodeName       = node.NodeName;
                    svcStat.ProductBarcode = node.CurrentStat.ProductBarcode;
                    svcStat.StatDescribe   = node.CurrentStat.StatDescribe;
                    svcStat.Status         = node.CurrentStat.Status.ToString();
                    svcNodeStatusList.Add(svcStat);
                }

                mainThread = new ThreadBaseModel(1, "业务线程");
                mainThread.LoopInterval = 10;
                mainThread.SetThreadRoutine(new DelegateThreadRoutine(BusinessLoop));
                if (!mainThread.TaskInit(ref reStr))
                {
                    logRecorder.AddLog(new LogModel(objectName, reStr, EnumLoglevel.错误));

                    return(false);
                }


                historyDataClearThread = new ThreadBaseModel(2, "日志清理线程");
                historyDataClearThread.LoopInterval = 60000;//1分钟清理一次
                historyDataClearThread.SetThreadRoutine(ClearLogLoop);
                if (!historyDataClearThread.TaskInit(ref reStr))
                {
                    logRecorder.AddLog(new LogModel(objectName, reStr, EnumLoglevel.错误));
                }
                printerLoopThread = new ThreadBaseModel(3, "贴标队列处理线程");
                printerLoopThread.LoopInterval = 500;//500
                printerLoopThread.SetThreadRoutine(PrinterQueueLoop);
                printerLoopThread.TaskInit(ref reStr);
                //   Console.WriteLine("P1");

                view.InitNodeMonitorview(this.nodeList);
                //   Console.WriteLine("P2");
                //宿主WCF服务
                Uri                 _baseAddress = new Uri("http://localhost:8733/ZZ/LineNodes/NodeMonitorSvc/");
                EndpointAddress     _Address     = new EndpointAddress(_baseAddress);
                BasicHttpBinding    _Binding     = new BasicHttpBinding();
                ContractDescription _Contract    = ContractDescription.GetContract(typeof(LineNodes.INodeMonitorSvc));
                ServiceEndpoint     endpoint     = new ServiceEndpoint(_Contract, _Binding, _Address);
                NodeMonitorSvc      monitorSvc   = new NodeMonitorSvc();

                monitorSvc.dlgtNodeStatus += GetSvcNodeStatus;
                monitorSvc.dlgtRunningDev += GetRunningDetectdevs;

                ServiceHost host = new ServiceHost(monitorSvc, _baseAddress);
                //添加终结点ABC
                host.Description.Endpoints.Add(endpoint);
                //启用元数据交换
                ServiceMetadataBehavior meta = new ServiceMetadataBehavior();

                meta.HttpGetEnabled = true;
                host.Description.Behaviors.Add(meta);
                host.Open();
                //  Console.WriteLine("P3");
                return(true);
            }
            catch (Exception ex)
            {
                view.PopupMes(ex.ToString());
                return(false);
            }
        }
コード例 #7
0
ファイル: NodeAirlossCheck.cs プロジェクト: zwxscu/ZAOJU3
        public override bool ExeBusiness(ref string reStr)
        {
            // int nodeStatus = 0; //状态机,0:初始化状态,1:有板进入,2:插头就绪,开始检测,3:检测完成,报警或放行,4:空板进入,放行
            if (!NodeStatParse(ref reStr))
            {
                return(false);
            }
            if (!checkEnable)
            {
                return(true);
            }
            switch (currentTaskPhase)
            {
            case 1:
            {
                DevCmdReset();
                rfidUID = string.Empty;
                this.currentStat.Status         = EnumNodeStatus.设备空闲;
                this.currentStat.ProductBarcode = "";
                this.currentStat.StatDescribe   = "设备空闲";
                checkFinished = false;

                currentTaskDescribe = "等待有板信号";
                break;
            }

            case 2:
            {
                checkRetryCounter = 0;

                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.currentTaskPhase = 5;
                        this.currentStat.StatDescribe = "未投产";
                        logRecorder.AddDebugLog(nodeName, "未投产,rfid:" + rfidUID);
                        checkEnable = false;
                        break;
                    }
                    //状态赋条码,
                    this.currentStat.ProductBarcode = productBind.productBarcode;

                    productBind.currentNode = this.nodeName;
                    productBindBll.Update(productBind);
                    string              cataCode      = productBind.productBarcode.Substring(0, 13);
                    ProductSizeCfgBll   productCfgBll = new ProductSizeCfgBll();
                    ProductSizeCfgModel m             = productCfgBll.GetModel(cataCode);
                    if (m == null)
                    {
                        this.ThrowErrorStat(productBind.productBarcode + "产品型号配置不存在", EnumNodeStatus.设备故障);
                        this.currentStat.StatDescribe = "无配置信息:" + cataCode;
                        checkEnable = false;
                        break;
                    }
                    if (m.baseSizeLevel == null)
                    {
                        m.baseSizeLevel = 0;
                    }
                    this.db1ValsToSnd[32] = (short)m.baseSizeLevel;
                    BarcodeFillDB1(productBind.productBarcode, 1);
                    int reDetectQuery = ReDetectQuery(productBind.productBarcode);
                    if (0 == reDetectQuery)
                    {
                        db1ValsToSnd[0] = db1StatCheckOK;
                        checkEnable     = false;
                        logRecorder.AddDebugLog(nodeName, string.Format("{0}本地已经存在检验记录,检验结果:OK", productBind.productBarcode));
                        break;
                    }
                    else if (1 == reDetectQuery)
                    {
                        db1ValsToSnd[0] = db1StatNG;
                        checkEnable     = false;
                        logRecorder.AddDebugLog(nodeName, string.Format("{0}本地已经存在检验记录,检验结果:NG", productBind.productBarcode));
                        break;
                    }

                    //查询本地数据库,之前工位是否有不合格项,若有,下线
                    // if (LineMonitorPresenter.checkPreStation)
                    {
                        if (!PreDetectCheck(productBind.productBarcode))
                        {
                            db1ValsToSnd[0] = db1StatNG;         //
                            logRecorder.AddDebugLog(this.nodeName, string.Format("{0} 在前面工位有检测NG项", productBind.productBarcode));
                            checkEnable = false;

                            break;
                        }
                    }

                    if (!LossCheck(productBind.productBarcode, ref reStr))
                    {
                        db1ValsToSnd[0] = db1StatNG;         //
                        logRecorder.AddDebugLog(this.nodeName, string.Format("{0} 检测漏项,{1}", productBind.productBarcode, reStr));
                        checkEnable = false;

                        break;
                    }
                }
                else
                {
                    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;
                }
                currentTaskPhase++;

                break;
            }

            case 3:
            {
                //插头就绪
                currentTaskDescribe = "等待插头就绪";
                if (db2Vals[1] == 1)
                {
                    db1ValsToSnd[31] = 1;        //流程锁定
                    //开始检测
                    currentTaskDescribe = "开始发送启动气密仪命令";
                    if (!airDetectRW.StartDetect(ref reStr))
                    {
                        //logRecorder.AddLog()
                        ThrowErrorStat("启动气密检测仪失败" + reStr, EnumNodeStatus.设备故障);
                        break;
                    }
                    this.currentStat.StatDescribe = "开始气密检测";
                    logRecorder.AddDebugLog(this.nodeName, this.currentStat.ProductBarcode + "开始检测");
                    currentTaskPhase++;
                    detectStartTime = DateTime.Now;
                }
                break;
            }

            case 4:
            {
                //查询检测结果,检测完成或超时
                currentTaskDescribe = "开始查询气密结果";
                AirlossDetectModel detectRe = null;
                detectRe = airDetectRW.QueryResultData(ref reStr);

                if (detectRe != null)
                {
                    // int checkRe = 0;  //0合格,1:不合格
                    if (detectRe.DetectResult == "OK")
                    {
                        //db1ValsToSnd[0] = db1StatCheckOK; //所有数据都上传之后再给放行信号
                        checkRe = 0;
                    }
                    else
                    {
                        checkRe = 1;
                        // db1ValsToSnd[0] = db1StatNG;

                        //检测不合格,下线
                        OutputRecord(this.currentStat.ProductBarcode);
                    }
                    //先存到本地数据库
                    checkCode = "";
                    if (checkRe > 0)
                    {
                        checkCode = this.detectCode;
                    }
                    else
                    {
                        checkCode = "";
                    }
                    currentTaskDescribe = "开始保存本地气密结果";
                    logRecorder.AddDebugLog(this.nodeName, string.Format("{0}检测数据,{1},{2},{3}", this.currentStat.ProductBarcode, detectRe.DetectVal.ToString(), detectRe.UnitDesc, detectRe.DetectResult));
                    if (!MesDatalocalSave(this.currentStat.ProductBarcode, checkRe, checkCode, detectRe.DetectVal.ToString(), 0))
                    {
                        logRecorder.AddLog(new LogModel(this.nodeName, "保存检测数据到本地数据库失败", EnumLoglevel.警告));
                        break;
                    }

                    currentTaskPhase++;
                }
                else
                {
                    TimeSpan timeElapse = System.DateTime.Now - detectStartTime;
                    if (timeElapse.TotalMilliseconds > detectTimeout)
                    {
                        detectStartTime = System.DateTime.Now;
                        logRecorder.AddDebugLog(this.nodeName, string.Format("检测超时,{0}毫秒,重新检测", detectTimeout));
                        currentStat.StatDescribe = string.Format("检测超时,重新检测");
                        if (checkRetryCounter < 2)
                        {
                            airDetectRW.StartDetect(ref reStr);
                        }

                        checkRetryCounter++;
                    }
                    if (checkRetryCounter > 2)
                    {
                        currentTaskDescribe = "气密超时,开始保存本地气密结果";
                        if (!MesDatalocalSave(this.currentStat.ProductBarcode, checkRe, checkCode, "0", 0))
                        {
                            logRecorder.AddLog(new LogModel(this.nodeName, "保存检测数据到本地数据库失败", EnumLoglevel.警告));
                            break;
                        }
                        checkRe         = 1;//超时
                        db1ValsToSnd[0] = db1StatNG;
                        logRecorder.AddDebugLog(this.nodeName, string.Format("检测超时,{0}毫秒", detectTimeout));
                        currentStat.StatDescribe = string.Format("检测超时,{0}毫秒", detectTimeout);
                        currentTaskPhase++;
                        break;
                    }
                }

                break;
            }

            case 5:
            {
                string[] mesProcessSeq = new string[] { "RQ-ZA230", "RQ-ZA240", "RQ-ZA220" };
                //string[] mesProcessSeq = new string[] { this.mesNodeID};
                currentTaskDescribe = "开始上传检测结果(气密2工位NG时才上传)";
                if (this.nodeID == "2002")
                {
                    //气密2,3要求合并,若当前为气密2,则检测NG时立即上传
                    if (1 == checkRe)
                    {
                        if (!UploadMesdata(true, this.currentStat.ProductBarcode, mesProcessSeq, ref reStr))
                        {
                            this.currentStat.StatDescribe = "上传MES失败";
                            logRecorder.AddDebugLog(this.nodeName, this.currentStat.StatDescribe);
                            break;
                        }
                    }
                }
                else
                {
                    if (!UploadMesdata(true, this.currentStat.ProductBarcode, mesProcessSeq, ref reStr))
                    {
                        this.currentStat.StatDescribe = "上传MES失败";
                        logRecorder.AddDebugLog(this.nodeName, this.currentStat.StatDescribe);
                        break;
                    }
                }

                string checkReStr = "OK";
                currentTaskDescribe = "放行";
                if (checkRe == 1)
                {
                    db1ValsToSnd[0] = db1StatNG;
                    checkReStr      = "NG";
                }
                else
                {
                    db1ValsToSnd[0] = db1StatCheckOK;
                }
                logRecorder.AddDebugLog(this.nodeName, this.currentStat.ProductBarcode + "检测完成," + checkReStr);
                this.currentStat.StatDescribe = "气密检测完成," + checkReStr;
                checkFinished = true;
                currentTaskPhase++;

                break;
            }

            case 6:
            {
                //流程结束
                this.currentStat.StatDescribe = "流程完成";
                currentTaskDescribe           = "流程结束";
                // this.currentTaskPhase++;
                break;
            }
            }
            return(true);
        }