From 57c5a34fe21a66a23b6b6de80ad66794691950ef Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Thu, 5 May 2022 18:55:38 +0100 Subject: [PATCH 01/12] New Park routine for the LX-200 Classic, uses the same technique as the 5.0.4 driver. --- Meade.net.Telescope/Telescope.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index b16920a..f36c6b2 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -1400,7 +1400,6 @@ namespace ASCOM.Meade.net { CheckConnected("CanUnpark"); - //todo make this return false for non LX-200 GPS telescopes LogMessage("CanUnpark", "Get - " + true); return SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS; } @@ -1742,11 +1741,20 @@ namespace ASCOM.Meade.net break; } + if (SharedResourcesWrapper.ProductName != TelescopeList.LX200CLASSIC) + { + SharedResourcesWrapper.SendBlind("hP"); + //:hP# Autostar, Autostar II and LX 16" Slew to Park Position + //Returns: Nothing + } + else + { + Tracking = false; + SlewToCoordinates(parkedPosition.RightAscension, parkedPosition.Declination); + } + //Setting park to true before sending the park command as the Autostar and Audiostar stop serial communications once the park command has been issued. SharedResourcesWrapper.SetParked(true, parkedPosition); - SharedResourcesWrapper.SendBlind("hP"); - //:hP# Autostar, Autostar II and LX 16" Slew to Park Position - //Returns: Nothing } private bool _userNewerPulseGuiding = true; From a9b8a60e43f22ed46d7166c23bb1578400da97ac Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Fri, 6 May 2022 12:14:24 +0100 Subject: [PATCH 02/12] Changes LX200 Park to use Alt 0 Az 0. i.e. Pointing level and North --- Meade.net.Telescope/Telescope.cs | 100 +++++++++++++++++++++++++++---- 1 file changed, 90 insertions(+), 10 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index f36c6b2..72f5955 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -1750,7 +1750,8 @@ namespace ASCOM.Meade.net else { Tracking = false; - SlewToCoordinates(parkedPosition.RightAscension, parkedPosition.Declination); + var parkAlt = AlignmentMode == AlignmentModes.algAltAz ? 0 : 90 - SiteLatitude; + SlewToAltAz(0, parkAlt, false); } //Setting park to true before sending the park command as the Autostar and Audiostar stop serial communications once the park command has been issued. @@ -2161,12 +2162,17 @@ namespace ASCOM.Meade.net } public void SlewToAltAz(double azimuth, double altitude) + { + SlewToAltAz(azimuth, altitude, true); + } + + public void SlewToAltAz(double azimuth, double altitude, bool polar) { LogMessage("SlewToAltAz", $"Az=~{azimuth} Alt={altitude}"); CheckConnected("SlewToAltAz"); CheckParked(); - SlewToAltAzAsync(azimuth, altitude); + SlewToAltAzAsync(azimuth, altitude, polar); while (Slewing) //wait for slew to complete { @@ -2175,6 +2181,11 @@ namespace ASCOM.Meade.net } public void SlewToAltAzAsync(double azimuth, double altitude) + { + SlewToAltAzAsync(azimuth, altitude, true); + } + + public void SlewToAltAzAsync(double azimuth, double altitude, bool polar) { CheckConnected("SlewToAltAzAsync"); CheckParked(); @@ -2193,18 +2204,87 @@ namespace ASCOM.Meade.net LogMessage("SlewToAltAzAsync", $"Az={azimuth} Alt={altitude}"); - HorizonCoordinates altAz = new HorizonCoordinates { Azimuth = azimuth, Altitude = altitude }; + if (polar) + { + HorizonCoordinates altAz = new HorizonCoordinates { Azimuth = azimuth, Altitude = altitude }; - var utcDateTime = UTCDate; - var latitude = SiteLatitude; - var longitude = SiteLongitude; + var utcDateTime = UTCDate; + var latitude = SiteLatitude; + var longitude = SiteLongitude; + var raDec = _astroMaths.ConvertHozToEq(utcDateTime, latitude, longitude, altAz); - var raDec = _astroMaths.ConvertHozToEq(utcDateTime, latitude, longitude, altAz); + TargetRightAscension = raDec.RightAscension; + TargetDeclination = raDec.Declination; + } + else + { + TargetAltitude = altitude; + TargetAzimuth = azimuth; + } - TargetRightAscension = raDec.RightAscension; - TargetDeclination = raDec.Declination; + DoSlewAsync(polar); + } - DoSlewAsync(true); + private double TargetAltitude + { + set + { + CheckConnected("TargetAltitude"); + CheckParked(); + + if (value < -90) + throw new ArgumentOutOfRangeException($"Target Altitude cannot be below -90."); + + if (value > 90) + throw new ArgumentOutOfRangeException($"Target Altitude cannot be above 90."); + + var dms = SharedResourcesWrapper.IsLongFormat ? + _utilities.DegreesToDMS(value, "*", "'", "", _digitsDe) : + _utilities.DegreesToDM(value, "*", "", _digitsDe); + + var s = value < 0 ? "-" : "+"; + + var command = $"Sa{s}{dms}"; + + LogMessage("TargetAltitude Set", $"{command}"); + var response = SharedResourcesWrapper.SendBool(command); + //:SasDD*MM# + // Set target object altitude to sDD*MM# or sDD*MM’SS# [LX 16”, Autostar, Autostar II] + // Returns: + // 1 Object within slew range + // 0 Object out of slew range + if (!response) + throw new InvalidOperationException("Target Altitude out of slew range."); + } + } + + private double TargetAzimuth + { + set + { + CheckConnected("TargetAzimuth"); + CheckParked(); + + if (value < 0) + throw new ArgumentOutOfRangeException($"Target Altitude cannot be below 0."); + + if (value >= 360) + throw new ArgumentOutOfRangeException($"Target Altitude cannot be above 360."); + + var dms = _utilities.DegreesToDM(value, "*", "", _digitsDe); + + var command = $"Sz{dms}"; + + LogMessage("TargetAzimuth Set", $"{command}"); + var response = SharedResourcesWrapper.SendBool(command); + //:SzDDD*MM# + // Sets the target Object Azimuth[LX 16” and Autostar II only] + // Returns: + // 0 – Invalid + // 1 - Valid + if (!response) + throw new InvalidOperationException("Target Azimuth out of slew range."); + } } private void DoSlewAsync(bool polar) From ceca3a15dce6f48a115e83b2c1d79d833cf4e389 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Fri, 6 May 2022 13:39:34 +0100 Subject: [PATCH 03/12] Added work around for LX200 classed to be able to turn tracking off when parking. --- Meade.net.Telescope/Telescope.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 72f5955..8d40d9d 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -1749,7 +1749,11 @@ namespace ASCOM.Meade.net } else { - Tracking = false; + if (CanSetTracking) + Tracking = false; + else + SharedResourcesWrapper.SendBlind("AL"); //todo need to route this to the real commands. + var parkAlt = AlignmentMode == AlignmentModes.algAltAz ? 0 : 90 - SiteLatitude; SlewToAltAz(0, parkAlt, false); } From ef498fc5a053e2071f3f6a93a1ada99683b7b22d Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Fri, 6 May 2022 20:09:40 +0100 Subject: [PATCH 04/12] Added some debugging messages --- Meade.net.Telescope/Telescope.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 8d40d9d..b3e5706 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -1749,16 +1749,27 @@ namespace ASCOM.Meade.net } else { + LogMessage("Park", $"Parking LX200 Classic"); if (CanSetTracking) + { + LogMessage("Park", $"Parking LX200 Classic - Setting Tracking False"); Tracking = false; + } else + { + LogMessage("Park", $"Setting Telescope to land targets."); SharedResourcesWrapper.SendBlind("AL"); //todo need to route this to the real commands. + } + var parkAlt = AlignmentMode == AlignmentModes.algAltAz ? 0 : 90 - SiteLatitude; + LogMessage("Park", $"Slewing to park position az:0 alt:{parkAlt}"); SlewToAltAz(0, parkAlt, false); + LogMessage("Park", $"Arrived at park position"); } //Setting park to true before sending the park command as the Autostar and Audiostar stop serial communications once the park command has been issued. + LogMessage("Park", $"Setting driver to parked"); SharedResourcesWrapper.SetParked(true, parkedPosition); } @@ -1768,7 +1779,7 @@ namespace ASCOM.Meade.net { LogMessage("PulseGuide", $"pulse guide direction {direction} duration {duration}"); try - { + { CheckConnected("PulseGuide"); CheckParked(); if (IsSlewingToTarget()) From af3cca76116358764569dc3e2bcc0b62fa59340c Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Fri, 6 May 2022 21:31:12 +0100 Subject: [PATCH 05/12] Modified the deubgging information. --- Meade.net.Telescope/Telescope.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index b3e5706..222a176 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -1750,18 +1750,17 @@ namespace ASCOM.Meade.net else { LogMessage("Park", $"Parking LX200 Classic"); - if (CanSetTracking) + LogMessage("Park", $"Setting Telescope to land targets."); + try { - LogMessage("Park", $"Parking LX200 Classic - Setting Tracking False"); - Tracking = false; - } - else - { - LogMessage("Park", $"Setting Telescope to land targets."); SharedResourcesWrapper.SendBlind("AL"); //todo need to route this to the real commands. + _utilities.WaitForMilliseconds(1000); //Need to wait 1 second according to old driver. + } + catch (Exception ex) + { + LogMessage("Park", $"AL command failed: {ex.Message}"); } - var parkAlt = AlignmentMode == AlignmentModes.algAltAz ? 0 : 90 - SiteLatitude; LogMessage("Park", $"Slewing to park position az:0 alt:{parkAlt}"); SlewToAltAz(0, parkAlt, false); From 0c70688b60e34321149df6b9e205f4d140ba57a2 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Sat, 7 May 2022 10:00:57 +0100 Subject: [PATCH 06/12] Removed the AL command as I think it's failing --- Meade.net.Telescope/Telescope.cs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 222a176..61bdf78 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -177,7 +177,7 @@ namespace ASCOM.Meade.net { get { - LogMessage("SupportedActions Get", "Returning empty arraylist"); + LogMessage("SupportedActions Get", "Returning Actions Array"); var supportedActions = new ArrayList {"handbox", "site"}; return supportedActions; } @@ -1750,16 +1750,16 @@ namespace ASCOM.Meade.net else { LogMessage("Park", $"Parking LX200 Classic"); - LogMessage("Park", $"Setting Telescope to land targets."); - try - { - SharedResourcesWrapper.SendBlind("AL"); //todo need to route this to the real commands. - _utilities.WaitForMilliseconds(1000); //Need to wait 1 second according to old driver. - } - catch (Exception ex) - { - LogMessage("Park", $"AL command failed: {ex.Message}"); - } + //LogMessage("Park", $"Setting Telescope to land targets."); + //try + //{ + // SharedResourcesWrapper.SendBlind("AL"); //todo need to route this to the real commands. + // _utilities.WaitForMilliseconds(1000); //Need to wait 1 second according to old driver. + //} + //catch (Exception ex) + //{ + // LogMessage("Park", $"AL command failed: {ex.Message}"); + //} var parkAlt = AlignmentMode == AlignmentModes.algAltAz ? 0 : 90 - SiteLatitude; LogMessage("Park", $"Slewing to park position az:0 alt:{parkAlt}"); From 5e65ea79462a9769c596c28d2c3f3c9682b3c566 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Sat, 7 May 2022 12:15:45 +0100 Subject: [PATCH 07/12] Added a log message for when connected check fails. --- Meade.net.Telescope/Telescope.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 61bdf78..96a22e1 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -3066,7 +3066,9 @@ namespace ASCOM.Meade.net { if (!IsConnected) { - throw new NotConnectedException($"Not connected to telescope when trying to execute: {message}"); + var msg = $"Not connected to telescope when trying to execute: {message}"; + LogMessage("CheckConnected", msg); + throw new NotConnectedException(msg); } } From 350dd23ed1abacfcdecf34864ce42735277aef63 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Sat, 7 May 2022 12:22:46 +0100 Subject: [PATCH 08/12] Added more error checks for connected, and found a couple of logic holds in the code that sets the IsConnected property. --- .../TelescopeUnitTests.cs | 18 +++++------------- Meade.net.Telescope/Telescope.cs | 2 ++ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index f6fe1d2..f668703 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -221,9 +221,7 @@ namespace Meade.net.Telescope.UnitTests { string expectedResult = "test result string"; _sharedResourcesWrapperMock.Setup(x => x.SendString("ED", false)).Returns(expectedResult); - _telescope.Connected = true; - - + ConnectTelescope(); var actualResult = _telescope.Action("handbox", "readdisplay"); @@ -830,21 +828,17 @@ namespace Meade.net.Telescope.UnitTests [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, AlignmentModes.algGermanPolar, "AP")] public void AlignmentMode_Set_WhenConnected_ThenSendsExpectedCommand(string productName, string firmware, AlignmentModes alignmentMode, string expectedCommand) { - _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(productName); - _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(firmware); - _telescope.Connected = true; + ConnectTelescope(productName, firmware); _telescope.AlignmentMode = alignmentMode; _sharedResourcesWrapperMock.Verify(x => x.SendBlind(expectedCommand, false), Times.Once); } - [TestCase("AUTOSTAR", "43Ef")] + [TestCase(TelescopeList.Autostar497, "43Ef")] public void AlignmentMode_Set_WhenAutostarFirmwareToLow_ThenThrowsException(string productName, string firmware) { - _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(productName); - _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(firmware); - _telescope.Connected = true; + ConnectTelescope(productName, firmware); var excpetion = Assert.Throws(() => _telescope.AlignmentMode = AlignmentModes.algAltAz); @@ -983,9 +977,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void CanSetGuideRates_Get_WhenConnectedToLX200GPS_ThenReturnsTrue() { - _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.LX200GPS); - _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => TelescopeList.LX200GPS_42G); - _telescope.Connected = true; + ConnectTelescope(TelescopeList.LX200GPS, TelescopeList.LX200GPS_42G); var result = _telescope.CanSetGuideRates; diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 96a22e1..ffeead3 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -508,12 +508,14 @@ namespace ASCOM.Meade.net } catch (Exception) { + IsConnected = false; SharedResourcesWrapper.Disconnect("Serial", DriverId); throw; } } catch (Exception ex) { + IsConnected = false; LogMessage("Connected Set", "Error connecting to port {0} - {1}", _profileProperties.ComPort, ex.Message); } } From 700802033b3f729ec6875ae147f5b2b869798a08 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Sat, 7 May 2022 14:00:29 +0100 Subject: [PATCH 09/12] Added Alt Az coordinates to the connected message. --- .../TelescopeUnitTests.cs | 4 +- Meade.net.Telescope/Telescope.cs | 110 +++++++++++------- Meade.net/SharedResources.cs | 3 +- 3 files changed, 69 insertions(+), 48 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index f668703..36ff739 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -477,7 +477,7 @@ namespace Meade.net.Telescope.UnitTests if (expectedConnected) { - _sharedResourcesWrapperMock.Verify(x => x.SendString("GZ", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString("GZ", false), Times.AtLeastOnce); _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}", false), Times.Never); } } @@ -488,7 +488,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(TelescopeList.LX200GPS, string.Empty); _sharedResourcesWrapperMock.Verify(x => x.Connect("Serial", It.IsAny(), It.IsAny()), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendString("GZ", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString("GZ", false), Times.AtLeastOnce); _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}", false), Times.Once); } diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index ffeead3..0095144 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -503,8 +503,9 @@ namespace ASCOM.Meade.net } var raAndDec = GetTelescopeRaAndDec(); + var altAndAz = GetTelescopeAltAz(); LogMessage("Connected Set", - $"Connected OK. Current RA = {_utilitiesExtra.HoursToHMS(raAndDec.RightAscension)} Dec = {_utilitiesExtra.DegreesToDMS(raAndDec.Declination)}"); + $"Connected OK. Current RA = {_utilitiesExtra.HoursToHMS(raAndDec.RightAscension)} Dec = {_utilitiesExtra.DegreesToDMS(raAndDec.Declination)} Az={altAndAz.Azimuth} Alt={altAndAz.Altitude}"); } catch (Exception) { @@ -1102,28 +1103,7 @@ namespace ASCOM.Meade.net if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) { - try - { - CheckParked(); - - //firmware bug in 44Eg, :GA# is returning the dec, not the altitude! - var result = SharedResourcesWrapper.SendString("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. - - var alt = _utilities.DMSToDegrees(result); - LogMessage("Altitude", $"{alt}"); - return alt; - } - catch (ParkedException) - { - var parkedPosition = SharedResourcesWrapper.ParkedPosition; - if (parkedPosition != null) - return parkedPosition.Altitude; - - throw; - } + return GetRealTelescopeAltitude(); } var altAz = CalcAltAzFromTelescopeEqData(); @@ -1132,6 +1112,32 @@ namespace ASCOM.Meade.net } } + private double GetRealTelescopeAltitude() + { + try + { + CheckParked(); + + //firmware bug in 44Eg, :GA# is returning the dec, not the altitude! + var result = SharedResourcesWrapper.SendString("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. + + var alt = _utilities.DMSToDegrees(result); + LogMessage("Altitude", $"{alt}"); + return alt; + } + catch (ParkedException) + { + var parkedPosition = SharedResourcesWrapper.ParkedPosition; + if (parkedPosition != null) + return parkedPosition.Altitude; + + throw; + } + } + private HorizonCoordinates CalcAltAzFromTelescopeEqData() { var altitudeData = new AltitudeData @@ -1159,6 +1165,15 @@ namespace ASCOM.Meade.net }; } + private HorizonCoordinates GetTelescopeAltAz() + { + return new HorizonCoordinates() + { + Altitude = GetRealTelescopeAltitude(), + Azimuth = GetRealTelescopeAzimuth() + }; + } + public double ApertureArea { get @@ -1212,28 +1227,7 @@ namespace ASCOM.Meade.net if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) { - try - { - CheckParked(); - - var result = SharedResourcesWrapper.SendString("GZ"); - //:GZ# Get telescope azimuth - //Returns: DDD*MM#T or DDD*MM'SS# - //The current telescope Azimuth depending on the selected precision. - - double az = _utilities.DMSToDegrees(result); - - LogMessage("Azimuth Get", $"{az}"); - return az; - } - catch (ParkedException) - { - var parkedPosition = SharedResourcesWrapper.ParkedPosition; - if (parkedPosition != null) - return parkedPosition.Azimuth; - - throw; - } + return GetRealTelescopeAzimuth(); } var altAz = CalcAltAzFromTelescopeEqData(); @@ -1242,6 +1236,32 @@ namespace ASCOM.Meade.net } } + private double GetRealTelescopeAzimuth() + { + try + { + CheckParked(); + + var result = SharedResourcesWrapper.SendString("GZ"); + //:GZ# Get telescope azimuth + //Returns: DDD*MM#T or DDD*MM'SS# + //The current telescope Azimuth depending on the selected precision. + + double az = _utilities.DMSToDegrees(result); + + LogMessage("Azimuth Get", $"{az}"); + return az; + } + catch (ParkedException) + { + var parkedPosition = SharedResourcesWrapper.ParkedPosition; + if (parkedPosition != null) + return parkedPosition.Azimuth; + + throw; + } + } + public bool CanFindHome { get diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index 4ad7cf6..aac7262 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -391,8 +391,9 @@ namespace ASCOM.Meade.net SharedSerial.Parity = (SerialParity)Enum.Parse(typeof(SerialParity), profileProperties.Parity); SharedSerial.Speed = (SerialSpeed)profileProperties.Speed; SharedSerial.Handshake = (SerialHandshake)Enum.Parse(typeof(SerialHandshake), profileProperties.Handshake); + SharedSerial.ReceiveTimeout = 5; //5 second timeout; SharedSerial.Connected = true; - + try { ProductName = SendString("GVP"); From a204f9c57f9e6bbb51bca3263e76991376017392 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Sat, 7 May 2022 16:54:22 +0100 Subject: [PATCH 10/12] Added more logging to DoSlewAsync, Added a retry to the AltAz Slew. --- Meade.net.Telescope/Telescope.cs | 47 ++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 0095144..4cae501 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -2204,7 +2204,7 @@ namespace ASCOM.Meade.net public void SlewToAltAz(double azimuth, double altitude, bool polar) { - LogMessage("SlewToAltAz", $"Az=~{azimuth} Alt={altitude}"); + LogMessage("SlewToAltAz", $"Az=~{azimuth} Alt={altitude} polar={polar}"); CheckConnected("SlewToAltAz"); CheckParked(); @@ -2238,7 +2238,7 @@ namespace ASCOM.Meade.net if (azimuth < 0) throw new InvalidValueException("Azimuth cannot be less than 0."); - LogMessage("SlewToAltAzAsync", $"Az={azimuth} Alt={altitude}"); + LogMessage("SlewToAltAzAsync", $"Az={azimuth} Alt={altitude} polar={polar}"); if (polar) { @@ -2325,6 +2325,7 @@ namespace ASCOM.Meade.net private void DoSlewAsync(bool polar) { + LogMessage("DoSlewAsync", "Beginning slew sequence"); CheckConnected("DoSlewAsync"); CheckParked(); if (Slewing) @@ -2336,6 +2337,7 @@ namespace ASCOM.Meade.net switch (polar) { case true: + LogMessage("DoSlewAsync", "Executing Polar slew"); var response = SharedResourcesWrapper.SendChar("MS"); //:MS# Slew to Target Object //Returns: @@ -2382,23 +2384,44 @@ namespace ASCOM.Meade.net break; case false: - var maResponse = SharedResourcesWrapper.SendChar("MA"); - //:MA# Autostar, LX 16", Autostar II - Slew to target Alt and Az - //Returns: - //0 - No fault - //1 - Fault - //LX200 - Not supported - - if (maResponse == "1") + Retry(6, () => { - throw new InvalidOperationException("fault"); - } + LogMessage("DoSlewAsync", "Executing Alt Az"); + var maResponse = SharedResourcesWrapper.SendChar("MA"); + //:MA# Autostar, LX 16", Autostar II - Slew to target Alt and Az + //Returns: + //0 - No fault + //1 - Fault + //LX200 - Not supported + + if (maResponse != "0") + { + throw new InvalidOperationException($"fault ({maResponse})"); + } + }); SetSlewingMinEndTime(); break; } } + private void Retry(int i, Action action) + { + while (i >= 0) + { + try + { + action(); + break; + } + catch (Exception e) + { + LogMessage("Retry", $"Attempt failed {i} attempts remaining error: {e.Message}"); + } + i--; + } + } + public void SlewToCoordinates(double rightAscension, double declination) { LogMessage("SlewToCoordinates", $"Ra={rightAscension}, Dec={declination}"); From 8eb093c13ad950dc20d32ccf73ca1736f00d41b8 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Sat, 7 May 2022 18:09:37 +0100 Subject: [PATCH 11/12] Upgraded the align mode command to have a retry and added support for land mode. --- Meade.net.Telescope/Telescope.cs | 43 +++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 4cae501..ac62ae2 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -979,10 +979,13 @@ namespace ASCOM.Meade.net if (IsGwCommandSupported()) { var alignmentStatus = GetScopeAlignmentStatus(); + LogMessage("AlignmentMode Get", $"alignmode = {alignmentStatus.AlignmentMode}"); return alignmentStatus.AlignmentMode; } - else + + return Retry(6, () => { + LogMessage("AlignmentMode Get", $"Sending Ack code."); const char ack = (char)6; //ACK <0x06> Query of alignment mounting mode. //Returns: @@ -995,22 +998,29 @@ namespace ASCOM.Meade.net switch (alignmentString) { case "A": + LogMessage("AlignmentMode Get", $"Telescope is in AltAz"); alignmentMode = AlignmentModes.algAltAz; break; case "P": + LogMessage("AlignmentMode Get", $"Telescope is in Polar"); alignmentMode = AlignmentModes.algPolar; break; + case "L": + LogMessage("AlignmentMode Get", $"Telescope is in Land mode"); + alignmentMode = AlignmentModes.algAltAz; + break; //case "G": - //alignmentMode = AlignmentModes.algGermanPolar; - //break; + //alignmentMode = AlignmentModes.algGermanPolar; + //break; default: - throw new InvalidValueException( - $"unknown alignment returned from telescope: {alignmentString}"); + var msg = $"unknown alignment returned from telescope: {alignmentString}"; + LogMessage("AlignmentMode Get", msg); + throw new InvalidValueException(msg); } LogMessage("AlignmentMode Get", $"alignmode = {alignmentMode}"); return alignmentMode; - } + }); } set { @@ -2422,6 +2432,27 @@ namespace ASCOM.Meade.net } } + private T Retry(int i, Func func) + { + while (true) + { + try + { + return func(); + } + catch (Exception e) + { + LogMessage("Retry", $"Attempt failed {i} attempts remaining error: {e.Message}"); + if (i > 0) + { + i--; + } + else + throw; + } + } + } + public void SlewToCoordinates(double rightAscension, double declination) { LogMessage("SlewToCoordinates", $"Ra={rightAscension}, Dec={declination}"); From 64e42f961c306c0e30552b30956514511260f554 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Sat, 7 May 2022 19:37:16 +0100 Subject: [PATCH 12/12] Maybe this is what's missing to get the telescope to park --- .../TelescopeUnitTests.cs | 16 +++++++------- Meade.net.Telescope/Telescope.cs | 21 +++++++------------ 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 36ff739..12eaea1 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -2715,15 +2715,15 @@ namespace Meade.net.Telescope.UnitTests Assert.That(_telescope.Tracking, Is.True); } - [TestCase(true)] - [TestCase(false)] - public void Tracking_Set_WhenCanSetTrackingIsFalse_ThenThrowsNotImplementedException(bool tracking) - { - // GW is not supported, so CanSetTracking is false - ConnectTelescope(firmwareVersion: TelescopeList.Autostar497_30Ee); + //[TestCase(true)] + //[TestCase(false)] + //public void Tracking_Set_WhenCanSetTrackingIsFalse_ThenThrowsNotImplementedException(bool tracking) + //{ + // // GW is not supported, so CanSetTracking is false + // ConnectTelescope(firmwareVersion: TelescopeList.Autostar497_30Ee); - Assert.Throws( () => { _telescope.Tracking = tracking; } ); - } + // Assert.Throws( () => { _telescope.Tracking = tracking; } ); + //} [TestCase(true, "AP")] [TestCase(false, "AL")] diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index ac62ae2..55d1b0a 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -1782,17 +1782,10 @@ namespace ASCOM.Meade.net else { LogMessage("Park", $"Parking LX200 Classic"); - //LogMessage("Park", $"Setting Telescope to land targets."); - //try - //{ - // SharedResourcesWrapper.SendBlind("AL"); //todo need to route this to the real commands. - // _utilities.WaitForMilliseconds(1000); //Need to wait 1 second according to old driver. - //} - //catch (Exception ex) - //{ - // LogMessage("Park", $"AL command failed: {ex.Message}"); - //} + + Tracking = false; + LogMessage("Park", $"Calculating Park Altitude"); var parkAlt = AlignmentMode == AlignmentModes.algAltAz ? 0 : 90 - SiteLatitude; LogMessage("Park", $"Slewing to park position az:0 alt:{parkAlt}"); SlewToAltAz(0, parkAlt, false); @@ -2812,10 +2805,10 @@ namespace ASCOM.Meade.net } set { - if (!CanSetTracking) - { - throw new ASCOM.NotImplementedException("Tracking Set"); - } + //if (!CanSetTracking) + //{ + // throw new ASCOM.NotImplementedException("Tracking Set"); + //} LogMessage("Tracking Set", $"{value}"); SharedResourcesWrapper.SendBlind(value ? "AP" : "AL"); //todo need to route this to the real commands.