示例#1
0
        private void dgv_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            EM_RES ret;

            if (e.RowIndex < 0 || e.RowIndex > list_ax.Count)
            {
                return;
            }
            if (list_ax.ElementAt(e.RowIndex).disc != dgv.Rows[e.RowIndex].Cells[0].Value.ToString())
            {
                MessageBox.Show("轴列表异常,请重新启动软件!");
                return;
            }

            AXIS ax = list_ax.ElementAt(e.RowIndex);

            //负向
            if (e.ColumnIndex == 14)
            {
                ret = ax.JOG_Step(ref VAR.gsys_set.bquit, AXIS.AX_DIR.N);
                if (ret != EM_RES.OK)
                {
                    MessageBox.Show(ax.disc + "负向移动异常!");
                }
            }
            //正向
            else if (e.ColumnIndex == 15)
            {
                ret = ax.JOG_Step(ref VAR.gsys_set.bquit, AXIS.AX_DIR.P);
                if (ret != EM_RES.OK)
                {
                    MessageBox.Show(ax.disc + "正向移动异常!");
                }
            }
            //定位
            else if (e.ColumnIndex == 13)
            {
                bool   bquit = false;
                double pos   = double.MaxValue;
                try
                {
                    if (dgv.Rows[e.RowIndex].Cells[12].Value == null || dgv.Rows[e.RowIndex].Cells[12].Value.ToString().Length == 0)
                    {
                        return;
                    }
                    pos = Convert.ToDouble(dgv.Rows[e.RowIndex].Cells[12].Value);
                }
                catch
                {
                    MessageBox.Show(ax.disc + "获取定位坐标异常,请确保定位栏坐标输入正常!");
                    return;
                }
                ret = ax.SetToManualHighSpd();
                if (ret != EM_RES.OK)
                {
                    MessageBox.Show(ax.disc + "速度设置异常!");
                }
                ret = ax.MoveTo(ref bquit, pos, 10000, true);
                if (ret != EM_RES.OK)
                {
                    MessageBox.Show(ax.disc + "定位异常!");
                }
            }
            else if (e.ColumnIndex == 16)
            {
                if (DialogResult.Yes != MessageBox.Show("是否执行回零操作!", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning))
                {
                    return;
                }
                VAR.gsys_set.bquit = false;
                ax.HomeTask(20000);
                while (true)
                {
                    if (ax.HomeTaskisEnd)
                    {
                        break;
                    }
                    Thread.Sleep(10);
                    Application.DoEvents();
                }
                VAR.msg.AddMsg(Msg.EM_MSGTYPE.DBG, string.Format("{0} end...", ax.disc));
                if (ax.HomeTaskRet != EM_RES.OK)
                {
                    ax.Stop();
                    MessageBox.Show(ax.disc + "回零异常!");
                }
                else
                {
                    MessageBox.Show(ax.disc + "回零成功!");
                }
            }
            //使能
            else if (e.ColumnIndex == 11)
            {
                if (ax.SVRON && DialogResult.Yes == MessageBox.Show("是否松开电机?\r\n松开后需要归零操作!", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning))
                {
                    ax.SVRON            = false;
                    VAR.gsys_set.status = EM_SYS_STA.UNKOWN;
                }
                else
                {
                    ax.SVRON = true;
                }
            }
        }