public MainWindow()
        {
            InitializeComponent();

            OutLevelComboBox.ItemsSource = OutLevelsStrings;
            ModeImage.Source             = new BitmapImage(new Uri("images/Mode_Heat.jpg", UriKind.Relative));

            Boolean USBDevDetected = USB_device.Open();

            ShowConnectionState(USBDevDetected);

            if (USBDevDetected)
            {
                byte[] USBPacket = new byte[USB_PACKET_SIZE];
                USBPacket[0]           = USB_REPORT_ID;
                USBPacket[USB_CMD_POS] = USB_CMD_EEPROM_READ;
                Boolean USBSuccess = USB_device.Write(USBPacket);

                USBSuccess = USB_device.Read(USBPacket);

                byte FirmwareVersion = USBPacket[USB_DATA_POS + MAXIMUM_ON_TIME_OFFSET + MAXIMUM_ON_TIME_SIZE];

                if (USBPacket[USB_DATA_POS + MODE_OFFSET] <= MODE_COOL)
                {
                    if (USBPacket[USB_DATA_POS + MODE_OFFSET] == MODE_HEAT)
                    {
                        HeatMode.IsChecked = true;
                        ModeImage.Source   = new BitmapImage(new Uri("images/Mode_Heat.jpg", UriKind.Relative));
                    }

                    else
                    {
                        CoolMode.IsChecked = true;
                        ModeImage.Source   = new BitmapImage(new Uri("images/Cool_Heat.jpg", UriKind.Relative));
                    }

                    Tnorm.Text = ((float)((USBPacket[USB_DATA_POS + TEMP_NOMINAL_OFFSET] | (USBPacket[USB_DATA_POS + TEMP_NOMINAL_OFFSET + 1] << 8)) / TEMP_FLOAT_TO_INT_VALUE)).ToString("f2");
                    dTH.Text   = ((float)((USBPacket[USB_DATA_POS + TEMP_DELTA_HIGH_OFFSET] | (USBPacket[USB_DATA_POS + TEMP_DELTA_HIGH_OFFSET + 1] << 8)) / TEMP_FLOAT_TO_INT_VALUE)).ToString("f2");
                    dTL.Text   = ((float)((USBPacket[USB_DATA_POS + TEMP_DELTA_LOW_OFFSET] | (USBPacket[USB_DATA_POS + TEMP_DELTA_LOW_OFFSET + 1] << 8)) / TEMP_FLOAT_TO_INT_VALUE)).ToString("f2");
                    OutLevelComboBox.SelectedIndex = USBPacket[USB_DATA_POS + ACTIVE_LEVEL_OFFSET];
                    RnomTextBox.Text   = (USBPacket[USB_DATA_POS + THERMISTOR_R_NOMINAL_OFFSET] | (USBPacket[USB_DATA_POS + THERMISTOR_R_NOMINAL_OFFSET + 1] << 8) | (USBPacket[USB_DATA_POS + THERMISTOR_R_NOMINAL_OFFSET + 2] << 16) | (USBPacket[USB_DATA_POS + THERMISTOR_R_NOMINAL_OFFSET + 3] << 24)).ToString();
                    BconstTextBox.Text = (USBPacket[USB_DATA_POS + THERMISTOR_B_CONSTANT_OFFSET] | (USBPacket[USB_DATA_POS + THERMISTOR_B_CONSTANT_OFFSET + 1] << 8)).ToString();

                    if (FirmwareVersion >= MINIMUM_FIRMWARE_VER)
                    {
                        if (USBPacket[USB_DATA_POS + PROTECTION_ACTIVE_OFFSET] == PROTECTION_ENABLED)
                        {
                            ProtectionCheck.IsChecked = true;
                        }

                        ProtectionTimeTextBox.Text = (USBPacket[USB_DATA_POS + MAXIMUM_ON_TIME_OFFSET] | (USBPacket[USB_DATA_POS + MAXIMUM_ON_TIME_OFFSET + 1] << 8)).ToString();
                    }
                    else
                    {
                        ProtectionBorder.IsEnabled = false;
                    }
                }

                if (FirmwareVersion < MINIMUM_FIRMWARE_VER)
                {
                    MessageBox.Show(OldFirmwareVersionMessage, OldFirmwareVersionHeader, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }
                else
                {
                    FirmwareTextBlock.Text = FirmwareVersionPhrase + (FirmwareVersion >> 4).ToString() + "." + (FirmwareVersion & 0x0F).ToString();
                }
            }
        }
        private void DownloadButton_Click(object sender, RoutedEventArgs e)
        {
            byte[] USBPacket = new byte[USB_PACKET_SIZE];
            USBPacket[0]           = USB_REPORT_ID;
            USBPacket[USB_CMD_POS] = USB_CMD_EEPROM_WRITE;

            if (HeatMode.IsChecked == true)
            {
                USBPacket[USB_DATA_POS + MODE_OFFSET] = MODE_HEAT;
            }
            else
            {
                USBPacket[USB_DATA_POS + MODE_OFFSET] = MODE_COOL;
            }

            Int16 IntSetValue = 0;

            if (TryParseStringToInt(Tnorm.Text, out IntSetValue))
            {
                USBPacket[USB_DATA_POS + TEMP_NOMINAL_OFFSET]     = (byte)IntSetValue;
                USBPacket[USB_DATA_POS + TEMP_NOMINAL_OFFSET + 1] = (byte)(IntSetValue >> 8);
            }
            else
            {
                UserInputErrorMessage(UserInputErrorTnom);
                return;
            }

            if (TryParseStringToInt(dTH.Text, out IntSetValue))
            {
                USBPacket[USB_DATA_POS + TEMP_DELTA_HIGH_OFFSET]     = (byte)IntSetValue;
                USBPacket[USB_DATA_POS + TEMP_DELTA_HIGH_OFFSET + 1] = (byte)(IntSetValue >> 8);
            }
            else
            {
                UserInputErrorMessage(UserInputErrordTH);
                return;
            }

            if (TryParseStringToInt(dTL.Text, out IntSetValue))
            {
                USBPacket[USB_DATA_POS + TEMP_DELTA_LOW_OFFSET]     = (byte)IntSetValue;
                USBPacket[USB_DATA_POS + TEMP_DELTA_LOW_OFFSET + 1] = (byte)(IntSetValue >> 8);
            }
            else
            {
                UserInputErrorMessage(UserInputErrordTL);
                return;
            }

            USBPacket[USB_DATA_POS + ACTIVE_LEVEL_OFFSET] = (byte)OutLevelComboBox.SelectedIndex;

            UInt32 Uint32Val = 0;

            if (UInt32.TryParse(RnomTextBox.Text, out Uint32Val))
            {
                for (byte i = 0; i < THERMISTOR_R_NOMINAL_SIZE; i++)
                {
                    USBPacket[USB_DATA_POS + THERMISTOR_R_NOMINAL_OFFSET + i] = (byte)(Uint32Val >> (8 * i));
                }
            }
            else
            {
                UserInputErrorMessage(UserInputErrorRnom);
                return;
            }

            if (UInt32.TryParse(BconstTextBox.Text, out Uint32Val))
            {
                USBPacket[USB_DATA_POS + THERMISTOR_B_CONSTANT_OFFSET]     = (byte)Uint32Val;
                USBPacket[USB_DATA_POS + THERMISTOR_B_CONSTANT_OFFSET + 1] = (byte)(Uint32Val >> 8);
            }
            else
            {
                UserInputErrorMessage(UserInputErrorBconst);
                return;
            }

            if (ProtectionCheck.IsChecked == true)
            {
                USBPacket[USB_DATA_POS + PROTECTION_ACTIVE_OFFSET] = PROTECTION_ENABLED;
            }
            else
            {
                USBPacket[USB_DATA_POS + PROTECTION_ACTIVE_OFFSET] = PROTECTION_DISABLED;
            }

            if ((!UInt32.TryParse(ProtectionTimeTextBox.Text, out Uint32Val)) || (!((Uint32Val >= PROTECTION_MINUTE_MIN) && (Uint32Val <= PROTECTION_MINUTE_MAX))))
            {
                UserInputErrorMessage(UserInputErrorProtectTime);
                return;
            }
            else
            {
                USBPacket[USB_DATA_POS + MAXIMUM_ON_TIME_OFFSET]     = (byte)Uint32Val;
                USBPacket[USB_DATA_POS + MAXIMUM_ON_TIME_OFFSET + 1] = (byte)(Uint32Val >> 8);
            }

            Boolean USBSuccess = USB_device.Write(USBPacket);

            if (USBSuccess)
            {
                MessageBox.Show(DownloadCommandSuccess, DownloadCommandHeader, MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                MessageBox.Show(DownloadCommandError, DownloadCommandHeader, MessageBoxButton.OK, MessageBoxImage.Error);
            }

            ShowConnectionState(USBSuccess);
        }