public static void AutoRun(ref PVar.WorkType StaWork) { try { switch (StaWork.Step) { case 10: if (PVar.Stop_Flag == false) { if (Once == false) { if (BVar.FileRorW.ReadINI("Material_index", "是否片料", "有", PVar.PublicParPath) == "有") { StaWork.IsHavePianliao = true; } else { StaWork.IsHavePianliao = false; } } StaWork.State = false; TimeOut = API.GetTickCount(); //StaWork.Step = 20; } break; case 20: if (StaWork.State == false && StaWork.Enable) { StaWork.State = true; TimeOut = API.GetTickCount(); StaWork.Step = 30; } else { if (API.GetTickCount() - TimeOut > 500) { TimeOut = API.GetTickCount(); StaWork.Step = 10; } } break; case 30: Once = true; if (StaWork.IsHavePianliao) { TimeOut = API.GetTickCount(); StaWork.Step = 10; } else { TimeOut = API.GetTickCount(); StaWork.Step = 40; } break; case 40: //判断料仓有无物料 if (Gg.GetDi(0, Gg.InPut0.片料到位检测) == 1) { TimeOut = API.GetTickCount(); StaWork.Step = 60; } else { } break; case 60: Gg.SetExDo(0, 0, Gg.OutPut2.夹上摸气缸, 1); Gg.SetExDo(0, 0, Gg.OutPut2.撕摸升降气缸, 0); Gg.SetExDo(0, 0, Gg.OutPut2.片料夹紧气缸左, 1); Gg.SetExDo(0, 0, Gg.OutPut2.片料夹紧气缸右, 1); Gg.SetExDo(0, 0, Gg.OutPut2.拉料无杆干气缸, 0); TimeOut = API.GetTickCount(); StaWork.Step = 70; break; case 70: if (Gg.GetExDi(0, Gg.InPut2.夹上摸气缸伸出) == 1 && Gg.GetExDi(0, Gg.InPut2.夹上摸气缸缩回) == 0 && Gg.GetExDi(0, Gg.InPut2.撕摸升降气缸缩回) == 1 && Gg.GetExDi(0, Gg.InPut2.撕摸升降气缸伸出) == 0 && Gg.GetExDi(0, Gg.InPut2.片料夹紧气缸左伸出) == 1 && Gg.GetExDi(0, Gg.InPut2.片料夹紧气缸右伸出) == 1 && Gg.GetExDi(0, Gg.InPut2.拉料无杆干气缸左) == 1 && Gg.GetExDi(0, Gg.InPut2.拉料无杆干气缸右) == 0) { TimeOut = API.GetTickCount(); StaWork.Step = 80; } if (API.GetTickCount() - TimeOut > 2000) { if (Gg.GetExDi(0, Gg.InPut2.夹上摸气缸伸出) == 0 || Gg.GetExDi(0, Gg.InPut2.夹上摸气缸缩回) == 1) { AddList("夹上摸气缸伸出信号异常,请检查!"); ShowList("夹上摸气缸伸出信号异常,请检查!"); } if (Gg.GetExDi(0, Gg.InPut2.撕摸升降气缸缩回) == 0 || Gg.GetExDi(0, Gg.InPut2.撕摸升降气缸伸出) == 1) { AddList("撕摸升降气缸缩回信号异常,请检查!"); ShowList("撕摸升降气缸缩回信号异常,请检查!"); } if (Gg.GetExDi(0, Gg.InPut2.片料夹紧气缸左伸出) == 0) { AddList("片料夹紧气缸左伸出信号异常,请检查!"); ShowList("片料夹紧气缸左伸出信号异常,请检查!"); } if (Gg.GetExDi(0, Gg.InPut2.片料夹紧气缸右伸出) == 0) { AddList("片料夹紧气缸右伸出信号异常,请检查!"); ShowList("片料夹紧气缸右伸出信号异常,请检查!"); } if (Gg.GetExDi(0, Gg.InPut2.拉料无杆干气缸左) == 0 || Gg.GetExDi(0, Gg.InPut2.拉料无杆干气缸右) == 1) { AddList("拉料无杆干气缸左信号异常,请检查!"); ShowList("拉料无杆干气缸左信号异常,请检查!"); } TimeOut = API.GetTickCount(); BufferStep = 70; StaWork.Step = 8000; } break; case 80: //取片料马达和拉料马达回到初始位置 Gg.AbsMotion(0, BVar.S2G_Y, mFunction.Pos.TeachAxis1[3, 0], PVar.ParAxis.Speed[BVar.S2G_Y]); Gg.AbsMotion(0, BVar.S2L_Z, mFunction.Pos.TeachAxis3[3, 3], PVar.ParAxis.Speed[BVar.S2L_Z]); TimeOut = API.GetTickCount(); StaWork.Step = 90; break; case 90: if (Gg.ZSPD(0, BVar.S2G_Y) && Gg.ZSPD(0, BVar.S2L_Z)) { TimeOut = API.GetTickCount(); StaWork.Step = 100; } break; case 100: Gg.SetExDo(0, 0, Gg.OutPut2.撕摸升降气缸, 1); TimeOut = API.GetTickCount(); StaWork.Step = 110; break; case 110: if (Gg.GetExDi(0, Gg.InPut2.撕摸升降气缸缩回) == 0 && Gg.GetExDi(0, Gg.InPut2.撕摸升降气缸伸出) == 1) { Gg.SetExDo(0, 0, Gg.OutPut2.取底膜破真空, 0); Gg.SetExDo(0, 0, Gg.OutPut2.取片料真空吸, 1); TimeOut = API.GetTickCount(); StaWork.Step = 120; } else { if (API.GetTickCount() - TimeOut > 2000) { AddList("撕摸升降气缸伸出信号异常,请检查!"); TimeOut = API.GetTickCount(); BufferStep = 110; StaWork.Step = 8000; } } break; case 120: if (Gg.GetDi(0, Gg.InPut0.取片料真空检测) == 1) { Gg.SetExDo(0, 0, Gg.OutPut2.夹上摸气缸, 0); TimeOut = API.GetTickCount(); StaWork.Step = 130; } else { if (API.GetTickCount() - TimeOut > 2000) { AddList("取片料真空检测信号异常,请检查!"); TimeOut = API.GetTickCount(); BufferStep = 120; StaWork.Step = 8000; } } break; case 130: if (Gg.GetExDi(0, Gg.InPut2.夹上摸气缸缩回) == 1 && Gg.GetExDi(0, Gg.InPut2.夹上摸气缸伸出) == 0) { Gg.SetExDo(0, 0, Gg.OutPut2.撕摸升降气缸, 0); TimeOut = API.GetTickCount(); StaWork.Step = 140; } else { if (API.GetTickCount() - TimeOut > 2000) { AddList("夹上摸气缸缩回测信号异常,请检查!"); TimeOut = API.GetTickCount(); BufferStep = 130; StaWork.Step = 8000; } } break; case 140: if (Gg.GetExDi(0, Gg.InPut2.撕摸升降气缸缩回) == 1 && Gg.GetExDi(0, Gg.InPut2.撕摸升降气缸伸出) == 0) { Gg.AbsMotion(0, BVar.S2G_Y, mFunction.Pos.TeachAxis1[3, 1], PVar.ParAxis.Speed[BVar.S2G_Y]); TimeOut = API.GetTickCount(); StaWork.Step = 150; } else { if (API.GetTickCount() - TimeOut > 2000) { AddList("撕摸升降气缸缩回信号异常,请检查!"); TimeOut = API.GetTickCount(); BufferStep = 140; StaWork.Step = 8000; } } break; case 150: if (Gg.ZSPD(0, BVar.S2G_Y)) { Gg.SetExDo(0, 0, Gg.OutPut2.撕摸升降气缸, 1); TimeOut = API.GetTickCount(); StaWork.Step = 160; } break; case 160: if (Gg.GetExDi(0, Gg.InPut2.撕摸升降气缸缩回) == 0 && Gg.GetExDi(0, Gg.InPut2.撕摸升降气缸伸出) == 1) { Gg.SetExDo(0, 0, Gg.OutPut2.取底膜破真空, 0); Gg.SetExDo(0, 0, Gg.OutPut2.取片料真空吸, 1); TimeOut = API.GetTickCount(); StaWork.Step = 120; } else { if (API.GetTickCount() - TimeOut > 2000) { AddList("撕摸升降气缸伸出信号异常,请检查!"); TimeOut = API.GetTickCount(); BufferStep = 110; StaWork.Step = 8000; } } break; case 23320: TimeOut = API.GetTickCount(); StaWork.Step = 100; break; case 800: StaWork.State = false; StaWork.Step = 10; break; case 1000: StaWork.Result = false; StaWork.State = false; StaWork.Step = 10; break; //遇到异常,设备先暂停,确定后处理************************ case 8000: PVar.IsSystemOnPauseMode = true; PVar.MacHold = true; PVar.Stop_Flag = false; Frm_Main.fMain.Btn_Start.Enabled = false; Frm_Main.fMain.Btn_Pause.Enabled = true; Frm_Main.fMain.Btn_Stop.Enabled = false; Frm_Main.fMain.Btn_Start.BZ_BackColor = PVar.BZColor_UnselectedBtn; Frm_Main.fMain.Btn_Pause.BZ_BackColor = PVar.BZColor_SelectedEndBtn; Frm_Main.fMain.Btn_Stop.BZ_BackColor = PVar.BZColor_UnselectedBtn; Frm_Engineering.fEngineering.Auto_Timer.Enabled = false; PVar.LampStatus = 20; StaWork.Step = BufferStep; break; } } catch (Exception exc) { string Error_Str = ""; string Error_Str1 = ""; Frm_Engineering.fEngineering.MacStop(); MessageBox.Show(exc.Message); Error_Str = PVar.BZ_LogPath + DateTime.Now.ToString("yyyyMMdd") + "\\" + DateTime.Now.ToString("yyyyMMdd") + "_代码异常记录" + ".txt"; Error_Str1 = "\r\n" + "※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※" + "\r\n" + "[" + DateTime.Now.ToString("HH:mm:ss") + "]" + "\r\n" + exc.ToString(); FileRw.WriteDattxt(Error_Str, Error_Str1); } }
public void HomeSub() { switch (StepHome) { case 10: Reset.State = true; AddList("设备初始化开始,请等待!"); Gg.SetDo(0, Gg.OutPut0.载具真空吸1, 0); Gg.SetDo(0, Gg.OutPut0.载具真空吸2, 0); Gg.SetDo(0, Gg.OutPut0.载具真空吸3, 0); Gg.SetDo(0, Gg.OutPut0.载具真空吸4, 0); Gg.SetDo(0, Gg.OutPut0.载具破真空1, 0); Gg.SetDo(0, Gg.OutPut0.载具破真空2, 0); Gg.SetDo(0, Gg.OutPut0.载具破真空3, 0); Gg.SetDo(0, Gg.OutPut0.载具破真空4, 0); Gg.SetDo(0, Gg.OutPut0.保压站刹车继电器, 0); Gg.SetDo(0, Gg.OutPut0.警示蜂鸣器, 0); Gg.SetDo(0, Gg.OutPut0.装配站刹车继电器, 0); Gg.SetDo(0, Gg.OutPut1.取料吸嘴破真空, 0); Gg.SetDo(0, Gg.OutPut1.取料吸嘴真空吸, 0); Gg.SetExDo(0, 0, Gg.OutPut2.NG蜂鸣器, 0); Gg.SetExDo(0, 0, Gg.OutPut2.NG指示灯, 0); Gg.SetExDo(0, 0, Gg.OutPut2.OK指示灯, 0); Gg.SetExDo(0, 0, Gg.OutPut2.保压升降气缸, 0); Gg.SetExDo(0, 0, Gg.OutPut2.除底摸平移气缸, 0); Gg.SetExDo(0, 0, Gg.OutPut2.除底膜吸嘴气缸, 0); Gg.SetExDo(0, 0, Gg.OutPut2.检气缸, 0); Gg.SetExDo(0, 0, Gg.OutPut2.拉料无杆干气缸, 0); Gg.SetExDo(0, 0, Gg.OutPut2.片料夹紧气缸右, 0); Gg.SetExDo(0, 0, Gg.OutPut2.片料夹紧气缸左, 0); Gg.SetExDo(0, 0, Gg.OutPut2.取底膜破真空, 0); Gg.SetExDo(0, 0, Gg.OutPut2.取底膜真空吸, 0); Gg.SetExDo(0, 0, Gg.OutPut2.取片料破真空, 0); Gg.SetExDo(0, 0, Gg.OutPut2.取片料真空吸, 0); Gg.SetExDo(0, 0, Gg.OutPut2.撕摸升降气缸, 0); ////界面 Frm_Main.fMain.Btn_Stop.Enabled = false; Frm_Main.fMain.Btn_Pause.Enabled = false; Frm_Main.fMain.Btn_Stop.BZ_BackColor = PVar.BZColor_UnselectedBtn; Frm_Main.fMain.Btn_Pause.BZ_BackColor = PVar.BZColor_UnselectedBtn; Frm_ProgressBar.IsShowProgresBar(true); InitTimeOut = API.GetTickCount(); StepHome = 20; break; case 20: Frm_ProgressBar.SetValueProgressBar(10); //初始化进度条的进度更新显示 if (Gg.GetDi(0, Gg.InPut0.载具真空检测1) == 0 && Gg.GetDi(0, Gg.InPut0.载具真空检测2) == 0 && Gg.GetDi(0, Gg.InPut0.载具真空检测3) == 0 && Gg.GetDi(0, Gg.InPut0.载具真空检测4) == 0 && Gg.GetExDi(0, Gg.InPut2.撕摸升降气缸缩回) == 1 && Gg.GetExDi(0, Gg.InPut2.撕摸升降气缸伸出) == 0 //&& Gg.GetExDi(0, Gg.InPut2.复检气缸缩回) == 1 && Gg.GetExDi(0, Gg.InPut2.复检气缸伸出) == 0 && Gg.GetExDi(0, Gg.InPut2.保压升降气缸缩回) == 1 && Gg.GetExDi(0, Gg.InPut2.保压升降气缸伸出) == 0 && Gg.GetExDi(0, Gg.InPut2.除底摸平移气缸缩回) == 1 && Gg.GetExDi(0, Gg.InPut2.除底摸平移气缸伸出) == 0 && Gg.GetExDi(0, Gg.InPut2.除底膜吸嘴气缸缩回) == 1 && Gg.GetExDi(0, Gg.InPut2.除底膜吸嘴气缸伸出) == 0) { InitTimeOut = API.GetTickCount(); StepHome = 30; } if (API.GetTickCount() - InitTimeOut > 2000) { if (Gg.GetDi(0, Gg.InPut0.载具真空检测1) == 1) { AddList("1#载具真空检测1异常,请检查!"); ShowList("1#载具真空检测1异常,请检查!"); } if (Gg.GetDi(0, Gg.InPut0.载具真空检测2) == 1) { AddList("2#载具真空检测2异常,请检查!"); ShowList("2#载具真空检测2异常,请检查!"); } if (Gg.GetDi(0, Gg.InPut0.载具真空检测3) == 1) { AddList("3#载具真空检测3异常,请检查!"); ShowList("3#载具真空检测3异常,请检查!"); } if (Gg.GetDi(0, Gg.InPut0.载具真空检测4) == 1) { AddList("4#载具真空检测3异常,请检查!"); ShowList("4#载具真空检测3异常,请检查!"); } if (Gg.GetExDi(0, Gg.InPut2.撕摸升降气缸缩回) == 0 || Gg.GetExDi(0, Gg.InPut2.撕摸升降气缸伸出) == 1) { AddList("撕摸升降气缸缩回信号异常,请检查!"); ShowList("撕摸升降气缸缩回信号异常,请检查!"); } //if (Gg.GetExDi(0, Gg.InPut2.复检气缸缩回) == 0 || Gg.GetExDi(0, Gg.InPut2.复检气缸伸出) == 1) // { // AddList("复检气缸缩回信号异常,请检查!"); // ShowList("复检气缸缩回信号异常,请检查!"); // } if (Gg.GetExDi(0, Gg.InPut2.保压升降气缸缩回) == 0 || Gg.GetExDi(0, Gg.InPut2.保压升降气缸伸出) == 1) { AddList("保压升降气缸缩回信号异常,请检查!"); ShowList("保压升降气缸缩回信号异常,请检查!"); } if (Gg.GetExDi(0, Gg.InPut2.除底摸平移气缸缩回) == 0 || Gg.GetExDi(0, Gg.InPut2.除底摸平移气缸伸出) == 1) { AddList("除底摸平移气缸缩回信号异常,请检查!"); ShowList("除底摸平移气缸缩回信号异常,请检查!"); } if (Gg.GetExDi(0, Gg.InPut2.除底膜吸嘴气缸缩回) == 0 || Gg.GetExDi(0, Gg.InPut2.除底膜吸嘴气缸伸出) == 1) { AddList("除底膜吸嘴气缸缩回信号异常,请检查!"); ShowList("除底膜吸嘴气缸缩回信号异常,请检查!"); } StepHome = 1000; } break; case 30: AddList("组装Z轴开始回原点…"); AddList("保压Z轴开始回原点…"); GoHome.Instance.AxisHome[0, 3].Result = false; GoHome.Instance.AxisHome[0, 8].Result = false; GoHome.Instance.AxisHome[0, 3].Enable = true; GoHome.Instance.AxisHome[0, 8].Enable = true; GoHome.Instance.AxisHome[0, 3].Step = 10; GoHome.Instance.AxisHome[0, 8].Step = 10; InitTimeOut = API.GetTickCount(); Frm_ProgressBar.SetValueProgressBar(30); StepHome = 40; break; case 40: GotoHome(0, 3, 20, -1000, 10, 1, 10); GotoHome(0, 8, 20, -1000, 10, 1, 10); if (GoHome.Instance.AxisHome[0, 3].Step == 0 && GoHome.Instance.AxisHome[0, 3].Enable) { GoHome.Instance.AxisHome[0, 3].Enable = false; if (GoHome.Instance.AxisHome[0, 3].Result) { AddList("组装Z轴回原点成功!"); } else { AddList("组装Z轴回原点失败!"); ShowList("组装Z轴回原点失败!"); StepHome = 1000; } } if (GoHome.Instance.AxisHome[0, 8].Step == 0 && GoHome.Instance.AxisHome[0, 8].Enable) { GoHome.Instance.AxisHome[0, 8].Enable = false; if (GoHome.Instance.AxisHome[0, 8].Result) { AddList("保压Z轴回原点成功!"); } else { AddList("保压Z轴回原点失败!"); ShowList("保压Z轴回原点失败!"); StepHome = 1000; } } if (GoHome.Instance.AxisHome[0, 3].Result && GoHome.Instance.AxisHome[0, 8].Result) { Frm_ProgressBar.SetValueProgressBar(50); InitTimeOut = API.GetTickCount(); StepHome = 50; } break; case 50: AddList("组装X轴开始回原点…"); AddList("组装Y轴开始回原点…"); AddList("组装R轴开始回原点…"); GoHome.Instance.AxisHome[0, 1].Result = false; GoHome.Instance.AxisHome[0, 2].Result = false; GoHome.Instance.AxisHome[0, 4].Result = false; GoHome.Instance.AxisHome[0, 1].Enable = true; GoHome.Instance.AxisHome[0, 2].Enable = true; GoHome.Instance.AxisHome[0, 4].Enable = true; GoHome.Instance.AxisHome[0, 1].Step = 10; GoHome.Instance.AxisHome[0, 2].Step = 10; GoHome.Instance.AxisHome[0, 4].Step = 10; InitTimeOut = API.GetTickCount(); StepHome = 60; break; case 60: GotoHome(0, 1, 20, -1000, 10, 1, 10); GotoHome(0, 2, 20, -1000, 10, 1, 10); GotoHome(0, 4, 20, -1000, 10, 1, 10); if (GoHome.Instance.AxisHome[0, 1].Step == 0 && GoHome.Instance.AxisHome[0, 1].Enable) { GoHome.Instance.AxisHome[0, 1].Enable = false; if (GoHome.Instance.AxisHome[0, 1].Result) { AddList("组装X轴回原点成功!"); } else { AddList("组装X轴回原点失败!"); ShowList("组装X轴回原点失败!"); StepHome = 1000; } } if (GoHome.Instance.AxisHome[0, 2].Step == 0 && GoHome.Instance.AxisHome[0, 2].Enable) { GoHome.Instance.AxisHome[0, 2].Enable = false; if (GoHome.Instance.AxisHome[0, 2].Result) { AddList("组装Y轴回原点成功!"); } else { AddList("组装Y轴回原点失败!"); ShowList("组装Y轴回原点失败!"); StepHome = 1000; } } if (GoHome.Instance.AxisHome[0, 4].Step == 0 && GoHome.Instance.AxisHome[0, 4].Enable) { GoHome.Instance.AxisHome[0, 4].Enable = false; if (GoHome.Instance.AxisHome[0, 4].Result) { AddList("组装R轴回原点成功!"); } else { AddList("组装R轴回原点失败!"); ShowList("组装R轴回原点失败!"); StepHome = 1000; } } if (GoHome.Instance.AxisHome[0, 1].Result && GoHome.Instance.AxisHome[0, 2].Result && GoHome.Instance.AxisHome[0, 4].Result) { Frm_ProgressBar.SetValueProgressBar(70); InitTimeOut = API.GetTickCount(); StepHome = 70; } break; case 70: AddList("上料Z轴开始回原点…"); AddList("平移Y轴开始回原点…"); AddList("拉料Z轴开始回原点…"); GoHome.Instance.AxisHome[0, 5].Result = false; GoHome.Instance.AxisHome[0, 6].Result = false; GoHome.Instance.AxisHome[0, 7].Result = false; GoHome.Instance.AxisHome[0, 5].Enable = true; GoHome.Instance.AxisHome[0, 6].Enable = true; GoHome.Instance.AxisHome[0, 7].Enable = true; GoHome.Instance.AxisHome[0, 5].Step = 10; GoHome.Instance.AxisHome[0, 6].Step = 10; GoHome.Instance.AxisHome[0, 7].Step = 10; InitTimeOut = API.GetTickCount(); StepHome = 80; break; case 80: GotoHome(0, 5, 20, -1000, 10, 1, 10); GotoHome(0, 6, 20, -1000, 10, 1, 30); GotoHome(0, 7, 20, -1000, 10, 1, 10); if (GoHome.Instance.AxisHome[0, 5].Step == 0 && GoHome.Instance.AxisHome[0, 5].Enable) { GoHome.Instance.AxisHome[0, 5].Enable = false; if (GoHome.Instance.AxisHome[0, 5].Result) { AddList("上料Z轴回原点成功!"); } else { AddList("上料Z轴回原点失败!"); ShowList("上料Z轴回原点失败!"); StepHome = 1000; } } if (GoHome.Instance.AxisHome[0, 6].Step == 0 && GoHome.Instance.AxisHome[0, 6].Enable) { GoHome.Instance.AxisHome[0, 6].Enable = false; if (GoHome.Instance.AxisHome[0, 6].Result) { AddList("平移Y轴回原点成功!"); } else { AddList("平移Y轴回原点失败!"); ShowList("平移Y轴回原点失败!"); StepHome = 1000; } } if (GoHome.Instance.AxisHome[0, 7].Step == 0 && GoHome.Instance.AxisHome[0, 7].Enable) { GoHome.Instance.AxisHome[0, 7].Enable = false; if (GoHome.Instance.AxisHome[0, 7].Result) { AddList("拉料Z轴回原点成功!"); } else { AddList("拉料Z轴回原点失败!"); ShowList("拉料Z轴回原点失败!"); StepHome = 1000; } } if (GoHome.Instance.AxisHome[0, 5].Result && GoHome.Instance.AxisHome[0, 6].Result && GoHome.Instance.AxisHome[0, 7].Result) { Frm_ProgressBar.SetValueProgressBar(80); InitTimeOut = API.GetTickCount(); StepHome = 90; } break; case 90: AddList("转盘R轴开始回原点…"); GoHome.Instance.AxisHome[1, 2].Result = false; GoHome.Instance.AxisHome[1, 1].Enable = true; GoHome.Instance.AxisHome[1, 1].Step = 10; InitTimeOut = API.GetTickCount(); StepHome = 100; break; case 100: GotoHome(1, 1, 30, -360, 5, mFunction.Pos.TeachAxis1[2, 0], 30); if (GoHome.Instance.AxisHome[1, 1].Step == 0 && GoHome.Instance.AxisHome[1, 1].Enable) { GoHome.Instance.AxisHome[1, 1].Enable = false; if (GoHome.Instance.AxisHome[1, 1].Result) { AddList("转盘R轴回原点成功!"); } else { AddList("转盘R轴回原点失败!"); ShowList("转盘R轴回原点失败!"); StepHome = 1000; } } if (GoHome.Instance.AxisHome[1, 1].Result) { Frm_ProgressBar.SetValueProgressBar(90); InitTimeOut = API.GetTickCount(); StepHome = 150; } break; case 150: AddList("各轴开始回待机位置…"); //组装站 Gg.AbsMotion(0, 1, mFunction.Pos.TeachAxis1[0, 0], 20); Gg.AbsMotion(0, 2, mFunction.Pos.TeachAxis2[0, 0], 20); Gg.AbsMotion(0, 3, mFunction.Pos.TeachAxis3[0, 0], 20); Gg.AbsMotion(0, 4, mFunction.Pos.TeachAxis4[0, 0], 20); //保压站 Gg.AbsMotion(0, 8, mFunction.Pos.TeachAxis1[1, 0], 20); //保压初始位置 Tools.AxisTmplPos[1, 1] = 0; //供料 Gg.AbsMotion(0, 5, mFunction.Pos.TeachAxis2[3, 4], 50); //供料起始位置 Gg.AbsMotion(0, 6, mFunction.Pos.TeachAxis1[3, 6], 100); //避让位置 Gg.AbsMotion(0, 7, mFunction.Pos.TeachAxis3[3, 7], 50); //换料位置 InitTimeOut = API.GetTickCount(); StepHome = 160; break; case 160: if (Gg.ZSPD(0, 1) && Gg.ZSPD(0, 2) && Gg.ZSPD(0, 3) && Gg.ZSPD(0, 4) && Gg.ZSPD(0, 5) && Gg.ZSPD(0, 6) && Gg.ZSPD(0, 7) && Gg.ZSPD(0, 8) && Gg.ZSPD(1, 1)) { AddList("各轴回待机位置完成!"); InitTimeOut = API.GetTickCount(); StepHome = 170; } else { if ((API.GetTickCount() - InitTimeOut) > 10000) { if (Gg.ZSPD(0, 1) == false) { AddList("组装X轴回待机位置失败!"); ShowList("组装X轴回待机位置失败!"); } if (Gg.ZSPD(0, 2) == false) { AddList("组装Y轴回待机位置失败!"); ShowList("组装Y轴回待机位置失败!"); } if (Gg.ZSPD(0, 3) == false) { AddList("组装Z轴回待机位置失败!"); ShowList("组装Z轴回待机位置失败!"); } if (Gg.ZSPD(0, 4) == false) { AddList("组装R轴回待机位置失败!"); ShowList("组装R轴回待机位置失败!"); } if (Gg.ZSPD(0, 5) == false) { AddList("上料Z轴回待机位置失败!"); ShowList("上料Z轴回待机位置失败!"); } if (Gg.ZSPD(0, 6) == false) { AddList("平移Y轴回待机位置失败!"); ShowList("平移Y轴回待机位置失败!"); } if (Gg.ZSPD(0, 7) == false) { AddList("拉料Z轴回待机位置失败!"); ShowList("拉料Z轴回待机位置失败!"); } if (Gg.ZSPD(0, 8) == false) { AddList("保压Z轴回待机位置失败!"); ShowList("保压Z轴回待机位置失败!"); } if (Gg.ZSPD(1, 1) == false) { AddList("转盘R轴回待机位置失败!"); ShowList("转盘R轴回待机位置失败!"); } StepHome = 1000; } } break; case 170: if (API.GetTickCount() - InitTimeOut > 500) { //gts.GT_SetPrfPos(1, 1, 0); //规划器置零 //gts.GT_SetEncPos(1, 1, 0); //编码器置零 //gts.GT_SynchAxisPos(1, 1 << 0); //将当前轴进行位置同步 InitTimeOut = API.GetTickCount(); StepHome = 800; } break; case 800: AddList("初始化完成"); ShowList("初始化完成"); PVar.LampStatus = 20; PVar.Stop_Flag = true; PVar.AutoRunFlag = false; PVar.MacHold = false; PVar.CPKDoneCounts = 0; PVar.WorkMode = 0; Frm_Main.fMain.Panel_CPK.Visible = false; Frm_Engineering.fEngineering.Btn_SelectMaterial.Enabled = true; //按钮初始化 Frm_Main.fMain.Btn_Start.Enabled = true; Frm_Main.fMain.Btn_Pause.Enabled = false; Frm_Main.fMain.Btn_Stop.Enabled = true; Frm_Main.fMain.Btn_Start.BZ_BackColor = PVar.BZColor_SelectedBtn; //'主页面初始化和自动运行按钮 Frm_Main.fMain.Btn_Pause.BZ_BackColor = PVar.BZColor_UnselectedBtn; Frm_Main.fMain.Btn_Stop.BZ_BackColor = PVar.BZColor_UnselectedBtn; Frm_Engineering.fEngineering.TabPage3.Parent = Frm_Engineering.fEngineering.TabControl1; Frm_Engineering.fEngineering.TabPage4.Parent = Frm_Engineering.fEngineering.TabControl1; Frm_ProgressBar.IsShowProgresBar(false); //'初始化进度条显示 Frm_Engineering.fEngineering.Home_Timer.Enabled = false; for (int i = 0; i <= 4; i++) { PVar.Sta_Work[i].State = false; PVar.Sta_Work[i].Result = false; PVar.Sta_Work[i].IsHaveHSG = false; PVar.Sta_Work[i].Step = 0; } Mod_ErrorCode.CheckSystemTimeStep = 0; GoHome.Instance.Reset.State = false; GoHome.Instance.Reset.Result = true; StepHome = 0; break; case 1000: PVar.LampStatus = 10; PVar.MacHold = false; PVar.Stop_Flag = true; Frm_Engineering.fEngineering.Btn_SelectMaterial.Enabled = false; //按钮初始化 Frm_Main.fMain.Btn_Start.Enabled = true; Frm_Main.fMain.Btn_Pause.Enabled = false; Frm_Main.fMain.Btn_Stop.Enabled = false; Frm_Main.fMain.Btn_Start.BZ_BackColor = PVar.BZColor_UnselectedBtn; //主页面初始化和自动运行按钮 Frm_Main.fMain.Btn_Pause.BZ_BackColor = PVar.BZColor_UnselectedBtn; Frm_Main.fMain.Btn_Stop.BZ_BackColor = PVar.BZColor_SelectedEndBtn; Frm_Engineering.fEngineering.Home_Timer.Enabled = false; Frm_ProgressBar.IsShowProgresBar(false); //初始化进度条显示 GoHome.Instance.Reset.Result = false; GoHome.Instance.Reset.State = false; StepHome = 0; break; } }
public static void AutoRun(ref PVar.WorkType StaWork) { try { switch (StaWork.Step) { case 10: if (PVar.Stop_Flag == false) { StaWork.State = false; TimeOut = API.GetTickCount(); StaWork.Step = 20; } break; case 20: //本站工作状态,工站使能,本站是否有产品,转盘工作状态 if (PVar.ParList.CheckSts[17] == false) { if (StaWork.State == false && StaWork.Enable && StaWork.Result && StaWork.IsHaveHSG && PVar.Sta_Work[1].State == false) { StaWork.State = true; StaWork.Result = false; //清空缓存的压力值 for (int i = PVar.Press.Count() - 1; i > 0; i--) { PVar.Press[i] = 0; } Command.Com2_Send(Command.压力控制打开); Gg.SetExDo(0, 0, Gg.OutPut2.保压升降气缸, 1); AddList("复检开始开始!"); TimeOut = API.GetTickCount(); StaWork.Step = 30; } else { StaWork.Step = 10; } } else { if (StaWork.State == false && StaWork.Enable && StaWork.IsHaveHSG && PVar.Sta_Work[1].State == false) { StaWork.State = true; StaWork.Result = false; //清空缓存的压力值 for (int i = PVar.Press.Count() - 1; i > 0; i--) { PVar.Press[i] = 0; } Command.Com2_Send(Command.压力控制打开); Gg.SetExDo(0, 0, Gg.OutPut2.保压升降气缸, 1); AddList("复检开始开始!"); TimeOut = API.GetTickCount(); StaWork.Step = 30; } } break; case 30: if (Gg.GetExDi(0, Gg.InPut2.保压升降气缸缩回) == 0 && Gg.GetExDi(0, Gg.InPut2.保压升降气缸伸出) == 1) { //AddList("保压升降气缸复位OK!"); Frm_Production.fProduction.Chart_Time.Enabled = true; TimeOut = API.GetTickCount(); StaWork.Step = 40; } else { if (API.GetTickCount() - TimeOut > 2000) { AddList("保压升降气缸伸出信号异常!"); ShowList("保压升降气缸伸出信号异常!"); TimeOut = API.GetTickCount(); StaWork.Step = 1000; } } break; case 40: if (API.GetTickCount() - TimeOut > 100) { Gg.AbsMotion(0, 8, mFunction.Pos.TeachAxis1[1, 1], PVar.ParAxis.Speed[BVar.S3_Z]); TimeOut = API.GetTickCount(); StaWork.Step = 50; } break; case 50: if (Gg.ZSPD(0, BVar.S3_Z)) { Gg.SetExDo(0, 0, Gg.OutPut2.保压升降气缸, 0); TimeOut = API.GetTickCount(); StaWork.Step = 60; } break; case 60: if (PVar.IsCOM2_Working) { //**保压位置+偏移值=终点最大行程 Gg.AbsMotion(0, 8, mFunction.Pos.TeachAxis1[1, 1] + PVar.ParList.Data[22], PVar.ParList.Data[23]); TimeOut = API.GetTickCount(); StaWork.Step = 70; } else { AddList("保压站压力传感器异常!"); ShowList("保压站压力传感器异常!"); TimeOut = API.GetTickCount(); StaWork.Step = 1000; } break; case 70: if (Gg.ZSPD(0, BVar.S3_Z)) { TimeOut = API.GetTickCount(); StaWork.Step = 80; } break; case 80: if (API.GetTickCount() - TimeOut > PVar.ParList.Data[41] * 1000) { Gg.AbsMotion(0, 8, mFunction.Pos.TeachAxis1[1, 0], PVar.ParAxis.Speed[BVar.S3_Z]); TimeOut = API.GetTickCount(); StaWork.Step = 90; } break; case 90: if (Gg.ZSPD(0, BVar.S3_Z)) { TimeOut = API.GetTickCount(); StaWork.Step = 800; } break; case 800: Frm_Production.fProduction.Chart_Time.Enabled = false; StaWork.Enable = false; StaWork.Result = true; StaWork.State = false; StaWork.Step = 10; break; case 1000: StaWork.Enable = false; StaWork.Result = false; StaWork.State = false; StaWork.Step = 10; break; //严重错误,急停处理 case 10000: Frm_Engineering.fEngineering.MacStop(); break; } } catch (Exception exc) { string Error_Str = ""; string Error_Str1 = ""; Frm_Engineering.fEngineering.MacStop(); MessageBox.Show(exc.Message); Error_Str = PVar.BZ_LogPath + DateTime.Now.ToString("yyyyMMdd") + "\\" + DateTime.Now.ToString("yyyyMMdd") + "_代码异常记录" + ".txt"; Error_Str1 = "\r\n" + "※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※" + "\r\n" + "[" + DateTime.Now.ToString("HH:mm:ss") + "]" + "\r\n" + exc.ToString(); FileRw.WriteDattxt(Error_Str, Error_Str1); } }
public static void AutoRun(ref PVar.WorkType StaWork) { try { switch (StaWork.Step) { case 10: if (PVar.Stop_Flag == false) { StaWork.State = false; TimeOut = API.GetTickCount(); //StaWork.Step = 20; } break; case 20: //本站工作状态,工站使能,转盘工作状态,本站是否有产品 if (StaWork.State == false && StaWork.Enable && StaWork.Result && PVar.Sta_Work[1].State == false && PVar.Sta_Work[4].IsHaveHSG) { StaWork.State = true; StaWork.Result = false; Gg.SetExDo(0, 0, Gg.OutPut2.检气缸, 0); AddList("复检开始开始!"); TimeOut = API.GetTickCount(); StaWork.Step = 30; } else { StaWork.Step = 10; } break; case 30: if (Gg.GetExDi(0, Gg.InPut2.检气缸缩回) == 1 && Gg.GetExDi(0, Gg.InPut2.检气缸伸出) == 0) { //AddList("复检气缸复位OK!"); TimeOut = API.GetTickCount(); StaWork.Step = 40; } else { if (API.GetTickCount() - TimeOut > 2000) { AddList("复检气缸缩回信号异常!"); ShowList("复检气缸缩回信号异常!"); TimeOut = API.GetTickCount(); StaWork.Step = 1000; } } break; case 40: if (API.GetTickCount() - TimeOut > 1000) { TimeOut = API.GetTickCount(); StaWork.Step = 50; } break; case 50: sRtn = Command.TCP_CCD2_Send(Command.检角度); if (sRtn == 1) //命令发送成功 { TimeOut = API.GetTickCount(); StaWork.Step = 60; } else if (sRtn == 2) //网络链接异常 { AddList("网络链接异常!"); ShowList("网络链接异常!"); TimeOut = API.GetTickCount(); StaWork.Step = 1000; } else { TimeOut = API.GetTickCount(); StaWork.Step = 1000; } break; case 60: if (Command.CCD2_Resule && PVar.CCD2_Data[0] == Command.检角度) { AddList("复检角度数据收到!"); CCD_Vale[1].X = Convert.ToDouble(PVar.CCD2_Data[1]); CCD_Vale[1].Y = Convert.ToDouble(PVar.CCD2_Data[2]); CCD_Vale[1].T = Convert.ToDouble(PVar.CCD2_Data[3]); CCD_Vale[1].CC = Convert.ToDouble(PVar.CCD2_Data[4]); CCD_Vale[1].Judge = Convert.ToDouble(PVar.CCD2_Data[5]); TimeOut = API.GetTickCount(); StaWork.Step = 70; } else { if (API.GetTickCount() - TimeOut > 2000) { AddList("等待复检角度数据超时!"); TimeOut = API.GetTickCount(); StaWork.Step = 1000; } } break; case 70: if (CCD_Vale[1].Judge == 0) { TimeOut = API.GetTickCount(); StaWork.Step = 80; } else if (CCD_Vale[1].Judge == 1) { AddList("复检角度模型搜索错误!"); TimeOut = API.GetTickCount(); StaWork.Step = 1000; } else { AddList("CCD复检角度其他异常!"); TimeOut = API.GetTickCount(); StaWork.Step = 1000; } break; case 80: Gg.SetExDo(0, 0, Gg.OutPut2.检气缸, 1); TimeOut = API.GetTickCount(); StaWork.Step = 90; break; case 90: if (Gg.GetExDi(0, Gg.InPut2.检气缸缩回) == 0 && Gg.GetExDi(0, Gg.InPut2.检气缸伸出) == 1) { AddList("复检气缸伸出OK!"); TimeOut = API.GetTickCount(); StaWork.Step = 100; } else { if (API.GetTickCount() - TimeOut > 4000) { AddList("复检气缸伸出信号异常!"); ShowList("复检气缸伸出信号异常!"); TimeOut = API.GetTickCount(); StaWork.Step = 1000; } } break; case 100: if (API.GetTickCount() - TimeOut > 1000) { TimeOut = API.GetTickCount(); StaWork.Step = 110; } break; case 110: sRtn = Command.TCP_CCD2_Send(Command.检同心度); if (sRtn == 1) //命令发送成功 { TimeOut = API.GetTickCount(); StaWork.Step = 120; } else if (sRtn == 2) //网络链接异常 { AddList("网络链接异常!"); ShowList("网络链接异常!"); TimeOut = API.GetTickCount(); StaWork.Step = 1000; } else { TimeOut = API.GetTickCount(); StaWork.Step = 1000; } break; case 120: if (Command.CCD2_Resule && PVar.CCD2_Data[0] == Command.检同心度) { AddList("复检同心度数据收到!"); CCD_Vale[2].X = Convert.ToDouble(PVar.CCD2_Data[1]); CCD_Vale[2].Y = Convert.ToDouble(PVar.CCD2_Data[2]); CCD_Vale[2].T = Convert.ToDouble(PVar.CCD2_Data[3]); CCD_Vale[2].CC = Convert.ToDouble(PVar.CCD2_Data[4]); CCD_Vale[2].Judge = Convert.ToDouble(PVar.CCD2_Data[5]); if (CCD_Vale[2].CC <= 0.05 && CCD_Vale[2].T <= 1) { BVar.ProData[4, 30] = "OK"; } else { BVar.ProData[4, 30] = "NG"; } TimeOut = API.GetTickCount(); StaWork.Step = 130; } else { if (API.GetTickCount() - TimeOut > 2000) { AddList("等待复检同心度数据超时!"); TimeOut = API.GetTickCount(); StaWork.Step = 1000; } } break; case 140: if (CCD_Vale[2].Judge == 0) { TimeOut = API.GetTickCount(); StaWork.Step = 150; } else if (CCD_Vale[2].Judge == 1) { AddList("复检角度模型搜索错误!"); TimeOut = API.GetTickCount(); StaWork.Step = 1000; } else { AddList("CCD复检角度其他异常!"); TimeOut = API.GetTickCount(); StaWork.Step = 1000; } break; case 150: Gg.SetExDo(0, 0, Gg.OutPut2.检气缸, 0); TimeOut = API.GetTickCount(); StaWork.Step = 300; break; ////复检数据处理 case 300: if (BVar.ProData[4, 30] == "OK") { StaWork.Result = true; Frm_Engineering.fEngineering.Label_NG_OK.Text = "OK"; Frm_Production.fProduction.DRB_YieldRetest.BZ_ResultText = "OK"; Frm_Production.fProduction.DRB_YieldRetest.BZ_ResultBackColor = Color.FromArgb(111, 192, 64); Gg.SetExDo(0, 0, Gg.OutPut2.OK指示灯, 1); Gg.SetExDo(0, 0, Gg.OutPut2.NG指示灯, 0); //Gg.SetExDo(0, 0, Gg.OutPut2.NG蜂鸣器, 0); } else { Frm_Engineering.fEngineering.Label_NG_OK.Text = "NG"; Frm_Production.fProduction.DRB_YieldRetest.BZ_ResultText = "NG"; Frm_Production.fProduction.DRB_YieldRetest.BZ_ResultBackColor = Color.FromArgb(200, 37, 6); Gg.SetExDo(0, 0, Gg.OutPut2.OK指示灯, 0); Gg.SetExDo(0, 0, Gg.OutPut2.NG指示灯, 1); //Gg.SetExDo(0, 0, Gg.OutPut2.NG蜂鸣器, 0); PVar.Ring_EN = true; } Write_FinalData(); TimeOut = API.GetTickCount(); StaWork.Step = 800; break; case 800: StaWork.Enable = false; ////StaWork.Result = true; 做为最总结过判断 StaWork.State = false; StaWork.Step = 10; break; case 1000: StaWork.Enable = false; StaWork.Result = false; StaWork.State = false; StaWork.Step = 10; break; } } catch (Exception ex) { string Error_Str = ""; string Error_Str1 = ""; Frm_Engineering.fEngineering.MacStop(); MessageBox.Show(ex.Message); Error_Str = PVar.BZ_LogPath + DateTime.Now.ToString("yyyyMMdd") + "\\" + DateTime.Now.ToString("yyyyMMdd") + "_代码异常记录" + ".txt"; Error_Str1 = "\r\n" + "※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※" + "\r\n" + "[" + DateTime.Now.ToString("HH:mm:ss") + "]" + "\r\n" + ex.ToString(); FileRw.WriteDattxt(Error_Str, Error_Str1); } }