/// <summary> /// 保存产品 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void btnSave_Click(object sender, EventArgs e) { Form_Wait.ShowForm(); await Task.Run(new Action(() => { //需要保存当前产品的相关参数 if (_operation != null) { JFDLAFBoxRecipe jFDLAFBoxRecipe = JFHubCenter.Instance.RecipeManager.GetRecipe("Box", (string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID")) as JFDLAFBoxRecipe; jFDLAFBoxRecipe.MagezineBox = _operation.MagezineBox; jFDLAFBoxRecipe.MgzIdx = _operation.MgzIdx; jFDLAFBoxRecipe.SaveParamsToCfg(); _operation.SaveParamsToCfg(); JFHubCenter.Instance.RecipeManager.RemoveRecipe("Product", (string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID")); JFHubCenter.Instance.RecipeManager.RemoveRecipe("Box", (string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID")); JFHubCenter.Instance.RecipeManager.AddRecipe(_operation.Categoty, _operation.ID, _operation as IJFRecipe); JFHubCenter.Instance.RecipeManager.AddRecipe("Box", _operation.ID, jFDLAFBoxRecipe as IJFRecipe); } JFHubCenter.Instance.RecipeManager.Save(); if (_operation != null) { if (_operation.MgzIdx == -1) { HTLog.Error("注意:当前产品未选择料盒型号,开始流程需要选择料盒型号."); return; } } })); Form_Wait.CloseForm(); }
protected override bool ActionGenuine(out string errorInfo) { JFDLAFBoxRecipe boxRecipe = ((JFDLAFBoxRecipe)JFHubCenter.Instance.RecipeManager.GetRecipe("Box", (string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID"))); if (boxRecipe == null) { errorInfo = "料盒Reccipe不存在"; return(false); } SetOutputParamValue(mHeightLastSlot, (double)boxRecipe.HeightLastSlot); SetOutputParamValue(mHeightLastSlot_y, (double)boxRecipe.HeightLastSlot_y); SetOutputParamValue(mHeightFirstSlot, (double)boxRecipe.HeightFirstSlot); SetOutputParamValue(mHeightFirstSlot_y, (double)boxRecipe.HeightFirstSlot_y); SetOutputParamValue(mHeightLastSlot_Unload, (double)boxRecipe.HeightLastSlot_Unload); SetOutputParamValue(mHeightLastSlot_Unload_y, (double)boxRecipe.HeightLastSlot_Unload_y); SetOutputParamValue(mHeightFirstSlot_Unload, (double)boxRecipe.HeightFirstSlot_Unload); SetOutputParamValue(mHeightFirstSlot_Unload_y, (double)boxRecipe.HeightFirstSlot_Unload_y); SetOutputParamValue(mSlotNumber, (int)boxRecipe.SlotNumber); SetOutputParamValue(mBlankNumber_Unload, (double)boxRecipe.BlankNumber_Unload); SetOutputParamValue(mFrameWidth, (double)boxRecipe.FrameWidth); SetOutputParamValue(mLoad_y_LoadUnLoadFramePos, (double)boxRecipe.Load_y_LoadUnLoadFramePos); SetOutputParamValue(mUnLoad_y_LoadUnLoadFramePos, (int)boxRecipe.UnLoad_y_LoadUnLoadFramePos); SetOutputParamValue(mLoad_x_PushRodWaitPos, (double)boxRecipe.Load_x_PushRodWaitPos); SetOutputParamValue(mLoad_x_PushRodOverPos, (double)boxRecipe.Load_x_PushRodOverPos); SetOutputParamValue(mLoad_x_ChuckLoadFramePos, (double)boxRecipe.Load_x_ChuckLoadFramePos); 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; }
/// <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; }
//主动做流程 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轴"); } }