示例#1
0
        /// <summary>
        /// 单轴运动
        /// </summary>
        public void Interpolation_Start(decimal PosX, decimal PosY)
        {
            //设置X轴误差带
            Gts_Return = MC.GT_SetAxisBand(1, Program.SystemContainer.SysPara.Axis_X_Band, 4 * Program.SystemContainer.SysPara.Axis_X_Time);//20-0.1um,4*2-250us
            LogErr?.Invoke("X轴到位误差带", Gts_Return);
            //设置Y轴误差带
            Gts_Return = MC.GT_SetAxisBand(2, Program.SystemContainer.SysPara.Axis_Y_Band, 4 * Program.SystemContainer.SysPara.Axis_Y_Time);//20-0.1um,4*2-250us
            LogErr?.Invoke("Y轴到位误差带", Gts_Return);


            //急停按钮按下终止运行
            if (Program.SystemContainer.IO.GlobalEMG)
            {
                Interpolation_Stop();
                return;
            }

            //二轴单独控制运动
            //1、计算二轴规划位置
            decimal GoX = (Program.SystemContainer.SysPara.Work.X - PosX) * Program.SystemContainer.SysPara.Gts_Pos_reference;
            decimal GoY = (Program.SystemContainer.SysPara.Work.Y - PosY) * Program.SystemContainer.SysPara.Gts_Pos_reference;

            //2、设置运行参数
            SetAxisPara(1, Program.SystemContainer.SysPara.AxisXAcc, Program.SystemContainer.SysPara.AxisXDcc, Program.SystemContainer.SysPara.AxisXSmoothTime, GoX, Program.SystemContainer.SysPara.AxisXVelocity); //X轴运行参数
            SetAxisPara(2, Program.SystemContainer.SysPara.AxisYAcc, Program.SystemContainer.SysPara.AxisYDcc, Program.SystemContainer.SysPara.AxisYSmoothTime, GoY, Program.SystemContainer.SysPara.AxisYVelocity); //Y轴运行参数
            //3、启动运动
            Gts_Return = MC.GT_Update(1 << (1 - 1));                                                                                                                                                                 //启动X轴运动
            Gts_Return = MC.GT_Update(1 << (2 - 1));                                                                                                                                                                 //启动Y轴运动
            //4、等待运动结束
            int stsX, stsY;

            do
            {
                //急停按钮按下终止运行
                if (Program.SystemContainer.IO.GlobalEMG)
                {
                    Interpolation_Stop();
                    return;
                }
                Gts_Return = MC.GT_GetSts(1, out stsX, 1, out pClock); //读取X轴状态
                Gts_Return = MC.GT_GetSts(2, out stsY, 1, out pClock); //读取Y轴状态
                Thread.Sleep(100);
            } while (((stsX & 0x400) != 0) || ((stsY & 0x400) != 0));  //等待两轴规划停止

            //到位检测
            do
            {
                //延时
                Thread.Sleep(Program.SystemContainer.SysPara.Posed_Time);
            } while (!Program.SystemContainer.IO.Axis01_Motor_Posed || !(Program.SystemContainer.IO.Axis02_Motor_Posed));
        }
示例#2
0
        /// <summary>
        /// 相对定位
        /// </summary>
        /// <param name="Axis"></param>
        /// <param name="acc"></param>
        /// <param name="dcc"></param>
        /// <param name="smoothTime"></param>
        /// <param name="pos"></param>
        /// <param name="vel"></param>
        public void Inc(short Axis, decimal acc, decimal dcc, short smoothTime, decimal pos, decimal vel)
        {
            //定义点位运动参数变量
            MC.TTrapPrm trapPrm = new MC.TTrapPrm();
            //定义当前位置变量
            double prfpos;
            //定义时钟
            uint pclock;
            //定义轴状态
            int sts;

            //将轴设置为点位运动模式
            Gts_Return = MC.GT_PrfTrap(Axis);
            LogErr?.Invoke("Motion--将轴设置为点位运动模式", Gts_Return);
            //读取点位运动运动参数
            Gts_Return = MC.GT_GetTrapPrm(Axis, out trapPrm);
            LogErr?.Invoke("Motion--读取轴点位运动运动参数", Gts_Return);
            //设置要修改的参数
            trapPrm.acc        = Convert.ToDouble(acc / Program.SystemContainer.SysPara.Gts_Acc_reference);
            trapPrm.dec        = Convert.ToDouble(dcc / Program.SystemContainer.SysPara.Gts_Acc_reference);
            trapPrm.smoothTime = smoothTime;
            //设置点位运动参数
            Gts_Return = MC.GT_SetTrapPrm(Axis, ref trapPrm);
            LogErr?.Invoke("Motion--读取轴设置点位运动参数", Gts_Return);

            //读取当前规划位置
            Gts_Return = MC.GT_GetPrfPos(Axis, out prfpos, 1, out pclock);
            LogErr?.Invoke("Motion--读取轴当前规划位置", Gts_Return);

            //设置目标位置
            Gts_Return = MC.GT_SetPos(Axis, Convert.ToInt32(Convert.ToDouble(pos * Program.SystemContainer.SysPara.Gts_Pos_reference) + prfpos));
            LogErr?.Invoke("Motion--设置目标位置", Gts_Return);

            //设置目标速度
            Gts_Return = MC.GT_SetVel(Axis, Convert.ToDouble(vel / Program.SystemContainer.SysPara.Gts_Vel_reference));
            LogErr?.Invoke("Motion--设置目标速度", Gts_Return);

            //启动轴运动
            Gts_Return = MC.GT_Update(1 << (Axis - 1));
            LogErr?.Invoke("Motion--启动轴运动", Gts_Return);

            do
            {
                //读取轴状态
                Gts_Return = MC.GT_GetSts(Axis, out sts, 1, out pclock);
                LogErr?.Invoke("Motion--读取轴状态", Gts_Return);
            } while ((sts & 0x400) != 0);//等待Axis规划停止
        }
