Пример #1
0
        public void ParseAndToString_AreReversible()
        {
            var x = new FirmwareMetadata("Behavior", new HarpVersion(2, 5), new HarpVersion(1, 6), new HarpVersion(1, 2), 0);
            var y = FirmwareMetadata.Parse(x.ToString());

            Assert.IsTrue(x.Equals(y));
        }
        internal static FirmwareMetadata GetTargetFirmwareMetadata()
        {
            var firmwareLocation = GetTargetFirmwareLocation();

            if (firmwareLocation == null)
            {
                return(null);
            }
            return(FirmwareMetadata.Parse(Path.GetFileNameWithoutExtension(firmwareLocation)));
        }
        private void ValidateDeviceFirmware()
        {
            if (configuration.WhoAmI == 0)
            {
                return;
            }
            if (configuration.WhoAmI != FP3002Configuration.DeviceWhoAmI)
            {
                MessageBox.Show(this, Properties.Resources.InvalidDeviceID_Error, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                CloseDevice();
                Close();
                return;
            }

            if (deviceFirmware == null)
            {
                deviceFirmware = configuration.GetFirmwareMetadata();
                var targetFirmware = FP3002Configuration.GetTargetFirmwareMetadata();
                if (!targetFirmware.Supports(nameof(FP3002), deviceFirmware.HardwareVersion, assemblyNumber: 0))
                {
                    MessageBox.Show(this, Properties.Resources.UnsupportedHardwareVersion_Error, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    CloseDevice();
                    Close();
                    return;
                }

                if (deviceFirmware.FirmwareVersion > targetFirmware.FirmwareVersion)
                {
                    MessageBox.Show(this, Properties.Resources.UpdateDriverVersion_Error, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    CloseDevice();
                    Close();
                    return;
                }

                if (!deviceFirmware.FirmwareVersion.Satisfies(targetFirmware.FirmwareVersion) || ModifierKeys == (Keys.Shift | Keys.Control | Keys.Alt))
                {
                    if (MessageBox.Show(this, Properties.Resources.UpdateDeviceFirmware_Question, Text, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                    {
                        CloseDevice();
                        SetConnectionStatus(ConnectionStatus.Reset);
                        var targetDeviceFirmware = FP3002Configuration.GetTargetDeviceFirmware();
                        using (var firmwareDialog = new FP3002FirmwareDialog(instance.PortName, targetDeviceFirmware))
                        {
                            firmwareDialog.ShowDialog(this);
                        }
                        deviceFirmware = null;
                        ResetDevice();
                        return;
                    }
                    else if (deviceFirmware.FirmwareVersion.Major < targetFirmware.FirmwareVersion.Major)
                    {
                        MessageBox.Show(this, Properties.Resources.UnsupportedFirmwareVersion_Error, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        CloseDevice();
                        Close();
                        return;
                    }
                }

                if (configuration.CameraSerialNumber == 0 || ModifierKeys == (Keys.Shift | Keys.Control))
                {
                    if (MessageBox.Show(this, Properties.Resources.UpdateCameraSerialNumber_Warning, Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                    {
                        CloseDevice();
                        using (var firmwareDialog = new FP3002CameraRegistrationDialog(instance.PortName))
                        {
                            firmwareDialog.ShowDialog(this);
                        }
                        ResetDevice();
                        return;
                    }
                }
            }

            propertyGrid.Refresh();
            SetConnectionStatus(ConnectionStatus.Ready);
        }