

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO.Ports;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

//Add
using System.Reflection;
using Excel = Microsoft.Office.Interop.Excel;
using static Jdas_Mbic.Bluecell_BootProtocol;
using System.Threading;
using System.IO;
using System.Windows.Forms.DataVisualization.Charting;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Drawing.Drawing2D;

namespace Jdas_Mbic
{

    
    public partial class JdasMbic : Form
    {
        public const double Table_Dbm_DefaultValue = 0;//31.5;
        public const int Table_DL_DefaultValue = 7;
        public const int Table_UL_DefaultValue = -15;
        public const int Table_Temp_DefaultValue = -10;
        public Serial serial = new Serial(); // Uart Open

        const byte ALARM_DLI_P4_LEVEL_LOW = 0x80;
        const byte ALARM_DLI_P3_LEVEL_LOW= 0x40;
        const byte ALARM_DLI_P2_LEVEL_LOW= 0x20;
        const byte ALARM_DLI_P1_LEVEL_LOW= 0x10;
        const byte ALARM_DLI_P4_LEVEL_HIGH= 0x08;
        const byte ALARM_DLI_P3_LEVEL_HIGH= 0x04;
        const byte ALARM_DLI_P2_LEVEL_HIGH= 0x02;
        const byte ALARM_DLI_P1_LEVEL_HIGH = 0x01;

        const byte ALARM_AGC_P4 = 0x80;
        const byte ALARM_AGC_P3 =0x40;
        const byte ALARM_AGC_P2 =0x20;
        const byte ALARM_AGC_P1 =0x10;

        const byte ALARM_DLI_SHUTDOWN_P4 = 0x08;
        const byte ALARM_DLI_SHUTDOWN_P3 = 0x04;
        const byte ALARM_DLI_SHUTDOWN_P2 = 0x02;
        const byte ALARM_DLI_SHUTDOWN_P1 = 0x01;
        const byte ALARM_ULO_P4_LEVEL_HIGH = 0x08;
        const byte ALARM_ULO_P3_LEVEL_HIGH = 0x04;
        const byte ALARM_ULO_P2_LEVEL_HIGH = 0x02;
        const byte ALARM_ULO_P1_LEVEL_HIGH = 0x01;
        const byte ALARM_ALC_P4 = 0x80;
        const byte ALARM_ALC_P3 = 0x40;
        const byte ALARM_ALC_P2 = 0x20;
        const byte ALARM_ALC_P1 = 0x10;
        const byte ALARM_ULO_SHUTDOWN_P4 = 0x08;
        const byte ALARM_ULO_SHUTDOWN_P3 = 0x04;
        const byte ALARM_ULO_SHUTDOWN_P2 = 0x02;
        const byte ALARM_ULO_SHUTDOWN_P1 = 0x01;

        public enum DLUL_Category
        {
            DL_DET = 0,
            UL_DET
        };
        enum Bluecell_CardType_t
        {
            BLUECELL_3_7G = 0,
            BLUECELL_3_8G,
            BLUECELL_3_9G,
            BLUECELL_4_0G,
            BLUECELL_4_1G,
            BLUECELL_4_6G,
            BLUECELL_SBM,
            BLUECELL_DCM,
            BLUECELL_KDDI,
            BLUECELL_4_7G,
            BLUECELL_4_8G,
            BLUECELL_4_9G,
            BLUECELL_5_0G,
        };
        enum HFR_CardType_t
        {
        	MBIC_3_7G = 0x80,
        	MBIC_3_8G = 0x81,
        	MBIC_3_9G = 0x82,
        	MBIC_4_0G = 0x83,
        	MBIC_4_1G = 0x84,
        	MBIC_4_6G = 0x85,
        	MBIC_4_7G = 0x86,
        	MBIC_4_8G = 0x87,
        	MBIC_4_9G = 0x88,
        	MBIC_5_0G = 0x89,
        	MBIC_DCM  = 0x8A,
        	MBIC_SBM  = 0x8B,
        	MBIC_KDDI = 0x8C
        }

        public enum MBIC_TableNumber
        {
            DLI_P1_Level_Table_Number = 0x00,
            DLI_P2_Level_Table_Number = 0x01,
            DLI_P3_Level_Table_Number = 0x02,
            DLI_P4_Level_Table_Number = 0x03,
            ULO_P1_Level_Table_Number = 0x10,
            ULO_P2_Level_Table_Number = 0x11,
            ULO_P3_Level_Table_Number = 0x12,
            ULO_P4_Level_Table_Number = 0x13,
            DLI_P1_ATT_Temp_guarantee_Table_Number = 0x20,
            DLI_P2_ATT_Temp_guarantee_Table_Number = 0x21,
            DLI_P3_ATT_Temp_guarantee_Table_Number = 0x22,
            DLI_P4_ATT_Temp_guarantee_Table_Number = 0x23,
            ULO_P1_ATT_Temp_guarantee_Table_Number = 0x30,
            ULO_P2_ATT_Temp_guarantee_Table_Number = 0x31,
            ULO_P3_ATT_Temp_guarantee_Table_Number = 0x32,
            ULO_P4_ATT_Temp_guarantee_Table_Number = 0x33,
            DLI_P1_ATT_Accuracy_Table_Number = 0x40,
            DLI_P2_ATT_Accuracy_Table_Number = 0x41,
            DLI_P3_ATT_Accuracy_Table_Number = 0x42,
            DLI_P4_ATT_Accuracy_Table_Number = 0x43,
            ULO_P1_ATT_Accuracy_Table_Number = 0x50,
            ULO_P2_ATT_Accuracy_Table_Number = 0x51,
            ULO_P3_ATT_Accuracy_Table_Number = 0x52,
            ULO_P4_ATT_Accuracy_Table_Number = 0x53,
        }
      
        public JdasMbic()
        {
            InitializeComponent();
            
        }
        DataTable table = new DataTable();
        private void JdasMbic_Load(object sender, EventArgs e)
        {
            serial.Serial_Main_Form_Get(this);
            serial.Serial_Initialize(ref comboBox_Port);

        }
        Hidden hidden = new Hidden();
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            Keys key = keyData & ~(Keys.Shift | Keys.Control);
            hidden = new Hidden();
            hidden.Owner = this; //부모값넘김
            switch (key)
            {
                case Keys.F:
                    // 조합키 사용 시
                    if ((keyData & Keys.Control) != 0)
                    {
                        MessageBox.Show("Ctrl+F8");
                    }
                    break;
                case Keys.F8:
                    // 단일키 사용시

                    hidden.Show();
                    hidden.main = this;
                    //MessageBox.Show("f8");
                    break;
                default:
                    //MessageBox.Show("지정되지 않은 키입니다.");
                    return base.ProcessCmdKey(ref msg, keyData);
            }
            return true;
        }


      
        private void dataGridView_TableSetting_CellClick(object sender, DataGridViewCellEventArgs e)
        {

        }
        /*
         * 
         * TABLE Setting Area
         * 
         */


     //   Bluecell_Serial bluecellserial = new Bluecell_Serial();

        public void button_PortOpen_Click(object sender, EventArgs e)
        {
            byte ret = 0;
            ret = serial.Serial_PortOpen(ref button_PortOpen, ref comboBox_Port);
            Serial_connectiondisable(ret);
            if (ret == 0 && timer_JdasMbic.Enabled == false)
            {
                timer_JdasMbic.Start(); //타이머를 발동시킨다.
            }
            else if (timer_JdasMbic.Enabled == true)
            {
                timer_JdasMbic.Stop(); //타이머를 멈춘다.
            }
            else
            {
                /*NOP*/
            }
            
            
            serial.Serial_Main_Form_Get(this);
        }

        private void button_terminal_Click(object sender, EventArgs e)
        {
            serial.Serial_TerminalOpen(serial);
        }
        
       
        public bool Serial_connectiondisable(byte on_off)
        {
            if (on_off != 2)
            {
                comboBox_Port.Enabled = Convert.ToBoolean(on_off);
                comboBox_baudrate.Enabled = Convert.ToBoolean(on_off);
            }
            else
            {
                return false;
            }
            return Convert.ToBoolean(on_off);
        }
        public bool TX_RX_Light = false;
        private delegate void StringSend(object label, String str);
        private delegate void SWVisible(object label, bool set);
        private delegate void GridviewSend(ref object gridview, string Text);
        private delegate void ByteSend(byte[] Text);
        private delegate String Stringreturn(object combobox);
        int offset = 0;
        byte[] rxBuffer;
#if false
        private void sPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            string startStr = "V";
            string endStr = "\n";

            try
            {

                if (offset == 0)
                {
                    rxBuffer = new byte[4096];
                }

                string rxString = "";
                int intRecSize = serialPort_JdasMbic.BytesToRead;

                if (intRecSize != 0)
                {




                    /* if (panel_GpsTest.Visible == true)
                     {
                         byte[] btdata = new byte[intRecSize];
                         serialPort_JdasMbic.Read(btdata, 0, intRecSize);
                         string data = Encoding.Default.GetString(rxBuffer);

                         this.Invoke(new StringSend(Data_Recv_Str), data);
                     }
                     else*/
                    {
                        serialPort_JdasMbic.Read(rxBuffer, offset, intRecSize);
                        offset += intRecSize;
                        for (int iTemp = 0; iTemp < offset; iTemp++)
                        {
                            rxString += Convert.ToChar(rxBuffer[iTemp]);
                        }
                        /*
                         * 
                         * Example
                         * if (panel_SensorTest.Visible == true)
                        {
                            startStr = "V";
                            endStr = "\n";
                        }

                        else if (panel_Catm1Test.Visible == true)
                        {
                            startStr = "B";
                            endStr = "\n";
                        }
                        else if (panel_GpsTest.Visible == true)
                        {
                            startStr = "$";
                            endStr = "\n";
                        }
                        
                         */
                        if (rxString.Contains(startStr))
                        {
                            rxString = rxString.Substring(rxString.IndexOf(startStr));
                            if (rxString.Contains(endStr))
                            {
                                this.Invoke(new StringSend(Data_Recv_Str), rxString);
                                //program.dataReceived(rxString, "Receive");
                                offset = 0;
                            }
                        }
                        else
                        {
                            this.Invoke(new StringSend(Data_Recv_Str), rxString);
                            offset = 0;
                        }
                    }

                }
            }
            catch { }

        }
#endif

        int LineLimit = 500;
        [DllImport("user32.dll")]
        public static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam);
        private const int WM_SETREDRAW = 11;
        public void Data_Recv_Str(string text)
        {

            System.Windows.Forms.RichTextBox tbReceived = null;
            //tbReceived = richTextBox_Sensor;

            int nLimitLines = Convert.ToInt32(LineLimit); //제한 라인 수
            try
            {
                try
                {
                    SendMessage(this.Handle, WM_SETREDRAW, false, 0);
                }
                catch (Exception e) { MessageBox.Show(e.StackTrace); }
                if (tbReceived.Lines.Length > nLimitLines)
                {
                    LinkedList<string> tempLines = new LinkedList<string>(tbReceived.Lines);
                    while ((tempLines.Count - nLimitLines) > 0)
                    {
                        tempLines.RemoveFirst();
                    }
                    tbReceived.Lines = tempLines.ToArray();
                }
                try
                {
                    SendMessage(this.Handle, WM_SETREDRAW, true, 0);
                }
                catch { return; }
                /* Example
                if (panel_SensorTest.Visible == true)
                {

                    Sensor_TestFunc(text);
                    tbReceived.AppendText(text);
                }
                else
                {
                    tbReceived.AppendText(text);
                }

                */
                
              tbReceived.SelectionStart = tbReceived.Text.Length;//맨 마지막 선택... 
                tbReceived.ScrollToCaret();
            }
            catch { try { SendMessage(this.Handle, WM_SETREDRAW, true, 0); } catch { return; } }
        }
        public void Data_Recv_Str(byte[] text)
        {
            string strtext = Encoding.Default.GetString(text);

            System.Windows.Forms.RichTextBox tbReceived = null;
          
//            tbReceived = richTextBox_Sensor;

            int nLimitLines = Convert.ToInt32(LineLimit); //제한 라인 수
            try
            {
                try
                {
                    SendMessage(this.Handle, WM_SETREDRAW, false, 0);
                }
                catch (Exception e) { MessageBox.Show(e.StackTrace); }
                if (tbReceived.Lines.Length > nLimitLines)
                {
                    LinkedList<string> tempLines = new LinkedList<string>(tbReceived.Lines);
                    while ((tempLines.Count - nLimitLines) > 0)
                    {
                        tempLines.RemoveFirst();
                    }
                    tbReceived.Lines = tempLines.ToArray();
                }
                try
                {
                    SendMessage(this.Handle, WM_SETREDRAW, true, 0);
                }
                catch { return; }
                /* Example
                if (panel_SensorTest.Visible == true)
                {
                    Sensor_TestFunc(strtext);
                    tbReceived.AppendText(strtext);
                }
                else
                {
                    tbReceived.AppendText(strtext);
                }
                */
                tbReceived.SelectionStart = tbReceived.Text.Length;//맨 마지막 선택... 
                tbReceived.ScrollToCaret();
            }
            catch { try { SendMessage(this.Handle, WM_SETREDRAW, true, 0); } catch { return; } }
        }
        Int64 Timer_Cnt = 0;
        public Int32 ReqTimer_Cnt = 0;
        Bluecell_BootProtocol bluecell_BootProtocol = new Bluecell_BootProtocol();
        private void timer1_Tick(object sender, EventArgs e)
        {
            Update_Serial update_Serial = null;
            bool req_set = false;
            if (update_Serial == null)
            {
                update_Serial = (Update_Serial)serial.FileDownloadClass_Get();
                if (update_Serial == null)
                    req_set = true;
                else if (update_Serial.Update_ready == false)
                    req_set = true;
            }
            if (req_set)
            {
                ReqTimer_Cnt++;
            }
            if (TX_RX_Light == true)
            {
                Timer_Cnt++;
            }
            if (Timer_Cnt < 1000)
            {
                if (this.pictureBox_G_TX.Visible == true)
                {
                    TX_Light_OFF();
                }
                if (this.pictureBox_G_RX.Visible == true)
                {
                    RX_Light_OFF();
                }
                Timer_Cnt = 0;
                TX_RX_Light = false;
            }
            if (ReqTimer_Cnt > 6)
            {
                bluecell_BootProtocol.Bluecell_RF_Status_Req(serial);
                ReqTimer_Cnt = 0;
            }
        }

      
        Update_Serial file = new Update_Serial();
        private void button_FirmwareUpdate_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            //FileDownload file = new FileDownload();
            file.ShowFileOpenDialog(ref serial, ofd);
        }
        public void TX_Light_ON()
        {
            this.pictureBox_G_TX.Visible = true;
            this.pictureBox_R_TX.Visible = false;
        }
        public void TX_Light_OFF()
        {
            this.pictureBox_R_TX.Visible = true;
            this.pictureBox_G_TX.Visible = false;
        }
        public void RX_Light_ON()
        {
            this.pictureBox_G_RX.Visible = true;
            this.pictureBox_R_RX.Visible = false;
        }
        public void RX_Light_OFF()
        {
            this.pictureBox_R_RX.Visible = true;
            this.pictureBox_G_RX.Visible = false;
        }
        const byte BLUECELL_RESET_LENGTH = 9;
        public const byte BLUECELL_HEADER = 0xBE;
        public const byte BLUECELL_TAILER = 0xEB;


      

        const byte BLUECELL_ATTEN_LENGTH = 32 + 5;
