diff --git a/.gitignore b/.gitignore index a6bb49f..f2ba386 100644 --- a/.gitignore +++ b/.gitignore @@ -218,5 +218,4 @@ _Pvt_Extensions # nCrunch items *.ncrunchsolution -*.DotSettings *.ncrunchproject diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 1afc3e7..16b330d 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; using System.Reflection; using ASCOM; using ASCOM.Astrometry.AstroUtils; @@ -22,6 +23,7 @@ namespace Meade.net.Telescope.UnitTests private Mock _astroUtilsMock; private Mock _sharedResourcesWrapperMock; private Mock _astroMathsMock; + private Mock _clockMock; private ProfileProperties _profileProperties; private ConnectionInfo _connectionInfo; @@ -63,8 +65,10 @@ namespace Meade.net.Telescope.UnitTests _astroMathsMock = new Mock(); + _clockMock = new Mock(); + _telescope = new ASCOM.Meade.net.Telescope(_utilMock.Object, _utilExtraMock.Object, _astroUtilsMock.Object, - _sharedResourcesWrapperMock.Object, _astroMathsMock.Object); + _sharedResourcesWrapperMock.Object, _astroMathsMock.Object, _clockMock.Object); } private void ConnectTelescope(string productName = TelescopeList.Autostar497, string firmwareVersion = TelescopeList.Autostar497_31Ee) @@ -1459,6 +1463,53 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Verify(x => x.SendBlind($":Q{d}#")); } + [TestCase(GuideDirections.guideEast)] + [TestCase(GuideDirections.guideWest)] + [TestCase(GuideDirections.guideNorth)] + [TestCase(GuideDirections.guideSouth)] + public void PulseGuide_WhenConnectedAndNewerPulseGuidingNotAvailable_ThenSendsOldCommandsAndDoesNotWaitForExtraSettleTime(GuideDirections direction) + { + short slewSettleTime = 10; + _profileProperties.SettleTime = slewSettleTime; + + var telescopeDecResult = "s12*34’56"; + var dmsResult = 1.2; + var telescopeRaResult = "HH:MM:SS"; + var hmsResult = 1.3; + + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); + _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); + _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(hmsResult); + + var duration = 0; + _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.Autostar497); + _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => TelescopeList.Autostar497_30Ee); + + _telescope.Connected = true; + + _telescope.PulseGuide(direction, duration); + + string d = string.Empty; + switch (direction) + { + case GuideDirections.guideEast: + d = "e"; + break; + case GuideDirections.guideWest: + d = "w"; + break; + case GuideDirections.guideNorth: + d = "n"; + break; + case GuideDirections.guideSouth: + d = "s"; + break; + } + + _clockMock.Verify(x => x.UtcNow, Times.Never); + } + [TestCase(GuideDirections.guideEast)] [TestCase(GuideDirections.guideWest)] [TestCase(GuideDirections.guideNorth)] @@ -1633,25 +1684,51 @@ namespace Meade.net.Telescope.UnitTests } [Test] - public void SlewSettleTime_Get_ThenThrowsException() + public void SlewSettleTime_Get_WhenNotConnected_ThenThrowsException() { - var excpetion = Assert.Throws(() => + var exception = Assert.Throws(() => { var result = _telescope.SlewSettleTime; Assert.Fail($"{result} should not have returned"); }); - - Assert.That(excpetion.Property, Is.EqualTo("SlewSettleTime")); - Assert.That(excpetion.AccessorSet, Is.False); + Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SlewSettleTime Get")); } [Test] - public void SlewSettleTime_Set_ThenThrowsException() + public void SlewSettleTime_Set_WhenNotConnected_ThenThrowsException() { - var excpetion = Assert.Throws(() => { _telescope.SlewSettleTime = 0; }); + var exception = Assert.Throws(() => + { + _telescope.SlewSettleTime = 13; + Assert.Fail($"should not have returned"); + }); + Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SlewSettleTime Set")); + } - Assert.That(excpetion.Property, Is.EqualTo("SlewSettleTime")); - Assert.That(excpetion.AccessorSet, Is.True); + [Test] + public void SlewSettleTime_Get_ReturnsExpectedValue() + { + ConnectTelescope(); + + var result = _telescope.SlewSettleTime; + + Assert.That(result, Is.EqualTo(0)); + } + + [TestCase(8)] + [TestCase(12)] + [TestCase(3)] + public void SlewSettleTime_Set_ThenReturnsNewSettleTime(short settleTime) + { + _profileProperties.SettleTime = 0; + + ConnectTelescope(); + + _telescope.SlewSettleTime = settleTime; + + var result = _telescope.SlewSettleTime; + + Assert.That(result, Is.EqualTo(settleTime)); } [Test] @@ -2309,6 +2386,64 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#"),Times.Once); } + + [TestCase(0, 0, "2021-10-03T20:36:00", "2021-10-03T20:36:01", false)] + [TestCase(5, 0, "2021-10-03T20:36:00", "2021-10-03T20:36:01", true)] + [TestCase(5, 0, "2021-10-03T20:36:00", "2021-10-03T20:36:06", false)] + [TestCase(10, 0, "2021-10-03T20:36:00", "2021-10-03T20:36:06", true)] + [TestCase(10, 0, "2021-10-03T20:36:00", "2021-10-03T20:36:09", true)] + [TestCase(10, 0, "2021-10-03T20:36:00", "2021-10-03T20:36:10", false)] + [TestCase(0, 5, "2021-10-03T20:36:00", "2021-10-03T20:36:01", true)] + [TestCase(0, 5, "2021-10-03T20:36:00", "2021-10-03T20:36:05", false)] + [TestCase(0, 10, "2021-10-03T20:36:00", "2021-10-03T20:36:05", true)] + [TestCase(0, 10, "2021-10-03T20:36:00", "2021-10-03T20:36:10", false)] + [TestCase(15, 10, "2021-10-03T20:36:00", "2021-10-03T20:36:10", true)] + [TestCase(15, 10, "2021-10-03T20:36:00", "2021-10-03T20:36:24", true)] + [TestCase(15, 10, "2021-10-03T20:36:00", "2021-10-03T20:36:25", false)] + public void Slewing_WhenTelescopeIsSlewing_ThenReturnsExpectedValueForSettleTime( short settleTime, short profileSettleTime, string startSlewing, string endSlewing, bool isSlewing) + { + _profileProperties.SettleTime = profileSettleTime; + + var timescalled = 0; + DateTime startSlewingDateTime = DateTime.ParseExact(startSlewing, "yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture); + DateTime endSlewingDatetime = DateTime.ParseExact(endSlewing, "yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture); + + _clockMock.Setup(x => x.UtcNow).Returns(() => + { + if (timescalled == 0) + { + timescalled++; + return startSlewingDateTime; + } + + return endSlewingDatetime; + }); + + var slewingText = "|"; + var notSlewingText = String.Empty; + + _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#")).Returns( () => + { + if (timescalled == 0) + { + return slewingText; + } + + return notSlewingText; + }); + + ConnectTelescope(); + + _telescope.SlewSettleTime = settleTime; + + var result = _telescope.Slewing; + + Assert.That(result, Is.EqualTo(true)); + + result = _telescope.Slewing; + + Assert.That(result, Is.EqualTo(isSlewing)); + } [TestCase(TelescopeList.LX200CLASSIC,"","|", true)] [TestCase(TelescopeList.LX200CLASSIC, "", "||||||||", true)] @@ -2351,6 +2486,60 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#"), Times.Never); } + [TestCase(1, TelescopeAxes.axisPrimary, 0, 0, false, false)] + [TestCase(-1, TelescopeAxes.axisPrimary, 0, 0, false, false)] + [TestCase(1, TelescopeAxes.axisSecondary, 0, 0, false, false)] + [TestCase(-1, TelescopeAxes.axisSecondary, 0, 0, false, false)] + + [TestCase(1, TelescopeAxes.axisPrimary, 10, 0, true, false)] + [TestCase(-1, TelescopeAxes.axisPrimary, 10, 0, true, false)] + [TestCase(1, TelescopeAxes.axisSecondary, 10, 0, true, false)] + [TestCase(-1, TelescopeAxes.axisSecondary, 10, 0, true, false)] + + [TestCase(1, TelescopeAxes.axisPrimary, 10, 20, true, true)] + [TestCase(-1, TelescopeAxes.axisPrimary, 10, 20, true, true)] + [TestCase(1, TelescopeAxes.axisSecondary, 10, 20, true, true)] + [TestCase(-1, TelescopeAxes.axisSecondary, 10, 20, true, true)] + public void Slewing_WhenTelescopeStops_ThenWaitsForSettleTime(int rate, TelescopeAxes axis, short profileSettleTime, short driverSettleTime, bool expectedResultInWaitingPeriod, bool afterProfileSettleTimeUp) + { + _profileProperties.SettleTime = profileSettleTime; + + DateTime currentTime = MakeTime("2021-01-23T22:02:10"); + + _clockMock.Setup(x => x.UtcNow).Returns(() => currentTime ); + + ConnectTelescope(); + + _telescope.SlewSettleTime = driverSettleTime; + + _telescope.MoveAxis(axis, rate); + + var result = _telescope.Slewing; + Assert.That(result, Is.True); + + _telescope.MoveAxis(axis, 0); + + currentTime = currentTime + TimeSpan.FromSeconds(profileSettleTime / 2); + + result = _telescope.Slewing; + Assert.That(result, Is.EqualTo(expectedResultInWaitingPeriod)); + + currentTime = currentTime + TimeSpan.FromSeconds(profileSettleTime / 2); + + result = _telescope.Slewing; + Assert.That(result, Is.EqualTo(afterProfileSettleTimeUp)); + + currentTime = currentTime + TimeSpan.FromSeconds(driverSettleTime); + + result = _telescope.Slewing; + Assert.That(result, Is.False); + } + + private DateTime MakeTime( string dateTimeString ) + { + return DateTime.ParseExact(dateTimeString, "yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture); + } + [Test] public void SlewToTargetAsync_WhenNotConnected_ThenThrowsException() diff --git a/Meade.net.Telescope/AstroMaths/AstroMathExtensions.cs b/Meade.net.Telescope/AstroMaths/AstroMathExtensions.cs index 9254007..183700e 100644 --- a/Meade.net.Telescope/AstroMaths/AstroMathExtensions.cs +++ b/Meade.net.Telescope/AstroMaths/AstroMathExtensions.cs @@ -58,7 +58,7 @@ namespace ASCOM.Meade.net.AstroMaths t0 -= 24; } - var ut = DateTimeToDecimalHours(utcDateTime); + var ut = utcDateTime.DateTimeToDecimalHours(); var a = ut * 1.002737909; var t1 = t0 + a; diff --git a/Meade.net.Telescope/Clock.cs b/Meade.net.Telescope/Clock.cs new file mode 100644 index 0000000..745e9a7 --- /dev/null +++ b/Meade.net.Telescope/Clock.cs @@ -0,0 +1,9 @@ +using System; + +namespace ASCOM.Meade.net +{ + public class Clock : IClock + { + public DateTime UtcNow => DateTime.UtcNow; + } +} \ No newline at end of file diff --git a/Meade.net.Telescope/IClock.cs b/Meade.net.Telescope/IClock.cs new file mode 100644 index 0000000..2745543 --- /dev/null +++ b/Meade.net.Telescope/IClock.cs @@ -0,0 +1,9 @@ +using System; + +namespace ASCOM.Meade.net +{ + public interface IClock + { + DateTime UtcNow { get; } + } +} \ No newline at end of file diff --git a/Meade.net.Telescope/Meade.net.Telescope.csproj b/Meade.net.Telescope/Meade.net.Telescope.csproj index af7987b..cfae8a4 100644 --- a/Meade.net.Telescope/Meade.net.Telescope.csproj +++ b/Meade.net.Telescope/Meade.net.Telescope.csproj @@ -124,8 +124,10 @@ + + diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index bf06b16..ada8098 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -60,16 +60,20 @@ namespace ASCOM.Meade.net private readonly IAstroMaths _astroMaths; + private readonly IClock _clock; + /// /// Private variable to hold number of decimals for RA /// private int _digitsRa = 2; /// - /// Private variable to hold number of decimals for DE + /// Private variable to hold number of decimals for Dec /// private int _digitsDe = 2; + private short _settleTime; + /// /// Initializes a new instance of the class. /// Must be public for COM registration. @@ -84,6 +88,7 @@ namespace ASCOM.Meade.net _utilitiesExtra = util; //Initialise util object _astroUtilities = new AstroUtils(); // Initialise astro utilities object _astroMaths = new AstroMaths.AstroMaths(); + _clock = new Clock(); Initialise(nameof(Telescope)); } @@ -116,8 +121,9 @@ namespace ASCOM.Meade.net sb.AppendLine(); } - public Telescope( IUtil util, IUtilExtra utilExtra, IAstroUtils astroUtilities, ISharedResourcesWrapper sharedResourcesWrapper, IAstroMaths astroMaths) : base(sharedResourcesWrapper) + public Telescope( IUtil util, IUtilExtra utilExtra, IAstroUtils astroUtilities, ISharedResourcesWrapper sharedResourcesWrapper, IAstroMaths astroMaths, IClock clock) : base(sharedResourcesWrapper) { + _clock = clock; _utilities = util; //Initialise util object _utilitiesExtra = utilExtra; //Initialise util object _astroUtilities = astroUtilities; // Initialise astro utilities object @@ -813,6 +819,7 @@ namespace ASCOM.Meade.net _movingPrimary = false; _movingSecondary = false; + SetSlewingMinEndTime(); } public AlignmentModes AlignmentMode @@ -1334,7 +1341,7 @@ namespace ASCOM.Meade.net private bool _movingPrimary; private bool _movingSecondary; - + public void MoveAxis(TelescopeAxes axis, double rate) { LogMessage("MoveAxis", $"Axis={axis} rate={rate}"); @@ -1377,6 +1384,11 @@ namespace ASCOM.Meade.net switch (rate.Compare(0)) { case ComparisonResult.Equals: + if (!_isGuiding) + { + SetSlewingMinEndTime(); + } + _movingPrimary = false; SharedResourcesWrapper.SendBlind(":Qe#"); //:Qe# Halt eastward Slews @@ -1386,7 +1398,6 @@ namespace ASCOM.Meade.net //Returns: Nothing break; case ComparisonResult.Greater: - SharedResourcesWrapper.SendBlind(":Me#"); //:Me# Move Telescope East at current slew rate //Returns: Nothing @@ -1404,6 +1415,10 @@ namespace ASCOM.Meade.net switch (rate.Compare(0)) { case ComparisonResult.Equals: + if (!_isGuiding) + { + SetSlewingMinEndTime(); + } _movingSecondary = false; SharedResourcesWrapper.SendBlind(":Qn#"); //:Qn# Halt northward Slews @@ -1424,9 +1439,7 @@ namespace ASCOM.Meade.net //Returns: Nothing _movingSecondary = true; break; - } - break; default: throw new InvalidValueException("Can not move this axis."); @@ -1554,7 +1567,7 @@ namespace ASCOM.Meade.net /// /// convert a HH:MM.T (classic LX200 RA Notation) string to a double hours. T is the decimal part of minutes which is converted into seconds /// - public double HMToHours(string hm) + public double HmToHours(string hm) { var token = hm.Split('.'); if (token.Length != 2) @@ -1575,7 +1588,7 @@ namespace ASCOM.Meade.net //Returns: HH:MM.T# or HH:MM:SS# //Depending which precision is set for the telescope - double rightAscension = HMToHours(result); + double rightAscension = HmToHours(result); LogMessage("RightAscension", $"Get - {result} convert to {rightAscension} {_utilitiesExtra.HoursToHMS(rightAscension)}"); return rightAscension; @@ -1660,7 +1673,7 @@ namespace ASCOM.Meade.net CheckConnected("SiteElevation Set"); LogMessage("SiteElevation", $"Set: {value}"); - if (value == base.SiteElevation) + if (Math.Abs(value - base.SiteElevation) < 0.1) { LogMessage("SiteElevation", $"Set: no change detected"); return; @@ -1774,14 +1787,15 @@ namespace ASCOM.Meade.net { get { - LogMessage("SlewSettleTime Get", "Not implemented"); - throw new PropertyNotImplementedException("SlewSettleTime", false); + CheckConnected("SlewSettleTime Get"); + LogMessage("SlewSettleTime Get", $"{_settleTime} Seconds"); + return _settleTime; } - // ReSharper disable once ValueParameterNotUsed set { - LogMessage("SlewSettleTime Set", "Not implemented"); - throw new PropertyNotImplementedException("SlewSettleTime", true); + CheckConnected("SlewSettleTime Set"); + LogMessage("SlewSettleTime Set", $"Setting from {_settleTime} to {value}"); + _settleTime = value; } } @@ -1859,6 +1873,7 @@ namespace ASCOM.Meade.net case "0": //We're slewing everything should be working just fine. LogMessage("DoSlewAsync", "Slewing to target"); + SetSlewingMinEndTime(); break; case "1": //Below Horizon @@ -1894,7 +1909,7 @@ namespace ASCOM.Meade.net { throw new InvalidOperationException("fault"); } - + SetSlewingMinEndTime(); break; } }); @@ -1962,16 +1977,34 @@ namespace ASCOM.Meade.net return _movingPrimary || _movingSecondary; } + private DateTime _earliestNonSlewingTime = DateTime.MinValue; + public bool Slewing { get { var isSlewing = GetSlewing(); + + if (isSlewing) + SetSlewingMinEndTime(); + else if (_clock.UtcNow < _earliestNonSlewingTime) + isSlewing = true; + LogMessage("Slewing", $"Result = {isSlewing}"); return isSlewing; } } + private void SetSlewingMinEndTime() + { + _earliestNonSlewingTime = _clock.UtcNow + GetTotalSlewingSettleTime(); + } + + private TimeSpan GetTotalSlewingSettleTime() + { + return TimeSpan.FromSeconds( SlewSettleTime + ProfileSettleTime ); + } + private bool GetSlewing() { if (!Connected) return false; @@ -1999,8 +2032,9 @@ namespace ASCOM.Meade.net bool isSlewing = false; try { - if (string.IsNullOrWhiteSpace(result)) + if (string.IsNullOrEmpty(result)) { + // ReSharper disable once RedundantAssignment isSlewing = false; return isSlewing; } @@ -2073,14 +2107,14 @@ namespace ASCOM.Meade.net // At least the classic LX200 low precision might not slew to the exact target position // This Requires to retrieve the aimed target ra de from the telescope double ra = RightAscension; - if (_targetRightAscension != InvalidParameter && + if (Math.Abs(_targetRightAscension - InvalidParameter) > 0.1 && _utilities.HoursToHMS(ra, ":", ":", ":", _digitsRa) != _utilities.HoursToHMS(_targetRightAscension, ":", ":", ":", _digitsRa)) { LogMessage("SyncToTarget", $"differ RA real {ra} targeted {_targetRightAscension}"); _targetRightAscension = ra; } double de = Declination; - if (_targetDeclination != InvalidParameter && + if (Math.Abs(_targetDeclination - InvalidParameter) > 0.1 && _utilities.DegreesToDMS(de, "*", ":", ":", _digitsDe) != _utilities.DegreesToDMS(_targetDeclination, "*", ":", ":", _digitsDe)) { LogMessage("SyncToTarget", $"differ DE real {de} targeted {_targetDeclination}"); @@ -2120,11 +2154,9 @@ namespace ASCOM.Meade.net if (value < -90) throw new InvalidValueException("Declination cannot be less than -90."); - var dms = ""; - if (IsLongFormat) - dms = _utilities.DegreesToDMS(value, "*", ":", ":", _digitsDe); - else - dms = _utilities.DegreesToDM(value, "*", "", _digitsDe); + var dms = IsLongFormat ? + _utilities.DegreesToDMS(value, "*", ":", ":", _digitsDe) : + _utilities.DegreesToDM(value, "*", "", _digitsDe); var s = value < 0 ? string.Empty : "+"; @@ -2177,12 +2209,9 @@ namespace ASCOM.Meade.net if (value >= 24) throw new InvalidValueException("Right ascension value cannot be greater than 23:59:59"); - var hms = ""; - if(IsLongFormat) - hms = _utilities.HoursToHMS(value, ":", ":", ":", _digitsRa); - else - //meade protocol defines H:MM.T format - hms = _utilities.HoursToHM(value, ":", "", _digitsRa).Replace(',','.'); + var hms = IsLongFormat ? + _utilities.HoursToHMS(value, ":", ":", ":", _digitsRa) : + _utilities.HoursToHM(value, ":", "", _digitsRa).Replace(',','.'); var command = $":Sr{hms}#"; LogMessage("TargetRightAscension Set", $"{command}"); diff --git a/Meade.net.sln.DotSettings b/Meade.net.sln.DotSettings new file mode 100644 index 0000000..a89188a --- /dev/null +++ b/Meade.net.sln.DotSettings @@ -0,0 +1,6 @@ + + False + True + True + True + True \ No newline at end of file diff --git a/Meade.net/LocalServer.cs b/Meade.net/LocalServer.cs index 2a719af..dcd3c4e 100644 --- a/Meade.net/LocalServer.cs +++ b/Meade.net/LocalServer.cs @@ -337,18 +337,23 @@ namespace ASCOM.Meade.net { key?.SetValue(null, progid); // Could be assyTitle/Desc??, but .NET components show ProgId here key?.SetValue("AppId", _sAppId); - using (RegistryKey key2 = key.CreateSubKey("Implemented Categories")) + if (key != null) { - key2?.CreateSubKey("{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}"); - } - using (RegistryKey key2 = key.CreateSubKey("ProgId")) - { - key2?.SetValue(null, progid); - } - key.CreateSubKey("Programmable"); - using (RegistryKey key2 = key.CreateSubKey("LocalServer32")) - { - key2?.SetValue(null, Application.ExecutablePath); + using (RegistryKey key2 = key.CreateSubKey("Implemented Categories")) + { + key2?.CreateSubKey("{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}"); + } + + using (RegistryKey key2 = key.CreateSubKey("ProgId")) + { + key2?.SetValue(null, progid); + } + + key.CreateSubKey("Programmable"); + using (RegistryKey key2 = key.CreateSubKey("LocalServer32")) + { + key2?.SetValue(null, Application.ExecutablePath); + } } } // diff --git a/Meade.net/MeadeTelescopeBase.cs b/Meade.net/MeadeTelescopeBase.cs index 1250461..51e0892 100644 --- a/Meade.net/MeadeTelescopeBase.cs +++ b/Meade.net/MeadeTelescopeBase.cs @@ -27,6 +27,7 @@ namespace ASCOM.Meade.net protected string Precision; protected string GuidingStyle; protected double SiteElevation; + protected short ProfileSettleTime; protected readonly ISharedResourcesWrapper SharedResourcesWrapper; @@ -67,6 +68,7 @@ namespace ASCOM.Meade.net Precision = profileProperties.Precision; GuidingStyle = profileProperties.GuidingStyle.ToLower(); SiteElevation = profileProperties.SiteElevation; + ProfileSettleTime = profileProperties.SettleTime; LogMessage("ReadProfile", $"Trace logger enabled: {Tl.Enabled}"); LogMessage("ReadProfile", $"Com Port: {ComPort}"); @@ -76,6 +78,7 @@ namespace ASCOM.Meade.net LogMessage("ReadProfile", $"Precision: {Precision}"); LogMessage("ReadProfile", $"Guiding Style: {GuidingStyle}"); LogMessage("ReadProfile", $"Site Elevation: {SiteElevation}"); + LogMessage("ReadProfile", $"Settle Time after slew: {ProfileSettleTime}"); } /// diff --git a/Meade.net/ProfileProperties.cs b/Meade.net/ProfileProperties.cs index f5155c4..b4f11cc 100644 --- a/Meade.net/ProfileProperties.cs +++ b/Meade.net/ProfileProperties.cs @@ -13,5 +13,6 @@ namespace ASCOM.Meade.net public bool DynamicBreaking { get; set; } public bool RtsDtrEnabled { get; set; } public double SiteElevation { get; set; } + public short SettleTime { get; set; } } } \ No newline at end of file diff --git a/Meade.net/Properties/Resources.Designer.cs b/Meade.net/Properties/Resources.Designer.cs index 1f4ff11..c735eec 100644 --- a/Meade.net/Properties/Resources.Designer.cs +++ b/Meade.net/Properties/Resources.Designer.cs @@ -135,5 +135,14 @@ namespace ASCOM.Meade.net.Properties { return ResourceManager.GetString("SetupDialogForm_TextBox1_TextChanged___0_00_0___of_sidereal_rate_", resourceCulture); } } + + /// + /// Looks up a localized string similar to Please enter only numbers.. + /// + internal static string SetupDialogForm_txtElevation_TextChanged_1_Please_enter_only_numbers_ { + get { + return ResourceManager.GetString("SetupDialogForm_txtElevation_TextChanged_1_Please_enter_only_numbers_", resourceCulture); + } + } } } diff --git a/Meade.net/Properties/Resources.resx b/Meade.net/Properties/Resources.resx index 67a3869..9de5db4 100644 --- a/Meade.net/Properties/Resources.resx +++ b/Meade.net/Properties/Resources.resx @@ -144,4 +144,7 @@ Valid are : -register, -unregister and -embedding {0} Settings ({1}) + + Please enter only numbers. + \ No newline at end of file diff --git a/Meade.net/SetupDialogForm.cs b/Meade.net/SetupDialogForm.cs index b6a7208..d56b963 100644 --- a/Meade.net/SetupDialogForm.cs +++ b/Meade.net/SetupDialogForm.cs @@ -88,6 +88,7 @@ namespace ASCOM.Meade.net cbxReverseDirection.Checked = profileProperties.ReverseFocusDirection; cbxDynamicBreaking.Checked = profileProperties.DynamicBreaking; + nudSettleTime.Value = profileProperties.SettleTime; } public ProfileProperties GetProfile() @@ -103,8 +104,9 @@ namespace ASCOM.Meade.net BacklashCompensation = int.Parse(txtBacklashSteps.Text), ReverseFocusDirection = cbxReverseDirection.Checked, DynamicBreaking = cbxDynamicBreaking.Checked, - SiteElevation = double.Parse(txtElevation.Text) - }; + SiteElevation = double.Parse(txtElevation.Text), + SettleTime = Convert.ToInt16(nudSettleTime.Value) + }; return profileProperties; } @@ -167,7 +169,7 @@ namespace ASCOM.Meade.net { if (System.Text.RegularExpressions.Regex.IsMatch(txtElevation.Text, "[^0-9]")) { - MessageBox.Show("Please enter only numbers."); + MessageBox.Show(Resources.SetupDialogForm_txtElevation_TextChanged_1_Please_enter_only_numbers_); txtElevation.Text = txtElevation.Text.Remove(txtElevation.Text.Length - 1); } } @@ -176,7 +178,7 @@ namespace ASCOM.Meade.net { if (System.Text.RegularExpressions.Regex.IsMatch(txtBacklashSteps.Text, "[^0-9]")) { - MessageBox.Show("Please enter only numbers."); + MessageBox.Show(Resources.SetupDialogForm_txtElevation_TextChanged_1_Please_enter_only_numbers_); txtBacklashSteps.Text = txtElevation.Text.Remove(txtBacklashSteps.Text.Length - 1); } } diff --git a/Meade.net/SetupDialogForm.designer.cs b/Meade.net/SetupDialogForm.designer.cs index 4d23524..d0858bd 100644 --- a/Meade.net/SetupDialogForm.designer.cs +++ b/Meade.net/SetupDialogForm.designer.cs @@ -61,7 +61,11 @@ namespace ASCOM.Meade.net this.label12 = new System.Windows.Forms.Label(); this.txtElevation = new System.Windows.Forms.TextBox(); this.label13 = new System.Windows.Forms.Label(); + this.label14 = new System.Windows.Forms.Label(); + this.nudSettleTime = new System.Windows.Forms.NumericUpDown(); + this.label15 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.picASCOM)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.nudSettleTime)).BeginInit(); this.SuspendLayout(); // // cmdOK @@ -231,10 +235,33 @@ namespace ASCOM.Meade.net resources.ApplyResources(this.label13, "label13"); this.label13.Name = "label13"; // + // label14 + // + resources.ApplyResources(this.label14, "label14"); + this.label14.Name = "label14"; + // + // nudSettleTime + // + resources.ApplyResources(this.nudSettleTime, "nudSettleTime"); + this.nudSettleTime.Maximum = new decimal(new int[] { + 32767, + 0, + 0, + 0}); + this.nudSettleTime.Name = "nudSettleTime"; + // + // label15 + // + resources.ApplyResources(this.label15, "label15"); + this.label15.Name = "label15"; + // // SetupDialogForm // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.label15); + this.Controls.Add(this.nudSettleTime); + this.Controls.Add(this.label14); this.Controls.Add(this.label13); this.Controls.Add(this.txtElevation); this.Controls.Add(this.label12); @@ -270,6 +297,7 @@ namespace ASCOM.Meade.net this.TopMost = true; this.Shown += new System.EventHandler(this.SetupDialogForm_Shown); ((System.ComponentModel.ISupportInitialize)(this.picASCOM)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.nudSettleTime)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -305,5 +333,8 @@ namespace ASCOM.Meade.net private Label label12; private TextBox txtElevation; private Label label13; + private Label label14; + private NumericUpDown nudSettleTime; + private Label label15; } } \ No newline at end of file diff --git a/Meade.net/SetupDialogForm.resx b/Meade.net/SetupDialogForm.resx index a71d20e..73de650 100644 --- a/Meade.net/SetupDialogForm.resx +++ b/Meade.net/SetupDialogForm.resx @@ -145,7 +145,7 @@ $this - 26 + 29 Bottom, Right @@ -172,7 +172,7 @@ $this - 25 + 28 12, 9 @@ -196,7 +196,7 @@ $this - 24 + 27 Top, Right @@ -223,7 +223,7 @@ $this - 23 + 26 True @@ -250,7 +250,7 @@ $this - 22 + 25 True @@ -277,7 +277,7 @@ $this - 21 + 24 97, 87 @@ -298,7 +298,7 @@ $this - 20 + 23 True @@ -325,7 +325,7 @@ $this - 19 + 22 97, 275 @@ -349,7 +349,7 @@ $this - 18 + 21 True @@ -376,7 +376,7 @@ $this - 17 + 20 True @@ -403,7 +403,7 @@ $this - 16 + 19 True @@ -430,7 +430,7 @@ $this - 15 + 18 Unchanged @@ -460,7 +460,7 @@ $this - 14 + 17 True @@ -490,7 +490,7 @@ $this - 13 + 16 Auto @@ -520,7 +520,7 @@ $this - 12 + 15 True @@ -550,7 +550,7 @@ $this - 11 + 14 True @@ -583,7 +583,7 @@ $this - 10 + 13 97, 411 @@ -607,7 +607,7 @@ $this - 8 + 11 True @@ -637,7 +637,7 @@ $this - 9 + 12 True @@ -667,7 +667,7 @@ $this - 7 + 10 True @@ -700,7 +700,7 @@ $this - 6 + 9 True @@ -727,7 +727,7 @@ $this - 5 + 8 True @@ -754,7 +754,7 @@ $this - 4 + 7 17, 17 @@ -790,7 +790,7 @@ $this - 3 + 6 17, 17 @@ -820,7 +820,7 @@ $this - 2 + 5 97, 202 @@ -841,7 +841,7 @@ $this - 1 + 4 True @@ -868,6 +868,81 @@ $this + 3 + + + True + + + 12, 236 + + + 56, 13 + + + 25 + + + Settle time + + + label14 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 2 + + + 97, 234 + + + 120, 20 + + + 26 + + + nudSettleTime + + + System.Windows.Forms.NumericUpDown, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 1 + + + True + + + 223, 236 + + + 47, 13 + + + 27 + + + seconds + + + label15 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + 0 diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index 625e9ed..1aae39b 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -146,6 +146,7 @@ namespace ASCOM.Meade.net private const string ReverseFocusDirectionName = "Reverse Focuser Direction"; private const string DynamicBreakingName = "Dynamic Breaking"; private const string SiteElevationName = "Site Elevation"; + private const string SettleTimeName = "Settle Time"; public static void WriteProfile(ProfileProperties profileProperties) { @@ -163,7 +164,8 @@ namespace ASCOM.Meade.net driverProfile.WriteValue(DriverId, BacklashCompensationName, profileProperties.BacklashCompensation.ToString()); driverProfile.WriteValue(DriverId, ReverseFocusDirectionName, profileProperties.ReverseFocusDirection.ToString()); driverProfile.WriteValue(DriverId, DynamicBreakingName, profileProperties.DynamicBreaking.ToString()); - driverProfile.WriteValue(DriverId, SiteElevationName, profileProperties.SiteElevation.ToString()); + driverProfile.WriteValue(DriverId, SiteElevationName, profileProperties.SiteElevation.ToString(CultureInfo.InvariantCulture)); + driverProfile.WriteValue(DriverId, SettleTimeName, profileProperties.SettleTime.ToString()); } } } @@ -178,6 +180,7 @@ namespace ASCOM.Meade.net private const string ReverseFocuserDiectionDefault = "true"; private const string DynamicBreakingDefault = "true"; private const string SiteElevationDefault = "0"; + private const string SettleTimeDefault = "2"; public static ProfileProperties ReadProfile() { @@ -197,6 +200,7 @@ namespace ASCOM.Meade.net profileProperties.ReverseFocusDirection = Convert.ToBoolean(driverProfile.GetValue(DriverId, ReverseFocusDirectionName, string.Empty, ReverseFocuserDiectionDefault)); profileProperties.DynamicBreaking = Convert.ToBoolean(driverProfile.GetValue(DriverId, DynamicBreakingName, string.Empty, DynamicBreakingDefault)); profileProperties.SiteElevation = Convert.ToInt32(driverProfile.GetValue(DriverId, SiteElevationName, string.Empty, SiteElevationDefault)); + profileProperties.SettleTime = Convert.ToInt16(driverProfile.GetValue(DriverId, SettleTimeName, string.Empty, SettleTimeDefault)); } return profileProperties;