diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index bc217c2..9fce5ed 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -30,6 +30,7 @@ namespace Meade.net.Telescope.UnitTests _profileProperties = new ProfileProperties(); _profileProperties.TraceLogger = false; _profileProperties.ComPort = "TestCom1"; + _profileProperties.GuideRateArcSecondsPerSecond = 1.23; _utilMock = new Mock(); _utilExtraMock = new Mock(); @@ -37,7 +38,8 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock = new Mock(); _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#")).Returns("DDD*MM’SS"); - + + _sharedResourcesWrapperMock.Setup(x => x.ReadProfile()).Returns(_profileProperties); _sharedResourcesWrapperMock.Setup(x => x.Lock(It.IsAny())).Callback(action => { action(); }); _sharedResourcesWrapperMock.Setup(x => x.Lock(It.IsAny>())).Returns>( (func) => func()); _sharedResourcesWrapperMock.Setup(x => x.Lock(It.IsAny>())).Returns>((func) => func()); @@ -643,8 +645,7 @@ namespace Meade.net.Telescope.UnitTests var result = _telescope.CanSetGuideRates; - //Assert.That(result, Is.True); - Assert.That(result, Is.False); + Assert.That(result, Is.True); } [Test] @@ -829,7 +830,7 @@ namespace Meade.net.Telescope.UnitTests { var result = _telescope.GuideRateDeclination; - Assert.That(result, Is.EqualTo(0.004178074616551509)); + Assert.That(result, Is.EqualTo(0.00034166666666666666)); } [Test] @@ -843,26 +844,26 @@ namespace Meade.net.Telescope.UnitTests Assert.That(excpetion.AccessorSet, Is.True); } - //[Test] - //public void GuideRateDeclination_Set_WhenIsSupported_ThenSetsNewGuideRate() - //{ - // var newGuideRate = 10; + [Test] + public void GuideRateDeclination_Set_WhenIsSupported_ThenSetsNewGuideRate() + { + var newGuideRate = 0.00034166666666666666; - // _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.LX200GPS); + _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.LX200GPS); - // _telescope.GuideRateDeclination = newGuideRate; + _telescope.GuideRateDeclination = newGuideRate; - // _sharedResourcesWrapperMock.Verify( x => x.SendBlind(":Rg10.0#"),Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":Rg01.2#"), Times.Once); - // Assert.That(_telescope.GuideRateDeclination, Is.EqualTo(newGuideRate)); - //} + Assert.That(_telescope.GuideRateDeclination, Is.EqualTo(newGuideRate)); + } [Test] public void GuideRateRightAscension_Get_ThenThrowsException() { var result = _telescope.GuideRateRightAscension; - Assert.That(result, Is.EqualTo(0.004178074616551509)); + Assert.That(result, Is.EqualTo(0.00034166666666666666)); } [Test] @@ -876,19 +877,19 @@ namespace Meade.net.Telescope.UnitTests Assert.That(excpetion.AccessorSet, Is.True); } - //[Test] - //public void GuideRateRightAscension_Set_WhenIsSupported_ThenSetsNewGuideRate() - //{ - // var newGuideRate = 10; + [Test] + public void GuideRateRightAscension_Set_WhenIsSupported_ThenSetsNewGuideRate() + { + var newGuideRate = 0.00034166666666666666; - // _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.LX200GPS); + _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.LX200GPS); - // _telescope.GuideRateRightAscension = newGuideRate; + _telescope.GuideRateRightAscension = newGuideRate; - // _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":Rg10.0#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":Rg01.2#"), Times.Once); - // Assert.That(_telescope.GuideRateDeclination, Is.EqualTo(newGuideRate)); - //} + Assert.That(_telescope.GuideRateDeclination, Is.EqualTo(newGuideRate)); + } [Test] public void IsPulseGuiding_Get_ReturnsFalse() diff --git a/Meade.net.Telescope/StringExtensions.cs b/Meade.net.Telescope/StringExtensions.cs index 85341c5..14909c1 100644 --- a/Meade.net.Telescope/StringExtensions.cs +++ b/Meade.net.Telescope/StringExtensions.cs @@ -6,5 +6,10 @@ namespace ASCOM.Meade.net { return int.Parse(str); } + + public static double ToDouble(this string str) + { + return double.Parse(str); + } } } \ No newline at end of file diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 35f5a27..28dc3b4 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -111,9 +111,7 @@ namespace ASCOM.Meade.net ReadProfile(); // Read device configuration from the ASCOM Profile store IsConnected = false; // Initialise connected to false - - _guideRate = 15.0 * (1.0 / 3600.0) / SIDRATE; - + LogMessage("Telescope", "Completed initialisation"); } @@ -376,15 +374,14 @@ namespace ASCOM.Meade.net return false; } - //todo implement ability to read and write the guide rate from the telescope. - //private bool IsGuideRateSettingSupported() - //{ - // if (_sharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) - // { - // return true; - // } - // return false; - //} + private bool IsGuideRateSettingSupported() + { + if (_sharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) + { + return true; + } + return false; + } private bool FirmwareIsGreaterThan(string minVersion) { @@ -759,8 +756,7 @@ namespace ASCOM.Meade.net { CheckConnected("CanSetGuideRates Get"); - //var canSetGuideRate = IsGuideRateSettingSupported(); - var canSetGuideRate = false; + var canSetGuideRate = IsGuideRateSettingSupported(); LogMessage("CanSetGuideRates", "Get - " + canSetGuideRate.ToString()); return canSetGuideRate; @@ -946,33 +942,48 @@ namespace ASCOM.Meade.net private void SetNewGuideRate(double value, string propertyName) { - //if (!IsGuideRateSettingSupported()) - //{ + if (!IsGuideRateSettingSupported()) + { LogMessage("GuideRateDeclination Set", "Not implemented"); throw new PropertyNotImplementedException(propertyName, true); - //} + } - //if (!value.InRange(0, 15.0417)) - //{ - // throw new InvalidValueException(propertyName, value.ToString(), "0 to 15.0417”/sec"); - //} + var valueInArcSecondsPerSecond = DegreesPerSecondToArcSecondPerSecond(value); - //_sharedResourcesWrapper.SendBlind($":Rg{value:00.0}#"); - ////:RgSS.S# - ////Set guide rate to +/ -SS.S to arc seconds per second.This rate is added to or subtracted from the current tracking - ////Rates when the CCD guider or handbox guider buttons are pressed when the guide rate is selected.Rate shall not exceed - ////sidereal speed(approx 15.0417”/sec)[Autostar II only] - ////Returns: Nothing + if (!valueInArcSecondsPerSecond.InRange(0, 15.0417)) + { + throw new InvalidValueException(propertyName, valueInArcSecondsPerSecond.ToString(), "0 to 15.0417”/sec"); + } - // _guideRate = value; + _sharedResourcesWrapper.SendBlind($":Rg{valueInArcSecondsPerSecond:00.0}#"); + //:RgSS.S# + //Set guide rate to +/ -SS.S to arc seconds per second.This rate is added to or subtracted from the current tracking + //Rates when the CCD guider or handbox guider buttons are pressed when the guide rate is selected.Rate shall not exceed + //sidereal speed(approx 15.0417”/sec)[Autostar II only] + //Returns: Nothing + + _guideRate = valueInArcSecondsPerSecond; + + WriteProfile(); + } + + private double DegreesPerSecondToArcSecondPerSecond(double value) + { + return value * 3600.0; + } + + private double ArcSecondPerSecondToDegreesPerSecond(double value) + { + return value / 3600.0; } public double GuideRateDeclination { get { - LogMessage("GuideRateDeclination Get", "Not implemented"); - return _guideRate; + var degreesPerSecond = ArcSecondPerSecondToDegreesPerSecond(_guideRate); + LogMessage("GuideRateDeclination Get", $"{_guideRate:00.0} arc seconds / second = {degreesPerSecond} degrees per second"); + return degreesPerSecond; } set { @@ -984,8 +995,9 @@ namespace ASCOM.Meade.net { get { - LogMessage("GuideRateRightAscension Get", "Not implemented"); - return _guideRate; + var degreesPerSecond = ArcSecondPerSecondToDegreesPerSecond(_guideRate); + LogMessage("GuideRateRightAscension Get", $"{_guideRate:00.0} arc seconds / second = {degreesPerSecond} degrees per second"); + return degreesPerSecond; } set { @@ -2087,11 +2099,24 @@ namespace ASCOM.Meade.net /// internal void ReadProfile() { - var profileProperties = _sharedResourcesWrapper.ReadProfile(); + ProfileProperties profileProperties = _sharedResourcesWrapper.ReadProfile(); _tl.Enabled = profileProperties.TraceLogger; _comPort = profileProperties.ComPort; + _guideRate = profileProperties.GuideRateArcSecondsPerSecond; } + internal void WriteProfile() + { + var profileProperties = new ProfileProperties + { + TraceLogger = _tl.Enabled, + ComPort = _comPort, + GuideRateArcSecondsPerSecond = _guideRate + }; + + _sharedResourcesWrapper.WriteProfile(profileProperties); + } + /// /// Log helper function that takes formatted strings and arguments /// diff --git a/Meade.net/GarbageCollection.cs b/Meade.net/GarbageCollection.cs index f6d5e82..a68096f 100644 --- a/Meade.net/GarbageCollection.cs +++ b/Meade.net/GarbageCollection.cs @@ -9,14 +9,12 @@ namespace ASCOM.Meade.net class GarbageCollection { private bool _mbContinueThread; - private bool _mGcWatchStopped; private readonly int _miInterval; private readonly ManualResetEvent _mEventThreadEnded; public GarbageCollection(int iInterval) { _mbContinueThread = true; - _mGcWatchStopped = false; _miInterval = iInterval; _mEventThreadEnded = new ManualResetEvent(false); } diff --git a/Meade.net/ProfileProperties.cs b/Meade.net/ProfileProperties.cs index a445dd4..6614cc8 100644 --- a/Meade.net/ProfileProperties.cs +++ b/Meade.net/ProfileProperties.cs @@ -5,5 +5,6 @@ namespace ASCOM.Meade.net // properies that are part of the profile public string ComPort { get; set; } public bool TraceLogger { get; set; } + public double GuideRateArcSecondsPerSecond { get; set; } } } \ No newline at end of file diff --git a/Meade.net/SetupDialogForm.cs b/Meade.net/SetupDialogForm.cs index c416f5d..433f63d 100644 --- a/Meade.net/SetupDialogForm.cs +++ b/Meade.net/SetupDialogForm.cs @@ -46,6 +46,8 @@ namespace ASCOM.Meade.net { comboBoxComPort.SelectedItem = profileProperties.ComPort; } + + txtGuideRate.Text = profileProperties.GuideRateArcSecondsPerSecond.ToString(); } public ProfileProperties GetProfile() @@ -63,5 +65,16 @@ namespace ASCOM.Meade.net { Activate(); } + + private void TextBox1_TextChanged(object sender, EventArgs e) + { + //const double SIDRATE = 0.9972695677; //synodic/solar seconds per sidereal second + var newGuideRate = double.Parse(txtGuideRate.Text); + + const double siderealArcSecondsPerSecond = 15.041; + var percentOfSideReal = (newGuideRate / siderealArcSecondsPerSecond * 100); + + lblPercentOfSiderealRate.Text = $"({percentOfSideReal:00.0}% of sidereal rate)"; + } } } \ No newline at end of file diff --git a/Meade.net/SetupDialogForm.designer.cs b/Meade.net/SetupDialogForm.designer.cs index 11f868f..b09f711 100644 --- a/Meade.net/SetupDialogForm.designer.cs +++ b/Meade.net/SetupDialogForm.designer.cs @@ -36,6 +36,10 @@ namespace ASCOM.Meade.net this.label2 = new System.Windows.Forms.Label(); this.chkTrace = new System.Windows.Forms.CheckBox(); this.comboBoxComPort = new System.Windows.Forms.ComboBox(); + this.label3 = new System.Windows.Forms.Label(); + this.txtGuideRate = new System.Windows.Forms.TextBox(); + this.label4 = new System.Windows.Forms.Label(); + this.lblPercentOfSiderealRate = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.picASCOM)).BeginInit(); this.SuspendLayout(); // @@ -86,10 +90,35 @@ namespace ASCOM.Meade.net resources.ApplyResources(this.comboBoxComPort, "comboBoxComPort"); this.comboBoxComPort.Name = "comboBoxComPort"; // + // label3 + // + resources.ApplyResources(this.label3, "label3"); + this.label3.Name = "label3"; + // + // txtGuideRate + // + resources.ApplyResources(this.txtGuideRate, "txtGuideRate"); + this.txtGuideRate.Name = "txtGuideRate"; + this.txtGuideRate.TextChanged += new System.EventHandler(this.TextBox1_TextChanged); + // + // label4 + // + resources.ApplyResources(this.label4, "label4"); + this.label4.Name = "label4"; + // + // lblPercentOfSiderealRate + // + resources.ApplyResources(this.lblPercentOfSiderealRate, "lblPercentOfSiderealRate"); + this.lblPercentOfSiderealRate.Name = "lblPercentOfSiderealRate"; + // // SetupDialogForm // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.lblPercentOfSiderealRate); + this.Controls.Add(this.label4); + this.Controls.Add(this.txtGuideRate); + this.Controls.Add(this.label3); this.Controls.Add(this.comboBoxComPort); this.Controls.Add(this.chkTrace); this.Controls.Add(this.label2); @@ -118,5 +147,9 @@ namespace ASCOM.Meade.net private System.Windows.Forms.Label label2; private System.Windows.Forms.CheckBox chkTrace; private System.Windows.Forms.ComboBox comboBoxComPort; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox txtGuideRate; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.Label lblPercentOfSiderealRate; } } \ No newline at end of file diff --git a/Meade.net/SetupDialogForm.resx b/Meade.net/SetupDialogForm.resx index b050dfb..99399de 100644 --- a/Meade.net/SetupDialogForm.resx +++ b/Meade.net/SetupDialogForm.resx @@ -123,7 +123,7 @@ - 281, 112 + 281, 225 59, 24 @@ -145,13 +145,13 @@ $this - 6 + 10 Bottom, Right - 281, 142 + 281, 255 59, 25 @@ -172,7 +172,7 @@ $this - 5 + 9 12, 9 @@ -196,7 +196,7 @@ $this - 4 + 8 Top, Right @@ -223,7 +223,7 @@ $this - 3 + 7 True @@ -250,7 +250,7 @@ $this - 2 + 6 True @@ -277,7 +277,7 @@ $this - 1 + 5 77, 87 @@ -298,6 +298,111 @@ $this + 4 + + + True + + + 13, 225 + + + 61, 13 + + + 8 + + + Guide Rate + + + label3 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 3 + + + 80, 222 + + + 46, 20 + + + 9 + + + 10.0 + + + txtGuideRate + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 2 + + + True + + + 132, 225 + + + 122, 13 + + + 10 + + + Arc seconds per second + + + label4 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 1 + + + True + + + 132, 238 + + + 105, 13 + + + 11 + + + (67% of sidereal rate) + + + lblPercentOfSiderealRate + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + 0 @@ -307,7 +412,7 @@ 6, 13 - 350, 175 + 350, 288 CenterScreen diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index 9068cf3..1e79de9 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -158,6 +158,7 @@ namespace ASCOM.Meade.net // Constants used for Profile persistence private const string ComPortProfileName = "COM Port"; private const string TraceStateProfileName = "Trace Level"; + private const string GuideRateProfileName = "Guide Rate Arc Seconds Per Second"; public static void WriteProfile(ProfileProperties profileProperties) { @@ -168,12 +169,14 @@ namespace ASCOM.Meade.net driverProfile.DeviceType = "Telescope"; driverProfile.WriteValue(DriverId, TraceStateProfileName, profileProperties.TraceLogger.ToString()); driverProfile.WriteValue(DriverId, ComPortProfileName, profileProperties.ComPort); + driverProfile.WriteValue(DriverId, GuideRateProfileName, profileProperties.GuideRateArcSecondsPerSecond.ToString()); } } } private const string ComPortDefault = "COM1"; private const string TraceStateDefault = "false"; + private const string GuideRateProfileNameDefault = "10.077939"; //67% of sidereal rate public static ProfileProperties ReadProfile() { @@ -183,10 +186,9 @@ namespace ASCOM.Meade.net using (Profile driverProfile = new Profile()) { driverProfile.DeviceType = "Telescope"; - profileProperties.ComPort = - driverProfile.GetValue(DriverId, ComPortProfileName, string.Empty, ComPortDefault); - profileProperties.TraceLogger = Convert.ToBoolean(driverProfile.GetValue(DriverId, - TraceStateProfileName, string.Empty, TraceStateDefault)); + profileProperties.ComPort = driverProfile.GetValue(DriverId, ComPortProfileName, string.Empty, ComPortDefault); + profileProperties.TraceLogger = Convert.ToBoolean(driverProfile.GetValue(DriverId, TraceStateProfileName, string.Empty, TraceStateDefault)); + profileProperties.GuideRateArcSecondsPerSecond = double.Parse(driverProfile.GetValue(DriverId, GuideRateProfileName, string.Empty, GuideRateProfileNameDefault)); } return profileProperties; diff --git a/Meade.net/Wrapper/SharedResourcesWrapper.cs b/Meade.net/Wrapper/SharedResourcesWrapper.cs index e4df7f5..c2fda79 100644 --- a/Meade.net/Wrapper/SharedResourcesWrapper.cs +++ b/Meade.net/Wrapper/SharedResourcesWrapper.cs @@ -23,6 +23,7 @@ namespace ASCOM.Meade.net.Wrapper ProfileProperties ReadProfile(); void SetupDialog(); + void WriteProfile(ProfileProperties profileProperties); } public class SharedResourcesWrapper : ISharedResourcesWrapper @@ -80,5 +81,10 @@ namespace ASCOM.Meade.net.Wrapper { SharedResources.SetupDialog(); } + + public void WriteProfile(ProfileProperties profileProperties) + { + SharedResources.WriteProfile(profileProperties); + } } } diff --git a/TelescopeTestConsole/TelescopeTestConsole.csproj b/TelescopeTestConsole/TelescopeTestConsole.csproj index 7fb2a6a..625da99 100644 --- a/TelescopeTestConsole/TelescopeTestConsole.csproj +++ b/TelescopeTestConsole/TelescopeTestConsole.csproj @@ -16,7 +16,7 @@ 512 - AnyCPU + x86 true full false