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

namespace FleetPC_4_E
{
    public partial class CSharpExample : Form
    {

        [DllImport("inpout32.dll")]
        private static extern UInt32 IsInpOutDriverOpen();
        [DllImport("inpout32.dll")]
        private static extern void Out32(UInt16 PortAddress, UInt32 Data);
        [DllImport("inpout32.dll")]
        //private static extern char Inp32(UInt16 PortAddress);
        private static extern UInt32 Inp32(UInt16 PortAddress);


        [DllImport("inpout32.dll")]
        private static extern void DlPortWritePortUshort(short PortAddress, ushort Data);
        [DllImport("inpout32.dll")]
        private static extern ushort DlPortReadPortUshort(short PortAddress);

        [DllImport("inpout32.dll")]
        private static extern void DlPortWritePortUlong(int PortAddress, uint Data);
        [DllImport("inpout32.dll")]
        private static extern uint DlPortReadPortUlong(int PortAddress);

        [DllImport("inpout32.dll")]
        private static extern bool IsXP64Bit();
        [DllImport("inpout32.dll")]
        private static extern int Opendriver(bool bX64);
        [DllImport("inpout32.dll")]
        private static extern void Closedriver();


        [DllImport("inpoutx64.dll")]
        private static extern bool GetPhysLong(ref int PortAddress, ref uint Data);
        [DllImport("inpoutx64.dll")]
        private static extern bool SetPhysLong(ref int PortAddress, ref uint Data);


        [DllImport("inpoutx64.dll", EntryPoint = "IsInpOutDriverOpen")]
        private static extern UInt32 IsInpOutDriverOpen_x64();
        [DllImport("inpoutx64.dll", EntryPoint = "Out32")]
        private static extern void Out32_x64(UInt16 PortAddress, UInt32 Data);
        [DllImport("inpoutx64.dll", EntryPoint = "Inp32")]
        //private static extern char Inp32_x64(UInt16 PortAddress);
        private static extern UInt32 Inp32_x64(UInt16 PortAddress);

        [DllImport("inpoutx64.dll", EntryPoint = "DlPortWritePortUshort")]
        private static extern void DlPortWritePortUshort_x64(short PortAddress, ushort Data);
        [DllImport("inpoutx64.dll", EntryPoint = "DlPortReadPortUshort")]
        private static extern ushort DlPortReadPortUshort_x64(short PortAddress);

        [DllImport("inpoutx64.dll", EntryPoint = "DlPortWritePortUlong")]
        private static extern void DlPortWritePortUlong_x64(int PortAddress, uint Data);
        [DllImport("inpoutx64.dll", EntryPoint = "DlPortReadPortUlong")]
        private static extern uint DlPortReadPortUlong_x64(int PortAddress);

        [DllImport("inpoutx64.dll", EntryPoint = "GetPhysLong")]
        private static extern bool GetPhysLong_x64(ref int PortAddress, ref uint Data);
        [DllImport("inpoutx64.dll", EntryPoint = "SetPhysLong")]
        private static extern bool SetPhysLong_x64(ref int PortAddress, ref uint Data);

        [DllImport("inpoutx64.dll", EntryPoint = "IsXP64Bit")]
        private static extern bool IsXP64Bit_x64();
        [DllImport("inpoutx64.dll", EntryPoint = "Opendriver")]
        private static extern int Opendriver_x64(bool bX64);
        [DllImport("inpoutx64.dll", EntryPoint = "Closedriver")]
        private static extern void Closedriver_x64();

        private UInt16 SMBus_Base = 0xF040;
        private UInt16 SMBus_MCU_SlaveAddress = 0x94;
        private bool[] DIs;//DI value
        private bool[] DOs;//DO value
		

 /// <summary>
    /// DIO enum list
    /// </summary>
    public enum DIO
    {
        DO1 = 0,
        DO2 = 1,
        DO3 = 2,
        DO4 = 3,
        DI1 = 0,
        DI2 = 1,
        DI3 = 2,
        DI4 = 3,
    };


    public static class Switch
    {
        public const bool ON = true;
        public const bool OFF = false;
        public const bool Enable = true;
        public const bool Disable = false;
        public const bool High = true;
        public const bool Low = false;
    }



        bool m_bX64 = false;

        public CSharpExample()
        {
            InitializeComponent();
            Driver_Check();
            SPIO_INI();
        }

