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; } } }
public static EM_RES Move(ref bool bquit, ref AXIS ax_x, double xpos, ref AXIS ax_y, double ypos, ref AXIS ax_z, double zpos, ref AXIS ax_r, double rpos, int time_out_ms = 10000, bool bdoevent = false) { EM_RES ret = EM_RES.OK; //start move if (ax_x != null) { ret = ax_x.MoveTo(ref bquit, xpos); if (ret != EM_RES.OK) { goto MOVE_END; } } if (ax_y != null) { ret = ax_y.MoveTo(ref bquit, ypos); if (ret != EM_RES.OK) { goto MOVE_END; } } if (ax_z != null) { ret = ax_z.MoveTo(ref bquit, zpos); if (ret != EM_RES.OK) { goto MOVE_END; } } if (ax_r != null) { ret = ax_r.MoveTo(ref bquit, rpos); if (ret != EM_RES.OK) { goto MOVE_END; } } //wait if (ax_x != null) { ret = ax_x.WaitForMoveDone(ref bquit, xpos, time_out_ms, bdoevent); if (ret != EM_RES.OK) { goto MOVE_END; } } if (ax_y != null) { ret = ax_y.WaitForMoveDone(ref bquit, ypos, time_out_ms, bdoevent); if (ret != EM_RES.OK) { goto MOVE_END; } } if (ax_z != null) { ret = ax_z.WaitForMoveDone(ref bquit, zpos, time_out_ms, bdoevent); if (ret != EM_RES.OK) { goto MOVE_END; } } if (ax_r != null) { ret = ax_r.WaitForMoveDone(ref bquit, rpos, time_out_ms, bdoevent); if (ret != EM_RES.OK) { goto MOVE_END; } } return(EM_RES.OK); MOVE_END: if (ax_x != null) { ax_x.Stop(); } if (ax_y != null) { ax_y.Stop(); } if (ax_z != null) { ax_z.Stop(); } if (ax_r != null) { ax_r.Stop(); } return(ret); }