示例#1
0
 public void FromRotatorInfo(RotatorInfo info)
 {
     if (info.Connected)
     {
         if (string.IsNullOrWhiteSpace(Rotator.Name))
         {
             Rotator.Name = info.Name;
         }
         Rotator.MechanicalPosition = info.MechanicalPosition;
         Rotator.Position           = info.Position;
         Rotator.StepSize           = info.StepSize;
     }
 }
示例#2
0
        public void FromRotatorInfoConnectedTest()
        {
            var info = new RotatorInfo()
            {
                Connected = true,
                Name      = "TestRotator",
                Position  = 123,
                StepSize  = 3.8f
            };

            var sut = new ImageMetaData();

            sut.FromRotatorInfo(info);

            Assert.AreEqual("TestRotator", sut.Rotator.Name);
            Assert.AreEqual(123, sut.Rotator.Position);
            Assert.AreEqual((double)3.8f, sut.Rotator.StepSize);
        }
示例#3
0
        public void FromRotatorInfoNotConnectedTest()
        {
            var info = new RotatorInfo()
            {
                Connected = false,
                Name      = "TestRotator",
                Position  = 123,
                StepSize  = 3.8f
            };

            var sut = new ImageMetaData();

            sut.FromRotatorInfo(info);

            Assert.AreEqual(string.Empty, sut.Rotator.Name);
            Assert.AreEqual(double.NaN, sut.Rotator.Position);
            Assert.AreEqual(double.NaN, sut.Rotator.StepSize);
        }
示例#4
0
 public void UpdateDeviceInfo(RotatorInfo deviceInfo)
 {
     this.rotatorInfo = deviceInfo;
 }
示例#5
0
        public async Task <bool> Connect()
        {
            await ss.WaitAsync();

            try {
                await Disconnect();

                if (updateTimer != null)
                {
                    await updateTimer.Stop();
                }

                if (RotatorChooserVM.SelectedDevice.Id == "No_Device")
                {
                    profileService.ActiveProfile.RotatorSettings.Id = RotatorChooserVM.SelectedDevice.Id;
                    return(false);
                }

                applicationStatusMediator.StatusUpdate(
                    new ApplicationStatus()
                {
                    Source = Title,
                    Status = Locale.Loc.Instance["LblConnecting"]
                }
                    );

                var rotator = (IRotator)RotatorChooserVM.SelectedDevice;
                _connectRotatorCts?.Dispose();
                _connectRotatorCts = new CancellationTokenSource();
                if (rotator != null)
                {
                    try {
                        var connected = await rotator?.Connect(_connectRotatorCts.Token);

                        _connectRotatorCts.Token.ThrowIfCancellationRequested();
                        if (connected)
                        {
                            this.rotator = rotator;

                            if (this.rotator.CanReverse)
                            {
                                this.rotator.Reverse = profileService.ActiveProfile.RotatorSettings.Reverse;
                            }

                            RotatorInfo = new RotatorInfo {
                                Connected     = true,
                                IsMoving      = rotator.IsMoving,
                                Name          = rotator.Name,
                                Description   = rotator.Description,
                                Position      = rotator.Position,
                                StepSize      = rotator.StepSize,
                                DriverInfo    = rotator.DriverInfo,
                                DriverVersion = rotator.DriverVersion,
                                CanReverse    = rotator.CanReverse,
                                Reverse       = rotator.Reverse
                            };

                            Notification.ShowSuccess(Locale.Loc.Instance["LblRotatorConnected"]);

                            updateTimer.Interval = profileService.ActiveProfile.ApplicationSettings.DevicePollingInterval;
                            updateTimer.Start();

                            TargetPosition = rotator.Position;
                            profileService.ActiveProfile.RotatorSettings.Id      = rotator.Id;
                            profileService.ActiveProfile.RotatorSettings.Reverse = this.rotator.Reverse;

                            Logger.Info($"Successfully connected Rotator. Id: {rotator.Id} Name: {rotator.Name} Driver Version: {rotator.DriverVersion}");

                            return(true);
                        }
                        else
                        {
                            RotatorInfo.Connected = false;
                            this.rotator          = null;
                            return(false);
                        }
                    } catch (OperationCanceledException) {
                        if (RotatorInfo.Connected)
                        {
                            await Disconnect();
                        }
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            } finally {
                ss.Release();
                applicationStatusMediator.StatusUpdate(
                    new ApplicationStatus()
                {
                    Source = Title,
                    Status = string.Empty
                }
                    );
            }
        }