/// <summary>
        /// 切换当前产品ID
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btSetProdID_Click(object sender, EventArgs e)
        {
            FormObtainBarcode dlg = new FormObtainBarcode();

            dlg.StartPosition = FormStartPosition.CenterScreen;
            dlg.Text          = "输入产品ID";
            string lastProdID = _ms.CurrRecipeID;

            if (string.IsNullOrEmpty(lastProdID))
            {
                lastProdID = JFHubCenter.Instance.SystemCfg.GetItemValue(MainStation.SCN_CurrentRecipeID) as string;
            }
            dlg.SetInitBarcode(lastProdID);
            JFDLAFRecipeManager rm = JFHubCenter.Instance.RecipeManager as JFDLAFRecipeManager;

            if (null != rm && rm.IsInitOK)
            {
                string[] allRecipeIDs = rm.AllRecipeIDsInCategoty(MainStation.SCN_CategotyProd);
                dlg.SetBarcodeOptions(allRecipeIDs);
            }

            dlg.ObtainMode = FormObtainBarcode.OBMode.Scanner;
            while (DialogResult.OK == dlg.ShowDialog())
            {
                string errorInfo;
                if (_ms.CurrRecipeID == dlg.Barcode && !string.IsNullOrEmpty(dlg.Barcode))
                {
                    return;
                }
                bool isSetProdIDOK = _ms.SetCurrRecipeID(dlg.Barcode, out errorInfo);
                if (isSetProdIDOK)
                {
                    lbProdID.Text      = dlg.Barcode;
                    lbProdID.ForeColor = Color.Black;
                    UpdateMappingByProdID(dlg.Barcode);
                    //if (!string.IsNullOrEmpty(_ms.CurrLotID))
                    //    _detectResultTransfer.SetRecipeLot(_ms.CurrRecipeID, _ms.CurrLotID, out string err);
                    break;
                }
                else
                {
                    if (DialogResult.Yes != MessageBox.Show("设置产品ID失败,错误信息:" + errorInfo + "是否重新输入?", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning))
                    {
                        break;
                    }
                }
            }
        }
        /// <summary>
        /// 设置产品信号/批次号
        /// </summary>
        /// <param name="recipeID"></param>
        /// <param name="lotID"></param>
        /// <param name="errorInfo"></param>
        /// <returns></returns>
        public bool SetRecipeLot(string recipeID, string lotID, out string errorInfo)
        {
            if (string.IsNullOrEmpty(recipeID))
            {
                errorInfo = "参数RecipeID为空字串";
                _recipeID = null;
                return(false);
            }
            JFDLAFRecipeManager rm = JFHubCenter.Instance.RecipeManager as JFDLAFRecipeManager;

            if (null == rm || !rm.IsInitOK)
            {
                errorInfo = "配方管理器未设置/未初始化!";
                _recipeID = null;
                return(false);
            }
            string[] allRecipeIDS = rm.AllRecipeIDsInCategoty("Product");
            if (null == allRecipeIDS || !allRecipeIDS.Contains(recipeID))
            {
                errorInfo = "RecipeID:\"" + recipeID + "\"在配方管理器中不存在!";
                _recipeID = null;
                return(false);
            }
            _recipeID = recipeID;
            _recipe   = rm.GetRecipe("Product", _recipeID) as JFDLAFProductRecipe;


            if (string.IsNullOrEmpty(lotID))
            {
                _lotID    = null;
                errorInfo = "参数项LotID为空值";
                return(false);
            }

            _lotID = lotID;

            int fovCountInPiece = _recipe.FovCount * _recipe.ICCount;//料片所有Fov数量

            _fovResults  = new DlafFovDetectResult[fovCountInPiece];
            _fovCounteds = new bool[fovCountInPiece];



            errorInfo = "Success";
            return(true);
        }
