FrmAgvTest.cs 4.5 KB
using OnlineStore.Common;
using OnlineStore.DeviceLibrary;
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 OnlineStore.AssemblyLine
{
    public partial class FrmAgvTest : Form
    {
        private Asa.AgvClient client;
        private string[] node = new string[] { "A1", "A2", "A3", "A4", "C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8" };

        public FrmAgvTest()
        {
            InitializeComponent();
        }
        private static string ServerIp = ConfigAppSettings.GetValue(Setting_Init.AgvServerIp);
        private void Form1_Load(object sender, EventArgs e)
        {
            label2.Text = "IP:" + ServerIp;
            client = new Asa.AgvClient (ServerIp);
            client.Log += Client_Log;
            client.Arrive += AgvClient_Arrive;
            // agvClient.CanEnter += AgvClient_CanEnter;
            client.Ready += AgvClient_Ready;
          //  client.GetRFID += AgvClient_GetRFID;
        }

        private void AgvClient_Ready(string name, string rfid)
        {
           //RFIDData data = new RFIDData(content);
            LogUtil.info("FrmAgvTest 收到 AgvClient_Ready [" + name + "] [" + rfid + "]   ");
        }

        private void AgvClient_Arrive(string name, string rfid)
        {
         //   RFIDData data = new RFIDData(content);
            LogUtil.info("FrmAgvTest 收到 AgvClient_Arrive [" + name + "] [" + rfid + "]   ");
        }

        //private static void AgvClient_GetRFID(string name, byte[] content)
        //{
        //    RFIDData data = new RFIDData(content);
        //    LogUtil.info("FrmAgvTest 收到 AgvClient_GetRFID [" + name + "] [" + data.ToData() + "]   ");
        //}
        private void Client_Log(string s)
        {
            try
            {
                LogUtil.info("FrmAgvTest LOG :" + s);
                Invoke(new Action(() => { textBox1.AppendText(s + "\r\n"); }));
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.ToString());
            }
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
          
        }

        private void button1_Click(object sender, EventArgs e)
        {
            client.Connect();
            for (int i = 0; i < node.Length; i++)
                client.SetStatus(node[i]);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            client.Close();
        }

        private void button8_Click(object sender, EventArgs e)
        {
            client.SetStatus(Parent.Text, "", textBox2.Text, Asa.ClientAction.FinishEnter, Asa.ClientLevel.High);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            client.SetStatus(Parent.Text, "", textBox2.Text, Asa.ClientAction.NeedLeave, Asa.ClientLevel.High);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            client.SetStatus(Parent.Text, "", textBox2.Text, Asa.ClientAction.NeedEnter, Asa.ClientLevel.High);
        }

        private void button9_Click_1(object sender, EventArgs e)
        {
            client.SetStatus(Parent.Text, "", textBox2.Text, Asa.ClientAction.None, Asa.ClientLevel.High);
        }

        private void button10_Click(object sender, EventArgs e)
        {
            client.SetStatus(Parent.Text, "", textBox2.Text, Asa.ClientAction.None, Asa.ClientLevel.High);
        }

        private void button11_Click(object sender, EventArgs e)
        {
            client.SetStatus(Parent.Text, "", textBox2.Text, Asa.ClientAction.NeedEnter, Asa.ClientLevel.High);

        }

        private void button12_Click(object sender, EventArgs e)
        {
            client.SetStatus(Parent.Text, "", textBox2.Text, Asa.ClientAction.FinishEnter, Asa.ClientLevel.High);

        }

        private void button7_Click_1(object sender, EventArgs e)
        {
            client.SetStatus(Parent.Text, "", textBox2.Text, Asa.ClientAction.None, Asa.ClientLevel.High);

        }

        private void button6_Click_1(object sender, EventArgs e)
        {
            client.SetStatus(Parent.Text, "", textBox2.Text, Asa.ClientAction.NeedLeave, Asa.ClientLevel.High);

        }

        private void button5_Click_1(object sender, EventArgs e)
        {
            client.SetStatus(Parent.Text, "", textBox2.Text, Asa.ClientAction.None, Asa.ClientLevel.High);

        }
    }
}