Ejemplo n.º 1
0
        public static void AutoRun(ref PVar.WorkType StaWork)
        {
            try
            {
                switch (StaWork.Step)
                {
                case 10:
                    if (PVar.Stop_Flag == false)
                    {
                        PVar.Sta_Work[1].IsHaveHSG = false;
                        StaWork.Result             = false;
                        StaWork.State = false;
                        StaWork.Step  = 20;
                        //PVar.Sta_Work[1].Step = 20;
                    }
                    break;

                case 20:
                    if (PVar.ParList.CheckSts[17] == false)
                    {
                        if (StaWork.State == false && Gg.GetDi(0, Gg.InPut0.放料光纤感应) == 1 && Gg.GetDi(0, Gg.InPut0.安全光幕) == 0)
                        {
                            AddList("光幕启动开始!");
                            TimeOut      = API.GetTickCount();
                            StaWork.Step = 30;
                        }
                        else
                        {
                            if (API.GetTickCount() - TimeOut > 1000)
                            {
                                TimeOut      = API.GetTickCount();
                                StaWork.Step = 10;
                            }
                        }
                    }
                    else
                    {
                        if (StaWork.State == false)
                        {
                            AddList("光幕启动开始!");
                            TimeOut      = API.GetTickCount();
                            StaWork.Step = 30;
                        }
                        else
                        {
                            if (API.GetTickCount() - TimeOut > 1000)
                            {
                                TimeOut      = API.GetTickCount();
                                StaWork.Step = 10;
                            }
                        }
                    }
                    break;


                case 30:
                    if (PVar.ParList.CheckSts[17] == false)
                    {
                        if (Gg.GetDi(0, Gg.InPut0.放料光纤感应) == 1 && Gg.GetDi(0, Gg.InPut0.安全光幕) == 1)
                        {
                            if (BVar.ProductTakeOut)
                            {
                                AddList("启动OK!");

                                //根据载具编号打开相对应的真空吸
                                BVar.OpenedVacumeNo = OpenFixtureVocume();
                                TimeOut             = API.GetTickCount();
                                StaWork.Step        = 40;
                            }
                            else
                            {
                                AddList("请先取出产品!");
                                ShowList("请先取出产品!");
                                //蜂鸣器
                                PVar.Ring_EN = true;
                                TimeOut      = API.GetTickCount();
                                StaWork.Step = 1000;
                            }
                        }
                        else
                        {
                            if (Gg.GetDi(0, Gg.InPut0.放料光纤感应) == 0 && Gg.GetDi(0, Gg.InPut0.安全光幕) == 1)
                            {
                                TimeOut      = API.GetTickCount();
                                StaWork.Step = 10;
                            }
                        }
                    }
                    else
                    {
                        AddList("启动OK!");
                        //根据载具编号打开相对应的真空吸
                        //BVar.OpenedVacumeNo = OpenFixtureVocume();
                        TimeOut      = API.GetTickCount();
                        StaWork.Step = 50;
                    }
                    break;

                case 40:
                    if (API.GetTickCount() - TimeOut > 1000)    //延时1秒,等待真空吸信号
                    {
                        TimeOut      = API.GetTickCount();
                        StaWork.Step = 50;
                    }
                    break;

                case 50:
                    if (PVar.ParList.CheckSts[17] == false)
                    {
                        if (Gg.GetDi(0, BVar.OpenedVacumeNo + 5) == 1)    //判断真空吸信号
                        {
                            TimeOut      = API.GetTickCount();
                            StaWork.Step = 60;
                        }
                        else
                        {
                            if (API.GetTickCount() - TimeOut > 2000)
                            {
                                AddList("HSG真空吸没达到检测值,请检查产品是否放好!");
                                ShowList("HSG真空吸没达到检测值,请检查产品是否放好!");
                                TimeOut      = API.GetTickCount();
                                StaWork.Step = 1000;
                            }
                        }
                    }
                    else
                    {
                        TimeOut      = API.GetTickCount();
                        StaWork.Step = 60;
                    }
                    break;

                case 60:    //等待所有工位结束工作
                    if (PVar.ParList.CheckSts[17] == false)
                    {
                        if (PVar.Stop_Flag == false)
                        {
                            if (Gg.GetDi(0, Gg.InPut0.安全光幕) == 1 && Gg.GetDi(0, BVar.OpenedVacumeNo + 5) == 1 && PVar.Sta_Work[2].State == false && PVar.Sta_Work[3].State == false && PVar.Sta_Work[4].State == false)
                            {
                                StaWork.State = true;
                                CT_Start      = true;
                                PVar.Sta_Work[1].IsHaveHSG = true;
                                Frm_Engineering.fEngineering.OvalShape_Sta0.BackColor = Color.DarkOrange;
                                Frm_Engineering.fEngineering.Chk_StaRound.BackColor   = Color.DarkOrange;
                                if (Gg.GetPrfPos(1, 1) > 300)       //int类型最大值为2^31-1=2147483647
                                {
                                    gts.GT_SetPrfPos(1, 1, 0);      //规划器置零
                                    gts.GT_SetEncPos(1, 1, 0);      //编码器置零
                                    gts.GT_SynchAxisPos(1, 1 << 0); //将当前轴进行位置同步
                                }

                                AddList("转盘开始转动!");
                                TimeOut      = API.GetTickCount();
                                StaWork.Step = 70;
                            }
                            else
                            {
                                if (Gg.GetDi(0, BVar.OpenedVacumeNo + 5) == 0)    //判断真空吸信号
                                {
                                    AddList("HSG真空吸力异常,启动失败,请重新启动!");
                                    ShowList("HSG真空吸力异常,启动失败,请重新启动!");
                                    TimeOut      = API.GetTickCount();
                                    StaWork.Step = 1000;
                                }
                            }
                        }
                        else
                        {
                            TimeOut      = API.GetTickCount();
                            StaWork.Step = 1000;
                        }
                    }
                    else
                    {
                        if (PVar.Stop_Flag == false)
                        {
                            if (Gg.GetDi(0, Gg.InPut0.安全光幕) == 1 && PVar.Sta_Work[2].State == false && PVar.Sta_Work[3].State == false && PVar.Sta_Work[4].State == false)
                            {
                                StaWork.State = true;
                                CT_Start      = true;
                                PVar.Sta_Work[1].IsHaveHSG = true;
                                Frm_Engineering.fEngineering.OvalShape_Sta0.BackColor = Color.DarkOrange;
                                Frm_Engineering.fEngineering.Chk_StaRound.BackColor   = Color.DarkOrange;
                                if (Gg.GetPrfPosmm(1, 1) > 300)     //int类型最大值为2^31-1=2147483647
                                {
                                    gts.GT_SetPrfPos(1, 1, 0);      //规划器置零
                                    gts.GT_SetEncPos(1, 1, 0);      //编码器置零
                                    gts.GT_SynchAxisPos(1, 1 << 0); //将当前轴进行位置同步
                                }

                                AddList("转盘开始转动!");
                                TimeOut      = API.GetTickCount();
                                StaWork.Step = 70;
                            }
                        }
                        else
                        {
                            TimeOut      = API.GetTickCount();
                            StaWork.Step = 1000;
                        }
                    }
                    break;

                case 70:
                    StationR_State();
                    Gg.StepMotion(1, 1, PVar.ParAxis.Speed[9], 90, "+");
                    TimeOut      = API.GetTickCount();
                    StaWork.Step = 80;
                    break;

                case 80:
                    if (Gg.ZSPD(1, 1))
                    {
                        Frm_Engineering.fEngineering.OvalShape_Sta0.BackColor = Color.FromArgb(192, 255, 192);
                        Frm_Engineering.fEngineering.Chk_StaRound.BackColor   = Color.FromArgb(192, 255, 192);
                        AddList("转盘转动到位!");
                        TimeOut      = API.GetTickCount();
                        StaWork.Step = 90;
                    }
                    else
                    {
                        if (API.GetTickCount() - TimeOut > 10000)
                        {
                            AddList("转盘转动超时!");
                            ShowList("转盘转动超时!");
                            TimeOut      = API.GetTickCount();
                            StaWork.Step = 10000;
                        }
                    }
                    break;

                case 90:
                    TimeOut      = API.GetTickCount();
                    StaWork.Step = 800;
                    break;

                case 800:
                    StaWork.Result = true;
                    StaWork.State  = false;
                    StaWork.Step   = 10;
                    break;

                case 1000:
                    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);
            }
        }