Beispiel #3
0
        public bool SetCurrRecipeID(string recipeID, out string errorInfo)
        {
            if (string.IsNullOrEmpty(recipeID))
            {
                errorInfo = "产品ID为null/空字串";
                return(false);
            }
            if (!CheckRecipeMgr(out errorInfo))
            {
                return(false);
            }

            JFDLAFRecipeManager rm = JFHubCenter.Instance.RecipeManager as JFDLAFRecipeManager;

            string[] allRecipeIDs = rm.AllRecipeIDsInCategoty(SCN_CategotyProd);
            if (null == allRecipeIDs || !allRecipeIDs.Contains(recipeID))
            {
                errorInfo = "产品ID:\"" + recipeID + "\"在配方管理器中不存在";
                return(false);
            }
            if (WorkStatus == JFWorkStatus.Running || WorkStatus == JFWorkStatus.Interactiving || WorkStatus == JFWorkStatus.Pausing)
            {
                errorInfo = "正在运行,不能修改产品ID";
                return(false);
            }

            IJFDataPool dp   = JFHubCenter.Instance.DataPool;
            bool        isOK = dp.SetItemValue(SDN_CurrRecipeID, recipeID);

            if (!isOK)
            {
                errorInfo = "写入数据池失败";
            }
            else
            {
                //将当前产品信息写入SystemCfg
                JFXCfg sysCfg = JFHubCenter.Instance.SystemCfg;
                if (sysCfg.ContainsItem(SCN_CurrentRecipeID))
                {
                    sysCfg.SetItemValue(SCN_CurrentRecipeID, recipeID); //将当前产品ID 加到配置项中
                    sysCfg.Save();
                }
                errorInfo = "Success";
            }
            return(isOK);
        }
