Пример #1
0
        private async Task <bool> ChooseTelescope()
        {
            var dlg = new DlgChooseOat()
            {
                Owner = Application.Current.MainWindow, WindowStartupLocation = WindowStartupLocation.CenterOwner
            };

            var result = dlg.ShowDialog();

            if (result == true)
            {
                //var chooser = new Chooser();
                //chooser.DeviceType = "Telescope";
                //var name = chooser.Choose("ASCOM.OpenAstroTracker.Telescope");
                //if (!string.IsNullOrEmpty(name))
                //{
                //	ScopeName = name;
                _commHandler = CommunicationHandlerFactory.ConnectToDevice(dlg.SelectedDevice);
                //_commHandler = new TcpCommunicationHandler(new IPAddress(new byte[] { 192, 168, 86, 61 }), 4030);
                _oatMount = new OatmealTelescopeCommandHandlers(_commHandler);
                await _oatMount.SetSiteLatitude((float)dlg.Latitude);

                await _oatMount.SetSiteLongitude((float)dlg.Longitude);

                return(true);
            }

            //	Settings.Default.Scope = name;

            //	Settings.Default.Save();
            //}

            RequeryCommands();
            return(false);
        }
Пример #2
0
        private async void OnConnectToTelescope()
        {
            if (MountConnected)
            {
                MountConnected = false;
                _commHandler.Disconnect();
                ScopeName     = string.Empty;
                ScopeHardware = string.Empty;
                _oatMount     = null;
                _commHandler  = null;
                RequeryCommands();
            }
            else
            {
                RequeryCommands();

                Log.WriteLine("Mount: Connect to OAT requested");

                if (await this.ChooseTelescope())
                {
                    try
                    {
                        //await +.WaitAsync();

                        Log.WriteLine("Mount: Request OAT Firmware version");
                        var result = await _oatMount.SendCommand("GVP#,#");

                        if (!result.Success)
                        {
                            Log.WriteLine("Mount: Unable to communicate with OAT. {0}", result.StatusMessage);
                            throw new AccessViolationException("Cannot connect. " + result.StatusMessage);
                        }

                        Log.WriteLine("Mount: Connected to OAT. Requesting firmware version..");
                        var resultNr = await _oatMount.SendCommand("GVN#,#");

                        ScopeName = $"{result.Data} {resultNr.Data}";

                        var hardware = await _oatMount.SendCommand("XGM#,#");

                        Log.WriteLine("Mount: Hardware is {0}", hardware);
                        var hwParts  = hardware.Data.Split(',');
                        var raParts  = hwParts[1].Split('|');
                        var decParts = hwParts[2].Split('|');
                        ScopeHardware = $"{hwParts[0]} board    RA {raParts[0]}, {raParts[1]}T    DEC {decParts[0]}, {decParts[1]}T";

                        _transform.SiteElevation = 0;                         //  _oatMount.SiteElevation;
                        Log.WriteLine("Mount: Getting OAT Latitude");
                        _transform.SiteLatitude = await _oatMount.GetSiteLatitude();

                        Log.WriteLine("Mount: Received Latitude {0}. Getting OAT Longitude...", _util.HoursToHMS(_transform.SiteLatitude, ":", ":", ":"));
                        _transform.SiteLongitude = await _oatMount.GetSiteLongitude();

                        Log.WriteLine("Mount: Received Longitude {0}.", _util.HoursToHMS(_transform.SiteLongitude, ":", ":", ":"));
                        _transform.SetAzimuthElevation(0, 90);
                        var lst  = _transform.RATopocentric;
                        var lstS = _util.HoursToHMS(lst, "", "", "");

                        Log.WriteLine("Mount: Current LST is {0}. Sending to OAT.", _util.HoursToHMS(lst, "h", "m", "s"));
                        var stringResult = await RunCustomOATCommandAsync(string.Format(":SHL{0}#,n", _util.HoursToHMS(lst, "", "", "")));

                        Log.WriteLine("Mount: Getting current OAT position");
                        await UpdateCurrentCoordinates();

                        TargetDECDegree = CurrentDECDegree;
                        TargetDECMinute = CurrentDECMinute;
                        TargetDECSecond = CurrentDECSecond;

                        TargetRAHour   = CurrentRAHour;
                        TargetRAMinute = CurrentRAMinute;
                        TargetRASecond = CurrentRASecond;
                        Log.WriteLine("Mount: Current OAT position is RA: {0:00}:{1:00}:{2:00} and DEC: {3:000}*{4:00}'{5:00}", CurrentRAHour, CurrentRAMinute, CurrentRASecond, CurrentDECDegree, CurrentDECMinute, CurrentDECSecond);

                        Log.WriteLine("Mount: Getting current OAT RA steps/degree...");
                        string steps = await RunCustomOATCommandAsync(string.Format(":XGR#,#"));

                        Log.WriteLine("Mount: Current RA steps/degree is {0}. Getting current DEC steps/degree...", steps);
                        _raStepsPerDegree = int.Parse(steps);
                        steps             = await RunCustomOATCommandAsync(string.Format(":XGD#,#"));

                        Log.WriteLine("Mount: Current DEC steps/degree is {0}. Getting current Speed factor...", steps);
                        _decStepsPerDegree = int.Parse(steps);
                        OnPropertyChanged("RAStepsPerDegree");
                        OnPropertyChanged("DECStepsPerDegree");

                        steps = await RunCustomOATCommandAsync(string.Format(":XGS#,#"));

                        Log.WriteLine("Mount: Current Speed factor is {0}...", steps);
                        SpeedCalibrationFactor = float.Parse(steps, _oatCulture);

                        //Log.WriteLine("Mount: Get OAT Tracking speed...");
                        //TrackingSpeed = await GetTrackingSpeed();
                        //Log.WriteLine("Mount: Tracking speed is {0:0.0000}.", TrackingSpeed);

                        Log.WriteLine("Mount: Reading Current OAT HA...");
                        await ReadHA();

                        MountConnected = true;
                        Log.WriteLine("Mount: Successfully connected and configured!");
                    }
                    catch (Exception ex)
                    {
                        Log.WriteLine("Mount: Failed to connect and configure OAT! {0}", ex.Message);
                        MessageBox.Show("Error trying to connect to OpenAstroTracker. " + ex.Message, "Connection Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    finally
                    {
                        //exclusiveAccess.Release();
                    }
                }
            }
        }
Пример #3
0
        private async void OnConnectToTelescope()
        {
            if (MountConnected)
            {
                MountConnected = false;
                _commHandler.Disconnect();
                _oatMount    = null;
                _commHandler = null;
                RequeryCommands();
            }
            else
            {
                RequeryCommands();

                if (await this.ChooseTelescope())
                {
                    try
                    {
                        //await +.WaitAsync();

                        var result = await _oatMount.SendCommand("GVP#,#");

                        if (!result.Success)
                        {
                            throw new AccessViolationException("Cannot connect. " + result.StatusMessage);
                        }
                        var resultNr = await _oatMount.SendCommand("GVN#,#");

                        ScopeName = $"{result.Data} {resultNr.Data}";

                        _transform.SiteElevation = 0;                         //  _oatMount.SiteElevation;
                        _transform.SiteLatitude  = await _oatMount.GetSiteLatitude();

                        _transform.SiteLongitude = await _oatMount.GetSiteLongitude();

                        _transform.SetAzimuthElevation(0, 90);
                        var lst  = _transform.RATopocentric;
                        var lstS = _util.HoursToHMS(lst, "", "", "");

                        Log("LST: {0}", _util.HoursToHMS(lst, "h", "m", "s"));
                        var stringResult = await RunCustomOATCommandAsync(string.Format(":SHL{0}#,n", _util.HoursToHMS(lst, "", "", "")));

                        lst -= _util.HMSToHours("02:58:51");
                        Log("HA: {0}", _util.HoursToHMS(lst, "h", "m", "s"));
                        await UpdateCurrentCoordinates();

                        TargetDECDegree = CurrentDECDegree;
                        TargetDECMinute = CurrentDECMinute;
                        TargetDECSecond = CurrentDECSecond;

                        TargetRAHour   = CurrentRAHour;
                        TargetRAMinute = CurrentRAMinute;
                        TargetRASecond = CurrentRASecond;

                        string steps = await RunCustomOATCommandAsync(string.Format(":XGR#,#"));

                        _raStepsPerDegree = int.Parse(steps);
                        steps             = await RunCustomOATCommandAsync(string.Format(":XGD#,#"));

                        _decStepsPerDegree = int.Parse(steps);
                        OnPropertyChanged("RAStepsPerDegree");
                        OnPropertyChanged("DECStepsPerDegree");

                        steps = await RunCustomOATCommandAsync(string.Format(":XGS#,#"));

                        SpeedCalibrationFactor = float.Parse(steps, _oatCulture);

                        await ReadHA();

                        MountConnected = true;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error trying to connect to OpenAstroTracker. " + ex.Message, "Connection Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    finally
                    {
                        //exclusiveAccess.Release();
                    }
                }
            }
        }