AxisJogControl.cs 4.3 KB
using System;
using System.Drawing;
using System.Windows.Forms;
using OnlineStore.LoadCSVLibrary;
using OnlineStore.Common;
using OnlineStore.DeviceLibrary;
using DeviceLib;

namespace OnlineStore.TinPasteStore.useControl
{
    public partial class AxisJogControl : UserControl
    {
        public AxisJogControl()
        {
            InitializeComponent();
        }
     
        public void SetParam(string conText, string addText, string delText, ConfigMoveAxis moveAxis)
        {
            this.ConText = conText;
            this.AddText = addText;
            this.DelText = delText;
            this.AxisInfo = moveAxis;
            this.SpeedValue = 2;
        }
        public string ConText
        {
            set { this.label1.Text = value; } 
            get { return this.label1.Text; }
        }
        public string AddText
        {
            set { this.btnMove.Text = value; }
            get { return this.btnMove.Text; }
        }
        public string DelText
        {
            set { this.btnMovej.Text = value; }
            get { return this.btnMovej.Text; }
        }

        public ConfigMoveAxis AxisInfo { get; set; }
        private int speedValue = 2;
        public int SpeedValue
        {
            set
            {
                speedValue = value;
                if (AxisInfo != null)
                {
                    this.txtSpeed.Text = (AxisInfo.TargetSpeed * speedValue / 10).ToString();
                }
            }
            get { return speedValue; }
        }

        private void btnMCopy_Click(object sender, EventArgs e)
        {
            Clipboard.SetDataObject(txtPosition.Text, true);
        }
        /// <summary>
        /// 判断进出轴是否在P1点
        /// </summary> 
        private bool InOutIsIsP1()
        { 
                return true; 
        }
        private void AxisMove(int speed)
        {
            LogUtil.debug("点动:[" + AxisInfo.DeviceName + "_" + AxisInfo.GetAxisValue() + "],speed=" + speed);
            ACServerManager.SpeedMove(AxisInfo.DeviceName, AxisInfo.GetAxisValue(), speed);
        }
        public void UpdatePosition()
        {
            int position = ACServerManager.GetTargetPosition(AxisInfo.DeviceName, AxisInfo.GetAxisValue());
            if (!txtPosition.Text.Equals(position.ToString()))
            {
                txtPosition.Text = position.ToString();
            }
        }
        private void btnMove_MouseDown(object sender, MouseEventArgs e)
        {
            if (!InOutIsIsP1())
            {
                return;
            }

            if (btnMove.BackColor.Equals(System.Drawing.SystemColors.Control))
            {
                int speed = FormUtil.GetIntValue(txtSpeed);
                if (speed <= 0)
                {
                    MessageBox.Show("提示", "请先输入正确的速度");
                    return;
                }
                btnMove.BackColor = Color.Green;
                AxisMove(speed);
            }
        }

        private void btnMove_MouseUp(object sender, MouseEventArgs e)
        {
            if (btnMove.BackColor == Color.Green)
            {
                btnMove.BackColor = System.Drawing.SystemColors.Control;
                ACServerManager.SuddenStop(AxisInfo.DeviceName, AxisInfo.GetAxisValue());
                UpdatePosition();
            }
        }

        private void btnMovej_MouseDown(object sender, MouseEventArgs e)
        {
            if (!InOutIsIsP1())
            {
                return;
            }
            if (btnMovej.BackColor.Equals(System.Drawing.SystemColors.Control))
            {
                int speed = FormUtil.GetIntValue(txtSpeed);
                if (speed <= 0)
                {
                    MessageBox.Show("提示", "请先输入正确的速度");
                    return;
                }
                btnMovej.BackColor = Color.Green;
                AxisMove(- speed);
            }
        }

        private void btnMovej_MouseUp(object sender, MouseEventArgs e)
        {
            if (btnMovej.BackColor == Color.Green)
            {
                btnMovej.BackColor = System.Drawing.SystemColors.Control;
                ACServerManager.SuddenStop(AxisInfo.DeviceName, AxisInfo.GetAxisValue());
                UpdatePosition();
            }
        }
    }
}