예제 #1
0
        private void Window_Closing(object sender, CancelEventArgs e)
        {
            // make sure we validate and save any final settings changes
            ValidateMacAddressTextBox();

            if (_isEditingGeneralOtpSettings)
            {
                // save updated settings to OTP
                try
                {
                    OtpSettings otpSettings = new OtpSettings(_deviceInfo.DevicePath);
                    bool        success     = otpSettings.WriteSettings(_deviceInfo.ProductID, _deviceInfo.MacAddress);

                    if (!success)
                    {
                        MessageBox.Show("Could not save configuration.");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Could not save configuration.\r\n\r\nError: " + ex.Message);
                }
            }
        }
        private void OnDeviceArrival(Guid classGuid, string devicePath)
        {
            if (classGuid == DEVICE_INTERFACE_GUID_STDFU)
            {
                bool alreadyFound = false;
                foreach (DeviceInfo deviceInfo in _devices)
                {
                    if (deviceInfo.DevicePath.ToUpper() == devicePath.ToUpper())
                    {
                        alreadyFound = true;
                        break;
                    }
                }
                if (!alreadyFound)
                {
                    // get the board's device type and settings
                    try
                    {
                        byte   productID;
                        byte[] macAddress;
                        byte   otpSlotsFree;

                        OtpSettings otpSettings = new OtpSettings(devicePath);
                        bool        success     = otpSettings.ReadSettings(out productID, out macAddress, out otpSlotsFree);
                        if (!success)
                        {
                            _devices.Add(new DeviceInfo()
                            {
                                CanUpdate       = false,
                                OtpSlotsFree    = 0,
                                IsChecked       = false,
                                DevicePath      = devicePath,
                                MacAddress      = macAddress,
                                ProductID       = productID,
                                ProductName     = "Unknown (please reconnect)",
                                UpgradeFirmware = null,
                                UpgradeVersion  = "Unknown",
                            });

                            return;
                        }
                        /* BEGIN: ADD THIS IN IF WE WANT TO AUTO-SET OUR OTP PRODUCT ID EN MASSE */
                        if (otpSlotsFree > 2)
                        {
                            otpSettings.ReadSettings(out productID, out macAddress, out otpSlotsFree);
                            if (productID == 0)
                            {
                                // 9=Netduino3Wifi
                                // 8=Netduino3Ethernet
                                // 5=NetduinoPlus2
                                // 7=Netduino3
                                // 6=Netduino2

                                otpSettings.WriteSettings(9, _macAddresses.GetNextAddress());
                                //otpSettings.WriteSettings(6, macAddress);
                            }

                            success = otpSettings.ReadSettings(out productID, out macAddress, out otpSlotsFree);
                            if (!success)
                            {
                                return;
                            }
                        }
                        /* END: ADD THIS IN IF WE WANT TO AUTO-SET OUR OTP PRODUCT ID EN MASSE */

                        // by default, we hide one OTP slot.  This is so that users cannot accidentally use up all slots--and have one final chance to change the cnofiguration.
                        if (otpSlotsFree >= 1 && _hideOneOtpSlot)
                        {
                            otpSlotsFree--;
                        }

                        // now find the latest firmware for this product
                        Firmware upgradeFirmware = null;
                        if (productID != 0)
                        {
                            upgradeFirmware = GetLatestFirmwareForProduct(productID);
                        }
                        string productName = (upgradeFirmware != null ? upgradeFirmware.ProductName : "STM Device in DFU Mode");

                        _devices.Add(new DeviceInfo()
                        {
                            CanUpdate       = (upgradeFirmware != null),
                            OtpSlotsFree    = otpSlotsFree,
                            IsChecked       = false,
                            DevicePath      = devicePath,
                            MacAddress      = macAddress,
                            ProductID       = productID,
                            ProductName     = productName,
                            UpgradeFirmware = upgradeFirmware,
                            UpgradeVersion  = (upgradeFirmware != null ? upgradeFirmware.Version.ToString() + (upgradeFirmware.VersionBetaSuffix != null ? " " + upgradeFirmware.VersionBetaSuffix : "") : "Unknown")
                        });
                    }
                    catch
                    {
                    }
                }
            }
        }