Beispiel #4
0
        /// <summary>
        ///
        /// </summary>
        void UpdateParamPanel()
        {
            if (_station == null)
            {
                cbLotID.Text      = "";
                cbRecipeID.Text   = "";
                rchPicFolder.Text = "";
                return;
            }
            string        crrSelRecipeID = cbRecipeID.Text;
            List <string> recipeIDsInCb  = new List <string>();

            foreach (object o in cbRecipeID.Items)
            {
                recipeIDsInCb.Add(o.ToString());
            }

            string        currSelLotID = cbLotID.Text;
            List <string> lotIDsInCb   = new List <string>();

            foreach (string o in cbLotID.Items)
            {
                lotIDsInCb.Add(o.ToString());
            }

            string currSelPicFolder = rchPicFolder.Text;

            JFDLAFRecipeManager rm = JFHubCenter.Instance.RecipeManager as JFDLAFRecipeManager;

            string[] allRecipeIDs = rm.AllRecipeIDsInCategoty("Product");
            if (null == allRecipeIDs || 0 == allRecipeIDs.Length)
            {
                cbRecipeID.Items.Clear();
                cbRecipeID.Text = currSelPicFolder;
                cbLotID.Items.Clear();
                cbRecipeID.Text = currSelLotID;
                lstBoxPieceIDs.Items.Clear();
                return;
            }

            bool isNeedResetRecipeCb = false;

            do
            {
                if (allRecipeIDs.Length != recipeIDsInCb.Count())
                {
                    isNeedResetRecipeCb = true;
                    break;
                }
                for (int i = 0; i < allRecipeIDs.Length; i++)
                {
                    if (allRecipeIDs[i] != recipeIDsInCb[i])
                    {
                        isNeedResetRecipeCb = true;
                        break;
                    }
                }
            } while (false);
            if (isNeedResetRecipeCb)
            {
                cbRecipeID.Items.Clear();
                foreach (string s in allRecipeIDs)
                {
                    cbRecipeID.Items.Add(s);
                }
                if (!string.IsNullOrWhiteSpace(crrSelRecipeID))
                {
                    cbRecipeID.Text = crrSelRecipeID;
                }
            }

            if (string.IsNullOrWhiteSpace(cbRecipeID.Text))
            {
                cbLotID.Items.Clear();
                cbLotID.Text = currSelLotID;
                lstBoxPieceIDs.Items.Clear();
                return;
            }
            if (string.IsNullOrWhiteSpace(currSelPicFolder))
            {
                cbLotID.Items.Clear();
                lstBoxPieceIDs.Items.Clear();
                cbLotID.Text = currSelLotID;
                return;
            }

            if (!Directory.Exists(currSelPicFolder))
            {
                cbLotID.Items.Clear();
                lstBoxPieceIDs.Items.Clear();
                cbLotID.Text = currSelLotID;
                return;
            }

            string recipeFolder = currSelPicFolder + "\\" + cbRecipeID.Text;

            if (!Directory.Exists(recipeFolder))
            {
                cbLotID.Items.Clear();
                lstBoxPieceIDs.Items.Clear();
                cbLotID.Text = currSelLotID;
                return;
            }
            string[] lotsFolders = Directory.GetDirectories(recipeFolder);
            if (null == lotsFolders || 0 == lotsFolders.Length)
            {
                cbLotID.Items.Clear();
                lstBoxPieceIDs.Items.Clear();
                cbLotID.Text = currSelLotID;
                return;
            }

            bool isNeedResetLotCb = false;

            do
            {
                if (lotsFolders.Length != lotIDsInCb.Count())
                {
                    isNeedResetLotCb = true;
                    break;
                }
                for (int i = 0; i < lotsFolders.Length; i++)
                {
                    if (lotsFolders[i] != lotIDsInCb[i])
                    {
                        isNeedResetLotCb = true;
                        break;
                    }
                }
            } while (false);

            if (isNeedResetLotCb)
            {
                cbLotID.Items.Clear();
                foreach (string s in lotsFolders)
                {
                    cbLotID.Items.Add(s.Substring(s.LastIndexOf("\\") + 1));
                }
                if (lotsFolders.Contains(currSelLotID))
                {
                    for (int i = 0; i < lotsFolders.Length; i++)
                    {
                        if (lotsFolders[i] == currSelLotID)
                        {
                            cbLotID.SelectedIndex = i;
                            return;
                        }
                    }
                }
                cbLotID.Text = currSelLotID;
            }
        }
        public bool InitInspectNode(string recipeID, out string errorInfo)
        {
            if (string.IsNullOrEmpty(recipeID))
            {
                errorInfo = "参数recipeID 为空字串";
                return(false);
            }

            JFDLAFRecipeManager rm = JFHubCenter.Instance.RecipeManager as JFDLAFRecipeManager;

            if (rm == null)
            {
                errorInfo = "配方管理器为空!";
                return(false);
            }

            if (!rm.IsInitOK)
            {
                errorInfo = "配方管理器未初始化:" + rm.GetInitErrorInfo();
                return(false);
            }

            string[] allRecipeIds = rm.AllRecipeIDsInCategoty(CategoyProduct);
            if (null == allRecipeIds || 0 == allRecipeIds.Length)
            {
                errorInfo = "配方管理器中不存在任何RecipeID";
                return(false);
            }

            if (!allRecipeIds.Contains(recipeID))
            {
                errorInfo = "配方管理器中不存在RecipeID = " + recipeID;
                return(false);
            }

            Dictionary <string, InspectNode> dctFovInspections = null;

            if (!_dctRecipeInspections.ContainsKey(recipeID)) //当前
            {
                dctFovInspections = new Dictionary <string, InspectNode>();
                _dctRecipeInspections.Add(recipeID, dctFovInspections);


                string rmPath = rm.GetInitParamValue("配方保存路径") as string;


                JFDLAFProductRecipe recipe   = rm.GetRecipe(CategoyProduct, recipeID) as JFDLAFProductRecipe;
                string[]            fovNames = recipe.FovNames();
                foreach (string fovName in fovNames)
                {
                    string recipePath = rmPath + "\\" + recipeID + "\\" + fovName + "\\Recipe\\";
                    string modelPath  = rmPath + "\\" + recipeID + "\\" + fovName + "\\Models\\";

                    InspectNode inspectNode = new InspectNode(modelPath, recipePath);
                    dctFovInspections.Add(fovName, inspectNode);
                }
            }
            string err;

            dctFovInspections = _dctRecipeInspections[recipeID];
            foreach (KeyValuePair <string, InspectNode> kv in dctFovInspections)
            {
                if (!kv.Value.InitInspectParam(out err))
                {
                    errorInfo = "Fov = " + kv.Key + " 初始化失败:" + err;
                    return(false);
                }
            }
            errorInfo = "Success";
            return(true);
        }
