示例#1
0
        private void buttonMoveStart_Click(object sender, EventArgs e)
        {
            if (Platform == null)
            {
                return;
            }

            buttonStartMove.Enabled = false;
            Cursor = Cursors.WaitCursor;
            try
            {
                var pos = Platform.Positions.FirstOrDefault(p => p.Name == comboBoxPos.Text.Split('-')[1]);
                if (pos != null)
                {
                    //get obj pos
                    var curpos = Platform.CurPos;
                    var objpos = textBoxMovePos.Select(t => double.Parse(t.Text)).Take(curpos.Length).ToArray();
                    for (int i = 0; i < curpos.Length; i++)
                    {
                        if (!checkBoxEnable[i].Checked)
                        {
                            objpos[i] = curpos[i];
                        }
                    }

                    if (comboBoxMoveMode.Text == "MoveP")
                    {
                        if (MessageBox.Show($"开始 MoveP 运动 {string.Join(", ", curpos.Select(p => p.ToString("F3")))} 到 {string.Join(", ", objpos.Select(p => p.ToString("F3")))} ?",
                                            Platform.Name, MessageBoxButtons.YesNo) != DialogResult.Yes)
                        {
                            return;
                        }

                        var ret = Platform.ExitAuto().MoveAbs(objpos, timeout: 10000, checkLimit: checkBoxCheckLimit.Checked);
                        if (!ret)
                        {
                            MessageBox.Show($"MoveP Error:{Platform.ShowStatus()}!", Platform.Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else if (comboBoxMoveMode.Text == "Jump")
                    {
                        var jh = double.Parse(comboBoxJumpHeight.Text);
                        if (MessageBox.Show($"开始 Jump 缩回高度 {jh:F3} 运动 {string.Join(", ", curpos.Select(p => p.ToString("F3")))} 到 {string.Join(", ", objpos.Select(p => p.ToString("F3")))} ?",
                                            Platform.Name, MessageBoxButtons.YesNo) != DialogResult.Yes)
                        {
                            return;
                        }

                        var ret = Platform.ExitAuto().Jump(objpos, jh, timeout: 10000, checkLimit: checkBoxCheckLimit.Checked);
                        if (!ret)
                        {
                            MessageBox.Show($"Jump Error:{Platform.ShowStatus()}!", Platform.Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        MessageBox.Show($"运动模式 Error:{comboBoxMoveMode.Text}!", Platform.Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"{Platform.ShowStatus()}:{ex.Message}");
            }
            finally
            {
                buttonStartMove.Enabled = true;
                Cursor = Cursors.Default;
            }
        }
        private void buttonManual_Click(object sender, EventArgs e)
        {
            var btn = sender as Button;

            try
            {
                if (btn != null)
                {
                    btn.Enabled = false;
                    Cursor      = Cursors.WaitCursor;
                    if (btn.Text.Contains("+"))
                    {
                        var i = Array.IndexOf(buttonMovePlusName, btn.Text);
                        if (i >= 0 && _platform.Axis[i] != null)
                        {
                            var  axis         = _platform.Axis[i];
                            var  step         = double.Parse(comboBox_Step[i].Text);
                            bool isCheckLimit = true;

                            if (step > 10 || axis.GetMel() || axis.GetPel())
                            {
                                if (MessageBox.Show($"{axis.Name} 开始移动 {step} mm  正限位 {axis.GetPel()} 负限位 {axis.GetMel()}?",
                                                    "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                                {
                                    return;
                                }

                                isCheckLimit = false;
                            }

                            var ret = _platform.ExitAuto().MoveRel(i, step, 10000, isCheckLimit);
                            if (!ret)
                            {
                                MessageBox.Show($"{axis.Name} 移动异常: {_platform.ShowStatus()} {axis.Error}!");
                            }
                        }
                    }
                    else if (btn.Text.Contains("-"))
                    {
                        var i = Array.IndexOf(buttonMoveMinusName, btn.Text);
                        if (i >= 0 && _platform.Axis[i] != null)
                        {
                            var axis         = _platform.Axis[i];
                            var step         = double.Parse(comboBox_Step[i].Text);
                            var isCheckLimit = true;

                            if (step > 10 || axis.GetMel() || axis.GetPel())
                            {
                                if (MessageBox.Show($"{axis.Name} 开始移动 -{step} mm  正限位 {axis.GetPel()} 负限位 {axis.GetMel()}?",
                                                    "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                                {
                                    return;
                                }
                                isCheckLimit = false;
                            }

                            var ret = _platform.ExitAuto().MoveRel(i, -step, 10000, isCheckLimit);
                            if (!ret)
                            {
                                MessageBox.Show($"{axis.Name} 移动异常: {_platform.ShowStatus()} {axis.Error}!");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Cursor = Cursors.Default;
                MessageBox.Show($"Move Error:{ex.Message}");
            }
            finally
            {
                Cursor = Cursors.Default;
                if (btn != null)
                {
                    btn.Enabled = true;
                }
            }
        }