FrmABB.cs 3.2 KB
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DoubleLine
{
    public partial class FrmABB : Form
    {
        public FrmABB()
        {
            InitializeComponent();
        }

        private void FrmABB_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < Common.ABB_Info.Length; i++)
                DgvABB.Rows.Add(Common.ABB_Info[i].Name, Common.ABB_Info[i].IP, Common.ABB_Info[i].State, Common.ABB_Info[i].IsOpen.ToString());
            CboAction.Items.Add(Common.ABB_MOVEGET);
            CboAction.Items.Add(Common.ABB_MOVEPUT);
            CboAction.Items.Add(Common.ABB_MOVEHOME);
            CboAction.Items.Add(Common.ABB_MOVEP);
            CboAction.SelectedIndex = 0;
            CboType.Items.Add("C:双层线其他规格料格");
            CboType.Items.Add("D:双层线7寸料格");
            CboType.SelectedIndex = 0;
        }

        private void BtnMove1_Click(object sender, EventArgs e)
        {
            if (DgvABB.SelectedCells.Count == 0) return;

            string command = CboAction.Text;
            string point = "p" + NudPoint1.Value;
            if (command == Common.ABB_MOVEPUT)
            {
                if (CboType.SelectedIndex == 0)
                    point = "cp" + NudPoint1.Value;
                else
                    point = "dp" + NudPoint1.Value;
            }
            string movement = RdoMove1.Checked ? "L" : "J";
            int speed = Convert.ToInt32(NudSpeed.Value);
            string s = string.Format("{0},{1},{2},{3}", command, point, movement, speed);
            int idx = DgvABB.SelectedCells[0].RowIndex;

            Common.ABB.SendCommand(idx, s);
        }

        private void BtnMove2_Click(object sender, EventArgs e)
        {
            if (DgvABB.SelectedCells.Count == 0) return;
            string command = CboAction.Text;
            string point = "p{0}";
            if (command == Common.ABB_MOVEPUT)
            {
                if (CboType.SelectedIndex == 0)
                    point = "cp{0}";
                else
                    point = "dp{0}";
            }
            string movement = RdoMove1.Checked ? "L" : "J";
            int speed = Convert.ToInt32(NudSpeed.Value);
            string s = string.Format("{0},{1},{2},{3}", command, point, movement, speed);

            int p1 = Convert.ToInt32(NudPoint1.Value);
            int p2 = Convert.ToInt32(NudPoint2.Value);
            string[] cmd = new string[Math.Abs(p1 - p2) + 1];
            if (p1 < p2)
            {
                for (int i = 0; i < cmd.Length; i++)
                    cmd[i] = string.Format(s, p1 + i);
            }
            else
            {
                for (int i = 0; i < cmd.Length; i++)
                    cmd[i] = string.Format(s, p1 - i);
            }

            int idx = DgvABB.SelectedCells[0].RowIndex;
            Common.ABB.Multitask(idx, cmd);
        }

        private void BtnStopMove_Click(object sender, EventArgs e)
        {
            Common.ABB.StopMultitask = true;
        }
    }
}