#if false
        private void button_ATT_Click_1(object sender, EventArgs e)
        {
            byte[] temp_buf = new byte[BLUECELL_ATTEN_LENGTH];
            Button btn = (Button)sender;
            byte datatype = (byte)Bluecell_BootProtocol.DATATYPE.ATTSET;
            Int16[] DL = new Int16[4];
            Int16[] UL = new Int16[4];
            Int16[] ALC_MAX = new Int16[4];
            Int16[] ALC_MIN = new Int16[4];
            byte tmp_H = 0;
            byte tmp_L = 0;
            DL[0] = Convert.ToInt16(numericUpDown_ATT_DL1.Value * 10);
            DL[1] = Convert.ToInt16(numericUpDown_ATT_DL2.Value * 10);
            DL[2] = Convert.ToInt16(numericUpDown_ATT_DL3.Value * 10);
            DL[3] = Convert.ToInt16(numericUpDown_ATT_DL4.Value * 10);

            UL[0] = Convert.ToInt16(numericUpDown_ATT_UL1.Value * 10);
            UL[1] = Convert.ToInt16(numericUpDown_ATT_UL2.Value * 10);
            UL[2] = Convert.ToInt16(numericUpDown_ATT_UL3.Value * 10);
            UL[3] = Convert.ToInt16(numericUpDown_ATT_UL4.Value * 10);

            /*ALC_MAX[0] = Convert.ToInt16(numericUpDown_ALC1_MAX.Value * 10);
            ALC_MAX[1] = Convert.ToInt16(numericUpDown_ALC2_MAX.Value * 10);
            ALC_MAX[2] = Convert.ToInt16(numericUpDown_ALC3_MAX.Value * 10);
            ALC_MAX[3] = Convert.ToInt16(numericUpDown_ALC4_MAX.Value * 10);

            ALC_MIN[0] = Convert.ToInt16(numericUpDown_ALC1_MIN.Value * 10);
            ALC_MIN[1] = Convert.ToInt16(numericUpDown_AGC2_MIN.Value * 10);
            ALC_MIN[2] = Convert.ToInt16(numericUpDown_AGC3_MIN.Value * 10);
            ALC_MIN[3] = Convert.ToInt16(numericUpDown_AGC4_MIN.Value * 10);
            */

            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Header] = BLUECELL_HEADER;
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type] = Convert.ToByte(datatype);
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length] = 6;

            for (int i = 0; i < 4; i++)
            {
                tmp_H = Convert.ToByte((DL[i] & 0xFF00) >> 8);
                tmp_L = Convert.ToByte((DL[i] & 0x00FF));
                temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + i * 2] = tmp_H;
                temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + i * 2 + 1] = tmp_L;
            }
            for (int i = 4; i < 8; i++)
            {
                tmp_H = Convert.ToByte((UL[i - 4] & 0xFF00) >> 8);
                tmp_L = Convert.ToByte((UL[i - 4] & 0x00FF));
                temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + i * 2] = tmp_H;
                temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + i * 2 + 1] = tmp_L;
            }
            for (int i = 8; i < 12; i++)
            {
                tmp_H = Convert.ToByte((ALC_MAX[i - 8] & 0xFF00) >> 8);
                tmp_L = Convert.ToByte((ALC_MAX[i - 8] & 0x00FF));
                temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + i * 2] = tmp_H;
                temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + i * 2 + 1] = tmp_L;
            }
            for (int i = 12; i < 16; i++)
            {
                tmp_H = Convert.ToByte((ALC_MIN[i - 12] & 0xFF00) >> 8);
                tmp_L = Convert.ToByte((ALC_MIN[i - 12] & 0x00FF));
                temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + i * 2] = tmp_H;
                temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + i * 2 + 1] = tmp_L;
            }

            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 16 * 2] = 1; //CRC
            serial.Serial_DataSend(temp_buf, temp_buf.Length);
            ReqTimer_Cnt = 0;
        }
