/// <summary> /// 根据当前所选ProductID更新Map控件 /// </summary> /// <param name="recipeID"></param> void UpdateMappingByProdID(string recipeID) { if (string.IsNullOrEmpty(recipeID)) { mappCtrl.Initial(0, 0, _dctDieStateColor, "未检测"); mappCtrl.IsShowBottomBar = true; return; } JFDLAFRecipeManager rm = JFHubCenter.Instance.RecipeManager as JFDLAFRecipeManager; _currRecipe = rm.GetRecipe(MainStation.SCN_CategotyProd, recipeID) as JFDLAFProductRecipe; if (null == _currRecipe) { mappCtrl.Initial(0, 0, _dctDieStateColor, "未检测"); mappCtrl.IsShowBottomBar = true; return; } int dieRow = _currRecipe.RowNumber;; //料片中的die行数 int dieCol = _currRecipe.ColumnNumber * _currRecipe.BlockNumber;; mappCtrl.Initial(dieRow, dieCol, _dctDieStateColor, "未检测"); mappCtrl.MinCellHeight = 5; mappCtrl.MinCellWidth = 5; mappCtrl.IsShowBottomBar = true; cbTaskImgShow.Items.Clear(); List <string> allTaskNames = new List <string>(); string[] allFovNames = _currRecipe.FovNames(); if (null != allFovNames) { List <string> taskNamesExisted = new List <string>(); foreach (string fovName in allFovNames) { string[] taskNames = _currRecipe.TaskNames(fovName); if (taskNames != null) { foreach (string taskName in taskNames) { if (!taskNamesExisted.Contains(taskName)) { taskNamesExisted.Add(taskName); cbTaskImgShow.Items.Add(taskName); } } } } } if (cbTaskImgShow.Items.Count > 0) { cbTaskImgShow.SelectedIndex = 0; } }
private void cbTaskName_SelectedIndexChanged(object sender, EventArgs e) { if (cbTaskName.SelectedIndex < 0) { return; } string currFovName = cbFovName.Text; string currTaskName = cbTaskName.Text; JFDLAFRecipeManager rm = JFHubCenter.Instance.RecipeManager as JFDLAFRecipeManager; JFDLAFProductRecipe recipe = rm.GetRecipe(CategoteProduct, cbRecipeID.Text) as JFDLAFProductRecipe; string taskVcName = recipe.VisionCfgName(currFovName, currTaskName); if (string.IsNullOrEmpty(taskVcName)) { cbTaskVc.SelectedIndex = -1; return; } cbTaskVc.Text = taskVcName; string[] allVcNames = JFHubCenter.Instance.VisionMgr.SingleVisionCfgNameByOwner(cbRecipeID.Text); if (allVcNames != null && allVcNames.Contains(taskVcName)) { cbTaskVc.BackColor = SystemColors.Control; } else { cbTaskVc.BackColor = Color.OrangeRed; } }
/// <summary> /// Fov 选择改变 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cbFovName_SelectedIndexChanged(object sender, EventArgs e) { if (cbFovName.SelectedIndex < 0) { cbTaskName.Text = ""; btFixFov.Enabled = false; return; } string currFovName = cbFovName.Text; string currTaskName = cbTaskName.Text; JFDLAFRecipeManager rm = JFHubCenter.Instance.RecipeManager as JFDLAFRecipeManager; JFDLAFProductRecipe recipe = rm.GetRecipe(CategoteProduct, cbRecipeID.Text) as JFDLAFProductRecipe; string[] allFovNames = recipe.FovNames(); if (!allFovNames.Contains(currFovName)) { MessageBox.Show("当前Recipe未包含FovName:" + currFovName); cbTaskName.Text = ""; btFixFov.Enabled = false; return; } btFixFov.Enabled = true; double x, y; recipe.GetFovOffset(currFovName, out x, out y); lbFovOffset.Text = string.Format("x:{0:F3} y:{1:F3}", x, y); string[] allTaskNames = recipe.TaskNames(currFovName); cbTaskName.Items.Clear(); if (null != allTaskNames) { foreach (string s in allTaskNames) { cbTaskName.Items.Add(s); } } if (!string.IsNullOrEmpty(currTaskName)) { if (_isTaskVcEditting) { _isTaskVcEditting = false; cbTaskVc.Enabled = false; btTaskVcEditCancel.Enabled = false; btTaskVcEditSave.Text = "设置"; } cbTaskName.Text = currTaskName; if (allTaskNames != null && allTaskNames.Contains(currTaskName)) { cbTaskName.BackColor = SystemColors.Control; } else { cbTaskName.BackColor = Color.OrangeRed; } } }
private void cbIcCol_SelectedIndexChanged(object sender, EventArgs e) { string recipeID = cbRecipeID.Text; if (string.IsNullOrEmpty(recipeID)) { return; } JFDLAFRecipeManager rm = JFHubCenter.Instance.RecipeManager as JFDLAFRecipeManager; JFDLAFProductRecipe recipe = rm.GetRecipe(CategoteProduct, cbRecipeID.Text) as JFDLAFProductRecipe; if (null == recipe) { return; } if (cbIcRow.SelectedIndex < 0) { return; } if (cbIcCol.SelectedIndex < 0) { return; } double x, y; recipe.GetICSnapCenter(Convert.ToInt32(cbIcRow.SelectedItem), Convert.ToInt32(cbIcCol.SelectedItem), out x, out y); lbICPos.Text = string.Format("x:{0:F3} y:{1:F3}", x, y); }
/// <summary> /// 加载产品 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void btnLoadProduct_Click(object sender, EventArgs e) { string Errstring = ""; if (lbxProductCategory.SelectedIndex == -1) { return; } btnLoadProduct.Enabled = false; string pdt = null; pdt = lbxProductCategory.SelectedValue.ToString(); btnLoadProduct.Enabled = true; Form_Wait.ShowForm(); await Task.Run(new Action(() => { try { //需要加载当前产品相关的参数 _operation = JFHubCenter.Instance.RecipeManager.GetRecipe("Product", pdt) as JFDLAFProductRecipe; if (_operation == null) { HTUi.TipError("Recipe Manager中不存在配方:" + pdt); return; } if (Errstring == "") { HTLog.Info("加载产品完成."); HTUi.TipHint("加载产品完成"); if (_operation.MgzIdx == -1) { HTLog.Error("注意:当前产品未选择料盒型号,开始流程需要选择料盒型号."); } } else { HTLog.Error("加载产品失败!!!" + Errstring); HTUi.TipError("加载产品失败"); HTUi.PopWarn("产品加载失败\n" + Errstring); } } catch (Exception EXP) { HTLog.Error(String.Format("{0}加载新产品失败\n", EXP.ToString())); HTUi.TipError("加载新产品失败"); } })); if (_operation != null) { SetupUI(); } JFHubCenter.Instance.SystemCfg.SetItemValue("CurrentID", pdt); JFHubCenter.Instance.SystemCfg.Save(); Form_Wait.CloseForm(); }
public void SetRecipe(JFDLAFProductRecipe operation) { _operation = operation; if (Created) { SetupUI(); } }
HObject _hoFullImg = null; //Recipe全图 void UpdateMapCtrl() { string currSelRecipeID = cbRecipeID.Text; if (string.IsNullOrEmpty(currSelRecipeID)) { mapDetectCells.Initial(1, 1, _dctDieStateColor, "未检测"); htFullImg.Refresh(); return; } JFDLAFRecipeManager rm = JFHubCenter.Instance.RecipeManager as JFDLAFRecipeManager; if (null == rm || !rm.IsInitOK) { mapDetectCells.Initial(1, 1, _dctDieStateColor, "未检测"); htFullImg.Refresh(); return; } JFDLAFProductRecipe recipe = rm.GetRecipe("Product", currSelRecipeID) as JFDLAFProductRecipe; if (null == recipe) { mapDetectCells.Initial(1, 1, _dctDieStateColor, "未检测"); htFullImg.Refresh(); return; } { int row = recipe.RowCount; int col = recipe.ColCount * recipe.FovCount; mapDetectCells.Initial(row, col, _dctDieStateColor, "未检测"); } string fullImgPath = recipe.GetFrameMapImgFullPath(currSelRecipeID); if (string.IsNullOrEmpty(fullImgPath)) { htFullImg.Refresh(); return; } if (!File.Exists(fullImgPath)) { htFullImg.Refresh(); return; } if (null != _hoFullImg) { _hoFullImg.Dispose(); _hoFullImg = null; } HOperatorSet.GenEmptyObj(out _hoFullImg); HOperatorSet.ReadImage(out _hoFullImg, fullImgPath); htFullImg.DispImage(_hoFullImg); }
public bool Init(string cmrCalibFilePath, JFDLAFProductRecipe recipe, int imgWidth, int imgHeight, out string errorInfo) { _isInitOK = false; errorInfo = "None-Options"; _calibFilePath = cmrCalibFilePath; _imgWidth = imgWidth; _imgHegiht = imgHeight; if (!File.Exists(_calibFilePath)) { errorInfo = "相机标定文件:\"" + _calibFilePath + "\" 不存在"; return(false); } if (!InitUV2XYParam(out errorInfo)) { return(false); } _recipe = recipe; if (null == _recipe) //日后添加其他合法性检测 { errorInfo = "Recipe对象无效/空值"; return(false); } if (_leftMarkModel != null) { _leftMarkModel.Dispose(); } if (_rightMarkModel != null) { _rightMarkModel.Dispose(); } _leftMarkModel = new Model(); _rightMarkModel = new Model(); if (!_leftMarkModel.ReadModelCorrect(JFHubCenter.Instance.RecipeManager.GetInitParamValue((string)JFHubCenter.Instance.RecipeManager.InitParamNames[2]) + "\\" + _recipe.ID + "\\CheckPosModels")) { errorInfo = "无法读取该产品左矫正点模板信息.\n"; return(false); } if (!_rightMarkModel.ReadModelCorrect(JFHubCenter.Instance.RecipeManager.GetInitParamValue((string)JFHubCenter.Instance.RecipeManager.InitParamNames[2]) + "\\" + _recipe.ID + "\\CheckPosModelsR")) { errorInfo = "无法读取该产品右矫正点模板信息.\n"; return(false); } _isInitOK = true; errorInfo = "Success"; return(true); }
/// <summary> /// 取消 Task参数编辑 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btTaskVcEditCancel_Click(object sender, EventArgs e) { _isTaskVcEditting = false; cbTaskName.Enabled = true; cbTaskVc.Enabled = false; btTaskVcEditSave.Text = "编辑"; btTaskVcEditCancel.Enabled = false; JFDLAFRecipeManager rm = JFHubCenter.Instance.RecipeManager as JFDLAFRecipeManager; JFDLAFProductRecipe recipe = rm.GetRecipe(CategoteProduct, cbRecipeID.Text) as JFDLAFProductRecipe; string taskVcName = recipe.VisionCfgName(cbFovName.Text, cbTaskName.Text); cbTaskVc.Text = taskVcName; }
/// <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); }
/// <summary> /// 调整视觉配置为当前Task所选 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btFixTask_Click(object sender, EventArgs e) { string recipeID = cbRecipeID.Text; string fovName = cbFovName.Text; string taskName = cbTaskName.Text; if (string.IsNullOrEmpty(recipeID)) { MessageBox.Show("请选择RecipeID"); return; } if (string.IsNullOrEmpty(fovName)) { MessageBox.Show("请选择Fov Name"); return; } JFDLAFRecipeManager rm = JFHubCenter.Instance.RecipeManager as JFDLAFRecipeManager; JFDLAFProductRecipe recipe = rm.GetRecipe(CategoteProduct, cbRecipeID.Text) as JFDLAFProductRecipe; if (null == recipe) { MessageBox.Show("RecipeID:" + recipeID + " 产品配方不存在"); return; } string taskVc = recipe.VisionCfgName(fovName, taskName); if (string.IsNullOrEmpty(taskVc)) { MessageBox.Show("请先设置视觉配置"); return; } string errorInfo = ""; if (!_station.FixTaskVisionCfg(taskName, out errorInfo)) { MessageBox.Show("操作失败:" + errorInfo); return; } }
/// <summary> /// 设置/保存 Task视觉参数配置 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btTaskVcEditSave_Click(object sender, EventArgs e) { if (!_isTaskVcEditting) { string taskName = cbTaskName.Text; if (string.IsNullOrEmpty(taskName)) { MessageBox.Show("请选择需要设置的Task"); return; } _isTaskVcEditting = true; cbTaskName.Enabled = false; cbTaskVc.Enabled = true; btTaskVcEditSave.Text = "保存"; btTaskVcEditCancel.Enabled = true; } else { string taskVcName = cbTaskVc.Text; if (string.IsNullOrEmpty(taskVcName)) { MessageBox.Show("请选择需要保存的视觉配置名称"); return; } _isTaskVcEditting = false; cbTaskName.Enabled = true; cbTaskVc.Enabled = false; btTaskVcEditSave.Text = "编辑"; btTaskVcEditCancel.Enabled = false; JFDLAFRecipeManager rm = JFHubCenter.Instance.RecipeManager as JFDLAFRecipeManager; JFDLAFProductRecipe recipe = rm.GetRecipe(CategoteProduct, cbRecipeID.Text) as JFDLAFProductRecipe; recipe.SetVisionCfgName(cbFovName.Text, cbTaskName.Text, taskVcName); JFTipsDelayClose.Show("已保存\"taskVcName\" 到:" + cbTaskName.Text, 1); } }
private void btMark2EditSave_Click(object sender, EventArgs e) { if (!_isMark2VcEdit) { _isMark2VcEdit = true; cbMarkVc2.Enabled = true; btMark2EditSave.Text = "Sv"; } else { string vcName = cbMarkVc2.Text; if (string.IsNullOrEmpty(vcName)) { MessageBox.Show("请选择视觉配置名称"); return; } JFDLAFRecipeManager rm = JFHubCenter.Instance.RecipeManager as JFDLAFRecipeManager; JFDLAFProductRecipe recipe = rm.GetRecipe(CategoteProduct, cbRecipeID.Text) as JFDLAFProductRecipe; recipe.SetMark2LightCfg(vcName); _isMark2VcEdit = false; cbMarkVc2.Enabled = false; btMark2EditSave.Text = "Vc"; } }
/// <summary> /// 检查参数列表(是否有未设置选项) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btChkCfg_Click(object sender, EventArgs e) { string recipeID = cbRecipeID.Text; if (string.IsNullOrEmpty(recipeID)) { MessageBox.Show("RecipeID未选择"); return; } JFDLAFRecipeManager rm = JFHubCenter.Instance.RecipeManager as JFDLAFRecipeManager; JFDLAFProductRecipe recipe = rm.GetRecipe(CategoteProduct, cbRecipeID.Text) as JFDLAFProductRecipe; if (null == recipe) { MessageBox.Show("RecipeID = \"" + recipeID + "\"产品配方不存在"); return; } JFVisionManager vm = JFHubCenter.Instance.VisionMgr; bool isCfgOK = true; StringBuilder errorInfo = new StringBuilder(); string mark1Cfg = recipe.GetMark1LightCfg(); if (string.IsNullOrEmpty(mark1Cfg)) { isCfgOK = false; errorInfo.AppendLine("Mark1视觉配置未设置"); } else { if (!vm.ContainSingleVisionCfgByName(mark1Cfg)) { isCfgOK = false; errorInfo.AppendLine("Mark1视觉参数:\"" + mark1Cfg + "\" 在视觉配置表中不存在"); } } string mark2Cfg = recipe.GetMark2LightCfg(); if (string.IsNullOrEmpty(mark2Cfg)) { isCfgOK = false; errorInfo.AppendLine("Mark2视觉配置未设置"); } else { if (!vm.ContainSingleVisionCfgByName(mark2Cfg)) { isCfgOK = false; errorInfo.AppendLine("Mark2视觉参数:\"" + mark2Cfg + "\" 在视觉配置表中不存在"); } } string[] allFovNames = recipe.FovNames(); if (null != allFovNames) { foreach (string fovName in allFovNames) { string[] taskNames = recipe.TaskNames(fovName); if (null != taskNames) { foreach (string taskName in taskNames) { string vcName = recipe.VisionCfgName(fovName, taskName); if (string.IsNullOrEmpty(vcName)) { isCfgOK = false; errorInfo.AppendLine("Fov:\"" + fovName + "\" Task:\"" + taskName + "\" 视觉参数未设置"); } else { if (!vm.ContainSingleVisionCfgByName(vcName)) { isCfgOK = false; errorInfo.AppendLine("Fov:\"" + fovName + "\" Task:\"" + taskName + "\" 视觉参数:\"" + vcName + "\"在视觉配置中不存在"); } } } } } } if (isCfgOK) { MessageBox.Show("所有视觉参数已配置完成!"); return; } else { MessageBox.Show(errorInfo.ToString()); return; } }
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); }
/// <summary> /// 重命名产品 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnRename_Click(object sender, EventArgs e) { string souce = (string)lbxProductCategory.SelectedValue; if (souce == (string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID")) { HTUi.PopError("当前产品名称不可修改"); return; } String newname = ""; if (!MSG.Inputbox("new", "rename", out newname)) { return; } if (newname == string.Empty) { HTUi.PopWarn("命名错误,名字不能为空"); return; } var pdtlist = GetProductList(); foreach (var pdt in pdtlist) { if (pdt == newname) { HTUi.PopWarn("命名冲突,当前产品已存在"); return; } } //重新命名Recipe manager中recipe ID JFDLAFProductRecipe jFDLAFProductRecipe = JFHubCenter.Instance.RecipeManager.GetRecipe("Product", (string)souce) as JFDLAFProductRecipe; if (jFDLAFProductRecipe == null) { HTUi.PopWarn("Recipe Manager中不存在recipe:" + souce); return; } jFDLAFProductRecipe.Categoty = "Product"; jFDLAFProductRecipe.ID = newname; JFDLAFBoxRecipe jFDLAFBoxRecipe = JFHubCenter.Instance.RecipeManager.GetRecipe("Box", (string)souce) as JFDLAFBoxRecipe; if (jFDLAFBoxRecipe == null) { HTUi.PopWarn("Recipe Manager中不存在recipe:" + souce); return; } jFDLAFBoxRecipe.Categoty = "Box"; jFDLAFBoxRecipe.ID = newname; JFHubCenter.Instance.RecipeManager.AddRecipe(jFDLAFProductRecipe.Categoty, jFDLAFProductRecipe.ID, jFDLAFProductRecipe as IJFRecipe); JFHubCenter.Instance.RecipeManager.AddRecipe(jFDLAFBoxRecipe.Categoty, jFDLAFBoxRecipe.ID, jFDLAFBoxRecipe as IJFRecipe); JFHubCenter.Instance.RecipeManager.RemoveRecipe("Product", souce); JFHubCenter.Instance.RecipeManager.RemoveRecipe("Box", souce); JFHubCenter.Instance.RecipeManager.Save(); ChangeProdcutName(newname, souce); HTUi.TipHint("重命名成功!"); lbxProductCategory.DataSource = GetProductList(); return; }
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); }
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.正在检测); }
public void InitStationParams() { try { Dict = new JFXmlDictionary <string, object>(); visionCfgParams = new JFXmlDictionary <string, JFXmlDictionary <string, JFXmlDictionary <string, string> > >(); //系统参数 imageFolder = (string)JFHubCenter.Instance.RecipeManager.GetInitParamValue((string)JFHubCenter.Instance.RecipeManager.InitParamNames[2]); ActivePdt = (string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID"); formIniConfig = new IniFiles(imageFolder + "\\" + ActivePdt + "\\scanPoint.ini"); //工站参数 width = (double)GetCfgParamValue(mwidth); height = (double)GetCfgParamValue(mheight); _RunMode = (int)GetCfgParamValue(mRunMode); Num_Camera = (int)GetCfgParamValue(mNum_Camera); SelectedIndex = (int)GetCfgParamValue(mSelectIndex); Z_safe = (double)GetCfgParamValue(mZ_safe); jFDLAFProductRecipe = ((JFDLAFProductRecipe)JFHubCenter.Instance.RecipeManager.GetRecipe("Product", (string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID"))); //Recipe参数 if (jFDLAFProductRecipe != null) { FrameLength = jFDLAFProductRecipe.FrameLength; RowNumber = jFDLAFProductRecipe.RowNumber; ColumnNumber = jFDLAFProductRecipe.ColumnNumber; BlockNumber = jFDLAFProductRecipe.BlockNumber; visionCfgParams = jFDLAFProductRecipe.visionCfgParams; ZFocus = jFDLAFProductRecipe.ZFocus; } else { return; } if (jFDLAFProductRecipe.AutoMappingStationProInf != "") { string xmlTxt = jFDLAFProductRecipe.AutoMappingStationProInf; Dict = JFFunctions.FromXTString(xmlTxt, Dict.GetType()) as JFXmlDictionary <string, object>; xmlTxt = Dict.ContainsKey(mVisionCfgName) ? (string)Dict[mVisionCfgName] : ""; if (xmlTxt != "") { visionCfgParams = JFFunctions.FromXTString(xmlTxt, visionCfgParams.GetType()) as JFXmlDictionary <string, JFXmlDictionary <string, JFXmlDictionary <string, string> > >; } //工站中默认的参数 genMapStartX = Dict.ContainsKey(mgenMapStartX) ? (double)Dict[mgenMapStartX] : 0; genMapStartY = Dict.ContainsKey(mgenMapStartY) ? (double)Dict[mgenMapStartY] : 0; genMapEndX = Dict.ContainsKey(mgenMapEndX) ? (double)Dict[mgenMapEndX] : 0; genMapEndY = Dict.ContainsKey(mgenMapEndY) ? (double)Dict[mgenMapEndY] : 0; sameSpace = Dict.ContainsKey(msameSpace) ? (double)Dict[msameSpace] : 0; lctScoreThresh = Dict.ContainsKey(mlctScoreThresh) ? (double)Dict[mlctScoreThresh] : 0; checkMdlMethod = Dict.ContainsKey(mcheckMdlMethod) ? (int)Dict[mcheckMdlMethod] : 0; usedoubleCheck = Dict.ContainsKey(musedoubleCheck) ? (int)Dict[musedoubleCheck] : 0; //ZFocus = Dict.ContainsKey(mZFocus) ? (double)Dict[mZFocus] : 0; hv_dieWidth = Dict.ContainsKey(mdieWidth) ? (double)Dict[mdieWidth] : 0; hv_dieHeight = Dict.ContainsKey(mdieHeight) ? (double)Dict[mdieHeight] : 0; ref_x = Dict.ContainsKey(mref_x) ? (double)Dict[mref_x] : 0; ref_y = Dict.ContainsKey(mref_y) ? (double)Dict[mref_y] : 0; ref_z = Dict.ContainsKey(mref_z) ? (double)Dict[mref_z] : 0; scanRowNum = Dict.ContainsKey(mscanRowNum) ? (int)Dict[mscanRowNum] : 0; scanColNum = Dict.ContainsKey(mscanColNum) ? (int)Dict[mscanColNum] : 0; clipPosNum = Dict.ContainsKey(mclipPosNum) ? (int)Dict[mclipPosNum] : 0; scanPosNum = Dict.ContainsKey(mscanPosNum) ? (int)Dict[mscanPosNum] : 0; if (Dict.ContainsKey(mFovRow)) { ICFovRow = (List <double>)Dict[mFovRow]; } if (Dict.ContainsKey(mFovCol)) { ICFovCol = (List <double>)Dict[mFovCol]; } } else { if (Config.ContainsItem((string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID"))) { string xmlTxt = (string)GetCfgParamValue((string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID")); Dict = JFFunctions.FromXTString(xmlTxt, Dict.GetType()) as JFXmlDictionary <string, object>; xmlTxt = Dict.ContainsKey(mVisionCfgName) ? (string)Dict[mVisionCfgName] : ""; if (xmlTxt != "") { visionCfgParams = JFFunctions.FromXTString(xmlTxt, visionCfgParams.GetType()) as JFXmlDictionary <string, JFXmlDictionary <string, JFXmlDictionary <string, string> > >; } //工站中默认的参数 genMapStartX = Dict.ContainsKey(mgenMapStartX) ? (double)Dict[mgenMapStartX] : 0; genMapStartY = Dict.ContainsKey(mgenMapStartY) ? (double)Dict[mgenMapStartY] : 0; genMapEndX = Dict.ContainsKey(mgenMapEndX) ? (double)Dict[mgenMapEndX] : 0; genMapEndY = Dict.ContainsKey(mgenMapEndY) ? (double)Dict[mgenMapEndY] : 0; sameSpace = Dict.ContainsKey(msameSpace) ? (double)Dict[msameSpace] : 0; lctScoreThresh = Dict.ContainsKey(mlctScoreThresh) ? (double)Dict[mlctScoreThresh] : 0; checkMdlMethod = Dict.ContainsKey(mcheckMdlMethod) ? (int)Dict[mcheckMdlMethod] : 0; usedoubleCheck = Dict.ContainsKey(musedoubleCheck) ? (int)Dict[musedoubleCheck] : 0; //ZFocus = Dict.ContainsKey(mZFocus) ? (double)Dict[mZFocus] : 0; hv_dieWidth = Dict.ContainsKey(mdieWidth) ? (double)Dict[mdieWidth] : 0; hv_dieHeight = Dict.ContainsKey(mdieHeight) ? (double)Dict[mdieHeight] : 0; ref_x = Dict.ContainsKey(mref_x) ? (double)Dict[mref_x] : 0; ref_y = Dict.ContainsKey(mref_y) ? (double)Dict[mref_y] : 0; ref_z = Dict.ContainsKey(mref_z) ? (double)Dict[mref_z] : 0; scanRowNum = Dict.ContainsKey(mscanRowNum) ? (int)Dict[mscanRowNum] : 0; scanColNum = Dict.ContainsKey(mscanColNum) ? (int)Dict[mscanColNum] : 0; clipPosNum = Dict.ContainsKey(mclipPosNum) ? (int)Dict[mclipPosNum] : 0; scanPosNum = Dict.ContainsKey(mscanPosNum) ? (int)Dict[mscanPosNum] : 0; if (Dict.ContainsKey(mFovRow)) { ICFovRow = (List <double>)Dict[mFovRow]; } if (Dict.ContainsKey(mFovCol)) { ICFovCol = (List <double>)Dict[mFovCol]; } } } //else if(File.Exists(imageFolder + "\\" + ActivePdt + "\\scanPoint.ini")) //{ // formIniConfig.ReadDouble("ScanPoints", "genMapStartX", out genMapStartX); // formIniConfig.ReadDouble("ScanPoints", "genMapStartY", out genMapStartY); // formIniConfig.ReadDouble("ScanPoints", "genMapEndX", out genMapEndX); // formIniConfig.ReadDouble("ScanPoints", "genMapEndY", out genMapEndY); // formIniConfig.ReadDouble("ScanPoints", "sameSpace", out sameSpace); // formIniConfig.ReadDouble("ScanPoints", "scaleFactor", out scaleFactor); // formIniConfig.ReadDouble("ScanPoints", "lctScoreThresh", out lctScoreThresh); // formIniConfig.ReadDouble("ScanPoints", "checkPosX", out checkPosX); // formIniConfig.ReadDouble("ScanPoints", "checkPosY", out checkPosY); // formIniConfig.ReadDouble("ScanPoints", "checkPosScoreThresh", out checkPosScoreThresh); // formIniConfig.ReadDouble("ScanPoints", "widthFactor", out widthFactor); // formIniConfig.ReadDouble("ScanPoints", "heightFactor", out heightFactor); // formIniConfig.ReadInteger("ScanPoints", "CheckModelMethod", out checkMdlMethod); // formIniConfig.ReadDouble("ScanPoints", "checkPosRX", out checkPosRX); // formIniConfig.ReadDouble("ScanPoints", "checkPosRY", out checkPosRY); // formIniConfig.ReadDouble("ScanPoints", "checkPosRScoreThresh", out checkPosRScoreThresh); // formIniConfig.ReadInteger("ScanPoints", "useDoubleCheck", out usedoubleCheck); // ICFovRow = new List<double>(); // ICFovCol = new List<double>(); //} } catch { } }
protected override bool ActionGenuine(out string errorInfo) { while (true) { if (1 == _workCmd)//当前为暂停状态 { Thread.Sleep(10); continue; } else if (-1 == _workCmd)//指令退出 { char step = 'a'; errorInfo = "收到退出指令"; _workCmd = 0; _isRunning = false; return(false); } else if (0 == _workCmd)//指令退出 { errorInfo = "收到回复指令"; _workCmd = 0; _isRunning = true; if (_station == null) { errorInfo = "工站未设置"; return(false); } double InsetDis = (double)_station.GetCfgParamValue(FrameInsertDis); double TrackTotalDis = (double)_station.GetCfgParamValue(LeftClampRightPos) - (double)_station.GetCfgParamValue(LeftClampWaitPos); // double _FrameLong = (double)_station.GetCfgParamValue(FrameLongth); double _CheckPos = (double)_station.GetCfgParamValue(CheckPos); double RightEndPos = (double)_station.GetCfgParamValue(LeftClampRightPos); double _ClampLongth = (double)_station.GetCfgParamValue(ClampLongth); JFDLAFProductRecipe BoardRecipe = ((JFDLAFProductRecipe)JFHubCenter.Instance.RecipeManager.GetRecipe("Product", (string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID"))); double _FrameLong = BoardRecipe.FrameLength; int delay = 10000; switch (step) { case 'a': if (!JFWaitDi(LeftFrameCheckName, out errorInfo, true)) { errorInfo = _station.Name + ":" + LeftFrameCheckName + "获取DI状态失败!"; _workCmd = 0; _isRunning = false; return(false); } RightFactPos = InsetDis; step = 'b'; break; case 'b': //if (!Move(LeftClampName, LeftClampOpenPos, true, delay, out errorInfo)) // return false; if (!_station.SetDO(CyClampName, true, out errorInfo)) { return(false); } if (!JFWaitDi(CylClampUpcheck, out errorInfo, true, 4000)) { errorInfo = _station.Name + ":" + CylClampUpcheck + "获取DI状态失败!"; _workCmd = 0; _isRunning = false; return(false); } step = 'c'; break; case 'c': if (!Move(LeftPushName, LeftClampWaitPos, true, delay, out errorInfo)) { return(false); } step = 'd'; break; case 'd': if (!_station.SetDO(CyClampName, false, out errorInfo)) { return(false); } if (!JFWaitDi(CylClampUpcheck, out errorInfo, false, 2000)) { errorInfo = _station.Name + ":" + CylClampDowncheck + "获取DI状态失败!"; _workCmd = 0; _isRunning = false; return(false); } step = 'e'; break; case 'e': if (!Move(LeftPushName, LeftClampRightPos, true, delay, out errorInfo)) { return(false); } RightFactPos += TrackTotalDis; LeftFactPos = RightFactPos - _FrameLong; NeedPos = _CheckPos + _FrameLong - RightFactPos; step = 'f'; break; case 'f': //if (!Move(LeftClampName, LeftClampOpenPos, true, delay, out errorInfo)) // return false; if (!_station.SetDO(CyClampName, true, out errorInfo)) { return(false); } if (!JFWaitDi(CylClampUpcheck, out errorInfo, true, 2000)) { errorInfo = _station.Name + ":" + CylClampUpcheck + "获取DI状态失败!"; _workCmd = 0; _isRunning = false; return(false); } //if (NeedPos > TrackTotalDis) // { // if (LeftFactPos > 30) // step = 'g'; // step = 'c'; // } // else // { // if (LeftFactPos > 30) // step = 'g'; // } // step = 'c'; if (LeftFactPos > _ClampLongth) { step = 'g'; } else { step = 'c'; } break; case 'g': double MotorBack = NeedPos; double clampRightPos = RightEndPos + _ClampLongth; double ShoulBackPos = clampRightPos - LeftFactPos; // MotorPos = (double)_station.GetCfgParamValue(LeftClampRightPos) - MotorBack; MotorPos = (double)_station.GetCfgParamValue(LeftClampRightPos) - ShoulBackPos - 10; if (!_station.MoveAxis(LeftPushName, MotorPos, true, out errorInfo)) { errorInfo = _station.Name + ":" + LeftPushName + "运动超时未完成!"; _workCmd = 0; _isRunning = false; return(false); } if (_station.WaitMotionDone(LeftPushName, 10000) != JFWorkCmdResult.Success) { errorInfo = _station.Name + ":" + LeftClampName + "运动超时未完成!"; _workCmd = 0; _isRunning = false; return(false); } step = 'h'; break; case 'h': //if (!Move(LeftClampName, LeftClampClosePos, true, delay, out errorInfo)) // return false; if (!_station.SetDO(CyClampName, false, out errorInfo)) { return(false); } if (!JFWaitDi(CylClampUpcheck, out errorInfo, false, 2000)) { errorInfo = _station.Name + ":" + CylClampDowncheck + "获取DI状态失败!"; _workCmd = 0; _isRunning = false; return(false); } step = 'i'; break; case 'i': //if (!_station.MoveAxis(LeftPushName, MotorPos + NeedPos + 5, true, out errorInfo)) if (!_station.MoveAxis(LeftPushName, _CheckPos, true, out errorInfo)) { errorInfo = _station.Name + ":" + LeftPushName + "运动超时未完成!"; _workCmd = 0; _isRunning = false; return(false); } if (_station.WaitMotionDone(LeftPushName, 10000) != JFWorkCmdResult.Success) { errorInfo = _station.Name + ":" + LeftClampName + "运动超时未完成!"; _workCmd = 0; _isRunning = false; return(false); } step = 'j'; break; case 'j': if (!_station.SetDO(CyClampName, true, out errorInfo)) { return(false); } if (!JFWaitDi(CylClampUpcheck, out errorInfo, true, 2000)) { errorInfo = _station.Name + ":" + CylClampUpcheck + "获取DI状态失败!"; _workCmd = 0; _isRunning = false; return(false); } if (!Move(LeftPushName, LeftClampWaitPos, true, delay, out errorInfo)) { return(false); } step = 'a'; RightFactPos = 0; errorInfo = "Success"; return(true); default: errorInfo = _station.Name + ":" + "Action 调用出错!"; return(false); } } } // errorInfo = "Success"; // return true; }
/// <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; } } }
//主动做流程 protected override void RunLoopInWork() { string errorInfo; JFWorkCmdResult wcr = JFWorkCmdResult.UnknownError; bool diSigON = false; object obj = null; switch (CurrCS) { //case STStatus.已停止: // break; case STStatus.开始运行: SendMsg2Outter("开始运行任务主流程"); _Clamp(false); //打开夹手气缸 //先检测轨道上是否有残留工件 if (!GetDIByAlias(DevAN_DIPieceInFeed, out diSigON, out errorInfo)) { ExitWork(WorkExitCode.Exception, "获取进料口感应信号失败,Error:" + errorInfo); } if (diSigON) { ExitWork(WorkExitCode.Exception, "工站复位失败:进料口有工件"); } //if (!GetDIByAlias(DevAN_DIPieceInDetect, out diSigON, out errorInfo)) // ExitWork(WorkExitCode.Exception, "获取检测位感应信号失败,Error:" + errorInfo); //if (diSigON) // ExitWork(WorkExitCode.Exception, "工站复位失败:检测位置有工件"); if (!GetDIByAlias(DevAN_DIPieceInEject, out diSigON, out errorInfo)) { ExitWork(WorkExitCode.Exception, "获取出料口感应信号失败,Error:" + errorInfo); } if (diSigON) { ExitWork(WorkExitCode.Exception, "工站复位失败:出料口有工件"); } ChangeCS(STStatus.等待检测Z轴避位); break; case STStatus.等待检测Z轴避位: //归零时等待Z轴抬起后,再进行下一步动作 if (!WaitSPBoolByAliasName(GPN_DetectAvoid, true, out errorInfo)) { ExitWork(WorkExitCode.Exception, errorInfo); } ChangeCS(STStatus.调节导轨宽度); break; //case STStatus.复位: //主流程运行时不会进入 // break; case STStatus.调节导轨宽度: string currRecipeIncfg = JFHubCenter.Instance.SystemCfg.GetItemValue(SYS_CurrentRecipeID) as string; JFDLAFProductRecipe productRecipe = JFHubCenter.Instance.RecipeManager.GetRecipe("Product", currRecipeIncfg) as JFDLAFProductRecipe; JFDLAFBoxRecipe boxRecipe = JFHubCenter.Instance.RecipeManager.GetRecipe("Box", /*productRecipe.magezineBox*/ _currPieceID) as JFDLAFBoxRecipe; if (_isAxisIntervelFitted) //已经调节过轨道宽度 { if (currRecipeIncfg == _currPieceID) { if (_trackIntervel == boxRecipe.FrameWidth) //防止参数被修改 { ChangeCS(STStatus.移动到待机位置); break; } } } _trackIntervel = boxRecipe.FrameWidth; _isAxisIntervelFitted = false; SendMsg2Outter("开始调节轨道宽度到:" + _trackIntervel); //开始调解轨道宽度 double axisTargetPos = _trackIntervel - _trackOrg; //轴实际位置为产品宽度-轴归零后的间距 if (!MoveAxisByAlias(DevAN_AxisIntervel, axisTargetPos, true, out errorInfo)) { ExitWork(WorkExitCode.Exception, "移动轴:" + DevAN_AxisIntervel + " 失败,ErrorInfo:" + errorInfo); } wcr = WaitMotionDoneByAlias(DevAN_AxisIntervel); if (JFWorkCmdResult.Success != wcr) { ExitWork(WorkExitCode.Exception, "等待轴运动完成失败,Ret = " + wcr); } _isAxisIntervelFitted = true; //SetSPAliasValue(GPN_PickDone, false); ChangeCS(STStatus.移动到待机位置); break; case STStatus.移动到待机位置: if (!MoveToWorkPosition(WPN_Standby, out errorInfo)) { ExitWork(WorkExitCode.Exception, "进料X轴移动到待机位置失败:" + errorInfo); } if (!WaitToWorkPosition(WPN_Standby, out errorInfo)) { ExitWork(WorkExitCode.Exception, "等待移动到待机位置失败,errorInfo:" + errorInfo); } SetSPAliasValue(GPN_FeedReady, true); ChangeCS(STStatus.等待进料信号); break; case STStatus.等待进料信号: //等待料仓向轨道送料完成信号 && 检测工站等待进料 && 出料工站允许进料 while (true) { CheckCmd(CycleMilliseconds); //本站的送料完成信号必须为false,(防止送料完成后重复送料) if (!GetSPAliasValue(GPN_FeedOK, out obj)) //上料仓工件已准备好 { ExitWork(WorkExitCode.Exception, "获取变量=" + GPN_FeedOK + " 失败!"); } if ((bool)obj) { CheckCmd(100); continue; } if (!GetSPAliasValue(GPN_LoadReady, out obj)) //上料仓工件已准备好 { ExitWork(WorkExitCode.Exception, "获取变量=" + GPN_LoadReady + " 失败!"); } if (!(bool)obj) { CheckCmd(100); continue; } if (!GetSPAliasValue(GPN_DetectAvoid, out obj)) //Z轴是否以避位 { ExitWork(WorkExitCode.Exception, "获取变量=" + GPN_DetectAvoid + " 失败!"); } if (!(bool)obj) { CheckCmd(100); continue; } if (!GetSPAliasValue(GPN_DetectReady, out obj)) //工站准备好检测 { ExitWork(WorkExitCode.Exception, "获取变量=" + GPN_DetectReady + " 失败!"); } if (!(bool)obj) { CheckCmd(100); continue; } if (!GetSPAliasValue(GPN_EjectReady, out obj)) //出料站允许送料 { ExitWork(WorkExitCode.Exception, "获取变量=" + GPN_EjectReady + " 失败!"); } if (!(bool)obj) { CheckCmd(100); continue; } break; } ChangeCS(STStatus.进料); break; case STStatus.进料: //轨道(自身)向检测位置送料 SetSPAliasValue(GPN_FeedReady, false); _Clamp(true); //下压夹爪 double clampDis = 0; //需要夹住工件往返运动的距离 double pushDis = 0; //最后一次退料的距离; if (_feedDistance < _singleTripLength) //总行程 { clampDis = _feedDistance; //只需要夹持一次就好 } else { clampDis = _piece2HandEdge + 5; //预留退料间隙5mm pushDis = _feedDistance - _piece2HandEdge; } while (clampDis > _singleTripLength) { //往返运动一次 SendMsg2Outter("夹料距离:" + _singleTripLength); _ClampFeedPiece(_singleTripLength); clampDis -= _singleTripLength; } if (clampDis > 0) //最后一节不足一个行程的部分 { SendMsg2Outter("夹料距离:" + clampDis); _ClampFeedPiece(clampDis); } if (pushDis > 0) //闭合夹爪,推料到位 { SendMsg2Outter("推料距离:" + pushDis); _Clamp(true); if (!MoveAxisByAlias(DevAN_AxisFeed, pushDis, false, out errorInfo)) { ExitWork(WorkExitCode.Exception, "推料失败,ErrorInfo:" + errorInfo); } wcr = WaitMotionDoneByAlias(DevAN_AxisFeed); if (wcr != JFWorkCmdResult.Success) { ExitWork(WorkExitCode.Exception, "等待推料到位失败,ErrorInfo:" + errorInfo); } } SetSPAliasValue(GPN_PickDone, true); //通知上料仓 ,工件已经取走 //打开夹爪 _Clamp(false); //返回待机位置 if (!MoveToWorkPosition(WPN_Standby, out errorInfo)) { ExitWork(WorkExitCode.Exception, "进料完成返回待机位置失败,ErrorInfo:" + errorInfo); } if (!WaitToWorkPosition(WPN_Standby, out errorInfo)) { ExitWork(WorkExitCode.Exception, "进料完成后,等待返回待机位置失败,ErrorInfo:" + errorInfo); } //将送料完成信号置为true SetSPAliasValue(GPN_FeedOK, true); SetSPAliasValue(GPN_FeedReady, true); //通知料仓,本站开始等待送料完成 ChangeCS(STStatus.等待进料信号); break; default: ExitWork(WorkExitCode.Exception, "工作流程中未命中的Custom-Status:" + CurrCS.ToString()); break; } }
double _piece2HandEdge = 0; //料仓送料完成后,料片左边缘到夹手右边缘的距离 /// <summary> /// 准备运行所需要的参数 /// </summary> void _BuildTaskParam() { _currPieceID = JFHubCenter.Instance.SystemCfg.GetItemValue(SYS_CurrentRecipeID) as string; if (string.IsNullOrEmpty(_currPieceID)) { ExitWork(WorkExitCode.Exception, " 系统数据项:" + SYS_CurrentRecipeID + " 未设置"); } JFDLAFProductRecipe productRecipe = JFHubCenter.Instance.RecipeManager.GetRecipe("Product", _currPieceID) as JFDLAFProductRecipe; if (null == productRecipe) { ExitWork(WorkExitCode.Exception, "产品配方:" + _currPieceID + " 不存在"); } if (string.IsNullOrEmpty(productRecipe.magezineBox)) { ExitWork(WorkExitCode.Exception, "产品配方:" + _currPieceID + " 未包含BoxID配置项"); } JFDLAFBoxRecipe boxRecipe = JFHubCenter.Instance.RecipeManager.GetRecipe("Box", /*productRecipe.magezineBox*/ _currPieceID) as JFDLAFBoxRecipe; if (null == boxRecipe) { ExitWork(WorkExitCode.Exception, "产品配方:" + _currPieceID + " BoxID:" + productRecipe.magezineBox + " 在配方管理器中不存在"); } //_trackIntervel = boxRecipe.FrameWidth; if (boxRecipe.FrameWidth <= 0) { ExitWork(WorkExitCode.Exception, " BoxID:" + productRecipe.magezineBox + " 参数项FrameWidth = " + _trackIntervel + " 为非法值!"); } _feedDistance = (double)GetCfgParamValue(SCN_FeedDistance); if (_feedDistance <= 0) { ExitWork(WorkExitCode.Exception, "运行参数:" + SCN_FeedDistance + " =" + _feedDistance + " 为非法值"); } _singleTripLength = (double)GetCfgParamValue(SCN_PushLength); if (_singleTripLength <= 0) { ExitWork(WorkExitCode.Exception, "运行参数:" + SCN_PushLength + " =" + _singleTripLength + " 为非法值"); } _piece2HandEdge = (double)GetCfgParamValue(SCN_Piece2Hand); if (_piece2HandEdge <= 0) { ExitWork(WorkExitCode.Exception, "运行参数:" + SCN_Piece2Hand + " =" + _piece2HandEdge + " 为非法值"); } _trackOrg = (double)GetCfgParamValue(SCN_TrackOrgWidth); if (_trackOrg <= 0) { ExitWork(WorkExitCode.Exception, "运行参数:" + SCN_TrackOrgWidth + " =" + _trackOrg + " 为非法值"); } //检查待机点位是否设置 JFMultiAxisPosition standbyPos = GetWorkPosition(WPN_Standby); string axisXName = GetDecChnGlobName(NamedChnType.Axis, DevAN_AxisFeed); if (string.IsNullOrEmpty(axisXName)) { ExitWork(WorkExitCode.Exception, "轴替身:" + DevAN_AxisFeed + " 未邦定全局轴名称"); } if (standbyPos.AxisNames.Length != 1 || !standbyPos.ContainAxis(axisXName)) { ExitWork(WorkExitCode.Exception, "进料待机点位设置错误!只能包含进料X轴"); } }
protected override bool ActionGenuine(out string errorInfo) { while (true) { if (1 == _workCmd)//当前为暂停状态 { _station.StopAxis(RighClampName); _station.StopAxis(RighPushName); Thread.Sleep(10); continue; } else if (-1 == _workCmd)//指令退出 { _station.StopAxis(RighClampName); _station.StopAxis(RighPushName); step = 'a'; errorInfo = "收到退出指令"; _workCmd = 0; _isRunning = false; return(false); } else if (0 == _workCmd)//指令退出 { double TrackTotalDis = (double)_station.GetCfgParamValue(RighClampWaitPos) - (double)_station.GetCfgParamValue(RighClampRightPos); double LeftPos = (double)_station.GetCfgParamValue(RighClampWaitPos); double RightPos = (double)_station.GetCfgParamValue(RighClampRightPos); //double _FrameLongth = (double)_station.GetCfgParamValue(FrameLongth); JFDLAFProductRecipe BoardRecipe = ((JFDLAFProductRecipe)JFHubCenter.Instance.RecipeManager.GetRecipe("Product", (string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID"))); double _FrameLongth = BoardRecipe.FrameLength; int delay = 10000; errorInfo = ""; switch (step) { case 'a': PushCount = 0; step = 'b'; break; case 'b': //if (!Move(RighClampName, RighClampOpenPos, true, delay, out errorInfo)) // return false; if (!_station.SetDO(CyClampName, true, out errorInfo)) { return(false); } if (!JFWaitDi(CylClampUpcheck, out errorInfo, true, 4000)) { errorInfo = _station.Name + ":" + CylClampUpcheck + "获取DI状态失败!"; _workCmd = 0; _isRunning = false; return(false); } step = 'c'; break; case 'c': if (!Move(RighPushName, RighClampWaitPos, true, delay, out errorInfo)) { return(false); } step = 'd'; break; case 'd': //if (!Move(RighClampName, RighClampClosePos, true, delay, out errorInfo)) // return false; if (!_station.SetDO(CyClampName, false, out errorInfo)) { return(false); } if (!JFWaitDi(CylClampUpcheck, out errorInfo, false, 2000)) { errorInfo = _station.Name + ":" + CylClampDowncheck + "获取DI状态失败!"; _workCmd = 0; _isRunning = false; return(false); } step = 'e'; break; case 'e': if (!Move(RighPushName, RighClampRightPos, true, delay, out errorInfo)) { return(false); } step = 'f'; break; case 'f': //if (!Move(RighClampName, RighClampOpenPos, true, delay, out errorInfo)) // return false; if (!_station.SetDO(CyClampName, true, out errorInfo)) { return(false); } if (!JFWaitDi(CylClampUpcheck, out errorInfo, true, 4000)) { errorInfo = _station.Name + ":" + CylClampUpcheck + "获取DI状态失败!"; _workCmd = 0; _isRunning = false; return(false); } step = 'g'; break; case 'g': double MotorBack = RightPos - _FrameLongth; if (!_station.MoveAxis(RighPushName, MotorBack, true, out errorInfo)) { return(false); } if (!JFMotionDone(RighPushName, out errorInfo, delay)) { return(false); } PushCount++; step = 'h'; break; case 'h': //if (!Move(RighClampName, RighClampClosePos, true, delay, out errorInfo)) // return false; if (!_station.SetDO(CyClampName, false, out errorInfo)) { return(false); } if (!JFWaitDi(CylClampUpcheck, out errorInfo, false, 2000)) { errorInfo = _station.Name + ":" + CylClampDowncheck + "获取DI状态失败!"; _workCmd = 0; _isRunning = false; return(false); } step = 'i'; break; case 'i': if (!_station.MoveAxis(RighPushName, RightPos, true, out errorInfo)) { return(false); } if (JFWaitDi(RightFrameCheckName, out errorInfo, true, 6000)) { _station.StopAxis(RighPushName); step = 'j'; break; } // step = 'j'; break; case 'j': //if (!Move(RighClampName, RighClampOpenPos, true, delay, out errorInfo)) // return false; if (!_station.SetDO(CyClampName, true, out errorInfo)) { return(false); } if (!JFWaitDi(CylClampUpcheck, out errorInfo, true, 4000)) { errorInfo = _station.Name + ":" + CylClampUpcheck + "获取DI状态失败!"; _workCmd = 0; _isRunning = false; return(false); } step = 'k'; break; case 'k': //_station.StopAxis(RighPushName); if (!_station.GetAxisPosition(RighPushName, out InStopPos, out errorInfo)) { return(false); } // NeedPos = RightPos - InStopPos; // ShouldBack = NeedPos + 185; // BackPos = _FrameLongth - NeedPos; // MotorBackPos = InStopPos- BackPos - 5; //MotorBackPos = InStopPos - _FrameLongth; MotorBackPos = RightPos - _FrameLongth - 50; step = 'l'; break; case 'l': if (!_station.MoveAxis(RighPushName, MotorBackPos, true, out errorInfo)) { errorInfo = _station.Name + ":" + RighPushName + "运动超时未完成!"; _workCmd = 0; _isRunning = false; return(false); } if (_station.WaitMotionDone(RighPushName, 10000) != JFWorkCmdResult.Success) { errorInfo = _station.Name + ":" + RighPushName + "运动超时未完成!"; _workCmd = 0; _isRunning = false; return(false); } step = 'm'; break; case 'm': //if (!Move(RighClampName, RighClampClosePos, true, delay, out errorInfo)) // return false; if (!_station.SetDO(CyClampName, false, out errorInfo)) { return(false); } if (!JFWaitDi(CylClampUpcheck, out errorInfo, false, 2000)) { errorInfo = _station.Name + ":" + CylClampDowncheck + "获取DI状态失败!"; _workCmd = 0; _isRunning = false; return(false); } step = 'n'; break; case 'n': if (!_station.SetDO(CylPushUp, true, out errorInfo)) { return(false); } if (!JFWaitDi(CylPushUpcheck, out errorInfo, true, 4000)) { errorInfo = _station.Name + ":" + CylPushUpcheck + "获取DI状态失败!"; _workCmd = 0; _isRunning = false; return(false); } //if (!Move(RighPushName, RighClampRightPos, true, delay, out errorInfo)) // return false; if (!_station.MoveAxis(RighPushName, RightPos, true, out errorInfo)) { errorInfo = _station.Name + ":" + RighPushName + "运动超时未完成!"; _workCmd = 0; _isRunning = false; return(false); } DateTime startTime = DateTime.Now; do { if (JFWaitDi(CylProtect, out errorInfo, true, 1)) { _station.StopAxis(RighPushName); errorInfo = _station.Name + ":" + CylProtect + "发生碰撞!"; return(false); } TimeSpan ts = DateTime.Now - startTime; if (ts.TotalMilliseconds >= 5000) { errorInfo = _station.Name + ":" + RighPushName + "运动超时未完成!";; return(false); } } while (_station.WaitMotionDone(RighPushName, 1) != JFWorkCmdResult.Success); step = 'o'; break; case 'o': double backposition = (double)_station.GetCfgParamValue(RighClampRightPos) - 100; if (!_station.MoveAxis(RighPushName, backposition, true, out errorInfo)) { errorInfo = _station.Name + ":" + RighPushName + "运动超时未完成!"; _workCmd = 0; _isRunning = false; return(false); } if (_station.WaitMotionDone(RighPushName, 10000) != JFWorkCmdResult.Success) { errorInfo = _station.Name + ":" + RighPushName + "运动超时未完成!"; _workCmd = 0; _isRunning = false; return(false); } if (!_station.SetDO(CylPushUp, false, out errorInfo)) { return(false); } if (!JFWaitDi(CylPushUpcheck, out errorInfo, false, 4000)) { errorInfo = _station.Name + ":" + CylPushUpcheck + "获取DI状态失败!"; _workCmd = 0; _isRunning = false; return(false); } step = 'a'; errorInfo = "Success"; return(true); default: errorInfo = _station.Name + ":" + "Action 调用出错!"; return(false); } } } // return true; }
/// <summary> /// 创建产品 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnCreateProduct_Click(object sender, EventArgs e) { String newfile = ""; if (!MSG.Inputbox("Copy&New", "请输入新的产品名", out newfile)) { return; } if (newfile == string.Empty) { HTUi.PopWarn("命名错误,名字不能为空"); return; } //新增Product Recipe到recipe Dictionary中 JFDLAFProductRecipe jFDLAFProductRecipe = new JFDLAFProductRecipe(); if (JFHubCenter.Instance.RecipeManager.GetRecipe("Product", (string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID")) != null) { jFDLAFProductRecipe = ((JFDLAFProductRecipe)JFHubCenter.Instance.RecipeManager.GetRecipe("Product", (string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID"))).Clone(); } jFDLAFProductRecipe.ID = newfile; jFDLAFProductRecipe.Categoty = "Product"; jFDLAFProductRecipe.SaveParamsToCfg(); JFHubCenter.Instance.RecipeManager.AddRecipe(jFDLAFProductRecipe.Categoty, jFDLAFProductRecipe.ID, jFDLAFProductRecipe as IJFRecipe); ////新增Box Recipe到recipe Dictionary中 JFDLAFBoxRecipe jFDLAFBoxRecipe = new JFDLAFBoxRecipe(); if (JFHubCenter.Instance.RecipeManager.GetRecipe("Box", (string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID")) != null) { jFDLAFBoxRecipe = ((JFDLAFBoxRecipe)JFHubCenter.Instance.RecipeManager.GetRecipe("Box", (string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID"))).Clone(); } jFDLAFBoxRecipe.MagezineBox = jFDLAFProductRecipe.MagezineBox; jFDLAFBoxRecipe.MgzIdx = jFDLAFProductRecipe.MgzIdx; jFDLAFBoxRecipe.ID = newfile; jFDLAFBoxRecipe.Categoty = "Box"; jFDLAFBoxRecipe.SaveParamsToCfg(); JFHubCenter.Instance.RecipeManager.AddRecipe(jFDLAFBoxRecipe.Categoty, jFDLAFBoxRecipe.ID, jFDLAFBoxRecipe as IJFRecipe); //此处后面需要保存 JFHubCenter.Instance.RecipeManager.Save(); var pdtlist = GetProductList(); foreach (var pdt in pdtlist) { if (pdt == newfile) { HTUi.PopWarn("无法新建,当前产品已存在"); return; } } string souce = (string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID"); if (!CreateProduct(souce, newfile)) { HTUi.PopWarn("产品创建失败!"); return; } HTLog.Info("产品创建成功!"); HTUi.TipHint("产品创建成功!"); lbxProductCategory.DataSource = GetProductList(); return; }