Exemplo n.º 1
0
        public void AddNgModule(ScrewNGModule ngMod)
        {
            List <ScrewNGModule> ngMods = this.NGModules.FindAll(n => n.ChannelIndex == ngMod.ChannelIndex && n.ModPos == ngMod.ModPos);

            logRecorder.AddDebugLog("A线锁螺丝", "添加数据通道:" + ngMod.ChannelIndex + ",位置:" + ngMod.ModPos);
            if (ngMods == null || ngMods.Count == 0)
            {
                logRecorder.AddDebugLog("A线锁螺丝", "添加成功:" + ngMod.ChannelIndex + "-" + ngMod.ModPos);
                this.NGModules.Add(ngMod);
            }
        }
Exemplo n.º 2
0
        protected bool ExeBindA(ref string reStr)
        {
            if (!nodeEnabled)
            {
                return(true);
            }
            if (!ExeBusinessAB(ref reStr))
            {
                return(false);
            }
            switch (currentTaskPhase)
            {
            case 1:
            {
                if (!RfidReadAB())
                {
                    break;
                }
                this.screwNgHandler = new ScrewNGHandler(this.plcRW, this.plcRW2, this.channelIndex, this.logRecorder);

                bool needReparid = false;
                if (this.repairProcess.GetNeedRepairALine(this.rfidUID, this.NodeID, ref needReparid, ref reStr) == false)
                {
                    this.logRecorder.AddDebugLog(this.nodeName, "获取返修状态失败:" + reStr);
                    break;
                }
                this.logRecorder.AddDebugLog(this.nodeName, "获取返修状态成功:" + needReparid + "," + reStr);
                if (needReparid == false)
                {
                    currentTaskPhase = 9;        //直接放行
                    this.TxtLogRecorder.WriteLog("工艺流程当前工位不需要加工,直接放行,工装板号:" + this.rfidUID);
                    this.repairProcess.ReportToMesByProcessStationID(this.nodeID, this.rfidUID);
                    break;
                }

                this.currentTask.TaskParam = rfidUID;
                this.currentTask.TaskPhase = this.currentTaskPhase;
                this.ctlTaskBll.Update(this.currentTask);
                //db1ValsToSnd[1] = 2;//


                if (!ProductTraceRecord())
                {
                    break;
                }
                currentTaskPhase++;
                this.TxtLogRecorder.WriteLog("工位流程开始加工!");
                this.currentTask.TaskPhase = this.currentTaskPhase;
                this.ctlTaskBll.Update(this.currentTask);
                break;
            }

            case 2:
            {
                List <DBAccess.Model.BatteryModuleModel> modList = modBll.GetModelList(string.Format("palletID='{0}' and palletBinded=1", this.rfidUID));

                if (!PreMech(modList, ref reStr))
                {
                    Console.WriteLine(string.Format("{0},{1}", nodeName, reStr));
                    break;
                }
                if (modList.Count() < 1)
                {
                    currentTaskPhase = 6;
                    break;
                }
                currentTaskPhase++;
                this.currentTask.TaskPhase = this.currentTaskPhase;
                this.ctlTaskBll.Update(this.currentTask);
                break;
            }

            case 3:
            {
                //发送启动加工命令
                //int channelIndex = 1;
                //if (this.db2Vals[0] == 1 || this.db2Vals[0] == 2)
                //{
                //    channelIndex = this.db2Vals[0];
                //}
                //else
                //{
                //    this.currentTaskDescribe = "通道号无效!";
                //    break;
                //}
                List <DBAccess.Model.BatteryModuleModel> modList = modBll.GetModelList(string.Format("palletID='{0}' and palletBinded=1", this.rfidUID));
                if (modList.Count() < 1)
                {
                    this.db1ValsToSnd[channelIndex - 1] = 4;
                    currentTaskPhase = 5;
                    break;
                }
                List <string> products = new List <string>();
                Thread.Sleep(2000);        //延时10秒等待下边设备
                foreach (DBAccess.Model.BatteryModuleModel m in modList)
                {
                    products.Add(m.batModuleID);
                }
                if (!SysCfgModel.SimMode)
                {
                    if (products.Count() > 0)
                    {
                        if (ccdDevAcc != null)
                        {
                            if (!ccdDevAcc.StartDev(products, ccdDevName, ref reStr))
                            {
                                this.currentTaskDescribe = "发送设备加工启动命令失败:" + reStr;
                                //Console.WriteLine(string.Format("{0}发送设备加工启动命令失败,{1}", nodeName, reStr));
                                break;
                            }
                            else
                            {
                                logRecorder.AddDebugLog(nodeName, "发送设备加工启动命令成功");
                            }
                        }
                    }
                }
                devOpenSt = System.DateTime.Now;
                currentTaskPhase++;
                this.currentTask.TaskPhase = this.currentTaskPhase;
                this.ctlTaskBll.Update(this.currentTask);
                break;
            }

            case 4:
            {
                #region 原来上传MES逻辑
                //System.DateTime cur = System.DateTime.Now;
                //TimeSpan ts = cur - devOpenSt;
                //if (ts.TotalSeconds < 30)
                //{
                //    break;
                //}
                //IDictionary<string, string> ccdDataDic = ccdDevAcc.GetData(ccdDevName, ref reStr);
                //if (ccdDataDic == null || ccdDataDic.Keys.Count() < 1)
                //{
                //    //Console.WriteLine(string.Format("{0}获取CCD{1}数据失败,{2}",nodeName,ccdDevName,reStr));
                //    this.currentTaskDescribe = string.Format("获取CCD{0}数据失败,{1}", ccdDevName, reStr);
                //    break;
                //}
                //foreach (string keyStr in ccdDataDic.Keys)
                //{
                //    string str = string.Format("CCD数据,产品ID:{0},数据:{1}", keyStr, ccdDataDic[keyStr]);
                //    logRecorder.AddDebugLog(nodeName, str);
                //    AddProcessRecord(keyStr, "模块", "检测数据", string.Format("读取到{0}检测数据", ccdDevName), ccdDataDic[keyStr]);
                //    string upLoadMesScrewData = "";
                //    if (GetScrewData(ccdDataDic[keyStr], ref upLoadMesScrewData) == false)
                //    {

                //        logRecorder.AddDebugLog(nodeName, "CCD数据格式错误!无法转换为MES需要格式!");
                //        continue;
                //    }
                //    if (UploadMesScrewData(keyStr, upLoadMesScrewData) == false)
                //    {
                //        logRecorder.AddDebugLog(nodeName, "上传MES锁螺丝数据失败!");
                //        continue;
                //    }
                //    logRecorder.AddDebugLog(nodeName, "上传MES锁螺丝数据成功!");
                //}
                #endregion
                //==更改为读取数据库形式,根据模块条码获取数据,判断所有条码的数据上传成功后执行下一步======//
                int readDataApply = 0;
                Console.WriteLine("sd1");
                bool isScrewCpt = false;                                                                          //所有螺丝加工完成标识
                List <DBAccess.Model.BatteryModuleModel> modList       = modBll.GetModelList(string.Format("palletID='{0}' and palletBinded=1", this.rfidUID));
                List <DBAccess.Model.BatteryModuleModel> uploadModList = modList.FindAll(mod => mod.tag3 == "1"); //查询已经上传的条码,上传的为1,没有的为0或为空
                if (uploadModList != null && uploadModList.Count == modList.Count)
                {
                    isScrewCpt = true;
                }

                Console.WriteLine("sd2");
                if (isScrewCpt == true)
                {
                    currentTaskPhase++;
                    this.currentTask.TaskPhase = this.currentTaskPhase;
                    this.ctlTaskBll.Update(this.currentTask);
                    break;
                }
                Console.WriteLine("sd3");
                if (this.plcRW2.ReadDB("D9000", ref readDataApply) == false)
                {
                    break;
                }
                Console.WriteLine("sd4");
                if (readDataApply != 1)
                {
                    break;
                }

                Console.WriteLine("sd5");
                List <DBAccess.Model.BatteryModuleModel> unUploadModList = modList.FindAll(mod => mod.tag3 != "1");       //
                foreach (DBAccess.Model.BatteryModuleModel module in unUploadModList)
                {
                    ALineScrewDB.dbModel screwModel = bllScrewDb.GetModelByModuleID(module.batModuleID);

                    if (screwModel == null)
                    {
                        continue;
                    }

                    string mesScrewData = "";
                    if (GetScrewData(screwModel, ref mesScrewData, ref reStr) == false)
                    {
                        Console.WriteLine("模块:" + screwModel.二维码 + ",获取螺丝数据失败:" + reStr);
                        continue;
                    }

                    int status = UploadMesScrewData(module.batModuleID, mesScrewData, ref reStr);
                    if (status == 0)
                    {
                        if (this.plcRW2.WriteDB("D9000", 2) == false)
                        {
                            break;
                        }
                        logRecorder.AddDebugLog(nodeName, "上传MES锁螺丝数据成功!数据:" + module.batModuleID + ":" + mesScrewData + "返回:" + reStr);
                    }
                    else if (status == 1)
                    {
                        ScrewNGModule screwNgMod = new ScrewNGModule();
                        screwNgMod.ChannelIndex = this.channelIndex;
                        screwNgMod.ModPos       = int.Parse(module.tag2);
                        Console.WriteLine("tag2:" + module.tag2);
                        this.screwNgHandler.AddNgModule(screwNgMod);
                        module.palletBinded = false;   //NG解绑
                        module.checkResult  = 2;       //NG
                        modBll.Update(module);
                        logRecorder.AddDebugLog(nodeName, "上传MES锁螺丝数据成功,但返回NG!" + module.batModuleID + ":" + reStr);
                        if (this.plcRW2.WriteDB("D9000", 3) == false)
                        {
                            break;
                        }
                    }
                    else
                    {
                        //Console.WriteLine();
                        logRecorder.AddDebugLog(nodeName, "上传MES锁螺丝数据失败!" + reStr);
                        this.TxtLogRecorder.WriteLog("上传MES锁螺丝数据失败!" + reStr);
                        continue;
                    }
                    this.TxtLogRecorder.WriteLog("上传MES锁螺丝数据成功!数据:" + module.batModuleID + ":" + mesScrewData);
                    module.tag3 = "1";
                    modBll.Update(module);
                    //screwModel.UpLoad = "是";

                    //bllScrewDb.Update(screwModel);
                }
                //========================================================================================//
                if (isScrewCpt == false)
                {
                    break;
                }
                // Console.WriteLine("sd6");
                currentTaskPhase++;
                this.currentTask.TaskPhase = this.currentTaskPhase;
                this.ctlTaskBll.Update(this.currentTask);
                break;
            }

            case 5:
            {
                //发送停止加工命令
                if (!ccdDevAcc.EndDev(this.ccdDevName, ref reStr))
                {
                    //logRecorder.AddDebugLog(nodeName, "发送设备停止命令失败");
                    //  Console.WriteLine(nodeName + "发送设备停止命令失败");
                    this.currentTaskDescribe = "发送设备停止命令失败";
                    break;
                }
                else
                {
                    logRecorder.AddDebugLog(nodeName, "发送设备停止命令成功");
                }
                currentTaskPhase++;
                this.currentTask.TaskPhase = this.currentTaskPhase;
                this.ctlTaskBll.Update(this.currentTask);
                this.TxtLogRecorder.WriteLog("停止设备成功!");
                break;
            }

            case 6:
            {
                currentTaskDescribe = "发送有料字";
                List <DBAccess.Model.BatteryModuleModel> modList = modBll.GetModelList(string.Format("palletID='{0}' and palletBinded=1", this.rfidUID));

                if (!AfterMech(modList, ref reStr))
                {
                    // Console.WriteLine(string.Format("{0},{1}", nodeName, reStr));
                    currentTaskDescribe = reStr;
                    break;
                }
                currentTaskPhase++;
                this.currentTask.TaskPhase = this.currentTaskPhase;
                this.ctlTaskBll.Update(this.currentTask);
                logRecorder.AddDebugLog(nodeName, "发送有料字");
                break;
            }

            case 7:
            {
                db1ValsToSnd[2 + this.channelIndex - 1] = 3;

                currentStat.StatDescribe = "工装板放行";
                this.currentTaskPhase++;
                this.currentTask.TaskPhase = this.currentTaskPhase;
                this.ctlTaskBll.Update(this.currentTask);
                break;
            }

            case 8:
            {
                currentStat.StatDescribe = "NG流程处理";
                Console.WriteLine("sd7");
                if (this.screwNgHandler.Execute() == false)
                {
                    break;
                }
                List <DBAccess.Model.BatteryModuleModel> modList = modBll.GetModelList(string.Format("palletID='{0}'", this.rfidUID));
                foreach (DBAccess.Model.BatteryModuleModel mod in modList)       //锁螺丝工位有拍出流程 不需要记录NG
                {
                    mod.checkResult = 0;
                    modBll.Update(mod);
                }

                currentStat.StatDescribe = "流程完成";
                // Console.WriteLine("sd8");
                this.TxtLogRecorder.WriteLog("此工位流程处理完成!");
                this.currentTask.TaskPhase = this.currentTaskPhase;
                this.ctlTaskBll.Update(this.currentTask);
                break;
            }

            case 9:    //返修流程不要返修的直接放行
            {
                db1ValsToSnd[2 + this.channelIndex - 1] = 3;
                if (this.repairProcess.NeedRepair == false)
                {
                    string chennelAddr = this.screwNgHandler.addrChannelCfg[this.channelIndex];
                    if (this.PlcRW.WriteDB(chennelAddr, 2) == false)
                    {
                        break;
                    }
                }
                this.TxtLogRecorder.WriteLog("此工位流程处理完成!");
                break;
            }

            default:
                break;
            }
            return(true);
        }