#endif
        private void button_ATT_Click_2(object sender, EventArgs e)
        {
            Crc16 crc = new Crc16();
            byte[] temp_buf = new byte[TableGetMaxLength];
            NumericUpDown numeric = (NumericUpDown)sender;
            byte tmp_H = 0;
            byte tmp_L = 0;
            UInt16 Length = TableGetMaxLength - 3;
            Int16 UserData = 0;
            if (numeric.Name == "numericUpDown_Path1_GainValue"
            || numeric.Name == "numericUpDown_Path2_GainValue"
            || numeric.Name == "numericUpDown_Path3_GainValue"
            || numeric.Name == "numericUpDown_Path4_GainValue")
            {
                UserData = Convert.ToInt16(numeric.Value);
            }
            else
            {
                UserData = Convert.ToInt16(numeric.Value * 10);
            }
           

            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Header] = BLUECELL_HEADER;
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length_H] = Convert.ToByte((Length & 0xFF00) >> 8);
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length_L] = Convert.ToByte(Length & 0x00FF);
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_CrcIndex] = TableGetMaxLength - 2;

            tmp_H = Convert.ToByte((UserData & 0xFF00) >> 8);
            tmp_L = Convert.ToByte((UserData & 0x00FF));

            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data] = tmp_H;
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 1] = tmp_L;


            switch (numeric.Name)
            {
                case "numericUpDown_ATT_DL1":
                    temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                        = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_ATT_DL1;
                    break;
                case "numericUpDown_ATT_DL2":
                    temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                        = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_ATT_DL2;
                    break;
                case "numericUpDown_ATT_DL3":
                    temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                        = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_ATT_DL3;
                    break;
                case "numericUpDown_ATT_DL4":
                    temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                        = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_ATT_DL4;
                    break;
                case "numericUpDown_ATT_UL1":
                    temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                        = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_ATT_UL1;
                    break;
                case "numericUpDown_ATT_UL2":
                    temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                        = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_ATT_UL2;
                    break;
                case "numericUpDown_ATT_UL3":
                    temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                        = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_ATT_UL3;
                    break;
                case "numericUpDown_ATT_UL4":
                    temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                        = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_ATT_UL4;
                    break;
                case "numericUpDown_DL1_User":
                    temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                        = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_ATT_DL1_USER;
                    break;
                case "numericUpDown_DL2_User":
                    temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                        = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_ATT_DL2_USER;
                    break;
                case "numericUpDown_DL3_User":
                    temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                        = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_ATT_DL3_USER;
                    break;
                case "numericUpDown_DL4_User":
                    temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                        = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_ATT_DL4_USER;
                    break;
                case "numericUpDown_UL1_User":
                    temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                        = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_ATT_UL1_USER;
                    break;
                case "numericUpDown_UL2_User":
                    temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                        = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_ATT_UL2_USER;
                    break;
                case "numericUpDown_UL3_User":
                    temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                        = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_ATT_UL3_USER;
                    break;
                case "numericUpDown_UL4_User":
                    temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                        = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_ATT_UL4_USER;
                    break;
                case "numericUpDown_Path1_GainValue":
                    temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                        = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_Path1_GainValue;

                    break;
                case "numericUpDown_Path2_GainValue":
                    temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                        = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_Path2_GainValue;

                    break;
                case "numericUpDown_Path3_GainValue":
                    temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                        = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_Path3_GainValue;

                    break;
                case "numericUpDown_Path4_GainValue":
                    temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                        = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_Path4_GainValue;

                    break;
            }
            UInt16 CRCRET = crc.CRC16_Generate(temp_buf, Length );
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 2] = Convert.ToByte((CRCRET & 0xFF00) >> 8);
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 3] = Convert.ToByte(CRCRET & 0x00FF);
            serial.Serial_DataSend(temp_buf, temp_buf.Length);
            ReqTimer_Cnt = 0;
        }


        
        


        enum BluecellReqIndex{
          bluecell_header,
          bluecell_type,
          bluecell_length,
          bluecell_crcindex,
          Path1_GainValue,
          Path2_GainValue,
          Path3_GainValue,
          Path4_GainValue,
          ATT_DL1_PATH,
          ATT_DL2_PATH,
          ATT_DL3_PATH,
          ATT_DL4_PATH,
          ATT_UL1_PATH,
          ATT_UL2_PATH,
          ATT_UL3_PATH,
          ATT_UL4_PATH,
          ATT_DL1_H,
          ATT_DL1_L,
          ATT_DL2_H,
          ATT_DL2_L,
          ATT_DL3_H,
          ATT_DL3_L,
          ATT_DL4_H,
          ATT_DL4_L,
          ATT_UL1_H,
          ATT_UL1_L,
          ATT_UL2_H,
          ATT_UL2_L,
          ATT_UL3_H,
          ATT_UL3_L,
          ATT_UL4_H,
          ATT_UL4_L,
          ULO_P1_Level1_H,
          ULO_P1_Level1_L,
          ULO_P2_Level2_H,
          ULO_P2_Level2_L,
          ULO_P3_Level3_H,
          ULO_P3_Level3_L,
          ULO_P4_Level4_H,
          ULO_P4_Level4_L,
          DLI_P1_Level1_H,
          DLI_P1_Level1_L,
          DLI_P2_Level2_H,
          DLI_P2_Level2_L,
          DLI_P3_Level3_H,
          DLI_P3_Level3_L,
          DLI_P4_Level4_H,
          DLI_P4_Level4_L,
          DET_TEMP,
          DLI_AGC_ON_OFF,
          ULO_ALC_ON_OFF,
          ULO_Level1_H,
          ULO_Level1_L,
          ULO_Level2_H,
          ULO_Level2_L,
          ULO_Level3_H,
          ULO_Level3_L,
          ULO_Level4_H,
          ULO_Level4_L,
          DLI_Level1_H,
          DLI_Level1_L,
          DLI_Level2_H,
          DLI_Level2_L,
          DLI_Level3_H,
          DLI_Level3_L,
          DLI_Level4_H,
          DLI_Level4_L,
          ULO_ALC_Threshold_H,
          ULO_ALC_Threshold_L,
          bluecell_User_DL1_H,
          bluecell_User_DL1_L,
          bluecell_User_DL2_H,
          bluecell_User_DL2_L,
          bluecell_User_DL3_H,
          bluecell_User_DL3_L,
          bluecell_User_DL4_H,
          bluecell_User_DL4_L,
          bluecell_User_UL1_H,
          bluecell_User_UL1_L,
          bluecell_User_UL2_H,
          bluecell_User_UL2_L,
          bluecell_User_UL3_H,
          bluecell_User_UL3_L,
          bluecell_User_UL4_H,
          bluecell_User_UL4_L,
          bluecell_User_TEMP_H,
          bluecell_User_TEMP_L,
          bluecell_User_TEMP_OFFSET,
          Temp_High_Threshold,
          Temp_High_Threshold_Default,
          DLI_Level_High_Threshold_H,
          DLI_Level_High_Threshold_L,
          DLI_Level_Low_Threshold_H,
          DLI_Level_Low_Threshold_L,
          DLI_Level_High_Low_Threshold_default,
          ALARM_TEMP_HIGH, //bit
          ALARM_DLI_Level,
          ALARM_DLI_SHTUTDOWN,
          ALARM_DLI_AGC_Alarm,
          ALARM_ULO_ALC_Alarm,
          ALARM_ULO_Level,
          ALARM_ULO_SHTUTDOWN,
          ALARM_MASK1,
          ALARM_MASK2,
          ALARM_MASK3,
          ALARM_MASK4,
          ALARM_MASK5,
          ALARM_TESTMODE,
          ALARM_Test_Dummy1,
          ALARM_Test_Dummy2,
          ALARM_Test_Dummy3,
          ALARM_Test_Dummy4,
          ALARM_Test_Dummy5,
          CPUVERSION1,
          CPUVERSION2,
          CPUVERSION3,
          CPU_Current_Bank,
          CPU_Bank_Select,//Reboot_by,
          CPU_Bank1_Image_Version1,
          CPU_Bank1_Image_Version2,
          CPU_Bank1_Image_Version3,
          CPU_Bank1_Image_BuildTime1,
          CPU_Bank1_Image_BuildTime2,
          CPU_Bank1_Image_BuildTime3,
          CPU_Bank1_Image_BuildTime4,
          CPU_Bank1_Image_BuildTime5,
          CPU_Bank1_Image_BuildTime6,
          CPU_Bank1_Image_Name,
          CPU_Bank2_Image_Version1 = CPU_Bank1_Image_Name +32,
          CPU_Bank2_Image_Version2,
          CPU_Bank2_Image_Version3,
          CPU_Bank2_Image_BuildTime1,
          CPU_Bank2_Image_BuildTime2,
          CPU_Bank2_Image_BuildTime3,
          CPU_Bank2_Image_BuildTime4,
          CPU_Bank2_Image_BuildTime5,
          CPU_Bank2_Image_BuildTime6,
          CPU_Bank2_Image_Name,
          S_W_Reset=  CPU_Bank2_Image_Name + 32,
          Factory_Set_Initialization,
          Temp_High_Alarm,
          LED_TEST,
          NODE,
          Type,
          PCB_Version,
          Serial_Number = PCB_Version + 2, // INDEX : 20
          Manufacture = Serial_Number +20,
          Manufacture_Date,
          Freq_ID  = Manufacture_Date + 3,
          Carrier_ID,
          Carrier_ON_OFF,
          DLI_Level_High_Alarm1,
          DLI_Level_High_Alarm2,
          DLI_Level_High_Alarm3,
          DLI_Level_High_Alarm4,
          DLI_Level_Low_Alarm1,
          DLI_Level_Low_Alarm2,
          DLI_Level_Low_Alarm3,
          DLI_Level_Low_Alarm4,
          DLI_FRBT_Atten1_H,
          DLI_FRBT_Atten1_L,
          DLI_FRBT_Atten2_H,
          DLI_FRBT_Atten2_L,
          DLI_FRBT_Atten3_H,
          DLI_FRBT_Atten3_L,
          DLI_FRBT_Atten4_H,
          DLI_FRBT_Atten4_L,
          DLI_FRBT_D_Day,
          DLI_FRBT_Status,
          DLI_AGC_Threshold_H,
          DLI_AGC_Threshold_L,
          DLI_AGC_Threshold_default,
          DLI_Shutdown_ON_OFF,
          DLI_Shutdown_Threshold_H,
          DLI_Shutdown_Threshold_L,
          DLI_Shutdown_Threshold_Default,
          DLI_Shutdown_Retry_Count1,
          DLI_Shutdown_Retry_Count2,
          DLI_Shutdown_Retry_Count3,
          DLI_Shutdown_Retry_Count4,
          DLI_AGC_Alarm1,
          DLI_AGC_Alarm2,
          DLI_AGC_Alarm3,
          DLI_AGC_Alarm4,
          DLI_Shutdown_Alarm1,
          DLI_Shutdown_Alarm2,
          DLI_Shutdown_Alarm3,
          DLI_Shutdown_Alarm4,
          ULO_Level_High_Threshold_H,
          ULO_Level_High_Threshold_L,
          ULO_Level_High_Threshold_default,
          ULO_Level_High_Alarm1,
          ULO_Level_High_Alarm2,
          ULO_Level_High_Alarm3,
          ULO_Level_High_Alarm4,
          ULO_ALC_Threshold_Default,
          ULO_Shutdown_ON_OFF,
          ULO_Shutdown_Threshold_H,
          ULO_Shutdown_Threshold_L,
          ULO_Shutdown_Threshold_Default,
          ULO_Shutdown_Retry_Count1,
          ULO_Shutdown_Retry_Count2,
          ULO_Shutdown_Retry_Count3,
          ULO_Shutdown_Retry_Count4,
          ULO_ALC_Alarm1,
          ULO_ALC_Alarm2,
          ULO_ALC_Alarm3,
          ULO_ALC_Alarm4,
          ULO_Shutdown_Alarm1,
          ULO_Shutdown_Alarm2,
          ULO_Shutdown_Alarm3,
          ULO_Shutdown_Alarm4,
            MBIC_ULO_ALC_Atten1_H,
            MBIC_ULO_ALC_Atten1_L,
            MBIC_ULO_ALC_Atten2_H,
            MBIC_ULO_ALC_Atten2_L,
            MBIC_ULO_ALC_Atten3_H,
            MBIC_ULO_ALC_Atten3_L,
            MBIC_ULO_ALC_Atten4_H,
            MBIC_ULO_ALC_Atten4_L,
            DL_Det_ALL_Offset,
            MBIC_Download_Auto_Restart_Set,
            Path_TempSave_Bit,/*DL1 / DL 2 /DL3 /DL4 /UL1/UL2/UL3/UL4*/
            Path_TempShutdown_Set,/*DL1 / DL 2 /DL3 /DL4 /UL1/UL2/UL3/UL4*/
            SelfTest,
            SelfTest_ATT_DL1_H,
            SelfTest_ATT_DL1_L,
            SelfTest_ATT_DL2_H,
            SelfTest_ATT_DL2_L,
            SelfTest_ATT_DL3_H,
            SelfTest_ATT_DL3_L,
            SelfTest_ATT_DL4_H,
            SelfTest_ATT_DL4_L,
            SelfTest_ATT_UL1_H,
            SelfTest_ATT_UL1_L,
            SelfTest_ATT_UL2_H,
            SelfTest_ATT_UL2_L,
            SelfTest_ATT_UL3_H,
            SelfTest_ATT_UL3_L,
            SelfTest_ATT_UL4_H,
            SelfTest_ATT_UL4_L,
            Reserve = SelfTest_ATT_UL4_L + 16,
            /**/
            bluecell_crc_H,
            bluecell_crc_L,
            bluecell_etx,


        };
        const byte Reqdatastartindex = 4;
        //private delegate void StringSend(object label, String str);
        private void Numeric_Text_Set(object label, String str)
        {
            NumericUpDown Temp_label = (NumericUpDown)label;
            Temp_label.Text = str;
        }
        private void TextBox_Text_Set(object label, String str)
        {
            TextBox Temp_label = (TextBox)label;
            Temp_label.Text = str;
        }
        private void String_Text_Set(object label, String str)
        {
            String Temp_label = (String)label;
            Temp_label = str;
        }
        private void Label_Text_Set(object label, String str)
        {
            Label Temp_label = (Label)label;
            Temp_label.Text = str;
        }
        private void Table_Text_Set(object label, String str)
        {
            label = str;
        }
        private String ComboBox_Text_Get(object data)
        {
            ComboBox Temp_data = (ComboBox)data;
            return Temp_data.Text;
        }
        private void PicVisible_Text_Set(object label, bool set)
        {
            PictureBox Temp_pic = (PictureBox)label;
            Temp_pic.Visible = set;
        }
        private void CheckBoxVisible_Text_Set(object label, bool set)
        {
            CheckBox Temp_pic = (CheckBox) label;
            Temp_pic.Checked = set;
        }
        private void Button_Text_Set(object label, string val)
        {
            Button temp_button = (Button)label;
            temp_button.Text = val;
        }
        private Double ADCValueTodBmConvert(DataGridView table,object[] RefData, object[] AdcData, object Currdata)
        {
            /* 
             * RefData  : Dbm 값 
               AdcData  : Dbm과 매칭되어있는 ADC값 
               Currdata : 현재 ADC 값 
             */
            object data = Currdata; // 현재 ADC 값 
            double[] Vitual_array = new double[10];
            double step = 0;
            double temp,temp1;
            Double ret = 0xFF,Currentret = 0;
            int LastIndex = 0;
            int dot = 0;
            for(int i = 0; i < table.RowCount; i++)
            {
                try
                {
                    step = (Convert.ToDouble(AdcData[i]) - Convert.ToDouble(AdcData[i + 1])) *0.1;
                    for (int a = 0; a < 10; a++)
                    {
                        Vitual_array[a] = Convert.ToDouble(AdcData[i]) - (step * a);
                        /*현재 ADC 값과 테이블의 ADC값의 모든값들을 마이너스 합 후 */
                        Currentret = Convert.ToDouble(Vitual_array[a]) - Convert.ToDouble(data);


                        /*만약 0보다 작을 시 절대값을 취해준다.*/
                        if (Currentret < 0)
                        {
                            Currentret = (Currentret * -2) + Currentret;
                        }
                        /*만약 현재 결과 값이 이전 결과 값보다 
                         * 작을 경우 그값이 최종 결과 값이다.*/
                        if (ret >= Currentret)
                        {
                            ret = Currentret;
                            LastIndex = i;
                            dot = a;
                        }
                    }
                }
                catch { }
                

            }
            temp = Convert.ToDouble(AdcData[LastIndex]);
            temp1 = Convert.ToDouble(Currdata);
            if (temp1 < temp)
                return Convert.ToDouble(RefData[LastIndex + 1]) + (dot * 0.1);
            else
                return Convert.ToDouble(RefData[0]);

        }
       
        public void GUIDataStatusSet(byte[] buf)
        {
            double Volt_Calc_val = 0.001;//3.3 / 4095;
            double adcdata = 0;
            Int16 dBmdata = 0;
            short LiMitdata = 0;
            short AttData = 0;

            if (buf[(int)BluecellReqIndex.DLI_AGC_ON_OFF] == 0)
            {
                this.Invoke(new StringSend(Button_Text_Set), button_AGC, "OFF");// = false;
            }
            else
            {
                this.Invoke(new StringSend(Button_Text_Set), button_AGC, "ON");// = false;
            }

            if (buf[(int)BluecellReqIndex.ULO_ALC_ON_OFF] == 0)
            {
                this.Invoke(new StringSend(Button_Text_Set), button_ALC, "OFF");// = false;
            }
            else
            {
                this.Invoke(new StringSend(Button_Text_Set), button_ALC, "ON");// = false;
            }
            switch (buf[(int)BluecellReqIndex.Type])
            {
                case (int)HFR_CardType_t.MBIC_3_7G: this.Invoke(new StringSend(TextBox_Text_Set), textBox_CardType, "3.7G DCM"); break;
                case (int)HFR_CardType_t.MBIC_3_8G:  this.Invoke(new StringSend(TextBox_Text_Set), textBox_CardType, "3.8G KDDI");break;
                case (int)HFR_CardType_t.MBIC_3_9G:  this.Invoke(new StringSend(TextBox_Text_Set), textBox_CardType, "3.9G RAKUTEN");break;
                case (int)HFR_CardType_t.MBIC_4_0G:  this.Invoke(new StringSend(TextBox_Text_Set), textBox_CardType, "4.0G SMB");break;
                case (int)HFR_CardType_t.MBIC_4_1G:  this.Invoke(new StringSend(TextBox_Text_Set), textBox_CardType, "4.1G KDDI");break;
                case (int)HFR_CardType_t.MBIC_4_6G:  this.Invoke(new StringSend(TextBox_Text_Set), textBox_CardType, "4.6G DCM");break;
                case (int)HFR_CardType_t.MBIC_4_7G:  this.Invoke(new StringSend(TextBox_Text_Set), textBox_CardType, "LOCAL1"); break;
                case (int)HFR_CardType_t.MBIC_4_8G:  this.Invoke(new StringSend(TextBox_Text_Set), textBox_CardType, "LOCAL2"); break;
                case (int)HFR_CardType_t.MBIC_4_9G:  this.Invoke(new StringSend(TextBox_Text_Set), textBox_CardType, "RESERVE1");break;
                case (int)HFR_CardType_t.MBIC_5_0G:  this.Invoke(new StringSend(TextBox_Text_Set), textBox_CardType, "RESERVE2");break;
                case (int)HFR_CardType_t.MBIC_DCM :  this.Invoke(new StringSend(TextBox_Text_Set), textBox_CardType, "LTE-DCM");break;
                case (int)HFR_CardType_t.MBIC_SBM :  this.Invoke(new StringSend(TextBox_Text_Set), textBox_CardType, "LTE-SBM");break;
                case (int)HFR_CardType_t.MBIC_KDDI: this.Invoke(new StringSend(TextBox_Text_Set), textBox_CardType, "LTE-KDDI"); break;
                default: this.Invoke(new StringSend(TextBox_Text_Set), textBox_CardType, "ID None"); break;
            }
            this.Invoke(new StringSend(TextBox_Text_Set), textBox_DLI_FRBT_D_Day, buf[(int)BluecellReqIndex.DLI_FRBT_D_Day].ToString());// = false;
            if(buf[(int)BluecellReqIndex.CPU_Current_Bank] == 1)
                this.Invoke(new StringSend(TextBox_Text_Set), textBox_CurrBank, "Bank 1");// = false;
            else if (buf[(int)BluecellReqIndex.CPU_Current_Bank] == 2)
                this.Invoke(new StringSend(TextBox_Text_Set), textBox_CurrBank, "Bank 2");// = false;
            else
                this.Invoke(new StringSend(TextBox_Text_Set), textBox_CurrBank, "Unknown");// = false;

            if (buf[(int)BluecellReqIndex.DLI_FRBT_Status] == 0)
            {
                this.Invoke(new StringSend(TextBox_Text_Set), textBox_FRBT_Status, "IDLE");// = false;
            }
            else if (buf[(int)BluecellReqIndex.DLI_FRBT_Status] == 1)
            {
                this.Invoke(new StringSend(TextBox_Text_Set), textBox_FRBT_Status, "TRACKING");// = false;
            }
            else if (buf[(int)BluecellReqIndex.DLI_FRBT_Status] == 2)
            {
                this.Invoke(new StringSend(TextBox_Text_Set), textBox_FRBT_Status, "RUNNING");// = false;
            }

             if (buf[(int)BluecellReqIndex.Carrier_ON_OFF] == 0)
            {
                this.Invoke(new StringSend(Button_Text_Set), button_Carrier, "OFF");// = false;
                this.Invoke(new StringSend(TextBox_Text_Set), textBox1_Carrier, "OFF");// = false;
            }
            else
            {
                this.Invoke(new StringSend(Button_Text_Set), button_Carrier, "ON");// = false;
                this.Invoke(new StringSend(TextBox_Text_Set), textBox1_Carrier, "ON");// = false;
            }
            if (buf[(int)BluecellReqIndex.Path_TempShutdown_Set] == 0)
            {
                this.Invoke(new StringSend(Button_Text_Set), button_TempShutdown, "OFF");// = false;
            }
            else
            {
                this.Invoke(new StringSend(Button_Text_Set), button_TempShutdown, "ON");// = false;
            }
            if (buf[(int)BluecellReqIndex.SelfTest] == 0)
            {
                this.Invoke(new StringSend(Button_Text_Set), button_SelfTest1, "OFF");// = false;
            }
            else
            {
                this.Invoke(new StringSend(Button_Text_Set), button_SelfTest1, "ON");// = false;
            }

            if (buf[(int)BluecellReqIndex.SelfTest] == 0)
            {
                this.Invoke(new StringSend(Button_Text_Set), button_SelfTest2, "OFF");// = false;
            }
            else
            {
                this.Invoke(new StringSend(Button_Text_Set), button_SelfTest2, "ON");// = false;

            }

            if (buf[(int)BluecellReqIndex.SelfTest] == 0)
            {
                this.Invoke(new StringSend(Button_Text_Set), button_SelfTest3, "OFF");// = false;
            }
            else
            {
                this.Invoke(new StringSend(Button_Text_Set), button_SelfTest3, "ON");// = false;
            }

            if (buf[(int)BluecellReqIndex.SelfTest] == 0)
            {
                this.Invoke(new StringSend(Button_Text_Set), button_SelfTest4, "OFF");// = false;
            }
            else
            {
                this.Invoke(new StringSend(Button_Text_Set), button_SelfTest4, "ON");// = false;
            }

            if (buf[(int)BluecellReqIndex.ATT_DL1_PATH] == 0)
            {
                this.Invoke(new StringSend(Button_Text_Set), button_DL1_PATH, "OFF");// = false;
            }
            else
            {
                this.Invoke(new StringSend(Button_Text_Set), button_DL1_PATH, "ON");// = false;
            }

            if (buf[(int)BluecellReqIndex.ATT_DL2_PATH] == 0)
            {
                this.Invoke(new StringSend(Button_Text_Set), button_DL2_PATH, "OFF");// = false;
            }
            else
            {
                this.Invoke(new StringSend(Button_Text_Set), button_DL2_PATH, "ON");// = false;
            }

            if (buf[(int)BluecellReqIndex.ATT_DL3_PATH] == 0)
            {
                this.Invoke(new StringSend(Button_Text_Set), button_DL3_PATH, "OFF");// = false;
            }
            else
            {
                this.Invoke(new StringSend(Button_Text_Set), button_DL3_PATH, "ON");// = false;
            }
            if (buf[(int)BluecellReqIndex.ATT_DL4_PATH] == 0)
            {
                this.Invoke(new StringSend(Button_Text_Set), button_DL4_PATH, "OFF");// = false;
            }
            else
            {
                this.Invoke(new StringSend(Button_Text_Set), button_DL4_PATH, "ON");// = false;
            }
            if (buf[(int)BluecellReqIndex.ATT_UL1_PATH] == 0)
            {
                this.Invoke(new StringSend(Button_Text_Set), button_UL1_PATH, "OFF");// = false;
            }
            else
            {
                this.Invoke(new StringSend(Button_Text_Set), button_UL1_PATH, "ON");// = false;
            }
            if (buf[(int)BluecellReqIndex.ATT_UL2_PATH] == 0)
            {
                this.Invoke(new StringSend(Button_Text_Set), button_UL2_PATH, "OFF");// = false;
            }
            else
            {
                this.Invoke(new StringSend(Button_Text_Set), button_UL2_PATH, "ON");// = false;
            }
            if (buf[(int)BluecellReqIndex.ATT_UL3_PATH] == 0)
            {
                this.Invoke(new StringSend(Button_Text_Set), button_UL3_PATH, "OFF");// = false;
            }
            else
            {
                this.Invoke(new StringSend(Button_Text_Set), button_UL3_PATH, "ON");// = false;
            }
            if (buf[(int)BluecellReqIndex.ATT_UL4_PATH] == 0)
            {
                this.Invoke(new StringSend(Button_Text_Set), button_UL4_PATH, "OFF");// = false;
            }
            else
            {
                this.Invoke(new StringSend(Button_Text_Set), button_UL4_PATH, "ON");// = false;
            }

            if (buf[(int)BluecellReqIndex.ALARM_TEMP_HIGH] != 0x80)
            {
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_TempHigh_Alarm_ON, false);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_TempHigh_Alarm_OFF, true);// = false;
            }
            else
            {
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_TempHigh_Alarm_ON, true);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_TempHigh_Alarm_OFF, false);// = false;
            }

            if (buf[(int)BluecellReqIndex.ALARM_DLI_Level] == 0)
            {
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path1_High_Alarm_ON, false);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path2_High_Alarm_ON, false);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path3_High_Alarm_ON, false);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path4_High_Alarm_ON, false);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path1_High_Alarm_OFF, true);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path2_High_Alarm_OFF, true);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path3_High_Alarm_OFF, true);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path4_High_Alarm_OFF, true);// = false;


                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path1_Low_Alarm_ON, false);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path2_Low_Alarm_ON, false);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path3_Low_Alarm_ON, false);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path4_Low_Alarm_ON, false);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path1_Low_Alarm_OFF, true);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path2_Low_Alarm_OFF, true);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path3_Low_Alarm_OFF, true);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path4_Low_Alarm_OFF, true);// = false;

            }
            else
            {
                /**
                    *  
                    *  DLI HIGH ALARM PART
                    * 
                    * **/


                if ((buf[(int)BluecellReqIndex.ALARM_DLI_Level] & ALARM_DLI_P1_LEVEL_HIGH) > 0)
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path1_High_Alarm_ON, true);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path1_High_Alarm_OFF, false);// = false;

                }
                else
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path1_High_Alarm_ON, false);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path1_High_Alarm_OFF, true);// = false;
                }

                if ((buf[(int)BluecellReqIndex.ALARM_DLI_Level] & ALARM_DLI_P2_LEVEL_HIGH) > 0)
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path2_High_Alarm_ON, true);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path2_High_Alarm_OFF, false);// = false;
                }
                else
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path2_High_Alarm_ON, false);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path2_High_Alarm_OFF, true);// = false;
                }

                if ((buf[(int)BluecellReqIndex.ALARM_DLI_Level] & ALARM_DLI_P3_LEVEL_HIGH) > 0)
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path3_High_Alarm_ON, true);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path3_High_Alarm_OFF, false);// = false;
                }
                else
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path3_High_Alarm_ON, false);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path3_High_Alarm_OFF, true);// = false;
                }
                if ((buf[(int)BluecellReqIndex.ALARM_DLI_Level] & ALARM_DLI_P4_LEVEL_HIGH) > 0)
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path4_High_Alarm_ON, true);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path4_High_Alarm_OFF, false);// = false;

                }
                else
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path4_High_Alarm_ON, false);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path4_High_Alarm_OFF, true);// = false;
                }
                /**
                    *  
                    *  DLI LOW ALARM PART
                    * 
                    * **/

                if ((buf[(int)BluecellReqIndex.ALARM_DLI_Level] & ALARM_DLI_P1_LEVEL_LOW) > 0)
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path1_Low_Alarm_ON, true);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path1_Low_Alarm_OFF, false);// = false;
                }
                else
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path1_Low_Alarm_ON, false);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path1_Low_Alarm_OFF, true);// = false;

                }

                if ((buf[(int)BluecellReqIndex.ALARM_DLI_Level] & ALARM_DLI_P2_LEVEL_LOW) > 0)
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path2_Low_Alarm_ON, true);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path2_Low_Alarm_OFF, false);// = false;
                }
                else
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path2_Low_Alarm_ON, false);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path2_Low_Alarm_OFF, true);// = false;

                }

                if ((buf[(int)BluecellReqIndex.ALARM_DLI_Level] & ALARM_DLI_P3_LEVEL_LOW) > 0)
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path3_Low_Alarm_ON, true);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path3_Low_Alarm_OFF, false);// = false;
                }
                else
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path3_Low_Alarm_ON, false);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path3_Low_Alarm_OFF, true);// = false;

                }

                if ((buf[(int)BluecellReqIndex.ALARM_DLI_Level] & ALARM_DLI_P4_LEVEL_LOW) > 0)
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path4_Low_Alarm_ON, true);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path4_Low_Alarm_OFF, false);// = false;

                }
                else
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path4_Low_Alarm_ON, false);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DLI_Path4_Low_Alarm_OFF, true);// = false;

                }

            }

            if (buf[(int)BluecellReqIndex.ALARM_DLI_SHTUTDOWN] == 0)
            {
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DL1_Shutdown_Alarm_ON, false);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DL2_Shutdown_Alarm_ON, false);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DL3_Shutdown_Alarm_ON, false);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DL4_Shutdown_Alarm_ON, false);// = false;

                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DL1_Shutdown_Alarm_OFF, true);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DL2_Shutdown_Alarm_OFF, true);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DL3_Shutdown_Alarm_OFF, true);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DL4_Shutdown_Alarm_OFF, true);// = false;
            }
            else
            {
                if ((buf[(int)BluecellReqIndex.ALARM_DLI_SHTUTDOWN] & ALARM_DLI_SHUTDOWN_P1) > 0)
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DL1_Shutdown_Alarm_ON, true);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DL1_Shutdown_Alarm_OFF, false);// = false;

                }
                else
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DL1_Shutdown_Alarm_ON, false);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DL1_Shutdown_Alarm_OFF, true);// = false;

                }
                if ((buf[(int)BluecellReqIndex.ALARM_DLI_SHTUTDOWN] & ALARM_DLI_SHUTDOWN_P2) > 0)
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DL2_Shutdown_Alarm_ON, true);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DL2_Shutdown_Alarm_OFF, false);// = false;

                }
                else
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DL2_Shutdown_Alarm_ON, false);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DL2_Shutdown_Alarm_OFF, true);// = false;

                }
                if ((buf[(int)BluecellReqIndex.ALARM_DLI_SHTUTDOWN] & ALARM_DLI_SHUTDOWN_P3) > 0)
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DL3_Shutdown_Alarm_ON, true);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DL3_Shutdown_Alarm_OFF, false);// = false;

                }
                else
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DL3_Shutdown_Alarm_ON, false);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DL3_Shutdown_Alarm_OFF, true);// = false;

                }
                if ((buf[(int)BluecellReqIndex.ALARM_DLI_SHTUTDOWN] & ALARM_DLI_SHUTDOWN_P4) > 0)
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DL4_Shutdown_Alarm_ON, true);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DL4_Shutdown_Alarm_OFF, false);// = false;

                }
                else
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DL4_Shutdown_Alarm_ON, false);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_DL4_Shutdown_Alarm_OFF, true);// = false;

                }
            }
            
            if (buf[(int)BluecellReqIndex.DLI_Shutdown_ON_OFF] == 0)
            {
                this.Invoke(new StringSend(Button_Text_Set), button_DL_Shutdown, "OFF");// = false;
            }
            else
            {
                this.Invoke(new StringSend(Button_Text_Set), button_DL_Shutdown, "ON");// = false;
            }
            

            if (buf[(int)BluecellReqIndex.ULO_Shutdown_ON_OFF] == 0)
            {
                this.Invoke(new StringSend(Button_Text_Set), button_UL_Shutdown, "OFF");// = false;
            }
            else
            {
                this.Invoke(new StringSend(Button_Text_Set), button_UL_Shutdown, "ON");// = false;
            }
            if (buf[(int)BluecellReqIndex.ALARM_DLI_AGC_Alarm] == 0)
            {
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_AGC1_Alarm_ON, false);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_AGC2_Alarm_ON, false);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_AGC3_Alarm_ON, false);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_AGC4_Alarm_ON, false);// = false;

                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_AGC1_Alarm_OFF, true);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_AGC2_Alarm_OFF, true);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_AGC3_Alarm_OFF, true);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_AGC4_Alarm_OFF, true);// = false;
            }
            else
            {
                if ((buf[(int)BluecellReqIndex.ALARM_DLI_AGC_Alarm] & ALARM_AGC_P1) > 0)
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_AGC1_Alarm_ON, true);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_AGC1_Alarm_OFF, false);// = false;
                }
                else
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_AGC1_Alarm_ON, false);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_AGC1_Alarm_OFF, true);// = fals
                }
                if ((buf[(int)BluecellReqIndex.ALARM_DLI_AGC_Alarm] & ALARM_AGC_P2) > 0)
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_AGC2_Alarm_ON, true);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_AGC2_Alarm_OFF, false);// = false;
                }
                else
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_AGC2_Alarm_ON, false);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_AGC2_Alarm_OFF, true);// = fals
                }

                if ((buf[(int)BluecellReqIndex.ALARM_DLI_AGC_Alarm] & ALARM_AGC_P3) > 0)
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_AGC3_Alarm_ON, true);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_AGC3_Alarm_OFF, false);// = false;
                }
                else
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_AGC3_Alarm_ON, false);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_AGC3_Alarm_OFF, true);// = fals
                }

                if ((buf[(int)BluecellReqIndex.ALARM_DLI_AGC_Alarm] & ALARM_AGC_P4) > 0)
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_AGC4_Alarm_ON, true);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_AGC4_Alarm_OFF, false);// = false;
                }
                else
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_AGC4_Alarm_ON, false);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_AGC4_Alarm_OFF, true);// = fals
                }

                
            }

            if (buf[(int)BluecellReqIndex.ALARM_ULO_ALC_Alarm] == 0)
            {
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ALC1_Alarm_ON, false);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ALC2_Alarm_ON, false);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ALC3_Alarm_ON, false);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ALC4_Alarm_ON, false);// = false;

                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ALC1_Alarm_OFF, true);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ALC2_Alarm_OFF, true);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ALC3_Alarm_OFF, true);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ALC4_Alarm_OFF, true);// = false;
            }
            else
            {
                if ((buf[(int)BluecellReqIndex.ALARM_ULO_ALC_Alarm] & ALARM_ALC_P1) > 0)
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ALC1_Alarm_ON, true);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ALC1_Alarm_OFF, false);// = false;
                }
                else
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ALC1_Alarm_ON, false);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ALC1_Alarm_OFF, true);// = fals
                }
                if ((buf[(int)BluecellReqIndex.ALARM_ULO_ALC_Alarm] & ALARM_ALC_P2) > 0)
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ALC2_Alarm_ON, true);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ALC2_Alarm_OFF, false);// = false;
                }
                else
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ALC2_Alarm_ON, false);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ALC2_Alarm_OFF, true);// = fals
                }

                if ((buf[(int)BluecellReqIndex.ALARM_ULO_ALC_Alarm] & ALARM_ALC_P3) > 0)
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ALC3_Alarm_ON, true);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ALC3_Alarm_OFF, false);// = false;
                }
                else
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ALC3_Alarm_ON, false);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ALC3_Alarm_OFF, true);// = fals
                }

                if ((buf[(int)BluecellReqIndex.ALARM_ULO_ALC_Alarm] & ALARM_ALC_P4) > 0)
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ALC4_Alarm_ON, true);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ALC4_Alarm_OFF, false);// = false;
                }
                else
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ALC4_Alarm_ON, false);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ALC4_Alarm_OFF, true);// = fals
                }


            }

            if (buf[(int)BluecellReqIndex.ALARM_ULO_Level] == 0)
            {

                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ULO_Path1_High_Alarm_ON, false);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ULO_Path2_High_Alarm_ON, false);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ULO_Path3_High_Alarm_ON, false);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ULO_Path4_High_Alarm_ON, false);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ULO_Path1_High_Alarm_OFF, true);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ULO_Path2_High_Alarm_OFF, true);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ULO_Path3_High_Alarm_OFF, true);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ULO_Path4_High_Alarm_OFF, true);// = false;
                    
            }
            else
            {
                /**
                *  
                *  ULO HIGH ALARM PART
                * 
                * **/
                if ((buf[(int)BluecellReqIndex.ALARM_ULO_Level] & ALARM_ULO_P1_LEVEL_HIGH) > 0)
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ULO_Path1_High_Alarm_ON, true);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ULO_Path1_High_Alarm_OFF, false);// = false;

                }

                if ((buf[(int)BluecellReqIndex.ALARM_ULO_Level] & ALARM_ULO_P2_LEVEL_HIGH) > 0)
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ULO_Path2_High_Alarm_ON, true);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ULO_Path2_High_Alarm_OFF, false);// = false;
                }

                if ((buf[(int)BluecellReqIndex.ALARM_ULO_Level] & ALARM_ULO_P3_LEVEL_HIGH) > 0)
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ULO_Path3_High_Alarm_ON, true);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ULO_Path3_High_Alarm_OFF, false);// = false;
                }

                if ((buf[(int)BluecellReqIndex.ALARM_ULO_Level] & ALARM_ULO_P4_LEVEL_HIGH) > 0)
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ULO_Path4_High_Alarm_ON, true);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_ULO_Path4_High_Alarm_OFF, false);// = false;

                }

                   
            }


            if (buf[(int)BluecellReqIndex.ALARM_ULO_SHTUTDOWN] == 0)
            {
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_UL1_Shutdown_Alarm_ON, false);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_UL2_Shutdown_Alarm_ON, false);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_UL3_Shutdown_Alarm_ON, false);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_UL4_Shutdown_Alarm_ON, false);// = false;

                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_UL1_Shutdown_Alarm_OFF, true);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_UL2_Shutdown_Alarm_OFF, true);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_UL3_Shutdown_Alarm_OFF, true);// = false;
                this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_UL4_Shutdown_Alarm_OFF, true);// = false;
            }
            else
            {
                if ((buf[(int)BluecellReqIndex.ALARM_ULO_SHTUTDOWN] & ALARM_ULO_SHUTDOWN_P1) > 0)
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_UL1_Shutdown_Alarm_ON, true);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_UL1_Shutdown_Alarm_OFF, false);// = false;

                }
                else
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_UL1_Shutdown_Alarm_ON, false);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_UL1_Shutdown_Alarm_OFF, true);// = false;

                }
                if ((buf[(int)BluecellReqIndex.ALARM_ULO_SHTUTDOWN] & ALARM_ULO_SHUTDOWN_P2) > 0)
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_UL2_Shutdown_Alarm_ON, true);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_UL2_Shutdown_Alarm_OFF, false);// = false;

                }
                else
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_UL2_Shutdown_Alarm_ON, false);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_UL2_Shutdown_Alarm_OFF, true);// = false;

                }
                if ((buf[(int)BluecellReqIndex.ALARM_ULO_SHTUTDOWN] & ALARM_ULO_SHUTDOWN_P3) > 0)
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_UL3_Shutdown_Alarm_ON, true);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_UL3_Shutdown_Alarm_OFF, false);// = false;

                }
                else
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_UL3_Shutdown_Alarm_ON, false);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_UL3_Shutdown_Alarm_OFF, true);// = false;

                }
                if ((buf[(int)BluecellReqIndex.ALARM_ULO_SHTUTDOWN] & ALARM_ULO_SHUTDOWN_P4) > 0)
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_UL4_Shutdown_Alarm_ON, true);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_UL4_Shutdown_Alarm_OFF, false);// = false;

                }
                else
                {
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_UL4_Shutdown_Alarm_ON, false);// = false;
                    this.Invoke(new SWVisible(PicVisible_Text_Set), pictureBox_UL4_Shutdown_Alarm_OFF, true);// = false;

                }
            }

            this.Invoke(new SWVisible(CheckBoxVisible_Text_Set), checkBox_Fix, IamSetting_Get());// = false;
            if (IamSetting_Get() == false)
            {
                LiMitdata = 0;
                LiMitdata += buf[(int)BluecellReqIndex.Temp_High_Threshold];
                this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_Temp_Threshold, LiMitdata.ToString());
                LiMitdata = 0;
                LiMitdata += buf[(int)BluecellReqIndex.Temp_High_Threshold_Default];
                this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_Temp_Threshold_Default, LiMitdata.ToString("N2"));
                LiMitdata = 0;
                LiMitdata += buf[(int)BluecellReqIndex.bluecell_User_TEMP_OFFSET];
                this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_Temperature_Offset, LiMitdata.ToString());
                LiMitdata = 0;
                LiMitdata += buf[(int)BluecellReqIndex.ALARM_MASK1];
                this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_MASK, LiMitdata.ToString());
                LiMitdata = 0;


                LiMitdata += (short)((buf[(int)BluecellReqIndex.DLI_AGC_Threshold_H] << 8) & 0xFF00);
                LiMitdata += (short)(buf[(int)BluecellReqIndex.DLI_AGC_Threshold_L] & 0x00FF);
                LiMitdata /= 10;
                this.Invoke(new StringSend(TextBox_Text_Set), textBox_DLI_AGC_Threshold, LiMitdata.ToString());

                LiMitdata = 0;
                LiMitdata += (short)((buf[(int)BluecellReqIndex.ULO_ALC_Threshold_H] << 8) & 0xFF00);
                LiMitdata += (short)(buf[(int)BluecellReqIndex.ULO_ALC_Threshold_L] & 0x00FF);
                LiMitdata /= 10;
                this.Invoke(new StringSend(TextBox_Text_Set), textBox_ULO_ALC_Threshold, LiMitdata.ToString());
                AttData = (short)(((buf[(int)BluecellReqIndex.ATT_DL1_H] << 8) & 0xFF00) | (buf[(int)BluecellReqIndex.ATT_DL1_L] & 0x00FF));
                adcdata = AttData *0.1;
                this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_ATT_DL1, adcdata.ToString("N2"));

                AttData = (short)(((buf[(int)BluecellReqIndex.ATT_DL2_H] << 8) & 0xFF00) | (buf[(int)BluecellReqIndex.ATT_DL2_L] & 0x00FF));
                adcdata = AttData *0.1;
                this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_ATT_DL2, adcdata.ToString("N2"));

                AttData = (short)(((buf[(int)BluecellReqIndex.ATT_DL3_H] << 8) & 0xFF00) | (buf[(int)BluecellReqIndex.ATT_DL3_L] & 0x00FF));
                adcdata = AttData *0.1;
                this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_ATT_DL3, adcdata.ToString("N2"));

                AttData = (short)(((buf[(int)BluecellReqIndex.ATT_DL4_H] << 8) & 0xFF00) | (buf[(int)BluecellReqIndex.ATT_DL4_L] & 0x00FF));
                adcdata = AttData *0.1;
                this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_ATT_DL4, adcdata.ToString("N2"));


                AttData = (short)(((buf[(int)BluecellReqIndex.ATT_UL1_H] << 8) & 0xFF00) | (buf[(int)BluecellReqIndex.ATT_UL1_L] & 0x00FF));
                adcdata = AttData *0.1;
                this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_ATT_UL1, adcdata.ToString("N2"));
                AttData = (short)(((buf[(int)BluecellReqIndex.ATT_UL2_H] << 8) & 0xFF00) | (buf[(int)BluecellReqIndex.ATT_UL2_L] & 0x00FF));
                adcdata = AttData *0.1;
                this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_ATT_UL2, adcdata.ToString("N2"));
                AttData = (short)(((buf[(int)BluecellReqIndex.ATT_UL3_H] << 8) & 0xFF00) | (buf[(int)BluecellReqIndex.ATT_UL3_L] & 0x00FF));
                adcdata = AttData *0.1;
                this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_ATT_UL3, adcdata.ToString("N2"));
                AttData = (short)(((buf[(int)BluecellReqIndex.ATT_UL4_H] << 8) & 0xFF00) | (buf[(int)BluecellReqIndex.ATT_UL4_L] & 0x00FF));
                adcdata = AttData *0.1;
                this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_ATT_UL4, adcdata.ToString("N2"));


                AttData = (short)(buf[(int)BluecellReqIndex.Path1_GainValue]);
                this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_Path1_GainValue, AttData.ToString());
                AttData = (short)(buf[(int)BluecellReqIndex.Path2_GainValue]);
                this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_Path2_GainValue, AttData.ToString());
                AttData = (short)(buf[(int)BluecellReqIndex.Path3_GainValue]);
                this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_Path3_GainValue, AttData.ToString());
                AttData = (short)(buf[(int)BluecellReqIndex.Path4_GainValue]);
                this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_Path4_GainValue, AttData.ToString());




                //this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_ALC4_MAX, adcdata.ToString("N2"));
                adcdata = 0;
                AttData = (short)(((buf[(int)BluecellReqIndex.bluecell_User_DL1_H] << 8) & 0xFF00) | (buf[(int)BluecellReqIndex.bluecell_User_DL1_L] & 0x00FF));
                adcdata = AttData *0.1;
                /*if ((((int)(adcdata) & 0xFF00) & 0xF000) == 0xF000)
                {
                    adcdata = (0xffff - adcdata) + 1;
                    adcdata *= -1;
                }
                adcdata = AttData *0.1;*/
                this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_DL1_User, adcdata.ToString("N2"));
                adcdata = 0;
                AttData = (short)(((buf[(int)BluecellReqIndex.bluecell_User_DL2_H] << 8) & 0xFF00) | (buf[(int)BluecellReqIndex.bluecell_User_DL2_L] & 0x00FF));
                adcdata = (AttData) *0.1;
                //adcdata += ((buf[(int)BluecellReqIndex.bluecell_User_DL2_H] << 8) & 0xFF00);
                //adcdata += (buf[(int)BluecellReqIndex.bluecell_User_DL2_L] & 0x00FF);
                /*if ((((int)(adcdata) & 0xFF00) & 0xF000) == 0xF000)
                {
                    adcdata = (0xffff - adcdata) + 1;
                    adcdata *= -1;
                }
                adcdata = AttData *0.1;*/
                this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_DL2_User, adcdata.ToString("N2"));
                adcdata = 0;
                AttData = (short)(((buf[(int)BluecellReqIndex.bluecell_User_DL3_H] << 8) & 0xFF00) | (buf[(int)BluecellReqIndex.bluecell_User_DL3_L] & 0x00FF));
                adcdata = AttData *0.1;
                //adcdata += ((buf[(int)BluecellReqIndex.bluecell_User_DL3_H] << 8) & 0xFF00);
                //adcdata += (buf[(int)BluecellReqIndex.bluecell_User_DL3_L] & 0x00FF);
                /*if ((((int)(adcdata) & 0xFF00) & 0xF000) == 0xF000)
                {
                    adcdata = (0xffff - adcdata) + 1;
                    adcdata *= -1;
                }
                adcdata = AttData *0.1;*/
                this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_DL3_User, adcdata.ToString("N2"));
                adcdata = 0;
                AttData = (short)(((buf[(int)BluecellReqIndex.bluecell_User_DL4_H] << 8) & 0xFF00) | (buf[(int)BluecellReqIndex.bluecell_User_DL4_L] & 0x00FF));
                adcdata = AttData *0.1;
                //adcdata += ((buf[(int)BluecellReqIndex.bluecell_User_DL4_H] << 8) & 0xFF00);
                //adcdata += (buf[(int)BluecellReqIndex.bluecell_User_DL4_L] & 0x00FF);
                /*if ((((int)(adcdata) & 0xFF00) & 0xF000) == 0xF000)
                {
                    adcdata = (0xffff - adcdata) + 1;
                    adcdata *= -1;
                }
                adcdata = AttData *0.1;*/
                this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_DL4_User, adcdata.ToString("N2"));
                adcdata = 0;
                AttData = (short)(((buf[(int)BluecellReqIndex.bluecell_User_UL1_H] << 8) & 0xFF00) | (buf[(int)BluecellReqIndex.bluecell_User_UL1_L] & 0x00FF));
                adcdata = AttData *0.1;




                //adcdata += ((buf[(int)BluecellReqIndex.bluecell_User_UL1_H] << 8) & 0xFF00);
                //adcdata += (buf[(int)BluecellReqIndex.bluecell_User_UL1_L] & 0x00FF);
                /*if ((((int)(adcdata) & 0xFF00) & 0xF000) == 0xF000)
                {
                    adcdata = (0xffff - adcdata) + 1;
                    adcdata *= -1;
                }
                adcdata = AttData *0.1;*/
                this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_UL1_User, adcdata.ToString("N2"));
                adcdata = 0;
                AttData = (short)(((buf[(int)BluecellReqIndex.bluecell_User_UL2_H] << 8) & 0xFF00) | (buf[(int)BluecellReqIndex.bluecell_User_UL2_L] & 0x00FF));
                adcdata = AttData *0.1;
                //adcdata += ((buf[(int)BluecellReqIndex.bluecell_User_UL2_H] << 8) & 0xFF00);
                //adcdata += (buf[(int)BluecellReqIndex.bluecell_User_UL2_L] & 0x00FF);
                /*if ((((int)(adcdata) & 0xFF00) & 0xF000) == 0xF000)
                {
                    adcdata = (0xffff - adcdata) + 1;
                    adcdata *= -1;
                }
                adcdata = AttData *0.1;*/
                this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_UL2_User, adcdata.ToString("N2"));
                adcdata = 0;
                AttData = (short)(((buf[(int)BluecellReqIndex.bluecell_User_UL3_H] << 8) & 0xFF00) | (buf[(int)BluecellReqIndex.bluecell_User_UL3_L] & 0x00FF));
                adcdata = AttData *0.1;
                //adcdata += ((buf[(int)BluecellReqIndex.bluecell_User_UL3_H] << 8) & 0xFF00);
                //adcdata += (buf[(int)BluecellReqIndex.bluecell_User_UL3_L] & 0x00FF);
                /*if ((((int)(adcdata) & 0xFF00) & 0xF000) == 0xF000)
                {
                    adcdata = (0xffff - adcdata) + 1;
                    adcdata *= -1;
                }
                adcdata = AttData *0.1;*/
                this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_UL3_User, adcdata.ToString("N2"));
                adcdata = 0;
                AttData = (short)(((buf[(int)BluecellReqIndex.bluecell_User_UL4_H] << 8) & 0xFF00) | (buf[(int)BluecellReqIndex.bluecell_User_UL4_L] & 0x00FF));
                adcdata = AttData *0.1;
                //adcdata += ((buf[(int)BluecellReqIndex.bluecell_User_UL4_H] << 8) & 0xFF00);
                //adcdata += (buf[(int)BluecellReqIndex.bluecell_User_UL4_L] & 0x00FF);
                /*if ((((int)(adcdata) & 0xFF00) & 0xF000) == 0xF000)
                {
                    adcdata = (0xffff - adcdata) + 1;
                    adcdata *= -1;
                }
                adcdata = AttData *0.1;*/
                this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_UL4_User, adcdata.ToString("N2"));
                adcdata = 0;

  

                AttData = (short)(((buf[(int)BluecellReqIndex.MBIC_ULO_ALC_Atten1_H] << 8) & 0xFF00) | (buf[(int)BluecellReqIndex.MBIC_ULO_ALC_Atten1_L] & 0x00FF));
                AttData /= 10;
                this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_ALC1, AttData.ToString());

                AttData = (short)(((buf[(int)BluecellReqIndex.MBIC_ULO_ALC_Atten2_H] << 8) & 0xFF00) | (buf[(int)BluecellReqIndex.MBIC_ULO_ALC_Atten2_L] & 0x00FF));
                AttData /= 10;
                this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_ALC2, AttData.ToString());

                AttData = (short)(((buf[(int)BluecellReqIndex.MBIC_ULO_ALC_Atten3_H] << 8) & 0xFF00) | (buf[(int)BluecellReqIndex.MBIC_ULO_ALC_Atten3_L] & 0x00FF));
                AttData /= 10;
                this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_ALC3, AttData.ToString());

                AttData = (short)(((buf[(int)BluecellReqIndex.MBIC_ULO_ALC_Atten4_H] << 8) & 0xFF00) | (buf[(int)BluecellReqIndex.MBIC_ULO_ALC_Atten4_L] & 0x00FF));
                AttData /= 10;
                this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_ALC4, AttData.ToString());

            }
            this.Invoke(new StringSend(TextBox_Text_Set), textBox_MunufactureDate,
                                             buf[(int)BluecellReqIndex.Manufacture_Date].ToString()
                                           + buf[(int)BluecellReqIndex.Manufacture_Date + 1].ToString("D2")
                                           + buf[(int)BluecellReqIndex.Manufacture_Date + 2].ToString("D2"));
            string tempstr = "";
            for (int strindex = 0; strindex < 20; strindex++)
                tempstr += Convert.ToChar(buf[(int)BluecellReqIndex.Serial_Number + strindex]);


            this.Invoke(new StringSend(TextBox_Text_Set), textBox_SerialNumber, tempstr);


            tempstr = buf[(int)BluecellReqIndex.PCB_Version].ToString();
            tempstr += ".";
            tempstr += buf[(int)BluecellReqIndex.PCB_Version + 1].ToString();
            this.Invoke(new StringSend(TextBox_Text_Set), textBox_PcbVersion, tempstr);


            tempstr = "";
            for (int strindex = 0; strindex < 31; strindex++)
                tempstr += Convert.ToChar(buf[(int)BluecellReqIndex.CPU_Bank1_Image_Name + strindex]);
            this.Invoke(new StringSend(TextBox_Text_Set), textBox_Bank1Name, tempstr);

            tempstr = "";
            for (int strindex = 0; strindex < 31; strindex++)
                tempstr += Convert.ToChar(buf[(int)BluecellReqIndex.CPU_Bank2_Image_Name + strindex]);
            this.Invoke(new StringSend(TextBox_Text_Set), textBox_Bank2Name, tempstr);



            AttData = (short)(((buf[(int)BluecellReqIndex.DLI_Shutdown_Threshold_H] << 8) & 0xFF00) | (buf[(int)BluecellReqIndex.DLI_Shutdown_Threshold_L] & 0x00FF));
            AttData = Convert.ToInt16(AttData * 0.1);
            //this.Invoke(new StringSend(Numeric_Text_Set), hidden.numericUpDown_DLI_Shutdown_Threshold, AttData.ToString());
            this.Invoke(new StringSend(TextBox_Text_Set), textBox_DL_ShutdownLimit, AttData.ToString());

            AttData = (short)(((buf[(int)BluecellReqIndex.ULO_Shutdown_Threshold_H] << 8) & 0xFF00) | (buf[(int)BluecellReqIndex.ULO_Shutdown_Threshold_L] & 0x00FF));
            AttData = Convert.ToInt16(AttData * 0.1);
            this.Invoke(new StringSend(TextBox_Text_Set), textBox_UL_ShutdownLimit, AttData.ToString());

            AttData = (short)(buf[(int)BluecellReqIndex.DL_Det_ALL_Offset]);
            this.Invoke(new StringSend(TextBox_Text_Set), textBox_DL1_TableOffset, ((sbyte)AttData).ToString());
            this.Invoke(new StringSend(TextBox_Text_Set), textBox_DL2_TableOffset, ((sbyte)AttData).ToString());
            this.Invoke(new StringSend(TextBox_Text_Set), textBox_DL3_TableOffset, ((sbyte)AttData).ToString());
            this.Invoke(new StringSend(TextBox_Text_Set), textBox_DL4_TableOffset, ((sbyte)AttData).ToString());


         

            AttData = (short)(((buf[(int)BluecellReqIndex.DLI_Level_High_Threshold_H] << 8) & 0xFF00) | (buf[(int)BluecellReqIndex.DLI_Level_High_Threshold_L] & 0x00FF));
            AttData = Convert.ToInt16(AttData * 0.1);
            this.Invoke(new StringSend(TextBox_Text_Set), textBox_DLI_Level_High_Threshold, AttData.ToString());

            AttData = (short)(((buf[(int)BluecellReqIndex.DLI_Level_Low_Threshold_H] << 8) & 0xFF00) | (buf[(int)BluecellReqIndex.DLI_Level_Low_Threshold_L] & 0x00FF));
            AttData = Convert.ToInt16(AttData * 0.1);
            this.Invoke(new StringSend(TextBox_Text_Set), textBox_DLI_Level_Low_Threshold, AttData.ToString());

            AttData = (short)(((buf[(int)BluecellReqIndex.ULO_Level_High_Threshold_H] << 8) & 0xFF00) | (buf[(int)BluecellReqIndex.ULO_Level_High_Threshold_L] & 0x00FF));
            AttData = Convert.ToInt16(AttData * 0.1);
            this.Invoke(new StringSend(TextBox_Text_Set), textBox_ULO_Level_High_Threshold, AttData.ToString());


            AttData = buf[(int)BluecellReqIndex.ULO_Shutdown_Retry_Count1];
            this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_ShutdownUL1, AttData.ToString());

            AttData = buf[(int)BluecellReqIndex.ULO_Shutdown_Retry_Count2];
            this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_ShutdownUL2, AttData.ToString());

            AttData = buf[(int)BluecellReqIndex.ULO_Shutdown_Retry_Count3];
            this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_ShutdownUL3, AttData.ToString());

            AttData = buf[(int)BluecellReqIndex.ULO_Shutdown_Retry_Count4];
            this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_ShutdownUL4, AttData.ToString());



            AttData = buf[(int)BluecellReqIndex.DLI_Shutdown_Retry_Count1];
            this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_ShutdownDL1, AttData.ToString());

            AttData = buf[(int)BluecellReqIndex.DLI_Shutdown_Retry_Count2];
            this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_ShutdownDL2, AttData.ToString());

            AttData = buf[(int)BluecellReqIndex.DLI_Shutdown_Retry_Count3];
            this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_ShutdownDL3, AttData.ToString());

            AttData = buf[(int)BluecellReqIndex.DLI_Shutdown_Retry_Count4];
            this.Invoke(new StringSend(Numeric_Text_Set), numericUpDown_ShutdownDL4, AttData.ToString());


            adcdata = 0;
            adcdata = ((buf[(int)BluecellReqIndex.DLI_P1_Level1_H] << 8) & 0xFF00);
            adcdata += (buf[(int)BluecellReqIndex.DLI_P1_Level1_L] & 0x00FF);
            adcdata *= Volt_Calc_val;
            this.Invoke(new StringSend(TextBox_Text_Set), textBox_DET_DL1, adcdata.ToString("N3"));
            dBmdata = 0;
            dBmdata = (short)((buf[(int)BluecellReqIndex.DLI_Level1_H] << 8) & 0xFF00);
            dBmdata += (short)(buf[(int)BluecellReqIndex.DLI_Level1_L] & 0x00FF);
            this.Invoke(new StringSend(TextBox_Text_Set), textBox_DET_DL1_dBm, (dBmdata * 0.1).ToString());
            //this.Invoke(new StringSend(TextBox_Text_Set), textBox_DET_DL1_dBm, adcdata.ToString("N2"));
            adcdata = 0;

            adcdata = ((buf[(int)BluecellReqIndex.DLI_P2_Level2_H] << 8) & 0xFF00);
            adcdata += (buf[(int)BluecellReqIndex.DLI_P2_Level2_L] & 0x00FF);
            adcdata *= Volt_Calc_val;
            this.Invoke(new StringSend(TextBox_Text_Set), textBox_DET_DL2, adcdata.ToString("N3"));
            dBmdata = 0;
            dBmdata = (short)((buf[(int)BluecellReqIndex.DLI_Level2_H] << 8) & 0xFF00);
            dBmdata += (short)(buf[(int)BluecellReqIndex.DLI_Level2_L] & 0x00FF);
            this.Invoke(new StringSend(TextBox_Text_Set), textBox_DET_DL2_dBm, (dBmdata * 0.1).ToString());
            adcdata = 0;

            adcdata = ((buf[(int)BluecellReqIndex.DLI_P3_Level3_H] << 8) & 0xFF00);
            adcdata += (buf[(int)BluecellReqIndex.DLI_P3_Level3_L] & 0x00FF);
            adcdata *= Volt_Calc_val;
            this.Invoke(new StringSend(TextBox_Text_Set), textBox_DET_DL3, adcdata.ToString("N3"));
            dBmdata = 0;
            dBmdata = (short)((buf[(int)BluecellReqIndex.DLI_Level3_H] << 8) & 0xFF00);
            dBmdata += (short)(buf[(int)BluecellReqIndex.DLI_Level3_L] & 0x00FF);
            this.Invoke(new StringSend(TextBox_Text_Set), textBox_DET_DL3_dBm, (dBmdata * 0.1).ToString());
            adcdata = 0;

            adcdata = ((buf[(int)BluecellReqIndex.DLI_P4_Level4_H] << 8) & 0xFF00);
            adcdata += (buf[(int)BluecellReqIndex.DLI_P4_Level4_L] & 0x00FF);
            adcdata *= Volt_Calc_val;
            this.Invoke(new StringSend(TextBox_Text_Set), textBox_DET_DL4, adcdata.ToString("N3"));
            dBmdata = 0;
            dBmdata = (short)((buf[(int)BluecellReqIndex.DLI_Level4_H] << 8) & 0xFF00);
            dBmdata += (short)(buf[(int)BluecellReqIndex.DLI_Level4_L] & 0x00FF);
            this.Invoke(new StringSend(TextBox_Text_Set), textBox_DET_DL4_dBm, (dBmdata * 0.1).ToString());
            adcdata = 0;


            adcdata = ((buf[(int)BluecellReqIndex.ULO_P1_Level1_H] << 8) & 0xFF00);
            adcdata += (buf[(int)BluecellReqIndex.ULO_P1_Level1_L] & 0x00FF);
            adcdata *= Volt_Calc_val;
            this.Invoke(new StringSend(TextBox_Text_Set), textBox_DET_UL1, adcdata.ToString("N3"));
            dBmdata = 0;
            dBmdata = (short)((buf[(int)BluecellReqIndex.ULO_Level1_H] << 8) & 0xFF00);
            dBmdata += (short)(buf[(int)BluecellReqIndex.ULO_Level1_L] & 0x00FF);
            this.Invoke(new StringSend(TextBox_Text_Set), textBox_DET_UL1_dBm, (dBmdata * 0.1).ToString());
            adcdata = 0;

            adcdata = ((buf[(int)BluecellReqIndex.ULO_P2_Level2_H] << 8) & 0xFF00);
            adcdata += (buf[(int)BluecellReqIndex.ULO_P2_Level2_L] & 0x00FF);
            adcdata *= Volt_Calc_val;
            this.Invoke(new StringSend(TextBox_Text_Set), textBox_DET_UL2, adcdata.ToString("N3"));
            dBmdata = 0;
            dBmdata = (short)((buf[(int)BluecellReqIndex.ULO_Level2_H] << 8) & 0xFF00);
            dBmdata += (short)(buf[(int)BluecellReqIndex.ULO_Level2_L] & 0x00FF);
            this.Invoke(new StringSend(TextBox_Text_Set), textBox_DET_UL2_dBm, (dBmdata * 0.1).ToString());
            adcdata = 0;

            adcdata = ((buf[(int)BluecellReqIndex.ULO_P3_Level3_H] << 8) & 0xFF00);
            adcdata += (buf[(int)BluecellReqIndex.ULO_P3_Level3_L] & 0x00FF);
            adcdata *= Volt_Calc_val;
            this.Invoke(new StringSend(TextBox_Text_Set), textBox_DET_UL3, adcdata.ToString("N3"));
            dBmdata = 0;
            dBmdata = (short)((buf[(int)BluecellReqIndex.ULO_Level3_H] << 8) & 0xFF00);
            dBmdata += (short)(buf[(int)BluecellReqIndex.ULO_Level3_L] & 0x00FF);
            this.Invoke(new StringSend(TextBox_Text_Set), textBox_DET_UL3_dBm, (dBmdata * 0.1).ToString());
            adcdata = 0;

            adcdata = ((buf[(int)BluecellReqIndex.ULO_P4_Level4_H] << 8) & 0xFF00);
            adcdata += (buf[(int)BluecellReqIndex.ULO_P4_Level4_L] & 0x00FF);
            adcdata *= Volt_Calc_val;
            this.Invoke(new StringSend(TextBox_Text_Set), textBox_DET_UL4, adcdata.ToString("N3"));
            dBmdata = 0;
            dBmdata = (short)((buf[(int)BluecellReqIndex.ULO_Level4_H] << 8) & 0xFF00);
            dBmdata += (short)(buf[(int)BluecellReqIndex.ULO_Level4_L] & 0x00FF);
            this.Invoke(new StringSend(TextBox_Text_Set), textBox_DET_UL4_dBm, (dBmdata * 0.1).ToString());
            adcdata = 0;