        private void Driver_Check()
        {
            uint nResult = 0;

            nResult = IsInpOutDriverOpen();
            m_bX64 = IsXP64Bit();
            if (nResult == 0)
            {
                Opendriver(m_bX64);
                //MessageBox.Show("Create driver");
                Closedriver();
            }

        }

        private void SMB_Write(UInt16 SMB_Addr, UInt16 DEV_Address, UInt16 DEV_Reg, UInt16 Value)
        {
            Out32(SMB_Addr, 0xFF);                                              // Clear SMBUS Status
            Thread.Sleep(10);                                                  // Delay 10 ms (1000 is 1 Sec) 
            Out32((ushort)(SMB_Addr + 0x04), DEV_Address);                      // EEPROM Address AE -Write / AF -Read
            Thread.Sleep(10);
            Out32((ushort)(SMB_Addr + 0x03), DEV_Reg);                          // EEPROM Reg Address
            Thread.Sleep(10);
            Out32((ushort)(SMB_Addr + 0x05), Value);                            // Write Data in EEPROM
            Thread.Sleep(10);
            Out32((ushort)(SMB_Addr + 0x02), 0x48);                             // Start to Send 
            Thread.Sleep(10);

        }

        private UInt32 SMB_Read(UInt16 SMB_Addr, UInt16 DEV_Address, UInt16 DEV_Reg)
        {
            UInt32 Value;
            Out32(SMB_Addr, 0xFF);                                              // Clear SMBUS Status
            Thread.Sleep(10);                                                  // Delay 10 ms (1000 is 1 Sec) 
            Out32((ushort)(SMB_Addr + 0x04), (ushort)(DEV_Address + 1));         // EEPROM Address AE -Write / AF -Read
            Thread.Sleep(10);
            Out32((ushort)(SMB_Addr + 0x03), DEV_Reg);                          // EEPROM Reg Address
            Thread.Sleep(10);
            Out32((ushort)(SMB_Addr + 0x02), 0x48);                             // Start to Send 
            Thread.Sleep(10);
            Value = Inp32((ushort)(SMB_Addr + 0x05));                           // Read Data in EEPROM
            Thread.Sleep(10);
            return Value;
        }

        private void SPIO_INI()
        {
            Out32(0x2E, 0x87);                                                  // Super I/O entry key Two 0x87 
            Out32(0x2E, 0x87);
            Out32(0x2E, 0x07);
            Out32(0x2F, 0x06);                                                  // Jump in GPIO
            Out32(0x2E, 0x30);                                                  // Set Base Address Reg 0x30
            Out32(0x2F, 0x01);                                                  // Set Base Address to Enabled
            Out32(0x2E, 0x0aa);                                                 // Exit Super I/O
        }




        private void button3_Click(object sender, EventArgs e)
        {

            UInt32 mini;

            mini = SMB_Read(SMBus_Base, SMBus_MCU_SlaveAddress, 0x39);								// Register 39 bit1 PIO1_25 SIM1 MINI CARD(V3P3_M2B_EN)
            
            mini = mini & 0xFD;			
			SMB_Write(SMBus_Base, SMBus_MCU_SlaveAddress, 0x39, (UInt16)mini);

            Thread.Sleep(2000);                                                 // Delay 2 Sec (1000 is 1 Sec) 

            mini = mini | 0x02;
            SMB_Write(SMBus_Base, SMBus_MCU_SlaveAddress, 0x39, (UInt16)mini);
			MessageBox.Show("Run Mini Card Reset Success", "FleetPC-4-F Test Tools V1.0", MessageBoxButtons.OK, MessageBoxIcon.Information);

        }

