FrmAxisDebug.cs 10.5 KB
using log4net;
using OnlineStore.Common;
using OnlineStore.DeviceLibrary;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace OnlineStore.ACSingleStore
{

    public partial class FrmAxisDebug : FrmBase
    {
        //private KTK_LA_BoxBean store;
        private ConfigMoveAxis middle = null;
        private ConfigMoveAxis updown = null;
        //private ConfigMoveAxis compress = null;
        private ConfigMoveAxis inout = null;
        private int compress_Slv = 0;

        public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        public FrmAxisDebug(AC_SA_BoxBean boxBean)
        { 
            middle = boxBean.Config.Middle_Axis;
            updown = boxBean.Config.UpDown_Axis;
 
            //compress_Slv = boxBean.Config.CompressAxis_Slv;
            inout = boxBean.Config.InOut_Axis;
            InitializeComponent(); 
            //txtComSpeed.Text = boxBean.Config.CompressAxis_EndSpeed.ToString();
            this.Text = boxBean.StoreName + "_轴点动调试";
        }

        private void AxisMove(ConfigMoveAxis axis, int speed)
        {
            LogUtil.debug(LOGGER, "点动:deviceName=" + axis.DeviceName + ",axis=" + axis.GetAxisValue() + ",speed=" + speed);
            ACServerManager.SpeedMove(axis.DeviceName, axis.GetAxisValue(), speed);

        }
        private void FrmAxisDebug_Load(object sender, EventArgs e)
        {
            txtMiddleSpeed.Text = middle.TargetSpeed.ToString();
            txtInOutSpeed.Text = inout.TargetSpeed.ToString();
            txtUpDownSpeed.Text = updown.TargetSpeed.ToString();
            timer1.Start();
        }

        private void btnMiddleMove_MouseDown(object sender, MouseEventArgs e)
        {
            int speed = FormUtil.GetIntValue(txtMiddleSpeed);
            if (speed <= 0)
            {
                MessageBox.Show("提示", "请先输入正确的速度");
                return;
            }
            btnMiddleMove.BackColor = Color.Green;
            AxisMove(middle, speed);
        }

        private void btnMiddleMove_MouseUp(object sender, MouseEventArgs e)
        {
            if (btnMiddleMove.BackColor == Color.Green)
            {
                btnMiddleMove.BackColor = System.Drawing.SystemColors.Control;
                ACServerManager.SuddenStop(middle.DeviceName, middle.GetAxisValue());
                UpdateMiddlePosition();
            }
        }

        private void btnUpDownMove_MouseDown(object sender, MouseEventArgs e)
        {
            int speed = FormUtil.GetIntValue(txtUpDownSpeed);
            if (speed <= 0)
            {
                MessageBox.Show("提示", "请先输入正确的速度");
                return;
            }
            btnUpDownMove.BackColor = Color.Green;
            AxisMove(updown, speed);
        }

        private void btnUpDownMove_MouseUp(object sender, MouseEventArgs e)
        {
            if (btnUpDownMove.BackColor == Color.Green)
            {
                btnUpDownMove.BackColor = System.Drawing.SystemColors.Control;                
                ACServerManager.SuddenStop(updown.DeviceName, updown.GetAxisValue());
                UpdateUpdownPosition();
            }
        }

        private void btnInOutMove_MouseDown(object sender, MouseEventArgs e)
        {
            if (ACStoreManager.store.LoacationIsDown().Equals(false))
            {
                MessageBox.Show("定位气缸不在下降端,不能移动进出轴", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            int speed = FormUtil.GetIntValue(txtInOutSpeed);
            if (speed <= 0)
            {
                MessageBox.Show("提示", "请先输入正确的速度");
                return;
            }
            this.btnInOutMove.BackColor = Color.Green;
            AxisMove(inout, speed);
        }

        private void btnInOutMove_MouseUp(object sender, MouseEventArgs e)
        {
            if (this.btnInOutMove.BackColor == Color.Green)
            {
                btnInOutMove.BackColor = System.Drawing.SystemColors.Control;
                ACServerManager.SuddenStop(inout.DeviceName, inout.GetAxisValue());
                UpdateInOutPosition();
            }
        }

        //private void btnComMove_MouseDown(object sender, MouseEventArgs e)
        //{
        //    int speed = FormUtil.GetIntValue(txtComSpeed);
        //    if (speed <= 0)
        //    {
        //        MessageBox.Show("提示", "请先输入正确的速度");
        //        return;
        //    }
        //    this.btnComMove.BackColor = Color.Green;
 
        //    ShuoKeControls.SetSpeed(compress_Slv, ShuoKeCMD.SetEndSpeed, speed); 
        //    ShuoKeControls.SetSpeed(compress_Slv, ShuoKeCMD.SetMaxSpeed, speed); 
        //    ShuoKeControls.VolMove(compress_Slv, speed);
        //}

        //private void btnComMove_MouseUp(object sender, MouseEventArgs e)
        //{
        //    if (this.btnComMove.BackColor == Color.Green)
        //    {
        //        btnComMove.BackColor = System.Drawing.SystemColors.Control;
        //        //ACServerManager.SuddenStop(compress.DeviceName, compress.GetAxisValue());
        //        ShuoKeControls.SuddownStop(compress_Slv);
        //    }
        //}

        private void btnMiddleMovej_MouseDown(object sender, MouseEventArgs e)
        {
            int speed = FormUtil.GetIntValue(txtMiddleSpeed);
            if (speed <= 0)
            {
                MessageBox.Show("提示", "请先输入正确的速度");
                return;
            }
            this.btnMiddleMovej.BackColor = Color.Green;
            AxisMove(middle, -speed);
        }

        private void btnMiddleMovej_MouseUp(object sender, MouseEventArgs e)
        {
            if (btnMiddleMovej.BackColor == Color.Green)
            {
                btnMiddleMovej.BackColor = System.Drawing.SystemColors.Control;
                ACServerManager.SuddenStop(middle.DeviceName, middle.GetAxisValue());
                UpdateMiddlePosition();
            }
        }

        private void btnUpDownMovej_MouseDown(object sender, MouseEventArgs e)
        {
            int speed = FormUtil.GetIntValue(txtUpDownSpeed);
            if (speed <= 0)
            {
                MessageBox.Show("提示", "请先输入正确的速度");
                return;
            }
            btnUpDownMovej.BackColor = Color.Green;
            AxisMove(updown, -speed);
        }

        private void btnUpDownMovej_MouseUp(object sender, MouseEventArgs e)
        {
            if (btnUpDownMovej.BackColor == Color.Green)
            {
                btnUpDownMovej.BackColor = System.Drawing.SystemColors.Control;
                ACServerManager.SuddenStop(updown.DeviceName, updown.GetAxisValue());
                UpdateUpdownPosition();
            }
        }

        private void btnInOutMovej_MouseDown(object sender, MouseEventArgs e)
        {
            if (ACStoreManager.store.LoacationIsDown().Equals(false))
            {
                MessageBox.Show("定位气缸不在下降端,不能移动进出轴", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            int speed = FormUtil.GetIntValue(txtInOutSpeed);
            if (speed <= 0)
            {
                MessageBox.Show("提示", "请先输入正确的速度");
                return;
            }
            this.btnInOutMovej.BackColor = Color.Green;
            AxisMove(inout, -speed);
        }

        private void btnInOutMovej_MouseUp(object sender, MouseEventArgs e)
        {
            if (btnInOutMovej.BackColor.Equals(Color.Green))
            {
                btnInOutMovej.BackColor = System.Drawing.SystemColors.Control;
                ACServerManager.SuddenStop(inout.DeviceName, inout.GetAxisValue());
                UpdateInOutPosition();
            } 
        }

        //private void btnComMovej_MouseDown(object sender, MouseEventArgs e)
        //{
        //    int speed = FormUtil.GetIntValue(txtComSpeed);
        //    if (speed <= 0)
        //    {
        //        MessageBox.Show("提示", "请先输入正确的速度");
        //        return;
        //    }
        //    this.btnComMovej.BackColor = Color.Green;
        //    //AxisMove(compress, -speed);   
        //    ShuoKeControls.SetSpeed(compress_Slv, ShuoKeCMD.SetEndSpeed, speed); 
        //    ShuoKeControls.SetSpeed(compress_Slv, ShuoKeCMD.SetMaxSpeed, speed);
        //    ShuoKeControls.VolMove(compress_Slv, speed);
        //}

        //private void btnComMovej_MouseUp(object sender, MouseEventArgs e)
        //{
        //    if (btnComMovej.BackColor.Equals(Color.Green))
        //    {
        //        btnComMovej.BackColor = System.Drawing.SystemColors.Control; 
        //        ShuoKeControls.SuddownStop(compress_Slv);
        //    }
        //}
       
        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
         

        private void FrmAxisDebug_Shown(object sender, EventArgs e)
        { 
            SetSkin(this);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (this.Visible)
            {
                UpdateMiddlePosition();
                UpdateInOutPosition();
                UpdateUpdownPosition(); 
            }
        }

        private void UpdateUpdownPosition()
        {
            int updownPosition = ACServerManager.GetTargetPosition(updown.DeviceName, updown.GetAxisValue());
            if (!txtUpdownPosition.Text.Equals(updownPosition.ToString()))
            {
                txtUpdownPosition.Text = updownPosition.ToString();
            }
        }

        private void UpdateMiddlePosition()
        {
            int middlePosition = ACServerManager.GetTargetPosition(middle.DeviceName, middle.GetAxisValue());
            if (!txtMiddlePosition.Text.Equals(middlePosition.ToString()))
            {
                txtMiddlePosition.Text = middlePosition.ToString();
            }
        }

        private void UpdateInOutPosition()
        {
            int inoutPosition = ACServerManager.GetTargetPosition(inout.DeviceName, inout.GetAxisValue());
            if (!txtInOutPosition.Text.Equals(inoutPosition.ToString()))
            {
                txtInOutPosition.Text = inoutPosition.ToString();
            }
        }
    }
}