From 2d69a4fba82d9fc7e13eba366c24cd5efa9bf0ff Mon Sep 17 00:00:00 2001 From: Colin Date: Mon, 6 May 2019 17:17:22 +0100 Subject: [PATCH] Added support for altitude --- MeadeAutostar497/AscomClasses/Telescope.cs | 5 +- .../Controller/ITelescopeController.cs | 1 + .../Controller/TelescopeController.cs | 50 +++++++++++++------ 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/MeadeAutostar497/AscomClasses/Telescope.cs b/MeadeAutostar497/AscomClasses/Telescope.cs index 9a7c05e..4dba4a4 100644 --- a/MeadeAutostar497/AscomClasses/Telescope.cs +++ b/MeadeAutostar497/AscomClasses/Telescope.cs @@ -306,8 +306,9 @@ namespace ASCOM.MeadeAutostar497 { get { - tl.LogMessage("Altitude", "Not implemented"); - throw new ASCOM.PropertyNotImplementedException("Altitude", false); + var alt = _telescopeController.Altitude; + tl.LogMessage("Altitude", $"{alt}"); + return alt; } } diff --git a/MeadeAutostar497/Controller/ITelescopeController.cs b/MeadeAutostar497/Controller/ITelescopeController.cs index 6f1f3fa..7815e6f 100644 --- a/MeadeAutostar497/Controller/ITelescopeController.cs +++ b/MeadeAutostar497/Controller/ITelescopeController.cs @@ -16,6 +16,7 @@ namespace ASCOM.MeadeAutostar497.Controller bool AtPark { get; } double Azimuth { get; } double Declination { get; } + double Altitude { get; } void AbortSlew(); void PulseGuide(GuideDirections direction, int duration); void Park(); diff --git a/MeadeAutostar497/Controller/TelescopeController.cs b/MeadeAutostar497/Controller/TelescopeController.cs index da3234b..a5f7139 100644 --- a/MeadeAutostar497/Controller/TelescopeController.cs +++ b/MeadeAutostar497/Controller/TelescopeController.cs @@ -190,16 +190,8 @@ namespace ASCOM.MeadeAutostar497.Controller get { var latitude = SerialPort.CommandTerminated( ":Gt#", "#"); - - double lat = int.Parse(latitude.Substring(1, 2)); - lat = lat + double.Parse(latitude.Substring(4, 2)) / 60; - if (latitude.Length == 9) - lat = lat + double.Parse(latitude.Substring(7, 2)) / 60 / 60; - if (latitude[0] == '-') - lat = -lat; - - return lat; + return DMSToDouble(latitude); } set { @@ -220,12 +212,31 @@ namespace ASCOM.MeadeAutostar497.Controller private double DMSToDouble(string DMS) { - double l = int.Parse(DMS.Substring(0, 3)); - l = l + double.Parse(DMS.Substring(4, 2)) / 60; - if (DMS.Length == 9) - l = l + double.Parse(DMS.Substring(7, 2)) / 60 / 60; + if (IsNumeric(DMS[0])) + { + double l = int.Parse(DMS.Substring(0, 3)); + l = l + double.Parse(DMS.Substring(4, 2)) / 60; + if (DMS.Length == 9) + l = l + double.Parse(DMS.Substring(7, 2)) / 60 / 60; - return l; + return l; + } + + double lat = int.Parse(DMS.Substring(1, 2)); + lat = lat + double.Parse(DMS.Substring(4, 2)) / 60; + if (DMS.Length == 9) + lat = lat + double.Parse(DMS.Substring(7, 2)) / 60 / 60; + + if (DMS[0] == '-') + lat = -lat; + + return lat; + } + + private bool IsNumeric(char c) + { + char[] nums = new[] {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; + return nums.Contains(c); } public double SiteLongitude @@ -339,6 +350,17 @@ namespace ASCOM.MeadeAutostar497.Controller } } + public double Altitude { + get + { + var result = SerialPort.CommandTerminated(":GA#", "#"); + //:GA# Get Telescope Altitude + //Returns: sDD* MM# or sDD*MM’SS# + //The current scope altitude. The returned format depending on the current precision setting. + return DMSToDouble(result); + } + } + public void AbortSlew() { SerialPort.Command("#:Q#");