Esempio n. 1
0
 public async Task Disconnect()
 {
     if (Telescope != null)
     {
         Logger.Info("Disconnected Telescope");
     }
     if (updateTimer != null)
     {
         await updateTimer.Stop();
     }
     Telescope?.Disconnect();
     Telescope     = null;
     TelescopeInfo = DeviceInfo.CreateDefaultInstance <TelescopeInfo>();
     BroadcastTelescopeInfo();
 }
Esempio n. 2
0
 public async Task Disconnect()
 {
     if (Cam != null)
     {
         Logger.Info("Disconnected Camera");
     }
     if (updateTimer != null)
     {
         await updateTimer.Stop();
     }
     _cancelChangeTemperatureCts?.Cancel();
     TempChangeRunning = false;
     Cam?.Disconnect();
     Cam        = null;
     CameraInfo = DeviceInfo.CreateDefaultInstance <CameraInfo>();
     BroadcastCameraInfo();
 }
Esempio n. 3
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
                }
                    );
            }
        }