Пример #1
0
        public AinuoDetectModel GetDetectResult(ref string reStr)
        {
            try
            {
                if (this.comportObj == null || (!this.comportObj.IsOpen))
                {
                    reStr = "串口未打卡";
                    return(null);
                }
                string strCmd = string.Format("{0}{1}{2}{3}{4}", "{", devAddr.ToString().PadLeft(3, '0'), "0", "00", "}"); //"{015000}";
                recvPhase = 0;
                strCmdRes = "";
                this.comportObj.Write(strCmd);
                int    timeCounter   = 0;
                int    reTryInterval = 100;
                int    timeOut       = 2000;
                string cmdResHead    = string.Format("{0}0", devAddr.ToString().PadLeft(3, '0'));
                while (timeCounter < timeOut)
                {
                    if (recvPhase == 2)
                    {
                        if (strCmdRes.Count() < 191)
                        {
                            reStr = "返回数据长度不足191字符(不包括头尾符)";
                            return(null);
                        }
                        if (strCmdRes.Trim().Substring(0, 4) == cmdResHead)
                        {
                            AinuoDetectModel detectModel = new AinuoDetectModel();
                            if (detectModel.Parse(strCmdRes.Substring(4, 184), ref reStr))
                            {
                                Console.WriteLine("{0}收到数据:{1}", devName, strCmdRes);
                                return(detectModel);
                            }
                            else
                            {
                                return(null);
                            }
                        }
                    }

                    Thread.Sleep(reTryInterval);

                    timeCounter += reTryInterval;
                }
                reStr = "应答超时:2秒,接收数据:" + strCmdRes;
                return(null);
            }
            catch (Exception ex)
            {
                reStr = ex.Message;
                return(null);
            }
        }
Пример #2
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);
        }