Beispiel #6
0
        protected override void PrepareWhenWorkStart()
        {
            if (string.IsNullOrEmpty(TestPicFolder))
            {
                ExitWork(WorkExitCode.Error, "检测失败:图片文件路径未设置");
            }
            if (!Directory.Exists(TestPicFolder))
            {
                ExitWork(WorkExitCode.Error, "检测失败,图片文件夹不存在:" + TestPicFolder);
            }
            IJFRecipeManager irm = JFHubCenter.Instance.RecipeManager;

            if (null == irm)
            {
                ExitWork(WorkExitCode.Error, "检测失败,配方管理器未设置");
            }
            if (!(irm is JFDLAFRecipeManager))
            {
                ExitWork(WorkExitCode.Error, "检测失败,配方管理器类型错误:" + irm.GetType().Name);
            }
            JFDLAFRecipeManager rm = irm as JFDLAFRecipeManager;

            if (!rm.IsInitOK)
            {
                ExitWork(WorkExitCode.Error, "检测失败,配方管理器未初始化,ErrorInfo:" + rm.GetInitErrorInfo());
            }



            if (string.IsNullOrEmpty(RecipeID))
            {
                ExitWork(WorkExitCode.Error, "检测失败:RecipeID未设置");
            }
            string[] allRecipeIDs = rm.AllRecipeIDsInCategoty("Product");
            if (null == allRecipeIDs || !allRecipeIDs.Contains(RecipeID))
            {
                ExitWork(WorkExitCode.Error, "检测失败,RecipeID:\"" + RecipeID + "\"在配方管理器中不存在");
            }

            if (string.IsNullOrEmpty(LotID))
            {
                ExitWork(WorkExitCode.Error, "检测失败:LotID未设置");
            }
            if (string.IsNullOrEmpty(_pieceID))
            {
                ExitWork(WorkExitCode.Error, "检测失败:未选择料片号");
            }
            _currPiecePicFolder = TestPicFolder + "\\" + RecipeID + "\\" + LotID + "\\" + _pieceID;
            if (!Directory.Exists(_currPiecePicFolder))
            {
                ExitWork(WorkExitCode.Error, "检测失败,产品图片文件夹:\"" + _currPiecePicFolder + "\" 不存在");
            }

            _currRecipe = rm.GetRecipe("Product", RecipeID) as JFDLAFProductRecipe;
            //初始化视觉算子
            string errorInfo;

            _ChangeCS(ODCS.算法初始化);
            JFDLAFInspectionManager.Instance.Clear(); //将所有已初始化的算子释放,重新初始化(适应外部修改配置)
            if (!JFDLAFInspectionManager.Instance.InitInspectNode(RecipeID, out errorInfo))
            {
                ExitWork(WorkExitCode.Error, "检测失败,图像算子初始化失败:" + errorInfo);
            }


            string cmrCalibDataFilePath = GetCfgParamValue("相机标定文件") as string;
            int    imgWidth             = (int)GetCfgParamValue("图像宽度/像素");
            int    imgHeight            = (int)GetCfgParamValue("图像高度/像素");

            if (!_visionFixer.Init(cmrCalibDataFilePath, _currRecipe, imgWidth, imgHeight, out errorInfo))
            {
                ExitWork(WorkExitCode.Error, "检测失败,图像矫正算子初始化失败:" + errorInfo);
            }



            _ChangeCS(ODCS.正在检测);
        }
