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;
using PCHMI;
using System.Threading;
using System.IO;


namespace CowainHmi.S1
{
    public partial class S1RFID : S1公共背景
    {
        private String DBnum = "";
        private String DBnum1 = "";
        private String DBnum2 = "";
        private int ID = 0;

        public S1RFID()
        {
            InitializeComponent();
        }

        private void S1RFID_Load(object sender, EventArgs e)
        {
            Read_RFID();

        }

        private void Read_RFID()
        {
            #region //判断RFID编号，给对应的地址赋值
            ID = PCHMI.VL.GET_INT16(0, "U51")-1;
            DBnum = "DB850";
            if (ID == 0) 
            {
                DBnum1 = "DB851";
                DBnum2 = "DB852";
            }
            if (ID == 1)
            {
                DBnum1 = "DB853";
                DBnum2 = "DB854";
            }
            if (ID == 2)
            {
                DBnum1 = "DB855";
                DBnum2 = "DB856";
            }
            if (ID == 3)
            {
                DBnum1 = "DB856";
                DBnum2 = "DB857";
            }
            if (ID == 4)
            {
                DBnum1 = "DB858";
                DBnum2 = "DB859";
            }



            #endregion

            if (ID >= 0) 
            {

                #region //RFID操作区地址关联
                this.ReadTime.监控地址 = $"{DBnum}.{ID * 26 + 22}";
                this.ReadTime.监控地址 = $"{DBnum}.{ID * 26 + 22}";
                this.WriteTime.监控地址 = $"{DBnum}.{ID * 26 + 24}";
                this.TagINLamp.监控地址 = $"{DBnum}.{ID * 26 + 18}.0";
                this.WriteOKLamp.监控地址 = $"{DBnum}.{ID * 26 + 18}.1";
                this.ReadOKLamp.监控地址 = $"{DBnum}.{ID * 26 + 18}.2";
                this.ReadWriteErrLamp.监控地址 = $"{DBnum}.{ID * 26 + 18}.5";
                this.Reading.指示灯地址 = $"{DBnum}.{ID * 26 + 20}.0";
                this.Writing.指示灯地址 = $"{DBnum}.{ID * 26 + 20}.1";
                this.HomeRfidbtn.开关功能.地址[0] = $"{DBnum}.{ID * 26}.0";
                this.HomeRfidbtn.指示灯地址 = $"{DBnum}.{ID * 26}.0";
                this.ManualRead.开关功能.地址[0] = $"{DBnum}.{ID * 26}.1";
                this.ManualRead.指示灯地址 = $"{DBnum}.{ID * 26}.1";
                this.ManualWrite.开关功能.地址[0] = $"{DBnum}.{ID * 26}.2";
                this.ManualWrite.指示灯地址 = $"{DBnum}.{ID * 26}.2";
                this.ReadStartID.监控地址 = $"{DBnum}.{ID * 26 + 2}";
                this.ReadLengths.监控地址 = $"{DBnum}.{ID * 26 + 4}";
                this.WriteStartID.监控地址 = $"{DBnum}.{ID * 26 + 8}";
                this.WriteLengths.监控地址 = $"{DBnum}.{ID * 26 + 10}";
                #endregion

                #region    //读取区地址关联
                this.ReadTraysTyp.监控地址 = $"{DBnum1}.0";
                this.ReadTraysID.监控地址 = $"{DBnum1}.2";
                this.ReadproductsTyp.监控地址 = $"{DBnum1}.4";
                this.ReadproductsSN.监控地址 = $"{DBnum1}.6";
                this.ReadproductsSN.Text = $"{DBnum1}.6";
                this.ReadOrderID.监控地址 = $"{DBnum1}.140";
                this.ReadOrderID.Text = $"{DBnum1}.140";
                this.ReadLastWork.监控地址 = $"{DBnum1}.66";
                this.ReadLastWork.Text = $"{DBnum1}.66";
                this.ReadLastWorkState.监控地址 = $"{DBnum1}.76";
                this.ReadLastWorkState.Text = $"{DBnum1}.76";
                this.ReadNextWork.监控地址 = $"{DBnum1}.86";
                this.ReadNextWork.Text = $"{DBnum1}.86";
                this.ReadStartTime.监控地址= $"{DBnum1}.96";
                this.ReadEndTime.监控地址 = $"{DBnum1}.118";
                #endregion
                #region //写入区地址关联
                this.WriteTraysTyp.监控地址 = $"{DBnum2}.0";
                this.WriteTraysID.监控地址 = $"{DBnum2}.2";
                this.WriteproductsTyp.监控地址 = $"{DBnum2}.4";
                this.WriteproductsSN.监控地址 = $"{DBnum2}.6";
                this.WriteproductsSN.Text = $"{DBnum2}.6";
                this.WriteOrderID.监控地址 = $"{DBnum2}.140";
                this.WriteOrderID.Text = $"{DBnum2}.140";
                this.WriteLastWork.监控地址 = $"{DBnum2}.66";
                this.WriteLastWork.Text = $"{DBnum2}.66";
                this.WriteLastWorkState.监控地址 = $"{DBnum2}.76";
                this.WriteLastWorkState.Text = $"{DBnum2}.76";
                this.WriteNextWork.监控地址 = $"{DBnum2}.86";
                this.WriteNextWork.Text = $"{DBnum2}.86";
                this.WriteStartTime.监控地址 = $"{DBnum2}.96";
                this.WriteNextWork.Text = $"{DBnum2}.96";
                this.WriteEndTime.监控地址 = $"{DBnum2}.118";
                this.WriteNextWork.Text = $"{DBnum2}.118";
                #endregion
            }
        }
        private void TxID_TextChanged(object sender, EventArgs e)
        {
            Read_RFID();
        }
       
    }
}
