/// <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 toolStripMenuItemReset_Click(object sender, EventArgs e) { IJFRecipeManager recipeMgr = JFHubCenter.Instance.RecipeManager; FormCreateInitor fm = new FormCreateInitor(); fm.MatchType = typeof(IJFRecipeManager); fm.SetFixedID("JF配方管理器"); if (null == recipeMgr) { fm.Text = "新建配方管理器"; } else { fm.Text = "重建配方管理器"; } if (DialogResult.OK != fm.ShowDialog()) { return; } if (null != recipeMgr) { JFHubCenter.Instance.InitorManager.Remove("JF配方管理器");//先删除当前RecipeMgr } recipeMgr = fm.Initor as IJFRecipeManager; JFHubCenter.Instance.InitorManager.Add(fm.ID, recipeMgr); AdjustManagerView2UI(); }
public void SetRecipeManager(IJFRecipeManager mgr) { _mgr = mgr; if (Created) { AdjustMgr2View(); } }
/// <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(); }
void AdjustManagerView2UI() { panel1.Controls.Clear(); IJFRecipeManager recipeMgr = JFHubCenter.Instance.RecipeManager; if (null == recipeMgr) { toolStripMenuItemReset.Text = "新建配方管理器"; toolStripTbTips.Text = "系统不存在配方管理器"; toolStripMenuItemInitMgr.Visible = false; toolStripMenuItemInitParam.Visible = false; toolStripMenuItemDialog.Visible = false; return; } else { toolStripMenuItemReset.Text = "重置配方管理器"; toolStripMenuItemInitMgr.Visible = true; toolStripMenuItemInitParam.Visible = true; if (!recipeMgr.IsInitOK) { toolStripTbTips.Text = "管理器初始化错误:" + recipeMgr.GetInitErrorInfo(); return; } toolStripTbTips.Text = "管理器已初始化!"; if (recipeMgr is IJFConfigUIProvider) { toolStripMenuItemDialog.Visible = true; } else { toolStripMenuItemDialog.Visible = false; } if (recipeMgr is IJFRealtimeUIProvider) { JFRealtimeUI ui = (recipeMgr as IJFRealtimeUIProvider).GetRealtimeUI(); ui.Dock = DockStyle.Fill; panel1.Controls.Add(ui); ui.Show(); ui.UpdateSrc2UI(); } } }
/// <summary> /// 配方管理器初始化 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void toolStripMenuItemInitMgr_Click(object sender, EventArgs e) { IJFRecipeManager recipeMgr = JFHubCenter.Instance.RecipeManager; if (null == recipeMgr) { MessageBox.Show("系统配置中不存在配方管理器"); return; } bool isOK = recipeMgr.Initialize(); if (!isOK) { MessageBox.Show("配方管理器初始化失败,ErrorInfo:" + recipeMgr.GetInitErrorInfo()); return; } AdjustManagerView2UI(); }
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); }
void AdjustStationView() { IJFRecipeManager mgr = JFHubCenter.Instance.RecipeManager; if (null == mgr) { Enabled = false; cbRecipeID.Text = "RecipeManager = null!"; return; } if (!mgr.IsInitOK) { Enabled = false; cbRecipeID.Text = "RecipeManager not init!"; return; } if (_station == null) { Enabled = false; return; } string _modelPicPath = _station.GetCfgParamValue(DLAFVisionTeachStation.SCItemName_ModelPicPath) as string; if (null == _modelPicPath) { tbModelPicPath.Text = ""; } tbModelPicPath.Text = _modelPicPath; Enabled = true; string currRecipeID = cbRecipeID.Text; //当前已选的RecipeID cbRecipeID.Items.Clear(); string[] allRecipeIDs = mgr.AllRecipeIDsInCategoty(CategoteProduct); if (null != allRecipeIDs && allRecipeIDs.Length > 0) { foreach (string s in allRecipeIDs) { cbRecipeID.Items.Add(s); } if (!string.IsNullOrEmpty(currRecipeID)) { if (allRecipeIDs.Contains(currRecipeID)) { cbRecipeID.Text = currRecipeID; } else { cbRecipeID.SelectedIndex = -1; } } } else { cbRecipeID.SelectedIndex = -1; } string currVAName = cbVAName.Text; cbVAName.Items.Clear(); JFVisionManager vm = JFHubCenter.Instance.VisionMgr; string[] allVANames = vm.AllSVAssistNames(); if (null != allVANames && allVANames.Length > 0) { foreach (string s in allVANames) { cbVAName.Items.Add(s); } if (!allVANames.Contains(currVAName)) { cbVAName.SelectedIndex = -1; } else { cbVAName.Text = currVAName; } } else { cbVAName.SelectedIndex = -1; } AdjustVisionCfg(); }