Beispiel #7
0
        public virtual bool Start(out string errorInfo)//开始运行
        {
            errorInfo = "Unknown Error";
            if (IsAlarming)
            {
                errorInfo = "当前处于报警状态";
                return(false);
            }
            if (IsStationRunning(WorkStatus))
            {
                errorInfo = "Success";
                return(true);
            }

            JFDLAFRecipeManager rm = JFHubCenter.Instance.RecipeManager as JFDLAFRecipeManager;

            if (null == rm)
            {
                errorInfo = "配方管理器未创建!";
                return(false);
            }
            if (!rm.IsInitOK)
            {
                errorInfo = "配方管理器初始化未完成,ErrorInfo:" + rm.GetInitErrorInfo();
                return(false);
            }



            JFStationManager stationMgr = JFHubCenter.Instance.StationMgr;


            string[] allEnableStationNames = stationMgr.AllEnabledStationNames();
            if (null == allEnableStationNames || 0 == allEnableStationNames.Length)
            {
                errorInfo = "不存在使能的工站";
                return(false);
            }

            foreach (string stationName in allEnableStationNames) // 先检查有没有正在运行的工站
            {
                IJFStation station = stationMgr.GetStation(stationName);
                if (IsStationRunning(station.CurrWorkStatus))
                {
                    errorInfo = "启动失败,工站:" + station.Name + " 当前状态:" + station.CurrWorkStatus.ToString();
                    return(false);
                }
            }

            ///检查当前RecipeID 和 LotID
            if (string.IsNullOrEmpty(CurrRecipeID))
            {
                errorInfo = "启动失败:当前产品ID未设置";
                return(false);
            }

            string[] allRecipeIDs = rm.AllRecipeIDsInCategoty(SCN_CategotyProd);
            if (null == allRecipeIDs || !allRecipeIDs.Contains(CurrRecipeID))
            {
                errorInfo = "启动失败,当前产品ID:" + CurrRecipeID + " 在配方管理器中不存在";
                return(false);
            }


            if (string.IsNullOrEmpty(CurrLotID))
            {
                errorInfo = "启动失败:当前批次号未设置!";
                return(false);
            }



            int failedIndex = -1; //启动失败的工站号

            foreach (string stationName in allEnableStationNames)
            {
                IJFStation      station = stationMgr.GetStation(stationName);
                JFWorkCmdResult ret     = station.Start();
                if (ret != JFWorkCmdResult.Success)
                {
                    errorInfo = "工站:" + station.Name + " 启动失败,Error:" + ret.ToString();
                    break;
                }
            }

            if (failedIndex > -1)
            {
                for (int i = 0; i < failedIndex + 1; i++)
                {
                    IJFStation station = stationMgr.GetStation(allEnableStationNames[i]);
                    if (JFWorkCmdResult.Success != station.Stop(100))
                    {
                        station.Abort();
                    }
                }
                return(false);
            }
            WorkStatus = JFWorkStatus.Running;
            errorInfo  = "Success";
            return(true);
        }
