/// <summary> /// 检查配方管理器是否存在 /// </summary> /// <param name="errorInfo"></param> /// <returns></returns> bool CheckRecipeMgr(out string errorInfo) { IJFRecipeManager rm = JFHubCenter.Instance.RecipeManager; if (null == rm) { errorInfo = "配方管理器未创建"; return(false); } if (rm.GetType() != typeof(JFDLAFRecipeManager) && !typeof(JFDLAFRecipeManager).IsAssignableFrom(rm.GetType())) { errorInfo = "当前配方管理器类型错误:" + rm.GetType().Name; return(false); } if (!rm.IsInitOK) { errorInfo = "配方管理器初始化未完成,ErrorInfo:" + rm.GetInitErrorInfo(); return(false); } errorInfo = "Success"; return(true); }
/// <summary> /// 显示配方管理器自定义窗口 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void toolStripMenuItemDialog_Click(object sender, EventArgs e) { IJFRecipeManager recipeMgr = JFHubCenter.Instance.RecipeManager; if (null == recipeMgr) { MessageBox.Show("系统配置中不存在配方管理器"); return; } if (!(recipeMgr is IJFConfigUIProvider)) { MessageBox.Show("当前配方管理器类型:" + recipeMgr.GetType().Name + " 未提供配置窗口"); return; } (recipeMgr as IJFConfigUIProvider).ShowCfgDialog(); }
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.正在检测); }
protected override bool ActionGenuine(out string errorInfo) { string recipeID = GetMethodInputValue("RecipeID") as string; if (string.IsNullOrEmpty(recipeID)) { errorInfo = "输入参数RecipeID 为空字串"; return(false); } IJFImage markImg1 = GetMethodInputValue("MarkImage1") as IJFImage; if (null == markImg1) { errorInfo = "MarkImage1 is null"; return(false); } IJFImage markImg2 = GetMethodInputValue("MarkImage2") as IJFImage; if (null == markImg1) { errorInfo = "MarkImage1 is null"; return(false); } IDLAFProductFixReceiver rcver = GetMethodInputValue("定位结果接收者") as IDLAFProductFixReceiver; if (null == rcver) { errorInfo = "定位结果接收者 未设置"; return(false); } double markSnapX1 = Convert.ToDouble(GetMethodInputValue("MarkSanpX1")); double markSnapY1 = Convert.ToDouble(GetMethodInputValue("MarkSanpY1")); double markSnapX2 = Convert.ToDouble(GetMethodInputValue("MarkSanpX2")); double markSnapY2 = Convert.ToDouble(GetMethodInputValue("MarkSanpY2")); double[] icCenterX = null; double[] icCenterY = null; double[] fovOffsetX = null; double[] fovOffsetY = null; int fixErrorCode = -1; string fixErrorInfo = "软件功能未实现"; //////////////////////////////////////////////添加定位算法流程 IJFRecipeManager irm = JFHubCenter.Instance.RecipeManager; if (null == irm) { errorInfo = "配方管理器未设置"; rcver.PFErrorInfo = errorInfo; rcver.PFErrorCode = -1; return(false); } if (!irm.IsInitOK) { errorInfo = "配方管理器未初始化 :" + irm.GetInitErrorInfo(); rcver.PFErrorInfo = errorInfo; rcver.PFErrorCode = -1; return(false); } JFDLAFRecipeManager rm = irm as JFDLAFRecipeManager; if (null == rm) { errorInfo = "配方管理器类型错误 :" + irm.GetType().Name; rcver.PFErrorInfo = errorInfo; rcver.PFErrorCode = -1; return(false); } JFDLAFProductRecipe recipe = rm.GetRecipe("Product", recipeID) as JFDLAFProductRecipe; if (null == recipe) { errorInfo = "RecipeID =\"" + recipeID + "\" 在配方管理器中不存在"; rcver.PFErrorInfo = errorInfo; rcver.PFErrorCode = -1; return(false); } ///使用原始拍照点位 icCenterX = new double[recipe.ICCount]; icCenterY = new double[recipe.ICCount]; for (int i = 0; i < recipe.RowCount; i++) { for (int j = 0; j < recipe.ColCount; j++) { recipe.GetICSnapCenter(i, j, out icCenterX[i * recipe.ColCount + j], out icCenterY[i * recipe.ColCount + j]); } } ///使用原始Fov偏移量 fovOffsetX = new double[recipe.FovCount]; fovOffsetY = new double[recipe.FovCount]; for (int i = 0; i < recipe.FovCount; i++) { recipe.GetFovOffset(recipe.FovNames()[i], out fovOffsetX[i], out fovOffsetY[i]); } fixErrorCode = 0; //当前为演示代码,返回模板图像拍照位置 rcver.PFRecipeID = recipeID; rcver.PFErrorInfo = fixErrorInfo; rcver.PFICCenterX = icCenterX; rcver.PFICCenterY = icCenterY; rcver.PFFovOffsetX = fovOffsetX; rcver.PFFovOffsetY = fovOffsetY; rcver.PFErrorCode = fixErrorCode; errorInfo = "Success"; return(true); }