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; } }
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); }
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); }
public void UpdateDeviceInfo(RotatorInfo deviceInfo) { this.rotatorInfo = deviceInfo; }
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 } ); } }