示例#3
0
        /// <summary>
        /// 刷新状态
        /// </summary>
        public void Refresh_IO(object sender, ElapsedEventArgs e)
        {
            //读取通用输出的值
            Gts_Return = MC.GT_GetDo(12, out Exo_16bit);
            //读取通用输入的值
            Gts_Return = MC.GT_GetDi(4, out Exi_16bit);
            //读取Axis01状态
            Gts_Return = MC.GT_GetSts(1, out Axis01_Sta, 1, out Axis01_Clk);
            //读取Axis02状态
            Gts_Return = MC.GT_GetSts(2, out Axis02_Sta, 1, out Axis02_Clk);
            //读取Axis_Home_Sta状态
            Gts_Return = MC.GT_GetDi(3, out Axis_Home_Sta);
            //读取Axis_Posed_Sta状态
            Gts_Return = MC.GT_GetDi(5, out Axis_Posed_Sta);
            //读取Axis_Clear_Sta状态
            Gts_Return = MC.GT_GetDo(11, out Axis_Clear_Sta);

            //读取规划位置
            Gts_Return = MC.GT_GetPrfPos(1, out Axis01_prfPos, 1, out Axis01_Clk);
            Gts_Return = MC.GT_GetPrfPos(2, out Axis02_prfPos, 1, out Axis02_Clk);

            //读取实际位置
            Gts_Return = MC.GT_GetAxisEncPos(1, out Axis01_encPos, 1, out Axis01_Clk);
            Gts_Return = MC.GT_GetAxisEncPos(2, out Axis02_encPos, 1, out Axis02_Clk);

            //读取当前速度
            Gts_Return = MC.GT_GetVel(1, out Axis01_vel);
            Gts_Return = MC.GT_GetVel(2, out Axis02_vel);

            //读取当前加减速
            Gts_Return = MC.GT_GetAxisPrfAcc(1, out Axis01_acc, 1, out Axis01_Clk);
            Gts_Return = MC.GT_GetAxisPrfAcc(1, out Axis01_dcc, 1, out Axis01_Clk);
            Gts_Return = MC.GT_GetAxisPrfAcc(2, out Axis02_acc, 1, out Axis02_Clk);
            Gts_Return = MC.GT_GetAxisPrfAcc(2, out Axis02_dcc, 1, out Axis02_Clk);

            //读取轴运动模式
            Gts_Return = MC.GT_GetPrfMode(1, out Axis01_mode, 1, out Axis01_Clk);
            Gts_Return = MC.GT_GetPrfMode(2, out Axis02_mode, 1, out Axis02_Clk);

            //刷新数值至相应的IO
            //刷新EXI
            EXI1 = (Exi_16bit & (1 << 1)) == 0; // 急停开关
            EXI2 = (Exi_16bit & (1 << 2)) == 0; // 除尘气缸伸出传感器
            EXI3 = (Exi_16bit & (1 << 3)) == 0; // 除尘气缸退回传感器
            EXI4 = (Exi_16bit & (1 << 4)) == 0; // 左门禁传感器
            EXI5 = (Exi_16bit & (1 << 5)) == 0; // 右门禁传感器
            EXI6 = (Exi_16bit & (1 << 6)) == 0; // 启动按钮1
            EXI7 = (Exi_16bit & (1 << 7)) == 0; // 启动按钮1
            EXI8 = (Exi_16bit & (1 << 8)) == 0; // 真空压力达标
            EXI9 = (Exi_16bit & (1 << 9)) == 0; // 安全传感器


            //刷新急停按钮状态
            if (EXI1 || SoftEMG)//按下,急停触发
            {
                EMGButton.Variable = 1;
            }
            else//抬起,急停解除
            {
                EMGButton.Variable = 0;
            }

            //输出按钮灯
            if (EXI6)
            {
                Button1_Lamp = 1;
            }
            else
            {
                Button1_Lamp = 0;
            };
            if (EXI7)
            {
                Button2_Lamp = 1;
            }
            else
            {
                Button2_Lamp = 0;
            };

            //刷新门传感器滤波函数值
            DoorSensorCheck.Variable = (EXI4 && EXI5) ? 1 : 0;

            //刷新安全传感器
            SafeSensorCheck.Variable = EXI9 ? 1 : 0;

            //输出照明灯
            //if ((!EXI4) || (!EXI5)) { Lamp_control = 1; } else { Lamp_control = 0; };

            //刷新EXO
            EXO1  = (Exo_16bit & (1 << 1)) == 0;                // 三色灯塔黄
            EXO2  = (Exo_16bit & (1 << 2)) == 0;                // 三色灯塔绿
            EXO3  = (Exo_16bit & (1 << 3)) == 0;                // 三色灯塔红
            EXO4  = (Exo_16bit & (1 << 4)) == 0;                // 蜂鸣器
            EXO5  = (Exo_16bit & (1 << 5)) == 0;                // 除尘气缸伸出
            EXO6  = (Exo_16bit & (1 << 6)) == 0;                // 除尘气缸退回
            EXO7  = (Exo_16bit & (1 << 7)) == 0;                // 吹气打开
            EXO8  = (Exo_16bit & (1 << 8)) == 0;                // 照明灯
            EXO9  = (Exo_16bit & (1 << 9)) == 0;                // 启动按钮1灯
            EXO10 = (Exo_16bit & (1 << 10)) == 0;               // 启动按钮2灯
            EXO11 = (Exo_16bit & (1 << 11)) == 0;               // X轴回零触发
            EXO12 = (Exo_16bit & (1 << 12)) == 0;               // Y轴回零触发
            EXO13 = (Exo_16bit & (1 << 13)) == 0;               // 红光开
            EXO14 = (Exo_16bit & (1 << 14)) == 0;               // 门打开
            EXO15 = (Exo_16bit & (1 << 15)) == 0;               // 门关闭
            //刷新Axis01 状态
            Axis01_Limit_Up    = (Axis01_Sta & (1 << 5)) != 0;  // Axis01轴正限位
            Axis01_Limit_Down  = (Axis01_Sta & (1 << 6)) != 0;  // Axis01轴负限位
            Axis01_Home        = (Axis_Home_Sta & 0x01) != 0;   // Axis01轴原点
            Axis01_Alarm       = (Axis01_Sta & (1 << 1)) != 0;  // Axis01轴报警
            Axis01_Alarm_Cl    = (Axis_Clear_Sta & 0x01) == 0;  //Axis01轴报警清除
            Axis01_MC_Err      = (Axis01_Sta & (1 << 4)) != 0;  // Axis01轴板卡报警(跟随误差越限)
            Axis01_EN          = (Axis01_Sta & (1 << 9)) != 0;  // Axis01轴使能
            Axis01_Busy        = (Axis01_Sta & (1 << 10)) != 0; // Axis01轴输出中
            Axis01_IO_Stop     = (Axis01_Sta & (1 << 7)) != 0;  // Axis01轴IO停止
            Axis01_IO_EMG      = (Axis01_Sta & (1 << 8)) != 0;  // Axis01轴IO急停
            Axis01_Motor_Posed = (Axis_Posed_Sta & 0x01) != 0;  // Axis01轴 电机到位
            Axis01_Upper_Posed = (Axis01_Sta & (1 << 11)) != 0; // Axis01轴 上位机到位

            //刷新Axis02 状态
            Axis02_Limit_Up    = (Axis02_Sta & (1 << 5)) != 0;      // Axis02轴正限位
            Axis02_Limit_Down  = (Axis02_Sta & (1 << 6)) != 0;      // Axis02轴负限位
            Axis02_Home        = (Axis_Home_Sta & (1 << 1)) != 0;   // Axis02轴原点
            Axis02_Alarm       = (Axis02_Sta & (1 << 1)) != 0;      // Axis02轴报警
            Axis02_Alarm_Cl    = (Axis_Clear_Sta & (1 << 1)) == 0;  //Axis02轴报警清除
            Axis02_MC_Err      = (Axis02_Sta & (1 << 4)) != 0;      // Axis02轴板卡报警(跟随误差越限)
            Axis02_EN          = (Axis02_Sta & (1 << 9)) != 0;      // Axis02轴使能
            Axis02_Busy        = (Axis02_Sta & (1 << 10)) != 0;     // Axis02轴输出中
            Axis02_IO_Stop     = (Axis02_Sta & (1 << 7)) != 0;      // Axis02轴IO停止
            Axis02_IO_EMG      = (Axis02_Sta & (1 << 8)) != 0;      // Axis02轴IO急停
            Axis02_Motor_Posed = (Axis_Posed_Sta & (1 << 1)) != 0;; // Axis02轴 电机到位
            Axis02_Upper_Posed = (Axis02_Sta & (1 << 11)) != 0;     // Axis02轴 上位机到位

            //轴故障
            Axis01_Err_Occur = Axis01_Limit_Up || Axis01_Limit_Down || Axis01_Alarm || Axis01_MC_Err || Axis01_IO_EMG;
            Axis02_Err_Occur = Axis02_Limit_Up || Axis02_Limit_Down || Axis02_Alarm || Axis02_MC_Err || Axis02_IO_EMG;

            //刷新轴原点状态
            Gts_Home_Flag = !Axis01_Err_Occur && Axis01_Home && Program.SystemContainer.GTS_Fun.Axis01_Homed && !Axis02_Err_Occur && Axis02_Home && Program.SystemContainer.GTS_Fun.Axis02_Homed;//任意(轴限位、报警、使能关闭、急停),致使原点标志丢失

            //轴1
            if (Axis01_Err_Occur && Program.SystemContainer.GTS_Fun.Axis01_Homed)//轴故障发生,同时轴已经回零
            {
                Axis01_Homed_Status.Variable = 1;
            }
            else
            {
                Axis01_Homed_Status.Variable = 0;
            }
            //轴2
            if (Axis02_Err_Occur && Program.SystemContainer.GTS_Fun.Axis02_Homed)//轴故障发生,同时轴已经回零
            {
                Axis02_Homed_Status.Variable = 1;
            }
            else
            {
                Axis02_Homed_Status.Variable = 0;
            }


            //全局报警
            GlobalAlarm = Axis01_Err_Occur || Axis02_Err_Occur;

            //全局警告报警处理
            if (GlobalAlarm || GlobalWarning)
            {
                Yellow_lamp   = 0; //黄色
                Green_lamp    = 0; //绿色
                Red_lamp      = 1; //红色
                Beeze_Control = 1;
            }
            else
            {
                if (GlobalRunnig)
                {
                    Yellow_lamp = 0; //黄色
                    Green_lamp  = 1; //绿色
                    Red_lamp    = 0; //红色
                }
                else
                {
                    Yellow_lamp = 1; //黄色
                    Green_lamp  = 0; //绿色
                    Red_lamp    = 0; //红色
                }
                Beeze_Control = 0;
            }
            //输出控制 0-输出,1-关闭输出
            //Cyc_control, Blow_control, Lamp_control;//定义气缸、吹气、照明控制字

            //Yellow_lamp,Green_lamp,Red_lamp,Beeze_Control,Button1_Lamp, Button2_Lamp;//定义灯塔黄、灯塔绿、灯塔红、蜂鸣控制字
            //灯塔黄控制
            if (Yellow_lamp == 1)
            {
                Gts_Return = MC.GT_SetDoBit(12, 2, 0);
            }
            else
            {
                Gts_Return = MC.GT_SetDoBit(12, 2, 1);
            }
            //灯塔绿控制
            if (Green_lamp == 1)
            {
                Gts_Return = MC.GT_SetDoBit(12, 3, 0);
            }
            else
            {
                Gts_Return = MC.GT_SetDoBit(12, 3, 1);
            }
            //灯塔红控制
            if (Red_lamp == 1)
            {
                Gts_Return = MC.GT_SetDoBit(12, 4, 0);
            }
            else
            {
                Gts_Return = MC.GT_SetDoBit(12, 4, 1);
            }
            //蜂鸣器控制
            if (Beeze_Control == 1)
            {
                if (Timer_1s_Flag)
                {
                    Gts_Return = MC.GT_SetDoBit(12, 5, 0);
                }
                else
                {
                    Gts_Return = MC.GT_SetDoBit(12, 5, 1);
                }
            }
            else
            {
                Gts_Return = MC.GT_SetDoBit(12, 5, 1);
            }
            //气缸控制
            if (Cyc_control == 1)//气缸打开
            {
                Gts_Return = MC.GT_SetDoBit(12, 6, 0);
                Gts_Return = MC.GT_SetDoBit(12, 7, 1);
            }
            else
            {
                Gts_Return = MC.GT_SetDoBit(12, 6, 1);
                Gts_Return = MC.GT_SetDoBit(12, 7, 0);
            }
            //吹气控制
            if (Blow_control == 1)//吹气打开
            {
                Gts_Return = MC.GT_SetDoBit(12, 8, 0);
            }
            else
            {
                Gts_Return = MC.GT_SetDoBit(12, 8, 1);
            }
            //照明控制
            if (Lamp_control == 1)//照明打开
            {
                Gts_Return = MC.GT_SetDoBit(12, 9, 0);
            }
            else
            {
                Gts_Return = MC.GT_SetDoBit(12, 9, 1);
            }
            //Button1_Lamp, Button2_Lamp;//定义启动按钮1灯、启动按钮2灯控制字
            //启动按钮1灯
            if (Button1_Lamp == 1)
            {
                Gts_Return = MC.GT_SetDoBit(12, 10, 0);
            }
            else
            {
                Gts_Return = MC.GT_SetDoBit(12, 10, 1);
            }
            //启动按钮2灯
            if (Button2_Lamp == 1)
            {
                Gts_Return = MC.GT_SetDoBit(12, 11, 0);
            }
            else
            {
                Gts_Return = MC.GT_SetDoBit(12, 11, 1);
            }
            //轴1回零触发
            if (Axis01_Home_Ex0_Control == 1)//轴1回零
            {
                Gts_Return = MC.GT_SetDoBit(12, 12, 0);
            }
            else
            {
                Gts_Return = MC.GT_SetDoBit(12, 12, 1);
            }
            //轴2回零触发
            if (Axis02_Home_Ex0_Control == 1)//轴2回零
            {
                Gts_Return = MC.GT_SetDoBit(12, 13, 0);
            }
            else
            {
                Gts_Return = MC.GT_SetDoBit(12, 13, 1);
            }

            //红色激光控制
            if (RedLaser_Control == 1)
            {
                Gts_Return = MC.GT_SetDoBit(12, 14, 0);
            }
            else
            {
                Gts_Return = MC.GT_SetDoBit(12, 14, 1);
            }

            //门控制
            if (Door_Control == 1)
            {
                Gts_Return = MC.GT_SetDoBit(12, 15, 0);
                Gts_Return = MC.GT_SetDoBit(12, 16, 1);
            }
            else
            {
                Gts_Return = MC.GT_SetDoBit(12, 15, 1);
                Gts_Return = MC.GT_SetDoBit(12, 16, 0);
            }

            //刷新双启按钮状态
            if (EXI4 && EXI5 && EXI6 && EXI7 && Gts_Home_Flag)
            {
                Start_Button.Variable = 1;
            }
            else
            {
                Start_Button.Variable = 0;
            }
        }