#if false
            adcdata += ((buf[(int)BluecellReqIndex.DET_TEMP_H] << 8) & 0xFF00);
            adcdata += (buf[(int)BluecellReqIndex.DET_TEMP_L] & 0x00FF);
            adcdata = adcdata * 3.3 / 4095;
            adcdata = (adcdata - 0.5) * 100;
#else
            adcdata = (sbyte)(buf[(int)BluecellReqIndex.DET_TEMP]);
#endif

            this.Invoke(new StringSend(Label_Text_Set), label_Temp, adcdata.ToString("N2") + "°C");
            adcdata = 0;
            //string tmp = Convert.ToInt32(buf[(int)BluecellReqIndex.CPUVERSION3],16).ToString();
            char pad = '0';
            string version = Convert.ToString(buf[(int)BluecellReqIndex.CPUVERSION1]).PadLeft(2,pad)
                             + "."
                             + Convert.ToString(buf[(int)BluecellReqIndex.CPUVERSION2]).PadLeft(2, pad)
            + "."
                             + Convert.ToInt32(buf[(int)BluecellReqIndex.CPUVERSION3]).ToString("X").PadLeft(2, pad);
            //Convert.ToInt32(buf[(int)BluecellReqIndex.CPUVERSION3], 16).ToString();
            //adcdata += (buf[(int)BluecellReqIndex.CPUVERSION2])/10;
            //adcdata += (buf[(int)BluecellReqIndex.CPUVERSION3]);
            this.Invoke(new StringSend(TextBox_Text_Set), textBox_CpuVersion, version);


         
          
           hidden.TableCurrentOutputSetting();

        }
        
        object[] DET_DL1_Table = new object[128];
        object[] DET_DL2_Table = new object[128];
        object[] DET_DL3_Table = new object[128];
        object[] DET_DL4_Table = new object[128];

        object[] DET_UL1_Table = new object[128];
        object[] DET_UL2_Table = new object[128];
        object[] DET_UL3_Table = new object[128];
        object[] DET_UL4_Table = new object[128];

        object[] DET_DL1_RefTable = new object[128];
        object[] DET_DL2_RefTable = new object[128];
        object[] DET_DL3_RefTable = new object[128];
        object[] DET_DL4_RefTable = new object[128];

        object[] DET_UL1_RefTable = new object[128];
        object[] DET_UL2_RefTable = new object[128];
        object[] DET_UL3_RefTable = new object[128];
        object[] DET_UL4_RefTable = new object[128];
       
        
        public void TableDataStatusSet(byte[] buf)
        {
            hidden.TableDataStatusSet(buf);
        }
        public void DateLabelInputFunc(string date)
        {
            this.Invoke(new StringSend(Label_Text_Set), label_CompileDate, date);
        }

        private void ATT_Enter(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {

                //button_ATT_Click_1(sender, null);
                button_ATT_Click_2(sender, null);
                //to do
            }
            else if(e.KeyCode == Keys.Escape)
            {
                Activi_Change__Setting(null,null);
            }
            else
            {
                return;
            }
        }
        private bool IamSetting = false;
        private void Activi_Change__SettingComplete(object sender, EventArgs e)
        {
            IamSetting = true;
        }

        public void Activi_Change__Setting(object sender, EventArgs e)
        {
            IamSetting = false;
        }
        public bool IamSetting_Get()
        {
            return IamSetting;
        }

        private void checkBox_Fix_CheckedChanged(object sender, EventArgs e)
        {


        }

        public const byte DET_TableMaxLength = 160 + 1+ 6 + 2; // Header + Type + Length + CRCINDEX + TableIndex + .....    +  CRC
        public const byte ATT_TableMaxLength = 96 + 1 +  6 + 2; // Header + Type + Length + CRCINDEX + TableIndex + .....    +  CRC
        public const byte Temp_TableMaxLength = 96 + 1 + 6 + 2; // Header + Type + Length + CRCINDEX + TableIndex + .....    +  CRC


        const byte TableGetMaxLength =  1 + 7 + 1;


        
        private void button_Save_Click(object sender, EventArgs e)
        {
            byte[] temp_buf = new byte[TableGetMaxLength];
            Int16 Length = 
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Header] = BLUECELL_HEADER;
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type] = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_StatusSave;
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length_H] = TableGetMaxLength - 2;
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_CrcIndex] = TableGetMaxLength - 2;
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data] = (byte)1;
            serial.Serial_DataSend(temp_buf, temp_buf.Length);
            ReqTimer_Cnt = 0;

        }

        private void numericUpDown_User_KeyDown(object sender, KeyEventArgs e)
        {
            NumericUpDown numeric = (NumericUpDown)sender;
            const byte TableGetMaxLength = 9;
            byte tmp_H = 0;
            byte tmp_L = 0;
            ReqTimer_Cnt = 0;
            if (e.KeyCode == Keys.Enter)
            {

                byte[] temp_buf = new byte[TableGetMaxLength];

                temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Header] = BLUECELL_HEADER;
                temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length_H] = Convert.ToByte(((TableGetMaxLength - 3) & 0xFF00) >> 8);
                temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length_L] = Convert.ToByte((TableGetMaxLength - 3) & 0x00FF);
                temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_CrcIndex] = TableGetMaxLength - 2;

                if (   numeric.Name == "numericUpDown_Temp_Threshold"
                    || numeric.Name == "numericUpDown_Temp_Threshold_Default"
                    || numeric.Name == "numericUpDown_Temperature_Offset"
                    || numeric.Name.Contains("Default") == true)
                {
                    Int16 UserData = Convert.ToInt16(numeric.Value);
                    //tmp_H = Convert.ToByte((UserData & 0xFF00) >> 8);
                    tmp_L = Convert.ToByte((UserData & 0x00FF));
                    //temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data] = tmp_H;
                    temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data] = tmp_L;
                }
                else
                {
                    Int16 UserData = Convert.ToInt16(numeric.Value * 10);
                    tmp_H = Convert.ToByte((UserData & 0xFF00) >> 8);
                    tmp_L = Convert.ToByte((UserData & 0x00FF));
                    temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data] = tmp_H;
                    temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 1] = tmp_L;
                }

                switch (numeric.Name)
                {
                    case "numericUpDown_Temp_Threshold":
                        temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                            = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_Temp_High_Threshold;
                        break;
                    case "numericUpDown_Temp_Threshold_Default":
                        temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                            = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_Temp_High_Threshold_Default;
                        break;
                    case "numericUpDown_Temperature_Offset":
                        temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                            = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_Temperature_Offset;
                        break;

                    case "numericUpDown_DL1_User":
                        temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type] 
                            = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_DL1_USER;
                        break;
                    case "numericUpDown_DL2_User":
                        temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                            = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_DL2_USER;
                        break;
                    case "numericUpDown_DL3_User":
                        temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                            = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_DL3_USER;
                        break;
                    case "numericUpDown_DL4_User":
                        temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                            = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_DL4_USER;
                        break;

                    case "numericUpDown_UL1_User":
                        temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                            = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_UL1_USER;
                       
                        break;
                    case "numericUpDown_UL2_User":
                        temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                           = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_UL2_USER;
                        break;
                    case "numericUpDown_UL3_User":

                        temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                           = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_UL3_USER;
                        break;
                    case "numericUpDown_UL4_User":
                        temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                           = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_UL4_USER;
                        break;
                    case "numericUpDown_TEMP_User":
                        temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                           = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_TEMP_USER;
                        break;
                    case "numericUpDown_DLI_Level_High_Threshold":
                        temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                           = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_DLI_Level_High_Threshold;
                        break;
                    case "numericUpDown_DLI_Level_Low_Threshold":
                        temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                           = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_DLI_Level_Low_Threshold;
                        break;
                    case "numericUpDown_DLI_Level_High_Low_Threshold_default":
                        temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                           = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_DLI_Level_High_Low_Threshold_default;
                        break;
                    case "numericUpDown_DLI_AGC_Threshold":
                        temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                           = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_DLI_AGC_Threshold;
                        break;
                    case "numericUpDown_DLI_AGC_Threshold_Default":
                        temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                           = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_DLI_AGC_Threshold_Default;
                        break;
                    case "numericUpDown_DLI_Shutdown_Threshold":
                        temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                           = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_DLI_Shutdown_Threshold;
                        break;
                    case "numericUpDown_DLI_Shutdown_Threshold_Default":
                        temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                           = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_DLI_Shutdown_Threshold_Default;
                        break;
                    case "numericUpDown_ULO_Level_High_Threshold":
                        temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                           = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_ULO_Level_High_Threshold;
                        break;
                    case "numericUpDown_DLI_Level_High_Threshold_default":
                        temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                           = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_DLI_Level_High_Low_Threshold_default;
                        break;
                    case "numericUpDown_ULO_ALC_Threshold":
                        temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                           = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_ULO_ALC_Threshold;
                        break;
                    case "numericUpDown_ULO_ALC_Threshold_Default":
                        temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                           = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_ULO_ALC_Threshold_Default;
                        break;
                    case "numericUpDown_ULO_Shutdown_Threshold":
                        temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                           = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_ULO_Shutdown_Threshold;
                        break;
                    case "numericUpDown_ULO_Shutdown_Threshold_Default":
                        temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                           = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_ULO_Shutdown_Threshold_Default;
                        break;
                    case "numericUpDown_MASK":
                        temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                           = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_Alarm_Mask;
                        break;
                    case "numericUpDown_ALC1":
                        temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                            = (byte)Bluecell_BootProtocol.DATATYPE.BLuecell_ATT_ALC1;
                        break;
                    case "numericUpDown_ALC2":
                        temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                           = (byte)Bluecell_BootProtocol.DATATYPE.BLuecell_ATT_ALC2;
                        break;
                    case "numericUpDown_ALC3":
                        temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                           = (byte)Bluecell_BootProtocol.DATATYPE.BLuecell_ATT_ALC3;
                        break;
                    case "numericUpDown_ALC4":
                        temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type]
                           = (byte)Bluecell_BootProtocol.DATATYPE.BLuecell_ATT_ALC4;
                        break;



                    default:break;
                }
                Crc16 crc = new Crc16();
                UInt16 CRCRET = crc.CRC16_Generate(temp_buf, Convert.ToByte((TableGetMaxLength - 3) & 0x00FF));
                temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 2] = Convert.ToByte((CRCRET & 0xFF00) >> 8);
                temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 3] = Convert.ToByte(CRCRET & 0x00FF);

                serial.Serial_DataSend(temp_buf, temp_buf.Length);
                ReqTimer_Cnt = 0;

                //to do
            }
            else if (e.KeyCode == Keys.Escape)
            {
                Activi_Change__Setting(null, null);
            }
            else
            {
                return;
            }
        }

        private void button_Reset_Click(object sender, EventArgs e)
        {
            label_CompileDate.Text = "";
            byte[] temp_buf = new byte[TableGetMaxLength];
            byte[] Temp_MBICResetCmd = { 0x16, 0x16, 0x16, 0x16, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x48, 0x00, 0x14, 0x06, 0x09, 0x00, 0x14, 0x33, 0x00, 0x01, 0x00, 0x04, 0xa7, 0xe0, 0x0e, 0x01, 0x00, 0xac, 0xda, 0x03 };
           // serial.Serial_DataSend(Temp_MBICResetCmd, Temp_MBICResetCmd.Length);
            //return;
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Header] = BLUECELL_HEADER;
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type] = (byte)Bluecell_BootProtocol.DATATYPE.BLUECELL_SOFTWARERESET;
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length_H] = Convert.ToByte((TableGetMaxLength - 2 & 0xFF00 )>> 8);
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length_L] = Convert.ToByte((TableGetMaxLength - 2 & 0x00FF));
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_CrcIndex] = TableGetMaxLength - 2;
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data] = (byte)1;
            serial.Serial_DataSend(temp_buf, temp_buf.Length);
            ReqTimer_Cnt = 0;
        }

        private void numericUpDown_ATT_DL1_ValueChanged(object sender, EventArgs e)
        {

        }
        



        private void button_LedTest_Click(object sender, EventArgs e)
        {
            byte[] temp_buf = new byte[BLUECELL_RESET_LENGTH];
            Button button = (Button)sender;
            DATATYPE datatype;
            ReqTimer_Cnt = 0;
            switch (button.Name)
            {
                case "button_LedTest":
                    datatype = DATATYPE.Bluecell_LED_TEST;
                    temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data] = 1;
                    break;
                default:
                    MessageBox.Show("잘 못된 값 입니다. 확인 부탁드립니다.");
                    return;
            }
            //pictureBox.Visible = false;
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Header] = BLUECELL_HEADER;
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type] = Convert.ToByte(datatype);
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length_H] = 0;
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length_L] = 6;
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_CrcIndex] = 5;
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 1] = 0;
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 2] = 1; //CRC
            serial.Serial_DataSend(temp_buf, temp_buf.Length);
        }
        UInt32[] crc32_tab = {
        0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
        0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
        0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
        0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
        0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
        0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
        0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
        0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
        0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
        0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
        0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
        0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
        0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
        0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
        0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
        0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
        0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
        0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
        0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
        0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
        0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
        0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
        0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
        0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
        0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
        0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
        0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
        0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
        0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
        0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
        0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
        0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
        0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
        0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
        0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
        0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
        0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
        0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
        0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
        0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
        0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
        0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
        0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
    };

        public UInt32 crc32(byte[] buf, UInt32 size)						
        {						
            
            UInt32 crcret = 0;
            int a = 0;

            
            crcret = crcret ^ ~0U;						
						
            while (size-- > 0) {						
                //printf("index : size :  %d    buf %x \r\n", size,* p);
                crcret = crc32_tab[(crcret ^ buf[a++]) & 0xFF] ^ (crcret >> 8);			
            }						
						
            return crcret ^ ~0U;						
        }

        public byte[] MBIC_BootLoader_DataArray;
        byte[] MBIC_Add_BootLoader_DataArray = new byte[128];
        const string MBIC_HeaderName = "JT-NRDAS ";
        
        public byte[] DataToConvertHex(string date)
        {
            char[] tmpret;
            byte[] ret = new byte[6];
            tmpret = date.ToCharArray();

            for (int i = 0; i < date.Length/2; i++)
            {
                ret[i] = Convert.ToByte((tmpret[i * 2] & 0x0F) * 10) ;
                ret[i] += Convert.ToByte((tmpret[(i * 2) + 1] & 0x0F));
            }

            return ret;
        }


        public Crc16 crc = new Crc16();

        byte[] MBIC_BootLoaderData;
        public MBIC_DownLoadWnc mbic_downloadwnc = new MBIC_DownLoadWnc();
        private void button_Test_Click(object sender, EventArgs e)
        {
#if false
            string MBIC_HeaderFileName = "jhfs-mbic-nrdas-v00.00." + numericUpDown_Version.Text+ ".mbc";
            char[] tempchardata;
            int TotalFrame = 0;
            OpenFileDialog Mbic_ofd = new OpenFileDialog();
            UInt32 Crcret = 0;
            byte[] tempdata = new byte[1027];
            int i = 0;
            int SendDataLength = 0;
            UInt16 CrcRet = 0;


            timer_JdasMbic.Stop(); //타이머를 멈춘다.
            //파일오픈창 생성 및 설정
            Mbic_ofd.Title = "업데이터 파일 탐색기";
            Mbic_ofd.FileName = "*.bin";
            Mbic_ofd.Filter = "binary 파일 (*.binary,*.bin) | *.binary;, *.bin; |  모든 파일 (*.*) | *.*";
            string s3 = DateTime.Now.ToString("yyMMddHHmmss");
            //string s3 = DateTime.Now.ToString("yyMMdd");

            //파일 오픈창 로드
            DialogResult dr = Mbic_ofd.ShowDialog();

            //OK버튼 클릭시
            if (dr == DialogResult.OK)
            {
                //File명과 확장자를 가지고 온다.
                string fileName = Mbic_ofd.SafeFileName;
                
                //File경로와 File명을 모두 가지고 온다.
                string fileFullName = Mbic_ofd.FileName;
                
                //File경로만 가지고 온다.
                string filePath = fileFullName.Replace(fileName, "");
                //this.serial.debug_hextoasciiConvert();

                //출력 예제용 로직
                //  label1.Text = "File Name  : " + fileName;
                // label2.Text = "Full Name  : " + fileFullName;
                // label3.Text = "File Path  : " + filePath;`
                //File경로 + 파일명 리턴
                //JT-NRDAS 

                tempchardata = MBIC_HeaderName.ToCharArray();
                for(i = 0; i < tempchardata.Length; i++)
                {
                    MBIC_Add_BootLoader_DataArray[i] = Convert.ToByte(tempchardata[i]);
                }
                MBIC_Add_BootLoader_DataArray[9] = 0x20; //file type : MBIC 0x20
                MBIC_Add_BootLoader_DataArray[10] = 0x00; //file type : CPU 0x00
                MBIC_Add_BootLoader_DataArray[11] = 0x00;//version
                MBIC_Add_BootLoader_DataArray[12] = 0x00;//version
                MBIC_Add_BootLoader_DataArray[13] = 0x01;//version

                tempchardata = MBIC_HeaderFileName.ToCharArray();
                for (i = 14; i < 14 + tempchardata.Length + 12; i++) // Total 41byte Filename
                {
                    try
                    {
                        MBIC_Add_BootLoader_DataArray[i] = Convert.ToByte(tempchardata[i - 14]);
                    }
                    catch
                    {
                        MBIC_Add_BootLoader_DataArray[i] = 0x20;
                    }
                }
                
                tempchardata = s3.ToCharArray();
                for (i = 55; i < 54 + tempchardata.Length / 2 + 1; i++)
                {
                    MBIC_Add_BootLoader_DataArray[i] = DataToConvertHex(s3)[i - 55];
                }

                MBIC_BootLoader_DataArray = File.ReadAllBytes(Mbic_ofd.FileName);
                MBIC_Add_BootLoader_DataArray[i++] = Convert.ToByte(((MBIC_BootLoader_DataArray.Length + 128) & 0xFF00) >> 8);
                MBIC_Add_BootLoader_DataArray[i++] = Convert.ToByte(((MBIC_BootLoader_DataArray.Length + 128)& 0x00FF));

                Crcret = crc32(MBIC_BootLoader_DataArray, Convert.ToUInt32(MBIC_BootLoader_DataArray.Length));
                MBIC_Add_BootLoader_DataArray[i++] = Convert.ToByte((Crcret & 0xFF000000) >> (8 * 3));
                MBIC_Add_BootLoader_DataArray[i++] = Convert.ToByte((Crcret & 0x00FF0000) >> (8 * 2));
                MBIC_Add_BootLoader_DataArray[i++] = Convert.ToByte((Crcret & 0x0000FF00) >> (8 * 1));
                MBIC_Add_BootLoader_DataArray[i++] = Convert.ToByte((Crcret & 0x000000FF) >> (8 * 0));

                for (i = 0; i < 62; i++)
                    MBIC_Add_BootLoader_DataArray[66 + i] = 0x00;

                byte[] RetBinary = new byte[MBIC_Add_BootLoader_DataArray.Length + MBIC_BootLoader_DataArray.Length];
                Array.Copy(MBIC_Add_BootLoader_DataArray, 0, RetBinary, 0, MBIC_Add_BootLoader_DataArray.Length);
                Array.Copy(MBIC_BootLoader_DataArray, 0, RetBinary, MBIC_Add_BootLoader_DataArray.Length, MBIC_BootLoader_DataArray.Length);

//                System.IO.FileStream infile = new System.IO.FileStream("FileName.bin", System.IO.FileMode.Create); //파일 스트림 선언
                //infile.Write(RetBinary, 0, RetBinary.Length);    //쓰기
//                infile.Close();                  //꼭 닫아 주세요. 파일 입출력엔 엄청 중요하죠.

                MBIC_BootLoaderData = bluecell_BootProtocol.MBIC_HeaderMergeFunction(RetBinary, RetBinary.Length);

                /*Download Start Request*/
                /*tempdata[0] = Convert.ToByte(((MBIC_BootLoader_DataArray.Length + 128) & 0xFF000000) >> 24);
                tempdata[1] = Convert.ToByte(((MBIC_BootLoader_DataArray.Length + 128) & 0x00FF0000) >> 16);
                tempdata[2] = Convert.ToByte(((MBIC_BootLoader_DataArray.Length + 128) & 0x0000FF00) >> 8);
                tempdata[3] = Convert.ToByte(((MBIC_BootLoader_DataArray.Length + 128) & 0x000000FF));*/
                TotalFrame = MBIC_BootLoader_DataArray.Length / 1024;
                if(MBIC_BootLoader_DataArray.Length % 1024 > 0)
                {
                    TotalFrame += 1;
                }

                tempdata[0] = Convert.ToByte(((TotalFrame) & 0xFF000000) >> 24);
                tempdata[1] = Convert.ToByte(((TotalFrame) & 0x00FF0000) >> 16);
                tempdata[2] = Convert.ToByte(((TotalFrame) & 0x0000FF00) >> 8);
                tempdata[3] = Convert.ToByte(((TotalFrame) & 0x000000FF));
                tempdata[4] = 0;
                tempdata[5] = 0;
                tempdata[6] = 0;
                tempdata[7] = 0;
                tempdata = bluecell_BootProtocol.MBIC_HeaderMergeFunction(tempdata, 8);
                tempdata[(int)MBICProt_st.MBIC_CMD_0] = 0x10;

                SendDataLength = 8 + 22 + 3;
                tempdata[(int)MBICProt_st.MBIC_LENGTH_0] = 0x00;
                tempdata[(int)MBICProt_st.MBIC_LENGTH_1] = (Byte)(SendDataLength - 25);
                tempdata[(int)MBICProt_st.MBIC_HEADERCHECKSUM_0] = crc.Chksum_Create(tempdata);


                CrcRet = crc.MBIC_CRC16_Generate(tempdata, SendDataLength - 25); //Length = Total Length - Header Length - Taile Length
                tempdata[SendDataLength - 3] = Convert.ToByte((CrcRet & 0xFF00) >> 8);
                tempdata[SendDataLength - 2] = Convert.ToByte(CrcRet & 0x00FF);
                tempdata[SendDataLength - 1] = 0x03;


                this.serial.Serial_DataSend(tempdata, 8 + 22 + 3);
                //this.serial.Serial_DataSend(MBIC_BootLoaderData, 1024 + 22 + 3);

                /*    
                    tempdata[0] = 0xbe;
                    tempdata[1] = Termianl_Reset;
                    tempdata[2] = 0x02;
                    tempdata[3] = STH30_CreateCrc(tempdata, tempdata[2]);
                    tempdata[4] = 0xeb;
                    this.serial.Serial_DataSend(tempdata, 5);*/
                try
                {
                    // Controller_Debug.Controller_TX_TextLoad(tempdata);
                }
                catch { }
            }
            //취소버튼 클릭시 또는 ESC키로 파일창을 종료 했을경우
            else if (dr == DialogResult.Cancel)
            {
            }
#else
            timer_JdasMbic.Stop(); //타이머를 멈춘다.
            mbic_downloadwnc = new MBIC_DownLoadWnc();
            mbic_downloadwnc.Owner = this; //부모값넘김

            mbic_downloadwnc.Show();
            mbic_downloadwnc.main = this;
#endif
        }
        private void button_Make_Click(object sender, EventArgs e)
        {
            char[] tempchardata;
            OpenFileDialog Mbic_ofd = new OpenFileDialog();
            UInt32 Crcret = 0;
            byte[] tempdata = new byte[1027];
            int i = 0;
            /*string dec = ;
            string hex = Convert.ToString(int.Parse(dec, 16).ToUpper();*/
            string hex = "24";
            string dec = Convert.ToInt32(hex, 10).ToString();
            char pad = '0';

            string MBIC_HeaderFileName = "jhfs-mbic-nrdas-v"+ numericUpDown_Version1.Text.PadLeft(2,pad)+ "." + numericUpDown_Version2.Text.PadLeft(2, pad) + "." + numericUpDown_Version3.Text.PadLeft(2, pad) + ".mbc";
            //현재 사용자 바탕화면 경로

            string localpath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            timer_JdasMbic.Stop(); //타이머를 멈춘다.
            //파일오픈창 생성 및 설정
            Mbic_ofd.Title = "업데이터 파일 탐색기";
            Mbic_ofd.FileName = "*.bin";
            Mbic_ofd.Filter = "binary 파일 (*.binary,*.bin) | *.binary;, *.bin; | 모든 파일 (*.*) | *.*";
            string s3 = DateTime.Now.ToString("yyMMddHHmmss");
            //string s3 = DateTime.Now.ToString("yyMMdd");

            //파일 오픈창 로드
            DialogResult dr = Mbic_ofd.ShowDialog();

            //OK버튼 클릭시
            if (dr == DialogResult.OK)
            {
                //File명과 확장자를 가지고 온다.
                string fileName = Mbic_ofd.SafeFileName;

                //File경로와 File명을 모두 가지고 온다.
                string fileFullName = Mbic_ofd.FileName;

                //File경로만 가지고 온다.
                string filePath = fileFullName.Replace(fileName, "");
                //this.serial.debug_hextoasciiConvert();

                //출력 예제용 로직
                //  label1.Text = "File Name  : " + fileName;
                // label2.Text = "Full Name  : " + fileFullName;
                // label3.Text = "File Path  : " + filePath;`
                //File경로 + 파일명 리턴
                //JT-NRDAS 

                tempchardata = MBIC_HeaderName.ToCharArray();
                for (i = 0; i < tempchardata.Length; i++)
                {
                    MBIC_Add_BootLoader_DataArray[i] = Convert.ToByte(tempchardata[i]);
                }
                MBIC_Add_BootLoader_DataArray[9] = 0x20; //file type : MBIC 0x20
                MBIC_Add_BootLoader_DataArray[10] = 0x00; //file type : CPU 0x00
                MBIC_Add_BootLoader_DataArray[11] = Convert.ToByte(numericUpDown_Version1.Text, 16);//version
                MBIC_Add_BootLoader_DataArray[12] = Convert.ToByte(numericUpDown_Version2.Text, 16);//version
                MBIC_Add_BootLoader_DataArray[13] = Convert.ToByte(numericUpDown_Version3.Text,16);//version

                tempchardata = MBIC_HeaderFileName.ToCharArray();
                for (i = 14; i < 14 + tempchardata.Length + 12; i++) // Total 41byte Filename
                {
                    try
                    {
                        MBIC_Add_BootLoader_DataArray[i] = Convert.ToByte(tempchardata[i - 14]);
                    }
                    catch
                    {
                        MBIC_Add_BootLoader_DataArray[i] = 0x20;
                    }
                }

                tempchardata = s3.ToCharArray();
                for (i = 55; i < 55 + tempchardata.Length / 2 ; i++)
                {
                    MBIC_Add_BootLoader_DataArray[i] = DataToConvertHex(s3)[i - 55];
                }

                MBIC_BootLoader_DataArray = File.ReadAllBytes(Mbic_ofd.FileName);

                MBIC_Add_BootLoader_DataArray[i++] = Convert.ToByte((MBIC_BootLoader_DataArray.Length & 0xFF000000) >> (8 * 3));
                MBIC_Add_BootLoader_DataArray[i++] = Convert.ToByte((MBIC_BootLoader_DataArray.Length & 0x00FF0000) >> (8 * 2));
                MBIC_Add_BootLoader_DataArray[i++] = Convert.ToByte((MBIC_BootLoader_DataArray.Length & 0x0000FF00) >> (8 * 1));
                MBIC_Add_BootLoader_DataArray[i++] = Convert.ToByte((MBIC_BootLoader_DataArray.Length & 0x000000FF) >> (8 * 0));

                Crcret = crc32( MBIC_BootLoader_DataArray, Convert.ToUInt32(MBIC_BootLoader_DataArray.Length));
                MBIC_Add_BootLoader_DataArray[i++] = Convert.ToByte((Crcret & 0xFF000000) >> (8 * 3));
                MBIC_Add_BootLoader_DataArray[i++] = Convert.ToByte((Crcret & 0x00FF0000) >> (8 * 2));
                MBIC_Add_BootLoader_DataArray[i++] = Convert.ToByte((Crcret & 0x0000FF00) >> (8 * 1));
                MBIC_Add_BootLoader_DataArray[i++] = Convert.ToByte((Crcret & 0x000000FF) >> (8 * 0));

                for (i = 0; i < 59; i++)
                    MBIC_Add_BootLoader_DataArray[69 + i] = 0x00;

                byte[] RetBinary = new byte[MBIC_Add_BootLoader_DataArray.Length + MBIC_BootLoader_DataArray.Length];
                Array.Copy(MBIC_Add_BootLoader_DataArray, 0, RetBinary, 0, MBIC_Add_BootLoader_DataArray.Length);
                Array.Copy(MBIC_BootLoader_DataArray, 0, RetBinary, MBIC_Add_BootLoader_DataArray.Length, MBIC_BootLoader_DataArray.Length);

                System.IO.FileStream infile = new System.IO.FileStream(localpath+"\\" + MBIC_HeaderFileName, System.IO.FileMode.Create); //파일 스트림 선언
                infile.Write(RetBinary, 0, RetBinary.Length);    //쓰기d
                infile.Close();                  //꼭 닫아 주세요. 파일 입출력엔 엄청 중요하죠.

             


            }
            //취소버튼 클릭시 또는 ESC키로 파일창을 종료 했을경우
            else if (dr == DialogResult.Cancel)
            {
            }
        }

      

        private void comboBox_BankSel_SelectedIndexChanged(object sender, EventArgs e)
        {
            byte[] temp_buf = new byte[9];
            byte Length = 5;
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Header] = BLUECELL_HEADER;
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type] = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_BankSelect;
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length_H] = 0;
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length_L] = 5;
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_CrcIndex] = 5;
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data] = Convert.ToByte(Convert.ToByte(comboBox_BankSel.SelectedIndex) + 1);
            UInt16 CRCRET = crc.CRC16_Generate(temp_buf, Length);
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 1] = Convert.ToByte((CRCRET & 0xFF00) >> 8);
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 2] = Convert.ToByte(CRCRET & 0x00FF);
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 3] = 0xeb;
            serial.Serial_DataSend(temp_buf, temp_buf.Length);
            ReqTimer_Cnt = 0;
        }
        public IEnumerable<int> ExtractNumbers(string text)
        {
            text += " ";
            var temp = string.Empty;
            for (var i = 0; i < text.Length; i++)
            {
                if (char.IsDigit(text[i]))
                {
                    if ('-'.Equals(text[i - 1]))
                    {
                        temp += text[i - 1];
                    }
                    temp += text[i];
                }
                else if (temp.Length > 0)
                {
                    yield return int.Parse(temp);
                    temp = string.Empty;
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            label_CompileDate.Text = "";
            byte[] temp_buf = new byte[TableGetMaxLength];
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Header] = BLUECELL_HEADER;
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type] = (byte)Bluecell_BootProtocol.DATATYPE.BLUECELL_SOFTWARERESET;
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length_H] = Convert.ToByte((TableGetMaxLength - 4 & 0xFF00) >> 8);
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length_L] = Convert.ToByte((TableGetMaxLength - 4 & 0x00FF));
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_CrcIndex] = TableGetMaxLength - 2;
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data] = (byte)1;
            UInt16 CRCRET = crc.CRC16_Generate(temp_buf, TableGetMaxLength - 4);
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 1] = Convert.ToByte((CRCRET & 0xFF00) >> 8);
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 2] = Convert.ToByte(CRCRET & 0x00FF);
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 3] = 0xeb;
            serial.Serial_DataSend(temp_buf, temp_buf.Length);
            ReqTimer_Cnt = 0;
        }

        private void button_FRBT_TimeSetting_Click(object sender, EventArgs e)
        {
            string Time = textBox_FRBT_TIME.Text;
            string[] Timearray = Time.Split('-');
            int i = 0;

            byte[] Timedata = new byte[6 + 4 + 3]; //Header CRC 4byte TYPE LENGTH 3byte
            Timedata[0] = 0xbe;
            Timedata[1] = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_TimeSetting;
            Timedata[2] = 0;
            Timedata[3] = (byte)(Timedata.Length - 4);
            for (i = 0; i < 6; i++)
                Timedata[4 + i] = Convert.ToByte(Timearray[i]);

            UInt16 CRCRET = crc.CRC16_Generate(Timedata, Timedata[(int)Bluecell_ProtIndex_p.Bluecell_Length_L]);
            Timedata[4 + i++] = Convert.ToByte((CRCRET & 0xFF00) >> 8);
            Timedata[4 + i++] = Convert.ToByte(CRCRET & 0x00FF);
            serial.Serial_DataSend(Timedata, Timedata.Length);


        }

        private void button_FactorySet_Click(object sender, EventArgs e)
        {
            byte[] tempdata = new byte[1 + 4 + 3]; //Header CRC 4byte TYPE LENGTH 3byte
            tempdata[0] = 0xbe;
            tempdata[1] = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_Factory_Set;
            tempdata[2] = 0;
            tempdata[3] = (byte)(tempdata.Length - 3);
            tempdata[5] = 1;
            UInt16 CRCRET = crc.CRC16_Generate(tempdata, tempdata[(int)Bluecell_ProtIndex_p.Bluecell_Length_L]);
            tempdata[6] = Convert.ToByte((CRCRET & 0xFF00) >> 8);
            tempdata[7] = Convert.ToByte(CRCRET & 0x00FF);
            serial.Serial_DataSend(tempdata, tempdata.Length);

        }

        private void button_Carrier_Click(object sender, EventArgs e)
        {
            byte[] tempdata = new byte[1 + 4 + 3]; //Header CRC 4byte TYPE LENGTH 3byte
            tempdata[0] = 0xbe;
            tempdata[1] = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_CarrierOnOff;
            tempdata[2] = 0;
            tempdata[3] = (byte)(tempdata.Length - 4);
            tempdata[5] = 1;
            UInt16 CRCRET = crc.CRC16_Generate(tempdata, tempdata[(int)Bluecell_ProtIndex_p.Bluecell_Length_L]);
            tempdata[6] = Convert.ToByte((CRCRET & 0xFF00) >> 8);
            tempdata[7] = Convert.ToByte(CRCRET & 0x00FF);
            serial.Serial_DataSend(tempdata, tempdata.Length);
        }

        private void button_Carrier_OFF_Click(object sender, EventArgs e)
        {
            byte[] tempdata = new byte[1 + 4 + 3]; //Header CRC 4byte TYPE LENGTH 3byte
            tempdata[0] = 0xbe;
            tempdata[1] = (byte)Bluecell_BootProtocol.DATATYPE.Bluecell_CarrierOnOff;
            tempdata[2] = 0;
            tempdata[3] = (byte)(tempdata.Length - 4);
            tempdata[5] = 0;
            UInt16 CRCRET = crc.CRC16_Generate(tempdata, tempdata[(int)Bluecell_ProtIndex_p.Bluecell_Length_L]);
            tempdata[6] = Convert.ToByte((CRCRET & 0xFF00) >> 8);
            tempdata[7] = Convert.ToByte(CRCRET & 0x00FF);
            serial.Serial_DataSend(tempdata, tempdata.Length);
        }


        private void button_PATH_Ctrl_Click(object sender, EventArgs e)
        {
            byte[] temp_buf = new byte[BLUECELL_RESET_LENGTH];
            Button button = (Button)sender;
            DATATYPE datatype;
            ReqTimer_Cnt = 0;

            if (button.Text == "OFF")
                temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data] = 1;
            else
                temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data] = 0;

            switch (button.Name)
            {
                case "button_DL1_PATH":
                    datatype = DATATYPE.ATT_DL1_PATH;
                    break;
                case "button_DL2_PATH":
                    datatype = DATATYPE.ATT_DL2_PATH;
                    break;
                case "button_DL3_PATH":
                    datatype = DATATYPE.ATT_DL3_PATH;
                    break;
                case "button_DL4_PATH":
                    datatype = DATATYPE.ATT_DL4_PATH;
                    break;
                case "button_UL1_PATH":
                    datatype = DATATYPE.ATT_UL1_PATH;
                    break;
                case "button_UL2_PATH":
                    datatype = DATATYPE.ATT_UL2_PATH;
                    break;
                case "button_UL3_PATH":
                    datatype = DATATYPE.ATT_UL3_PATH;
                    break;
                case "button_UL4_PATH":
                    datatype = DATATYPE.ATT_UL4_PATH;
                    break;
                case "button_SelfTest1":
                    datatype = DATATYPE.ATT_SelfTest;
                    break;
                case "button_SelfTest2":
                    datatype = DATATYPE.ATT_SelfTest;
                    break;
                case "button_SelfTest3":
                    datatype = DATATYPE.ATT_SelfTest;
                    break;
                case "button_SelfTest4":
                    datatype = DATATYPE.ATT_SelfTest;
                    break;
                case "button_DL_Shutdown":
                    datatype = DATATYPE.Bluecell_DLI_Shutdown_ON_OFF;
                    break;
                case "button_UL_Shutdown":
                    datatype = DATATYPE.Bluecell_ULO_Shutdown_ON_OFF;
                    break;
                case "button_ALC":
                    datatype = DATATYPE.Bluecell_ULO_ALC_ON_OFF;
                    break;
                case "button_AGC":
                    datatype = DATATYPE.Bluecell_DLI_AGC_ON_OFF;
                    break;
                case "button_Carrier":
                    datatype = DATATYPE.Bluecell_CarrierOnOff;
                    break;
                case "button_TempShutdown":
                    datatype = DATATYPE.Bluecell_Temp_Shutdown_Path_ON_OFF;
                    break;
                case "button_LedTest":
                    datatype = DATATYPE.Bluecell_LED_TEST;
                    temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data] = 1;
                    break;
                default:
                    MessageBox.Show("잘 못된 값 입니다. 확인 부탁드립니다.");
                    return;
            }
            
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Header] = BLUECELL_HEADER;
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type] = Convert.ToByte(datatype);
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length_H] = ((6 & 0xFF00) >> 8);
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length_L] = (6 & 0x00FF);
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_CrcIndex] = 5;
            //temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data] = 0;
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 1] = 0;
            UInt16 CRCRET = crc.CRC16_Generate(temp_buf, temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length_L]);
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 2] = Convert.ToByte((CRCRET & 0xFF00) >> 8);//CRC
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 3] = Convert.ToByte(CRCRET & 0x00FF);//CRC
            serial.Serial_DataSend(temp_buf, temp_buf.Length);
        }
        
        private void panel_MainTitle_Paint(object sender, PaintEventArgs e)
        {
           /* LinearGradientBrush br = new LinearGradientBrush(this.ClientRectangle,
                                                             Color.FromArgb(50, 56, 203),
                                                             Color.FromArgb(70, 255, 255),
                                                             180,
                                                             false);
            e.Graphics.FillRectangle(br, this.ClientRectangle);*/

        }

        private void panel_Serial_Paint(object sender, PaintEventArgs e)
        {

        }
        private Point mousePoint = new Point(0, 0);
        private void panel_MainTitle_MouseMove(object sender, MouseEventArgs e)
        {
            if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
            {
                Location = new Point(this.Left - (mousePoint.X - e.X),
                    this.Top - (mousePoint.Y - e.Y));
            }
            /*  if (e.Button == MouseButtons.Left)
              {
                  this.Location = new Point(this.Location.X + (mCurrentPosition.X + e.X), this.Location.Y + (mCurrentPosition.Y + e.Y));
              }*/
        }

        private void panel_MainTitle_DragEnter(object sender, DragEventArgs e)
        {
           /* if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                e.Effect = DragDropEffects.All;
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }*/
        }

        private void panel_MainTitle_MouseDown(object sender, MouseEventArgs e)
        {
            mousePoint = new Point(e.X, e.Y);
        }

        private void button_Exit_Click(object sender, EventArgs e)
        {
            Process.GetCurrentProcess().Kill();

        }

        private void button_ManufactureSet_Click(object sender, EventArgs e)
        {
            byte[] temp_buf = new byte[10];
            Button button = (Button)sender;
            DATATYPE datatype;
            ReqTimer_Cnt = 0;
            char[] tempchardata;
            string s3 = DateTime.Now.ToString("yyMMdd");

            tempchardata = s3.ToCharArray();
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data] = DataToConvertHex(s3)[0];
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 1] = DataToConvertHex(s3)[1];
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 2] = DataToConvertHex(s3)[2];
            datatype = DATATYPE.Bluecell_ManufactureDateSet;

            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Header] = BLUECELL_HEADER;
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type] = Convert.ToByte(datatype);
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length_H] = ((7 & 0xFF00) >> 8);
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length_L] = (7 & 0x00FF);
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_CrcIndex] = 5;
            //temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data] = 0;
            UInt16 CRCRET = crc.CRC16_Generate(temp_buf, temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length_L]);
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 3] = Convert.ToByte((CRCRET & 0xFF00) >> 8);//CRC
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 4] = Convert.ToByte(CRCRET & 0x00FF);//CRC
            serial.Serial_DataSend(temp_buf, temp_buf.Length);
        }
        //Serial Number : BL-J37C00-20050004  Example 
        private void button_SerialNumverSet_Click(object sender, EventArgs e)
        {
            byte[] temp_buf = new byte[26];
            int i = 0;
            Button button = (Button)sender;
            DATATYPE datatype;
            ReqTimer_Cnt = 0;
            char[] data = textBox_SerialNumber.Text.ToCharArray();

            //temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data] = textBox_SerialNumber.Text.Split();
            datatype = DATATYPE.Bluecell_SerialNumberSet;
            for (i = 0; i < data.Length; i++)
                temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + i] = (Byte)data[i];

            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Header] = BLUECELL_HEADER;
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type] = Convert.ToByte(datatype);
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length_H] = ((23 & 0xFF00) >> 8);
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length_L] = (23 & 0x00FF);
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_CrcIndex] = 5;
            //temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data] = 0;
            UInt16 CRCRET = crc.CRC16_Generate(temp_buf, temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length_L]);
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + i++] = Convert.ToByte((CRCRET & 0xFF00) >> 8);//CRC
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + i++] = Convert.ToByte(CRCRET & 0x00FF);//CRC
            serial.Serial_DataSend(temp_buf, temp_buf.Length);
        }

        private void button_PCBVersionSet_Click(object sender, EventArgs e)
        {
            byte[] temp_buf = new byte[9];
            int i = 0;
            Button button = (Button)sender;
            DATATYPE datatype;
            ReqTimer_Cnt = 0;
            string[] data = textBox_PcbVersion.Text.Split('.');

            //temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data] = textBox_SerialNumber.Text.Split();
            datatype = DATATYPE.Bluecell_PCBVersionSet;
            for (i = 0; i < data.Length; i++)
                temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + i] = Convert.ToByte(data[i]);

            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Header] = BLUECELL_HEADER;
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type] = Convert.ToByte(datatype);
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length_H] = ((6 & 0xFF00) >> 8);
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length_L] = (6 & 0x00FF);
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_CrcIndex] = 5;
            //temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data] = 0;
            UInt16 CRCRET = crc.CRC16_Generate(temp_buf, temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length_L]);
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + i++] = Convert.ToByte((CRCRET & 0xFF00) >> 8);//CRC
            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + i++] = Convert.ToByte(CRCRET & 0x00FF);//CRC
            serial.Serial_DataSend(temp_buf, temp_buf.Length);
        }
    }
    class AutoClosingMessageBox
    {
        [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
        static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
        [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
        static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);

        System.Threading.Timer _timeoutTimer; //쓰레드 타이머
        string _caption;

        const int WM_CLOSE = 0x0010; //close 명령 

        AutoClosingMessageBox(string text, string caption, int timeout)
        {
            _caption = caption;
            _timeoutTimer = new System.Threading.Timer(OnTimerElapsed,
                null, timeout, System.Threading.Timeout.Infinite);
            MessageBox.Show(text, caption);
        }

        //생성자 함수
        public static void Show(string text, string caption, int timeout)
        {
            new AutoClosingMessageBox(text, caption, timeout);
        }

        //시간이 다되면 close 메세지를 보냄

        void OnTimerElapsed(object state)
        {
            IntPtr mbWnd = FindWindow(null, _caption);
            if (mbWnd != IntPtr.Zero)
                SendMessage(mbWnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
            _timeoutTimer.Dispose();
        }
    }
}