        private void button11_Click(object sender, EventArgs e)
        {

			UInt16 Delay_Sec;     // Power Off Delay Time Value
			UInt16 Delay_Min;     // Power Off Delay Time Value
            UInt16 Delay_Hour;     // Power Off Delay Time Value


			Delay_Sec = UInt16.Parse(ignDelayOffSecNumericUpDown.Text, System.Globalization.NumberStyles.HexNumber);
			Delay_Min = UInt16.Parse(ignDelayOffMinNumericUpDown.Text, System.Globalization.NumberStyles.HexNumber);
            Delay_Hour = UInt16.Parse(ignDelayOffHourNumericUpDown.Text, System.Globalization.NumberStyles.HexNumber);

            if ((Delay_Hour < 0) || (Delay_Hour > 23) && (Delay_Min < 0) || (Delay_Min > 59) && (Delay_Sec < 0) || (Delay_Sec > 59))
            {
            MessageBox.Show("Setting error Ignition delay off time (Hour/Min/Sec)", "FleetPC-4-F Test Tools V1.0", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
			else
			{
		
			//SMB address:0xF040; Device address: 0x94; 
            SMB_Write(SMBus_Base, SMBus_MCU_SlaveAddress, 0x66, (UInt16)Delay_Sec);         // Delay Time setting Reg: 0x66, sec
            Thread.Sleep(100);                                       // Delay 100 ms
            SMB_Write(SMBus_Base, SMBus_MCU_SlaveAddress, 0x67, (UInt16)Delay_Min);         // Delay Time setting Reg: 0x67, min
            Thread.Sleep(100);                                       // Delay 100 ms
            SMB_Write(SMBus_Base, SMBus_MCU_SlaveAddress, 0x68, (UInt16)Delay_Hour);         // Delay Time setting Reg: 0x68, hour
            Thread.Sleep(100);                                       // Delay 100 ms
            MessageBox.Show("Setting Success", "FleetPC-4-F Test Tools V1.0", MessageBoxButtons.OK, MessageBoxIcon.Information);
			}


        }

        private void button12_Click(object sender, EventArgs e)
        {

			UInt32 Delay_Sec;     // Power Off Delay Time Value
			UInt32 Delay_Min;     // Power Off Delay Time Value
            UInt32 Delay_Hour;     // Power Off Delay Time Value

			Delay_Sec = SMB_Read(SMBus_Base, SMBus_MCU_SlaveAddress, 0x66);
			Thread.Sleep(100);                                       // Delay 100 ms
			Delay_Min = SMB_Read(SMBus_Base, SMBus_MCU_SlaveAddress, 0x67);
			Thread.Sleep(100);                                       // Delay 100 ms
			Delay_Hour = SMB_Read(SMBus_Base, SMBus_MCU_SlaveAddress, 0x68);
			Thread.Sleep(100);                                       // Delay 100 ms

			 if ((Delay_Hour > 23) || (Delay_Min > 59) || (Delay_Sec > 59)) 
			{
			MessageBox.Show("Get error Ignition delay off time", "FleetPC-4-F Test Tools V1.0", MessageBoxButtons.OK, MessageBoxIcon.Information);
			}
			else
			{
			ignDelayOffSecNumericUpDown.Value = (UInt16)Delay_Sec;

			ignDelayOffMinNumericUpDown.Value = (UInt16)Delay_Min;

            ignDelayOffHourNumericUpDown.Value = (UInt16)Delay_Hour;
			}
        }

        private void button1_Click(object sender, EventArgs e)
        {
            UInt16 IGN_Status;

	        /// Get Ignition Status,
	        /// True is IGN ON, False is IGN OFF
			IGN_Status = (UInt16)SMB_Read(SMBus_Base, SMBus_MCU_SlaveAddress, 0x12);				//Register IGN_Status
			Thread.Sleep(100);                                       // Delay 100 ms

			IGN_Status &= 1;
			
            if (IGN_Status == 0x01)         // If Register = 1 --> Ignition is On
            {
                MessageBox.Show("Ignition is On (High)", "FleetPC-4-F Test Tools V1.0", MessageBoxButtons.OK, MessageBoxIcon.Information);
                radioButton1.Checked = true;
            }
            else if (IGN_Status == 0x00)    // If Register = 0 --> Ignition is Off
            {
                MessageBox.Show("Ignition is Off (Low)", "FleetPC-4-F Test Tools V1.0", MessageBoxButtons.OK, MessageBoxIcon.Information);
                radioButton2.Checked = true;
            }

        }

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

        private void button16_Click(object sender, EventArgs e)
        /// Get/Set UPS Delay OFF Times,
        /// Array 0 is Hour(0x74) value,
        /// Array 1 is Min(0x73) value,
        /// Array 2 is Sec(0x72) value,		
        {
			UInt32 UPS_Off_Delay_Sec;     // UPS Off Delay Time Value
			UInt32 UPS_Off_Delay_Min;     // UPS Off Delay Time Value


			UPS_Off_Delay_Sec = UInt16.Parse(upsDelayOffSecNumericUpDown.Text, System.Globalization.NumberStyles.HexNumber);
			UPS_Off_Delay_Min = UInt16.Parse(upsDelayOffMinNumericUpDown.Text, System.Globalization.NumberStyles.HexNumber);

			//SMB address:0xF040; Device address: 0x94; 
            SMB_Write(SMBus_Base, SMBus_MCU_SlaveAddress, 0x72, (UInt16)UPS_Off_Delay_Sec);         // UPS Off Delay Time setting Reg: 0x72, sec
            Thread.Sleep(100);                                       // Delay 100 ms
            SMB_Write(SMBus_Base, SMBus_MCU_SlaveAddress, 0x73, (UInt16)UPS_Off_Delay_Min);         // UPS Off Delay Time setting Reg: 0x73, min
            Thread.Sleep(100);                                       // Delay 100 ms
            SMB_Write(SMBus_Base, SMBus_MCU_SlaveAddress, 0x74, 0x00);      				 // UPS Off Delay Time setting Reg: 0x74, hour
            Thread.Sleep(100);                                       // Delay 100 ms
            MessageBox.Show("Setting Success", "FleetPC-4-F Test Tools V1.0", MessageBoxButtons.OK, MessageBoxIcon.Information);

        }

        private void button15_Click(object sender, EventArgs e)
        /// Get UPS Delay OFF Times,
        /// Array 0 is Hour(0x74) value,
        /// Array 1 is Min(0x73) value,
        /// Array 2 is Sec(0x72) value,
		
        {

			UInt32 UPS_Off_Delay_Sec;     // UPS Off Delay Time Value
			UInt32 UPS_Off_Delay_Min;     // UPS Off Delay Time Value


			UPS_Off_Delay_Sec = SMB_Read(SMBus_Base, SMBus_MCU_SlaveAddress, 0x72);
			Thread.Sleep(100);                                       // Delay 100 ms
			UPS_Off_Delay_Min = SMB_Read(SMBus_Base, SMBus_MCU_SlaveAddress, 0x73);
			Thread.Sleep(100);                                       // Delay 100 ms

			 if ((UPS_Off_Delay_Min > 25) || (UPS_Off_Delay_Sec > 59)) 
			{
			MessageBox.Show("Get error UPS Delay OFF time", "FleetPC-4-F Test Tools V1.0", MessageBoxButtons.OK, MessageBoxIcon.Information);
			}
			else
			{
			upsDelayOffSecNumericUpDown.Value = (UInt16)UPS_Off_Delay_Sec;

			upsDelayOffMinNumericUpDown.Value = (UInt16)UPS_Off_Delay_Min;

			}
        }

        private void button25_Click(object sender, EventArgs e)
        {
            UInt32 UPS_Mode;
            UPS_Mode = SMB_Read(SMBus_Base, SMBus_MCU_SlaveAddress, 0x10);

            if (UPS_Mode != 0x7)
            {
                MessageBox.Show("Normal Operating Mode", "FleetPC-4-F Test Tools V1.0", MessageBoxButtons.OK, MessageBoxIcon.Information);
				upsModeNormalRadioButton.Checked = true;

            }
            else
            {
                MessageBox.Show("UPS Mode is ON", "FleetPC-4-F Test Tools V1.0", MessageBoxButtons.OK, MessageBoxIcon.Information);
				UpsModeUpsRadioButton.Checked = true;

            }

        }


        /// <summary>
        /// Get DO(0x31) value,
        /// Array total 4,
        /// Array 0 is DO1,
        /// Array 1 is DO2,
        /// Array 2 is DO3,
        /// Array 3 is DO4,
        /// True is ON, False is OFF
        /// </summary>
        /// <returns></returns>
        public bool[] Get_DO()
        {
            bool[] DO = new bool[8];
            UInt32 DO_value = SMB_Read(SMBus_Base, SMBus_MCU_SlaveAddress, 0x31);
            DO[0] = ((DO_value & 0x01) == 0x01) ? true : false;
            DO[1] = ((DO_value & 0x02) == 0x02) ? true : false;
            DO[2] = ((DO_value & 0x04) == 0x04) ? true : false;
            DO[3] = ((DO_value & 0x08) == 0x08) ? true : false;
            return DO;
        }
        /// <summary>
        /// Set DO(0x31) Port 1~4 ON or OFF
        /// </summary>
        /// <param name="port"> 0 is DO1, 1 is DO2, 2 is DO3, 3 is DO4 </param>
        /// <param name="OnOff">false is OFF, true is ON</param>
        public void Set_DO(int port, bool OnOff)
        {
            UInt32 DO = SMB_Read(SMBus_Base, SMBus_MCU_SlaveAddress, 0x31);

            switch (OnOff)
            {
                case Switch.OFF:
                    switch (port)
                    {
                        case (int)DIO.DO1:
                            DO = DO & 0xFE;
							//cl-MessageBox.Show("Set DO1 Low", "FleetPC-4-F Test Tools V1.0", MessageBoxButtons.OK, MessageBoxIcon.None);
                            break;

                        case (int)DIO.DO2:
                            DO = DO & 0xFD;
							//cl-MessageBox.Show("Set DO2 Low", "FleetPC-4-F Test Tools V1.0", MessageBoxButtons.OK, MessageBoxIcon.None);
                            break;

                        case (int)DIO.DO3:
                            DO = DO & 0xFB;
							//cl-MessageBox.Show("Set DO3 Low", "FleetPC-4-F Test Tools V1.0", MessageBoxButtons.OK, MessageBoxIcon.None);
                            break;

                        case (int)DIO.DO4:
                            DO = DO & 0xF7;
							//cl-MessageBox.Show("Set DO4 Low", "FleetPC-4-F Test Tools V1.0", MessageBoxButtons.OK, MessageBoxIcon.None);
                            break;
                        default:
                            break;
                    }
                    break;

                case Switch.ON:
                    switch (port)
                    {
                        case (int)DIO.DO1:
                            DO = DO | 0x01;
							//cl-MessageBox.Show("Set DO1 High", "FleetPC-4-F Test Tools V1.0", MessageBoxButtons.OK, MessageBoxIcon.None);
                            break;

                        case (int)DIO.DO2:
                            DO = DO | 0x02;
							//cl-MessageBox.Show("Set DO2 High", "FleetPC-4-F Test Tools V1.0", MessageBoxButtons.OK, MessageBoxIcon.None);
                            break;

                        case (int)DIO.DO3:
                            DO = DO | 0x04;
							//cl-MessageBox.Show("Set DO3 High", "FleetPC-4-F Test Tools V1.0", MessageBoxButtons.OK, MessageBoxIcon.None);
                            break;

                        case (int)DIO.DO4:
                            DO = DO | 0x08;
							//cl-MessageBox.Show("Set DO4 High", "FleetPC-4-F Test Tools V1.0", MessageBoxButtons.OK, MessageBoxIcon.None);
                            break;
                        default:
                            break;
                    }
                    break;

                default:
                    break;
            }
            SMB_Write(SMBus_Base, SMBus_MCU_SlaveAddress, 0x31, (UInt16)DO);
        }

        /// <summary>
        /// Get DI(0x30) value,
        /// Array total 4,
        /// Array 0 is DI1,
        /// Array 1 is DI2,
        /// Array 2 is DI3,
        /// Array 3 is DI4,
        /// True is ON, False is OFF
        /// </summary>
        /// <returns></returns>
        public bool[] Get_DI()
        {
            bool[] DI = new bool[8];
            UInt32 DI_value = SMB_Read(SMBus_Base, SMBus_MCU_SlaveAddress, 0x30);
            DI[0] = ((DI_value & 0x01) == 0x01) ? true : false;
            DI[1] = ((DI_value & 0x02) == 0x02) ? true : false;
            DI[2] = ((DI_value & 0x04) == 0x04) ? true : false;
            DI[3] = ((DI_value & 0x08) == 0x08) ? true : false;
            return DI;
        }
        private void DI_Fun(int i)
        {
            bool[] DI = null;
            DI = Get_DI();

            switch (i)
            {
                case (int)DIO.DI1:
                    switch (DI[i])
                    {
                        case Switch.High:
                            highDI1RadioButton.Checked = true;
                            break;

                        case Switch.Low:
                            lowDI1RadioButton.Checked = true;
                            break;
                    }
                    break;

                case (int)DIO.DI2:
                    switch (DI[i])
                    {
                        case Switch.High:
                            highDI2RadioButton.Checked = true;
                            break;

                        case Switch.Low:
                            lowDI2RadioButton.Checked = true;
                            break;
                    }
                    break;

                case (int)DIO.DI3:
                    switch (DI[i])
                    {
                        case Switch.High:
                            highDI3RadioButton.Checked = true;
                            break;

                        case Switch.Low:
                            lowDI3RadioButton.Checked = true;
                            break;
                    }
                    break;

                case (int)DIO.DI4:
                    switch (DI[i])
                    {
                        case Switch.High:
                            highDI4RadioButton.Checked = true;
                            break;

                        case Switch.Low:
                            lowDI4RadioButton.Checked = true;
                            break;
                    }
                    break;

                default:
                    break;
            }
        }


        private void getDIButton_Click(object sender, EventArgs e)
        {
            DIs = null;
            DIs = Get_DI();
            for (int i = 0; i < 4; i++)
            {
                switch (i)
                {
                    case (int)DIO.DI1:
                        switch (DIs[i])
                        {
                            case Switch.High:
                                highDI1RadioButton.Checked = true;
                                break;

                            case Switch.Low:
                                lowDI1RadioButton.Checked = true;
                                break;
                        }
                        break;

                    case (int)DIO.DI2:
                        switch (DIs[i])
                        {
                            case Switch.High:
                                highDI2RadioButton.Checked = true;
                                break;

                            case Switch.Low:
                                lowDI2RadioButton.Checked = true;
                                break;
                        }
                        break;

                    case (int)DIO.DI3:
                        switch (DIs[i])
                        {
                            case Switch.High:
                                highDI3RadioButton.Checked = true;
                                break;

                            case Switch.Low:
                                lowDI3RadioButton.Checked = true;
                                break;
                        }
                        break;

                    default:
                        break;
                }
            }
        }


        private void button29_Click(object sender, EventArgs e)
        {
            Out32(0x2E, 0x87);                                                  // Super I/O entry key Two 0x87 
            Out32(0x2E, 0x87);
            Out32(0x2E, 0x07);
            Out32(0x2F, 0x07);                                                  // WDT feature
            Out32(0x2E, 0x30);                                                  // Set Base Address Reg 0x30
            Out32(0x2F, 0x01);                                                  // Set Base Address to Enabled

			//WDOUT_EN via WDTRST#
            Out32(0x2E, 0xFA);
            Out32(0x2F, 0x01);                                                  // 
			
            // Set WDT Time Count
            Out32(0x2E, 0xF6);
            Out32(0x2F, 0x0a);                                                  // 10 Sec

            // Set WDT Sec and WD_PSWIDTH bit0&1, 01 : 25ms
            Out32(0x2E, 0xF5);
            Out32(0x2F, 0x32);                                                  // WDT feature
			
            Out32(0x2E, 0x0aa);                                                 // Exit Super I/O
            MessageBox.Show("Start WDT Count", "FleetPC-4-F Test Tools V1.0", MessageBoxButtons.OK, MessageBoxIcon.None);

			
        }

        private void getDI1Button_Click(object sender, EventArgs e)
        {
			DI_Fun(0);
        }

        private void getDI2Button_Click(object sender, EventArgs e)
        {
			DI_Fun(1);
        }

        private void getDI3Button_Click(object sender, EventArgs e)
        {
			DI_Fun(2);
        }

        private void getDI4Button_Click(object sender, EventArgs e)
        {
			DI_Fun(3);
        }

        private void getDOButton_Click(object sender, EventArgs e)
        {
            DOs = null;
            DOs = Get_DO();
            for (int i = 0; i < 4; i++)
            {
                switch (i)
                {
                    case (int)DIO.DO1:
                        switch (DOs[i])
                        {
                            case Switch.High:
                                highDO1RadioButton.Checked = true;
                                break;

                            case Switch.Low:
                                lowDO1RadioButton.Checked = true;
                                break;
                        }
                        break;

                    case (int)DIO.DO2:
                        switch (DOs[i])
                        {
                            case Switch.High:
                                highDO2RadioButton.Checked = true;
                                break;

                            case Switch.Low:
                                lowDO2RadioButton.Checked = true;
                                break;
                        }
                        break;

                    case (int)DIO.DO3:
                        switch (DOs[i])
                        {
                            case Switch.High:
                                highDO3RadioButton.Checked = true;
                                break;

                            case Switch.Low:
                                lowDO3RadioButton.Checked = true;
                                break;
                        }
                        break;

                    case (int)DIO.DO4:
                        switch (DOs[i])
                        {
                            case Switch.High:
                                highDO4RadioButton.Checked = true;
                                break;

                            case Switch.Low:
                                lowDO4RadioButton.Checked = true;
                                break;
                        }
                        break;

                    default:
                        break;
                }
            }

        }

        private void setDO1HighButton_Click(object sender, EventArgs e)
        {
			Set_DO((int)DIO.DO1, Switch.High);
			MessageBox.Show("Set DO Success", "FleetPC-4-F Test Tools V1.0", MessageBoxButtons.OK, MessageBoxIcon.None);
        }

        private void setDO2HighButton_Click(object sender, EventArgs e)
        {
			Set_DO((int)DIO.DO2, Switch.High);
			MessageBox.Show("Set DO Success", "FleetPC-4-F Test Tools V1.0", MessageBoxButtons.OK, MessageBoxIcon.None);
        }

        private void setDO3HighButton_Click(object sender, EventArgs e)
        {
			Set_DO((int)DIO.DO3, Switch.High);
			MessageBox.Show("Set DO Success", "FleetPC-4-F Test Tools V1.0", MessageBoxButtons.OK, MessageBoxIcon.None);
        }

        private void setDO4HighButton_Click(object sender, EventArgs e)
        {
			Set_DO((int)DIO.DO4, Switch.High);
			MessageBox.Show("Set DO Success", "FleetPC-4-F Test Tools V1.0", MessageBoxButtons.OK, MessageBoxIcon.None);
        }

        private void setDO1LowButton_Click(object sender, EventArgs e)
        {

			Set_DO((int)DIO.DO1, Switch.Low);
			MessageBox.Show("Set DO Success", "FleetPC-4-F Test Tools V1.0", MessageBoxButtons.OK, MessageBoxIcon.None);
        }			

        private void setDO2LowButton_Click(object sender, EventArgs e)
        {
			Set_DO((int)DIO.DO2, Switch.Low);
			MessageBox.Show("Set DO Success", "FleetPC-4-F Test Tools V1.0", MessageBoxButtons.OK, MessageBoxIcon.None);
        }

        private void setDO3LowButton_Click(object sender, EventArgs e)
        {
			Set_DO((int)DIO.DO3, Switch.Low);
			MessageBox.Show("Set DO Success", "FleetPC-4-F Test Tools V1.0", MessageBoxButtons.OK, MessageBoxIcon.None);
        }

        private void setDO4LowButton_Click(object sender, EventArgs e)
        {
			Set_DO((int)DIO.DO4, Switch.Low);
			MessageBox.Show("Set DO Success", "FleetPC-4-F Test Tools V1.0", MessageBoxButtons.OK, MessageBoxIcon.None);
        }

        private void button3_Click_2(object sender, EventArgs e)
        {
            UInt32[] MCU_FW = new UInt32[5];
            UInt32 MCU_FW_03_1;

            for (int i = 0; i < 5; i++)
            {
                MCU_FW[i] = SMB_Read(SMBus_Base, SMBus_MCU_SlaveAddress, (UInt16)(0x01 + i));
            }
            MCU_FW[0] &= 0x0f;
            MCU_FW[1] &= 0x0f;
            MCU_FW[2] &= 0x0f;
            MCU_FW_03_1 = ((MCU_FW[3] & 0xf0) >> 4);
            MCU_FW[3] &= 0xf;
            MCU_FW[4] &= 0x0f;


            textBox1.Text = "V : " + MCU_FW[0] + "." + MCU_FW[1] + "." + MCU_FW[2] + "-" + MCU_FW_03_1 + "." + MCU_FW[3] + "-" + MCU_FW[4];

        }

        private void button4_Click(object sender, EventArgs e)
        {
            UInt32 mini;

            mini = SMB_Read(SMBus_Base, SMBus_MCU_SlaveAddress, 0x39);                              // Register 39 bit1 PIO1_25 SIM1 MINI CARD(V3P3_M2B_EN)

            mini = mini & 0xFD;
            SMB_Write(SMBus_Base, SMBus_MCU_SlaveAddress, 0x39, (UInt16)mini);

            Thread.Sleep(2000);                                                 // Delay 2 Sec (1000 is 1 Sec) 

            mini = mini | 0x02;
            SMB_Write(SMBus_Base, SMBus_MCU_SlaveAddress, 0x39, (UInt16)mini);
            MessageBox.Show("Run Mini Card Reset Success", "FleetPC-4-F Test Tools V1.0", MessageBoxButtons.OK, MessageBoxIcon.Information);

        }
    }
}