Beispiel #8
0
        /// <summary>
        /// 产品ID改变
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cbRecipeID_SelectedIndexChanged(object sender, EventArgs e)
        {
            string errorInfo;

            if (cbRecipeID.SelectedIndex < 0)
            {
                _station.SetRecipeID(null, out errorInfo);
                gbFixProduct.Enabled = false;
                gbFixIC.Enabled      = false;
                gbFixFov.Enabled     = false;
                gbTaskSave.Enabled   = false;
                gbVisionGrab.Enabled = false;
                btChkCfg.Enabled     = false;
                btFlushVc.Enabled    = false;

                return;
            }

            if (!_station.SetRecipeID(cbRecipeID.Text, out errorInfo))
            {
                MessageBox.Show(errorInfo);
                cbRecipeID.Text = _station.CurrRecipeID();
                return;
            }
            string currRecipeID    = cbRecipeID.Text;
            JFDLAFRecipeManager rm = JFHubCenter.Instance.RecipeManager as JFDLAFRecipeManager;

            string[] allRecipeIDs = rm.AllRecipeIDsInCategoty(CategoteProduct);
            if (string.IsNullOrEmpty(currRecipeID) ||
                allRecipeIDs == null ||
                !allRecipeIDs.Contains(currRecipeID))
            {
                gbFixProduct.Enabled = false;
                gbFixFov.Enabled     = false;
                gbFixIC.Enabled      = false;
                gbTaskSave.Enabled   = false;
                gbVisionGrab.Enabled = false;
                btChkCfg.Enabled     = false;
                btFlushVc.Enabled    = false;
                return;
            }

            gbFixProduct.Enabled = true;
            gbFixFov.Enabled     = true;
            gbFixIC.Enabled      = true;
            gbTaskSave.Enabled   = true;
            gbVisionGrab.Enabled = true;
            btChkCfg.Enabled     = true;
            btFlushVc.Enabled    = true;

            JFDLAFProductRecipe recipe = rm.GetRecipe(CategoteProduct, currRecipeID) as JFDLAFProductRecipe;

            _isMark1VcEdit = false; //Mark1视觉参数是否正在配置
            _isMark2VcEdit = false;
            //btFixMark1.Text = "Vc"; //Vision Config
            //btFixMark2.Text = "Vc";
            btMark1EditSave.Text = "Vc";
            btMark2EditSave.Text = "Vc";
            // cbMarkVc1.Text = recipe.Mark1VisionCfgName;
            cbMarkVc1.Enabled = false;
            cbMarkVc2.Enabled = false;
            //cbMarkVc2.Text = recipe.Mark2VisionCfgName;
            double x1, y1, x2, y2;

            recipe.GetMarkSnapPos1(out x1, out y1);
            recipe.GetMarkSnapPos2(out x2, out y2);
            lbMarPos.Text = string.Format("x1:{0:F3} y1:{1:F3} \nx2:{2:F3} y2:{3:F3}", x1, y1, x2, y2);
            string mark1VcName = recipe.GetMark1LightCfg();
            string mark2VcName = recipe.GetMark2LightCfg();

            cbMarkVc1.Text = mark1VcName;
            cbMarkVc2.Text = mark2VcName;

            string currRowSel = cbIcRow.Text;
            string currColSel = cbIcCol.Text;

            cbIcRow.Items.Clear();
            for (int i = 0; i < recipe.RowCount; i++)
            {
                cbIcRow.Items.Add(i.ToString());
            }
            if (!string.IsNullOrEmpty(currRowSel))
            {
                if (Convert.ToInt32(currRowSel) < recipe.RowCount)
                {
                    cbIcRow.Text = currRowSel;
                }
                else
                {
                    cbIcRow.Text = "";
                }
            }

            cbIcCol.Items.Clear();
            for (int i = 0; i < recipe.ColCount; i++)
            {
                cbIcCol.Items.Add(i.ToString());
            }
            if (!string.IsNullOrEmpty(currColSel))
            {
                if (Convert.ToInt32(currColSel) < recipe.ColCount)
                {
                    cbIcCol.Text = currColSel;
                }
                else
                {
                    cbIcCol.Text = "";
                }
            }


            string currFovSel = cbFovName.Text;

            string[] allFovNames = recipe.FovNames();
            cbFovName.Items.Clear();
            if (null != allFovNames && allFovNames.Length > 0)
            {
                foreach (string s in allFovNames)
                {
                    cbFovName.Items.Add(s);
                }
            }

            if (!string.IsNullOrEmpty(currFovSel))
            {
                cbFovName.Text = currFovSel;
                if (allFovNames != null && allFovNames.Contains(currFovSel))
                {
                    cbFovName.BackColor = SystemColors.Control;
                }
                else
                {
                    cbFovName.BackColor = Color.OrangeRed;
                }
            }

            string currTaskNameSel = cbTaskName.Text;

            string[] allTaskNames = null;
            cbTaskName.Items.Clear();
            if (!string.IsNullOrEmpty(currFovSel))
            {
                allTaskNames = recipe.TaskNames(currFovSel);
                if (null != allTaskNames && allFovNames.Length > 0)
                {
                    foreach (string s in allTaskNames)
                    {
                        cbTaskName.Items.Add(s);
                    }
                }
            }

            if (!string.IsNullOrEmpty(currTaskNameSel))
            {
                cbTaskName.Text = currTaskNameSel;

                if (allTaskNames != null && allTaskNames.Contains(currTaskNameSel))
                {
                    cbTaskName.BackColor = SystemColors.Control;
                }
                else
                {
                    cbTaskName.BackColor = Color.OrangeRed;
                }
            }
        }