using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Test
{
    public partial class Form1 : Form
    {
        private Asa.RFID.ReadAll read;

        public Form1()
        {
            InitializeComponent();
        }
        PuYueRFID_C2S py;
        private void Form1_Load(object sender, EventArgs e)
        {
            read = new Asa.RFID.ReadAll(new string[] {"192.168.3.7" },"log"); 
            read.Type = Asa.RFID.DeviceType.PuYue;

            //read.Start(10001);
            //read.Start();
            //read.Received += Read_Received;

            py = new PuYueRFID_C2S("192.168.3.7");
            //py.ID_Changed_Event += Py_ID_Changed_Event;
            py.Open();


        }

        private void Py_ID_Changed_Event(object sender, string e)
        {
            this.Invoke((EventHandler)delegate
            {
                textBox1.Text += $"{(sender as PuYueRFID_C2S).IP}:{e}\r\n";
            });
        }

        private void Read_Received(string ip, string id)
        {
            this.Invoke((EventHandler)delegate
            {
                textBox1.Text += $"{ip}:{id}\r\n";
            });
            
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            read.Stop();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            int c= py.TryRead(out string id, out double ms);
            textBox1.Text = $"{c},{id},{ms}";
            
        }
    }
}