示例#4
0
        /// <summary>
        /// Gts工控卡 上位机Axes回零
        /// </summary>
        /// <param name="Axis"></param>
        /// <returns></returns>
        public int Home_Upper_Monitor(short Axis)
        {
            //命令返回值
            short Gts_Return;
            short Capture;//捕获状态值

            MC.TTrapPrm Home_TrapPrm = new MC.TTrapPrm();
            int         Axis_Sta;    //轴状态
            uint        Axis_Pclock; //轴时钟
            Int32       Axis_Pos;    //回零是触发Home开关时的轴位置
            double      prfPos;      //回零运动过程中规划位置
            //定义时钟
            uint pclock;

            //停止轴运动
            Gts_Return = MC.GT_Stop(1 << (Axis - 1), 0); //平滑停止轴运动
            LogErr?.Invoke("Motion--停止轴运动", Gts_Return);

            //清除指定轴报警和限位
            Gts_Return = MC.GT_ClrSts(Axis, 1);
            LogErr?.Invoke("Axis_Home----GT_ClrSts", Gts_Return);

            //回零准备,向正方向前进20mm,后触发回零
            //切换到点动模式
            Gts_Return = MC.GT_PrfTrap(Axis);
            LogErr?.Invoke("Axis_Home----GT_PrfTrap", Gts_Return);

            //读取点动模式运动参数
            Gts_Return = MC.GT_GetTrapPrm(Axis, out Home_TrapPrm);
            LogErr?.Invoke("Axis_Home----GT_GetTrapPrm", Gts_Return);

            //设置点动模式运动参数
            Home_TrapPrm.acc        = Convert.ToDouble(Program.SystemContainer.SysPara.Home_acc / Program.SystemContainer.SysPara.Gts_Acc_reference);
            Home_TrapPrm.dec        = Convert.ToDouble(Program.SystemContainer.SysPara.Home_dcc / Program.SystemContainer.SysPara.Gts_Acc_reference);
            Home_TrapPrm.smoothTime = Program.SystemContainer.SysPara.Home_smoothTime;

            //设置点动模式运动参数
            Gts_Return = MC.GT_SetTrapPrm(Axis, ref Home_TrapPrm);
            LogErr?.Invoke("Axis_Home----GT_SetTrapPrm", Gts_Return);

            //设置点动模式目标速度,即回原点速度
            Gts_Return = MC.GT_SetVel(Axis, Convert.ToDouble(Program.SystemContainer.SysPara.Home_High_Speed / Program.SystemContainer.SysPara.Gts_Vel_reference));
            LogErr?.Invoke("Axis_Home----GT_SetVel", Gts_Return);

            //读取当前规划位置
            Gts_Return = MC.GT_GetPrfPos(Axis, out prfPos, 1, out pclock);
            LogErr?.Invoke("Motion--读取轴当前规划位置", Gts_Return);

            //设置点动模式目标位置,即原点准备距离 20mm
            Gts_Return = MC.GT_SetPos(Axis, Convert.ToInt32(Convert.ToDouble(20 * Program.SystemContainer.SysPara.Gts_Pos_reference) + prfPos));
            LogErr?.Invoke("Motion--设置目标位置", Gts_Return);

            //启动运动
            Gts_Return = MC.GT_Update(1 << (Axis - 1));
            LogErr?.Invoke("Axis_Home----GT_Update", Gts_Return);

            do
            {
                //读取轴状态
                Gts_Return = MC.GT_GetSts(Axis, out Axis_Sta, 1, out Axis_Pclock);
            } while ((Axis_Sta & 0x400) != 0);

            //停止轴运动
            Gts_Return = MC.GT_Stop(1 << (Axis - 1), 0); //平滑停止轴运动
            LogErr?.Invoke("Motion--停止轴运动", Gts_Return);

            //延时一段时间,等待电机稳定
            Thread.Sleep(200);//200ms

            //触发回零
            //启动Home捕捉
            Gts_Return = MC.GT_SetCaptureMode(Axis, MC.CAPTURE_HOME);
            LogErr?.Invoke("Axis_Home----GT_SetCaptureMode", Gts_Return);

            //切换到点动模式
            Gts_Return = MC.GT_PrfTrap(Axis);
            LogErr?.Invoke("Axis_Home----GT_PrfTrap", Gts_Return);

            //读取点动模式运动参数
            Gts_Return = MC.GT_GetTrapPrm(Axis, out Home_TrapPrm);
            LogErr?.Invoke("Axis_Home----GT_GetTrapPrm", Gts_Return);

            //设置点动模式运动参数
            Home_TrapPrm.acc        = Convert.ToDouble(Program.SystemContainer.SysPara.Home_acc / Program.SystemContainer.SysPara.Gts_Acc_reference);
            Home_TrapPrm.dec        = Convert.ToDouble(Program.SystemContainer.SysPara.Home_dcc / Program.SystemContainer.SysPara.Gts_Acc_reference);
            Home_TrapPrm.smoothTime = Program.SystemContainer.SysPara.Home_smoothTime;

            //设置点动模式运动参数
            Gts_Return = MC.GT_SetTrapPrm(Axis, ref Home_TrapPrm);
            LogErr?.Invoke("Axis_Home----GT_SetTrapPrm", Gts_Return);

            //设置点动模式目标速度,即回原点速度
            Gts_Return = MC.GT_SetVel(Axis, Convert.ToDouble(Program.SystemContainer.SysPara.Home_High_Speed / Program.SystemContainer.SysPara.Gts_Vel_reference));
            LogErr?.Invoke("Axis_Home----GT_SetVel", Gts_Return);

            //设置点动模式目标位置,即原点搜索距离
            Gts_Return = MC.GT_SetPos(Axis, Convert.ToInt32(Program.SystemContainer.SysPara.Search_Home * Program.SystemContainer.SysPara.Gts_Pos_reference));
            LogErr?.Invoke("Axis_Home----GT_SetPos", Gts_Return);

            //启动运动
            Gts_Return = MC.GT_Update(1 << (Axis - 1));
            LogErr?.Invoke("Axis_Home----GT_Update", Gts_Return);


            do
            {
                //读取轴状态
                Gts_Return = MC.GT_GetSts(Axis, out Axis_Sta, 1, out Axis_Pclock);
                //读取捕获状态
                Gts_Return = MC.GT_GetCaptureStatus(Axis, out Capture, out Axis_Pos, 1, out Axis_Pclock);
                //读取编码器位置
                //Gts_Return = MC.GT_GetEncPos(Axis, out encPos, 1, out Axis_Pclock);
                //如果运动停止,返回出错信息
                if (0 == (Axis_Sta & 0x400))
                {
                    LogErr?.Invoke("Axis_Home----No Home found!!", 1);
                    return(1);//整个过程Home信号一直没有触发,返回值为1
                }
            } while (Capture == 0);

            /********************************待评估***********************************/

            /*
             * //清除捕捉状态
             * //Gts_Return = MC.GT_ClearCaptureStatus(Axis);
             * //LogErr?.Invoke("Axis_Home----清除捕捉状态", Gts_Return);
             *
             * //设置捕捉Home 下降沿
             * //Gts_Return = MC.GT_SetCaptureSense(Axis, MC.CAPTURE_HOME, 0);
             * //LogErr?.Invoke("Axis_Home----设置捕捉Home 下降沿", Gts_Return);
             *
             * //设定目标位置为捕获位置+偏移量
             * Gts_Return = MC.GT_SetPos(Axis, Axis_Pos + Home_OffSet);
             * LogErr?.Invoke("Axis_Home----GT_SetPos", Gts_Return);
             *
             * //在运动状态下更新目标位置
             * Gts_Return = MC.GT_Update(1 << (Axis - 1));
             * LogErr?.Invoke("Axis_Home----GT_Update", Gts_Return);
             *
             * do
             * {
             *  //读取轴状态
             *  Gts_Return = MC.GT_GetSts(Axis, out Axis_Sta, 1, out Axis_Pclock);
             *  //读取捕获状态
             *  Gts_Return = MC.GT_GetCaptureStatus(Axis, out Capture, out Axis_Pos, 1, out Axis_Pclock);
             *  //读取编码器位置
             *  //Gts_Return = MC.GT_GetEncPos(Axis, out encPos, 1, out Axis_Pclock);
             *  //如果运动停止,返回出错信息
             *  if (0 == (Axis_Sta & 0x400))
             *  {
             *      LogErr?.Invoke("Axis_Home----No Home found!!", 1);
             *      //反转回零标志
             *      Homing_Flag = !Homing_Flag;
             *      return 1;//整个过程Home信号一直没有触发,返回值为1
             *  }
             * } while (Capture ==0);
             */
            /********************************待评估***********************************/

            //停止轴运动
            Gts_Return = MC.GT_Stop(1 << (Axis - 1), 0); //平滑停止轴运动
            LogErr?.Invoke("Motion--停止轴运动", Gts_Return);

            //延时一段时间,等待电机稳定
            Thread.Sleep(500);//200ms
            //位置清零
            Gts_Return = MC.GT_ZeroPos(Axis, 1);
            LogErr?.Invoke("Axis_Home----GT_ZeroPos", Gts_Return);

            /***************************Home_Offset偏置距离 开始********************************************/

            if (Program.SystemContainer.SysPara.Home_OffSet != 0)
            {
                //切换到点动模式
                Gts_Return = MC.GT_PrfTrap(Axis);
                LogErr?.Invoke("Axis_Home----GT_PrfTrap", Gts_Return);

                //读取点动模式运动参数
                Gts_Return = MC.GT_GetTrapPrm(Axis, out Home_TrapPrm);
                LogErr?.Invoke("Axis_Home----GT_GetTrapPrm", Gts_Return);

                //设置点动模式运动参数
                Home_TrapPrm.acc        = Convert.ToDouble(Program.SystemContainer.SysPara.Home_acc / Program.SystemContainer.SysPara.Gts_Acc_reference);
                Home_TrapPrm.dec        = Convert.ToDouble(Program.SystemContainer.SysPara.Home_dcc / Program.SystemContainer.SysPara.Gts_Acc_reference);
                Home_TrapPrm.smoothTime = Program.SystemContainer.SysPara.Home_smoothTime;

                //设置点动模式运动参数
                Gts_Return = MC.GT_SetTrapPrm(Axis, ref Home_TrapPrm);
                LogErr?.Invoke("Axis_Home----GT_SetTrapPrm", Gts_Return);

                //设置点动模式目标速度,即回原点速度
                Gts_Return = MC.GT_SetVel(Axis, Convert.ToDouble(Program.SystemContainer.SysPara.Home_High_Speed / Program.SystemContainer.SysPara.Gts_Vel_reference));
                LogErr?.Invoke("Axis_Home----GT_SetVel", Gts_Return);

                //设置点动模式目标位置,即原点搜索距离
                Gts_Return = MC.GT_SetPos(Axis, Convert.ToInt32(Program.SystemContainer.SysPara.Home_OffSet * Program.SystemContainer.SysPara.Gts_Pos_reference));
                LogErr?.Invoke("Axis_Home----GT_SetPos", Gts_Return);

                //启动运动
                Gts_Return = MC.GT_Update(1 << (Axis - 1));
                LogErr?.Invoke("Axis_Home----GT_Update", Gts_Return);

                do
                {
                    //读取轴状态
                    Gts_Return = MC.GT_GetSts(Axis, out Axis_Sta, 1, out Axis_Pclock);
                    //读取规划位置
                    Gts_Return = MC.GT_GetPrfPos(Axis, out prfPos, 1, out Axis_Pclock);
                    //读取编码器位置
                    //Gts_Return = MC.GT_GetEncPos(Axis, out encPos, 1, out Axis_Pclock);
                } while ((Axis_Sta & 0x400) != 0);

                //检查是否到达 Home_OffSet
                if (prfPos != Convert.ToInt32(Program.SystemContainer.SysPara.Home_OffSet * Program.SystemContainer.SysPara.Gts_Pos_reference))
                {
                    LogErr?.Invoke("Axis_Home----Move to Home_OffSet err!!", 1);
                    return(2);
                }
                /***************************Home_Offset偏置距离 结束********************************************/
            }
            //延时一段时间,等待电机稳定
            Thread.Sleep(500);//200ms
            //位置清零
            Gts_Return = MC.GT_ZeroPos(Axis, 1);
            LogErr?.Invoke("Axis_Home----GT_ZeroPos", Gts_Return);
            return(0);
        }
        public void Refresh_IO()
        {
            //读取通用输出的值
            Gts_Return = MC.GT_GetDo(12, out Exo_16bit);
            Log.Commandhandler("Refresh--MC.GT_GetDo", Gts_Return);
            //读取通用输入的值
            Gts_Return = MC.GT_GetDi(4, out Exi_16bit);
            Log.Commandhandler("Refresh--MC.GT_GetDi", Gts_Return);
            //读取Axis01状态
            Gts_Return = MC.GT_GetSts(1, out Axis01_Sta, 1, out Axis01_Clk);
            Log.Commandhandler("Refresh_Axis01--MC.GT_GetSts", Gts_Return);
            //读取Axis02状态
            Gts_Return = MC.GT_GetSts(2, out Axis02_Sta, 1, out Axis02_Clk);
            Log.Commandhandler("Refresh_Axis02--MC.GT_GetSts", Gts_Return);
            //读取Axis_Home_Sta状态
            Gts_Return = MC.GT_GetDi(3, out Axis_Home_Sta);
            Log.Commandhandler("Refresh_Axis_Home_Sta--MC.GT_GetDi", Gts_Return);
            //读取Axis_Posed_Sta状态
            Gts_Return = MC.GT_GetDi(5, out Axis_Posed_Sta);
            Log.Commandhandler("Refresh_Axis_Posed_Sta--MC.GT_GetDi", Gts_Return);
            //读取Axis_Clear_Sta状态
            Gts_Return = MC.GT_GetDo(11, out Axis_Clear_Sta);
            Log.Commandhandler("Refresh_Axis_Clear_Sta--MC.GT_GetDo", Gts_Return);

            //读取规划位置
            Gts_Return = MC.GT_GetPrfPos(1, out Axis01_prfPos, 1, out Axis01_Clk);
            Gts_Return = MC.GT_GetPrfPos(2, out Axis02_prfPos, 1, out Axis02_Clk);

            //读取实际位置
            Gts_Return = MC.GT_GetAxisEncPos(1, out Axis01_encPos, 1, out Axis01_Clk);
            Gts_Return = MC.GT_GetAxisEncPos(2, out Axis02_encPos, 1, out Axis02_Clk);

            //读取当前速度
            Gts_Return = MC.GT_GetVel(1, out Axis01_vel);
            Gts_Return = MC.GT_GetVel(2, out Axis02_vel);

            //读取当前加减速
            Gts_Return = MC.GT_GetAxisPrfAcc(1, out Axis01_acc, 1, out Axis01_Clk);
            Gts_Return = MC.GT_GetAxisPrfAcc(1, out Axis01_dcc, 1, out Axis01_Clk);
            Gts_Return = MC.GT_GetAxisPrfAcc(2, out Axis02_acc, 1, out Axis02_Clk);
            Gts_Return = MC.GT_GetAxisPrfAcc(2, out Axis02_dcc, 1, out Axis02_Clk);

            //读取轴运动模式
            Gts_Return = MC.GT_GetPrfMode(1, out Axis01_mode, 1, out Axis01_Clk);
            Gts_Return = MC.GT_GetPrfMode(2, out Axis02_mode, 1, out Axis02_Clk);

            //刷新数值至相应的IO
            //刷新EXI
            EXI1 = (Exi_16bit & (1 << 1)) == 0; // 急停开关
            EXI2 = (Exi_16bit & (1 << 2)) == 0; // 除尘气缸伸出传感器
            EXI3 = (Exi_16bit & (1 << 3)) == 0; // 除尘气缸退回传感器
            EXI4 = (Exi_16bit & (1 << 4)) == 0; // 左门禁传感器
            EXI5 = (Exi_16bit & (1 << 5)) == 0; // 右门禁传感器
            EXI6 = (Exi_16bit & (1 << 6)) == 0; // 启动按钮1
            EXI7 = (Exi_16bit & (1 << 7)) == 0; // 启动按钮1
            EXI6 = (Exi_16bit & (1 << 6)) == 0; // 启动按钮1
            EXI7 = (Exi_16bit & (1 << 7)) == 0; // 启动按钮1

            //输出按钮灯
            if (EXI6)
            {
                Button1_Lamp = 1;
            }
            else
            {
                Button1_Lamp = 0;
            };
            if (EXI7)
            {
                Button2_Lamp = 1;
            }
            else
            {
                Button2_Lamp = 0;
            };

            //输出照明灯
            //if ((!EXI4) || (!EXI5)) { Lamp_control = 1; } else { Lamp_control = 0; };

            //刷新EXO
            EXO1  = (Exo_16bit & (1 << 1)) == 0;  // 三色灯塔黄
            EXO2  = (Exo_16bit & (1 << 2)) == 0;  // 三色灯塔绿
            EXO3  = (Exo_16bit & (1 << 3)) == 0;  // 三色灯塔红
            EXO4  = (Exo_16bit & (1 << 4)) == 0;  // 蜂鸣器
            EXO5  = (Exo_16bit & (1 << 5)) == 0;  // 除尘气缸伸出
            EXO6  = (Exo_16bit & (1 << 6)) == 0;  // 除尘气缸退回
            EXO7  = (Exo_16bit & (1 << 7)) == 0;  // 吹气打开
            EXO8  = (Exo_16bit & (1 << 8)) == 0;  // 照明灯
            EXO9  = (Exo_16bit & (1 << 9)) == 0;  // 启动按钮1灯
            EXO10 = (Exo_16bit & (1 << 10)) == 0; // 启动按钮2灯
            EXO11 = (Exo_16bit & (1 << 11)) == 0; // X轴回零触发
            EXO12 = (Exo_16bit & (1 << 12)) == 0; // Y轴回零触发

            //刷新Axis01 状态
            Axis01_Limit_Up    = (Axis01_Sta & (1 << 5)) != 0;      // Axis01轴正限位
            Axis01_Limit_Down  = (Axis01_Sta & (1 << 6)) != 0;      // Axis01轴负限位
            Axis01_Home        = (Axis_Home_Sta & 0x01) != 0;       // Axis01轴原点
            Axis01_Alarm       = (Axis01_Sta & (1 << 1)) != 0;      // Axis01轴报警
            Axis01_Alarm_Cl    = (Axis_Clear_Sta & 0x01) == 0;      //Axis01轴报警清除
            Axis01_MC_Err      = (Axis01_Sta & (1 << 4)) != 0;      // Axis01轴板卡报警(跟随误差越限)
            Axis01_EN          = (Axis01_Sta & (1 << 9)) != 0;      // Axis01轴使能
            Axis01_Busy        = (Axis01_Sta & (1 << 10)) != 0;     // Axis01轴输出中
            Axis01_IO_Stop     = (Axis01_Sta & (1 << 7)) != 0;      // Axis01轴IO停止
            Axis01_IO_EMG      = (Axis01_Sta & (1 << 8)) != 0;      // Axis01轴IO急停
            Axis01_Motor_Posed = (Axis_Posed_Sta & 0x01) != 0;      // Axis01轴 电机到位
            Axis01_Upper_Posed = (Axis01_Sta & (1 << 11)) != 0;     // Axis01轴 上位机到位
            //刷新Axis02 状态
            Axis02_Limit_Up    = (Axis02_Sta & (1 << 5)) != 0;      // Axis02轴正限位
            Axis02_Limit_Down  = (Axis02_Sta & (1 << 6)) != 0;      // Axis02轴负限位
            Axis02_Home        = (Axis_Home_Sta & (1 << 1)) != 0;   // Axis02轴原点
            Axis02_Alarm       = (Axis02_Sta & (1 << 1)) != 0;      // Axis02轴报警
            Axis02_Alarm_Cl    = (Axis_Clear_Sta & (1 << 1)) == 0;  //Axis02轴报警清除
            Axis02_MC_Err      = (Axis02_Sta & (1 << 4)) != 0;      // Axis02轴板卡报警(跟随误差越限)
            Axis02_EN          = (Axis02_Sta & (1 << 9)) != 0;      // Axis02轴使能
            Axis02_Busy        = (Axis02_Sta & (1 << 10)) != 0;     // Axis02轴输出中
            Axis02_IO_Stop     = (Axis02_Sta & (1 << 7)) != 0;      // Axis02轴IO停止
            Axis02_IO_EMG      = (Axis02_Sta & (1 << 8)) != 0;      // Axis02轴IO急停
            Axis02_Motor_Posed = (Axis_Posed_Sta & (1 << 1)) != 0;; // Axis02轴 电机到位
            Axis02_Upper_Posed = (Axis02_Sta & (1 << 11)) != 0;     // Axis02轴 上位机到位
            //刷新轴原点状态
            if (Gts_Home_Flag)
            {
                Gts_Home_Flag = !(Axis01_Limit_Up || Axis01_Limit_Down || Axis01_Alarm || Axis01_MC_Err || Axis01_IO_EMG || Axis02_Limit_Up || Axis02_Limit_Down || Axis02_Alarm || Axis02_MC_Err || Axis02_IO_EMG || EXI1);//任意(轴限位、报警、使能关闭、急停),致使原点标志丢失
            }

            //轴1回零触发
            if (Axis01_Home_Ex0_Control == 1)//轴1回零
            {
                Gts_Return = MC.GT_SetDoBit(12, 12, 0);
            }
            else
            {
                Gts_Return = MC.GT_SetDoBit(12, 12, 1);
            }
            //轴2回零触发
            if (Axis02_Home_Ex0_Control == 1)//轴2回零
            {
                Gts_Return = MC.GT_SetDoBit(12, 13, 0);
            }
            else
            {
                Gts_Return = MC.GT_SetDoBit(12, 13, 1);
            }
            //输出控制 0-输出,1-关闭输出
            //Cyc_control, Blow_control, Lamp_control;//定义气缸、吹气、照明控制字
            //气缸控制
            if (Cyc_control == 1)//气缸打开
            {
                Gts_Return = MC.GT_SetDoBit(12, 6, 0);
                Gts_Return = MC.GT_SetDoBit(12, 7, 1);
            }
            else
            {
                Gts_Return = MC.GT_SetDoBit(12, 6, 1);
                Gts_Return = MC.GT_SetDoBit(12, 7, 0);
            }
            //吹气控制
            if (Blow_control == 1)//吹气打开
            {
                Gts_Return = MC.GT_SetDoBit(12, 8, 0);
            }
            else
            {
                Gts_Return = MC.GT_SetDoBit(12, 8, 1);
            }
            //照明控制
            if (Lamp_control == 1)//照明打开
            {
                Gts_Return = MC.GT_SetDoBit(12, 9, 0);
            }
            else
            {
                Gts_Return = MC.GT_SetDoBit(12, 9, 1);
            }
            //Yellow_lamp,Green_lamp,Red_lamp,Beeze_Control,Button1_Lamp, Button2_Lamp;//定义灯塔黄、灯塔绿、灯塔红、蜂鸣控制字
            //灯塔黄控制
            if (Yellow_lamp == 1)
            {
                Gts_Return = MC.GT_SetDoBit(12, 2, 0);
            }
            else
            {
                Gts_Return = MC.GT_SetDoBit(12, 2, 1);
            }
            //灯塔绿控制
            if (Green_lamp == 1)
            {
                Gts_Return = MC.GT_SetDoBit(12, 3, 0);
            }
            else
            {
                Gts_Return = MC.GT_SetDoBit(12, 3, 1);
            }
            //灯塔红控制
            if (Red_lamp == 1)
            {
                Gts_Return = MC.GT_SetDoBit(12, 4, 0);
            }
            else
            {
                Gts_Return = MC.GT_SetDoBit(12, 4, 1);
            }
            //蜂鸣器控制
            if (Beeze_Control == 1)
            {
                if (Timer_1s_Flag)
                {
                    Gts_Return = MC.GT_SetDoBit(12, 5, 0);
                }
                else
                {
                    Gts_Return = MC.GT_SetDoBit(12, 5, 1);
                }
            }
            else
            {
                Gts_Return = MC.GT_SetDoBit(12, 5, 1);
            }
            //Button1_Lamp, Button2_Lamp;//定义启动按钮1灯、启动按钮2灯控制字
            //启动按钮1灯
            if (Button1_Lamp == 1)
            {
                Gts_Return = MC.GT_SetDoBit(12, 10, 0);
            }
            else
            {
                Gts_Return = MC.GT_SetDoBit(12, 10, 1);
            }
            //启动按钮2灯
            if (Button2_Lamp == 1)
            {
                Gts_Return = MC.GT_SetDoBit(12, 11, 0);
            }
            else
            {
                Gts_Return = MC.GT_SetDoBit(12, 11, 1);
            }
        }