From 6130cb6d64dee998b936d87201cbf2d28dae1564 Mon Sep 17 00:00:00 2001 From: Colin Date: Thu, 27 Feb 2020 22:57:19 +0000 Subject: [PATCH 1/4] Added new feature to allow the guiding style to be forced, Auto = driver decides. Pulse guiding will use the newer pulse guiding technique, Guide rate slew, will use the older technique. --- .../TelescopeUnitTests.cs | 24 +++-- Meade.net.Telescope/Telescope.cs | 28 +++-- .../SharedResourcesUnitTests.cs | 35 ++++-- Meade.net/ProfileProperties.cs | 1 + Meade.net/SetupDialogForm.cs | 13 ++- Meade.net/SetupDialogForm.designer.cs | 22 ++++ Meade.net/SetupDialogForm.resx | 102 ++++++++++++++---- Meade.net/SharedResources.cs | 7 +- 8 files changed, 183 insertions(+), 49 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 1bd772b..26b0bc5 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -34,7 +34,8 @@ namespace Meade.net.Telescope.UnitTests TraceLogger = false, ComPort = "TestCom1", GuideRateArcSecondsPerSecond = 1.23, - Precision = "Unchanged" + Precision = "Unchanged", + GuidingStyle = "Auto" }; _utilMock = new Mock(); @@ -446,17 +447,24 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Verify(x => x.Disconnect(It.IsAny(), It.IsAny()), Times.Once()); } - [TestCase("Autostar", "30Ab", false)] - [TestCase("Autostar", "31Ee", true)] - [TestCase("Autostar", "43Eg", true)] - [TestCase("Autostar II", "", false)] - [TestCase("LX2001", "", true)] - [TestCase(":GVP", "", false)] //LX200 Classic - public void IsNewPulseGuidingSupported_ThenIsSupported_ThenReturnsTrue(string productName, string firmware, bool isSupported) + [TestCase("Auto", "Autostar", "30Ab", false)] + [TestCase("Auto","Autostar", "31Ee", true)] + [TestCase("Auto","Autostar", "43Eg", true)] + [TestCase("Auto","Autostar II", "", false)] + [TestCase("Auto","LX2001", "", true)] + [TestCase("Auto",":GVP", "", false)] //LX200 Classic + [TestCase("Guide Rate Slew", "LX2001", "", false)] //force old style + [TestCase("Pulse Guiding", ":GVP", "", true)] //force new style + + public void IsNewPulseGuidingSupported_ThenIsSupported_ThenReturnsTrue(string guidingStyle, string productName, string firmware, bool isSupported) { _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(productName); _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(firmware); + _profileProperties.GuidingStyle = guidingStyle; + + _telescope.Connected = true; + var result = _telescope.IsNewPulseGuidingSupported(); Assert.That(result, Is.EqualTo(isSupported)); diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 8a41f33..a5f6141 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -481,17 +481,26 @@ namespace ASCOM.Meade.net public bool IsNewPulseGuidingSupported() { - if (_sharedResourcesWrapper.ProductName == TelescopeList.Autostar497) + switch (_guidingStyle) { - return FirmwareIsGreaterThan(TelescopeList.Autostar497_31Ee); - } + case "guide rate slew": + return false; + case "pulse guiding": + return true; - if (_sharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) - { - return true; - } + default: + if (_sharedResourcesWrapper.ProductName == TelescopeList.Autostar497) + { + return FirmwareIsGreaterThan(TelescopeList.Autostar497_31Ee); + } - return false; + if (_sharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) + { + return true; + } + + return false; + } } private bool IsLongFormatSupported() @@ -2131,6 +2140,7 @@ namespace ASCOM.Meade.net private DriveRates _trackingRate = DriveRates.driveSidereal; private string _precision; + private string _guidingStyle; public DriveRates TrackingRate { @@ -2427,11 +2437,13 @@ namespace ASCOM.Meade.net _comPort = profileProperties.ComPort; _guideRate = profileProperties.GuideRateArcSecondsPerSecond; _precision = profileProperties.Precision; + _guidingStyle = profileProperties.GuidingStyle.ToLower(); LogMessage("ReadProfile", $"Trace logger enabled: {_tl.Enabled}"); LogMessage("ReadProfile", $"Com Port: {_comPort}"); LogMessage("ReadProfile", $"Guide Rate: {_guideRate}"); LogMessage("ReadProfile", $"Precision: {_precision}"); + LogMessage("ReadProfile", $"Guiding Style: {_guidingStyle}"); } private void WriteProfile() diff --git a/Meade.net.UnitTests/SharedResourcesUnitTests.cs b/Meade.net.UnitTests/SharedResourcesUnitTests.cs index 1551ad2..27c6bd7 100644 --- a/Meade.net.UnitTests/SharedResourcesUnitTests.cs +++ b/Meade.net.UnitTests/SharedResourcesUnitTests.cs @@ -123,6 +123,7 @@ namespace Meade.net.UnitTests profileWrapperMock.Verify(x => x.WriteValue(DriverId, "COM Port", profileProperties.ComPort), Times.Once); profileWrapperMock.Verify(x => x.WriteValue(DriverId, "Guide Rate Arc Seconds Per Second", profileProperties.GuideRateArcSecondsPerSecond.ToString(CultureInfo.CurrentCulture)), Times.Once); profileWrapperMock.Verify(x => x.WriteValue(DriverId, "Precision", profileProperties.Precision), Times.Once); + profileWrapperMock.Verify(x => x.WriteValue(DriverId, "Guiding Style", profileProperties.GuidingStyle), Times.Once); } [Test] @@ -134,6 +135,7 @@ namespace Meade.net.UnitTests string TraceStateDefault = "false"; string GuideRateProfileNameDefault = "10.077939"; //67% of sidereal rate string PrecisionDefault = "Unchanged"; + string GuidingStyleDefault = "Auto"; Mock profileWrapperMock = new Mock(); profileWrapperMock.SetupAllProperties(); @@ -147,6 +149,8 @@ namespace Meade.net.UnitTests GuideRateProfileNameDefault)).Returns(GuideRateProfileNameDefault); profileWrapperMock.Setup(x => x.GetValue(DriverId, "Precision", string.Empty, PrecisionDefault)) .Returns(PrecisionDefault); + profileWrapperMock.Setup(x => x.GetValue(DriverId, "Guiding Style", string.Empty, GuidingStyleDefault)) + .Returns(GuidingStyleDefault); IProfileWrapper profeWrapper = profileWrapperMock.Object; @@ -163,6 +167,7 @@ namespace Meade.net.UnitTests Is.EqualTo(double.Parse(GuideRateProfileNameDefault))); Assert.That(profileProperties.TraceLogger, Is.EqualTo(bool.Parse(TraceStateDefault))); Assert.That(profileProperties.Precision, Is.EqualTo(PrecisionDefault)); + Assert.That(profileProperties.GuidingStyle, Is.EqualTo(GuidingStyleDefault)); } [TestCase("TCP")] @@ -247,11 +252,17 @@ namespace Meade.net.UnitTests _serialMock.Setup(x => x.ReceiveTerminated("#")).Returns(() => throw new Exception("Testerror")); var connectionResult = SharedResources.Connect(deviceId, string.Empty); - - Assert.That(connectionResult.SameDevice, Is.EqualTo(1)); - Assert.That(SharedResources.ProductName, Is.EqualTo(TelescopeList.LX200CLASSIC)); + try + { - SharedResources.Disconnect(deviceId, String.Empty); + + Assert.That(connectionResult.SameDevice, Is.EqualTo(1)); + Assert.That(SharedResources.ProductName, Is.EqualTo(TelescopeList.LX200CLASSIC)); + } + finally + { + SharedResources.Disconnect(deviceId, String.Empty); + } } [Test] @@ -291,12 +302,16 @@ namespace Meade.net.UnitTests _serialMock.Setup(x => x.ReceiveTerminated("#")).Returns(() => serialPortReturn); var connectionResult = SharedResources.Connect(deviceId, string.Empty); - - Assert.That(connectionResult.SameDevice, Is.EqualTo(1)); - Assert.That(SharedResources.ProductName, Is.EqualTo(TelescopeList.Autostar497)); - Assert.That(SharedResources.FirmwareVersion, Is.EqualTo(TelescopeList.Autostar497_43Eg)); - - SharedResources.Disconnect(deviceId, String.Empty); + try + { + Assert.That(connectionResult.SameDevice, Is.EqualTo(1)); + Assert.That(SharedResources.ProductName, Is.EqualTo(TelescopeList.Autostar497)); + Assert.That(SharedResources.FirmwareVersion, Is.EqualTo(TelescopeList.Autostar497_43Eg)); + } + finally + { + SharedResources.Disconnect(deviceId, String.Empty); + } } } } diff --git a/Meade.net/ProfileProperties.cs b/Meade.net/ProfileProperties.cs index 02f047a..56ee4a5 100644 --- a/Meade.net/ProfileProperties.cs +++ b/Meade.net/ProfileProperties.cs @@ -7,5 +7,6 @@ namespace ASCOM.Meade.net public bool TraceLogger { get; set; } public double GuideRateArcSecondsPerSecond { get; set; } public string Precision { get; set; } + public string GuidingStyle { get; set; } } } \ No newline at end of file diff --git a/Meade.net/SetupDialogForm.cs b/Meade.net/SetupDialogForm.cs index 0a26df9..8c7c814 100644 --- a/Meade.net/SetupDialogForm.cs +++ b/Meade.net/SetupDialogForm.cs @@ -71,6 +71,16 @@ namespace ASCOM.Meade.net { cboPrecision.SelectedItem = "Unchanged"; } + + try + { + cboGuidingStyle.SelectedItem = profileProperties.GuidingStyle; + } + catch (Exception e) + { + cboGuidingStyle.SelectedItem = "Auto"; + } + } public ProfileProperties GetProfile() @@ -80,7 +90,8 @@ namespace ASCOM.Meade.net TraceLogger = chkTrace.Checked, ComPort = comboBoxComPort.SelectedItem.ToString(), GuideRateArcSecondsPerSecond = double.Parse(txtGuideRate.Text.Trim()), - Precision = cboPrecision.SelectedItem.ToString() + Precision = cboPrecision.SelectedItem.ToString(), + GuidingStyle = cboGuidingStyle.SelectedItem.ToString() }; return profileProperties; diff --git a/Meade.net/SetupDialogForm.designer.cs b/Meade.net/SetupDialogForm.designer.cs index 10e1f06..4b40bb9 100644 --- a/Meade.net/SetupDialogForm.designer.cs +++ b/Meade.net/SetupDialogForm.designer.cs @@ -45,6 +45,8 @@ namespace ASCOM.Meade.net this.lblPercentOfSiderealRate = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label(); this.cboPrecision = new System.Windows.Forms.ComboBox(); + this.label6 = new System.Windows.Forms.Label(); + this.cboGuidingStyle = new System.Windows.Forms.ComboBox(); ((System.ComponentModel.ISupportInitialize)(this.picASCOM)).BeginInit(); this.SuspendLayout(); // @@ -133,10 +135,28 @@ namespace ASCOM.Meade.net resources.ApplyResources(this.cboPrecision, "cboPrecision"); this.cboPrecision.Name = "cboPrecision"; // + // label6 + // + resources.ApplyResources(this.label6, "label6"); + this.label6.Name = "label6"; + // + // cboGuidingStyle + // + this.cboGuidingStyle.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.cboGuidingStyle.FormattingEnabled = true; + this.cboGuidingStyle.Items.AddRange(new object[] { + resources.GetString("cboGuidingStyle.Items"), + resources.GetString("cboGuidingStyle.Items1"), + resources.GetString("cboGuidingStyle.Items2")}); + resources.ApplyResources(this.cboGuidingStyle, "cboGuidingStyle"); + this.cboGuidingStyle.Name = "cboGuidingStyle"; + // // SetupDialogForm // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.cboGuidingStyle); + this.Controls.Add(this.label6); this.Controls.Add(this.cboPrecision); this.Controls.Add(this.label5); this.Controls.Add(this.lblPercentOfSiderealRate); @@ -178,5 +198,7 @@ namespace ASCOM.Meade.net private Label lblPercentOfSiderealRate; private Label label5; private ComboBox cboPrecision; + private Label label6; + private ComboBox cboGuidingStyle; } } \ No newline at end of file diff --git a/Meade.net/SetupDialogForm.resx b/Meade.net/SetupDialogForm.resx index 84d89dc..4bb64fd 100644 --- a/Meade.net/SetupDialogForm.resx +++ b/Meade.net/SetupDialogForm.resx @@ -123,7 +123,7 @@ - 281, 225 + 281, 250 59, 24 @@ -145,13 +145,13 @@ $this - 12 + 14 Bottom, Right - 281, 255 + 281, 280 59, 25 @@ -172,7 +172,7 @@ $this - 11 + 13 12, 9 @@ -196,7 +196,7 @@ $this - 10 + 12 Top, Right @@ -223,7 +223,7 @@ $this - 9 + 11 True @@ -250,13 +250,13 @@ $this - 8 + 10 True - 77, 136 + 86, 136 69, 17 @@ -277,10 +277,10 @@ $this - 7 + 9 - 77, 87 + 86, 87 90, 21 @@ -298,7 +298,7 @@ $this - 6 + 8 True @@ -325,10 +325,10 @@ $this - 5 + 7 - 77, 159 + 86, 159 46, 20 @@ -349,13 +349,13 @@ $this - 4 + 6 True - 129, 162 + 138, 162 122, 13 @@ -376,13 +376,13 @@ $this - 3 + 5 True - 129, 175 + 138, 175 105, 13 @@ -403,7 +403,7 @@ $this - 2 + 4 True @@ -430,7 +430,7 @@ $this - 1 + 3 Unchanged @@ -442,7 +442,7 @@ High - 77, 191 + 86, 191 90, 21 @@ -460,6 +460,66 @@ $this + 2 + + + True + + + NoControl + + + 13, 221 + + + 67, 13 + + + 14 + + + Guiding style + + + label6 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 1 + + + Auto + + + Guide rate slew + + + Pulse guiding + + + 86, 218 + + + 90, 21 + + + 15 + + + cboGuidingStyle + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + 0 @@ -469,7 +529,7 @@ 6, 13 - 350, 288 + 350, 313 CenterScreen diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index b391c15..5b5b23b 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -139,7 +139,8 @@ namespace ASCOM.Meade.net private const string TraceStateProfileName = "Trace Level"; private const string GuideRateProfileName = "Guide Rate Arc Seconds Per Second"; private const string PrecisionProfileName = "Precision"; - + private const string GuidingStyleProfileName = "Guiding Style"; + public static void WriteProfile(ProfileProperties profileProperties) { lock (LockObject) @@ -151,6 +152,7 @@ namespace ASCOM.Meade.net driverProfile.WriteValue(DriverId, ComPortProfileName, profileProperties.ComPort); driverProfile.WriteValue(DriverId, GuideRateProfileName, profileProperties.GuideRateArcSecondsPerSecond.ToString(CultureInfo.InvariantCulture)); driverProfile.WriteValue(DriverId, PrecisionProfileName, profileProperties.Precision); + driverProfile.WriteValue(DriverId, GuidingStyleProfileName, profileProperties.GuidingStyle); } } } @@ -159,6 +161,8 @@ namespace ASCOM.Meade.net private const string TraceStateDefault = "false"; private const string GuideRateProfileNameDefault = "10.077939"; //67% of sidereal rate private const string PrecisionDefault = "Unchanged"; + private const string GuidingStyleDefault = "Auto"; + public static ProfileProperties ReadProfile() { @@ -172,6 +176,7 @@ namespace ASCOM.Meade.net profileProperties.TraceLogger = Convert.ToBoolean(driverProfile.GetValue(DriverId, TraceStateProfileName, string.Empty, TraceStateDefault)); profileProperties.GuideRateArcSecondsPerSecond = double.Parse(driverProfile.GetValue(DriverId, GuideRateProfileName, string.Empty, GuideRateProfileNameDefault), NumberFormatInfo.InvariantInfo); profileProperties.Precision = driverProfile.GetValue(DriverId, PrecisionProfileName, string.Empty, PrecisionDefault); + profileProperties.GuidingStyle = driverProfile.GetValue(DriverId, GuidingStyleProfileName, string.Empty, GuidingStyleDefault); } return profileProperties; From 07665b761780d4f570ef9ddf1d0857623e6b5b8d Mon Sep 17 00:00:00 2001 From: Colin Date: Thu, 27 Feb 2020 23:42:23 +0000 Subject: [PATCH 2/4] removed unused local variable --- Meade.net/SetupDialogForm.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Meade.net/SetupDialogForm.cs b/Meade.net/SetupDialogForm.cs index 8c7c814..851b048 100644 --- a/Meade.net/SetupDialogForm.cs +++ b/Meade.net/SetupDialogForm.cs @@ -76,7 +76,7 @@ namespace ASCOM.Meade.net { cboGuidingStyle.SelectedItem = profileProperties.GuidingStyle; } - catch (Exception e) + catch (Exception) { cboGuidingStyle.SelectedItem = "Auto"; } From b9522ae2a2548de46e8662810cf2c8ae4b6e8af2 Mon Sep 17 00:00:00 2001 From: Colin Date: Sat, 23 May 2020 18:40:04 +0100 Subject: [PATCH 3/4] Added and error message to the trace log when the com port is failing and looping back data --- Meade.net.Focuser.UnitTests/FocuserUnitTests.cs | 8 ++++---- Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs | 12 ++++++------ Meade.net.Telescope/Telescope.cs | 2 +- Meade.net.UnitTests/SharedResourcesUnitTests.cs | 11 +++++++---- Meade.net.focuser/Focuser.cs | 2 +- Meade.net/SharedResources.cs | 6 ++++-- Meade.net/Wrapper/SharedResourcesWrapper.cs | 7 ++++--- 7 files changed, 27 insertions(+), 21 deletions(-) diff --git a/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs b/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs index 4e68ce4..4fab074 100644 --- a/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs +++ b/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs @@ -181,7 +181,7 @@ namespace Meade.net.Focuser.UnitTests _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(firmware); _focuser.Connected = true; - _sharedResourcesWrapperMock.Verify(x => x.Connect("Serial", It.IsAny()), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.Connect("Serial", It.IsAny(), It.IsAny()), Times.Once); } @@ -189,20 +189,20 @@ namespace Meade.net.Focuser.UnitTests public void Connected_Set_SettingTrueWhenTrue_ThenDoesNothing() { ConnectFocuser(); - _sharedResourcesWrapperMock.Verify(x => x.Connect(It.IsAny(), It.IsAny()), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.Connect(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); //act _focuser.Connected = true; //assert - _sharedResourcesWrapperMock.Verify(x => x.Connect(It.IsAny(), It.IsAny()), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.Connect(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); } [Test] public void Connected_Set_SettingFalseWhenTrue_ThenDisconnects() { ConnectFocuser(); - _sharedResourcesWrapperMock.Verify(x => x.Connect(It.IsAny(), It.IsAny()), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.Connect(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); //act _focuser.Connected = false; diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 26b0bc5..7d5f056 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -56,7 +56,7 @@ namespace Meade.net.Telescope.UnitTests SameDevice = 1 }; - _sharedResourcesWrapperMock.Setup(x => x.Connect("Serial", It.IsAny())).Returns( () => _connectionInfo ); + _sharedResourcesWrapperMock.Setup(x => x.Connect("Serial", It.IsAny(), It.IsAny())).Returns( () => _connectionInfo ); _sharedResourcesWrapperMock.Setup(x => x.ReadProfile()).Returns(_profileProperties); @@ -384,7 +384,7 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(firmware); _telescope.Connected = true; - _sharedResourcesWrapperMock.Verify( x => x.Connect("Serial", It.IsAny()), Times.Once); + _sharedResourcesWrapperMock.Verify( x => x.Connect("Serial", It.IsAny(), It.IsAny()), Times.Once); _sharedResourcesWrapperMock.Verify(x => x.SendString("#:GZ#"), Times.Once); _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"#:Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}#"),Times.Once); @@ -400,7 +400,7 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(firmware); _telescope.Connected = true; - _sharedResourcesWrapperMock.Verify(x => x.Connect("Serial", It.IsAny()), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.Connect("Serial", It.IsAny(), It.IsAny()), Times.Once); _sharedResourcesWrapperMock.Verify(x => x.SendString("#:GZ#"), Times.Never); _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"#:Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}#"), Times.Never); } @@ -410,20 +410,20 @@ namespace Meade.net.Telescope.UnitTests public void Connected_Set_SettingTrueWhenTrue_ThenDoesNothing() { ConnectTelescope(); - _sharedResourcesWrapperMock.Verify( x => x.Connect(It.IsAny(), It.IsAny()),Times.Once); + _sharedResourcesWrapperMock.Verify( x => x.Connect(It.IsAny(), It.IsAny(), It.IsAny()),Times.Once); //act _telescope.Connected = true; //assert - _sharedResourcesWrapperMock.Verify(x => x.Connect(It.IsAny(), It.IsAny()), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.Connect(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); } [Test] public void Connected_Set_SettingFalseWhenTrue_ThenDisconnects() { ConnectTelescope(); - _sharedResourcesWrapperMock.Verify(x => x.Connect(It.IsAny(), It.IsAny()), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.Connect(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); //act _telescope.Connected = false; diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index a5f6141..c366a9c 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -406,7 +406,7 @@ namespace ASCOM.Meade.net ReadProfile(); LogMessage("Connected Set", "Connecting to port {0}", _comPort); - var connectionInfo = _sharedResourcesWrapper.Connect("Serial", DriverId); + var connectionInfo = _sharedResourcesWrapper.Connect("Serial", DriverId, _tl); try { LogMessage("Connected Set", $"Connected to port {_comPort}. Product: {_sharedResourcesWrapper.ProductName} Version:{_sharedResourcesWrapper.FirmwareVersion}"); diff --git a/Meade.net.UnitTests/SharedResourcesUnitTests.cs b/Meade.net.UnitTests/SharedResourcesUnitTests.cs index 27c6bd7..03d9e46 100644 --- a/Meade.net.UnitTests/SharedResourcesUnitTests.cs +++ b/Meade.net.UnitTests/SharedResourcesUnitTests.cs @@ -13,6 +13,7 @@ namespace Meade.net.UnitTests public class SharedResourcesUnitTests { private Mock _serialMock; + private Mock _traceLoggerMock; [SetUp] public void Setup() @@ -20,6 +21,8 @@ namespace Meade.net.UnitTests _serialMock = new Mock(); _serialMock.SetupAllProperties(); + _traceLoggerMock = new Mock(); + SharedResources.SharedSerial = _serialMock.Object; } @@ -174,7 +177,7 @@ namespace Meade.net.UnitTests [TestCase("Carrier Pigeon")] public void Connect_WhenDeviceIdIsNotSerial_ThenThrowsException( string deviceId) { - var result = Assert.Throws( () => { SharedResources.Connect(deviceId, string.Empty); } ); + var result = Assert.Throws( () => { SharedResources.Connect(deviceId, string.Empty, _traceLoggerMock.Object); } ); Assert.That( result.Message, Is.EqualTo($"deviceId {deviceId} not currently supported") ); } @@ -214,7 +217,7 @@ namespace Meade.net.UnitTests _serialMock.Setup(x => x.Transmit(":GVP#")).Callback(() => { serialPortReturn = ":GVP#"; }); _serialMock.Setup(x => x.ReceiveTerminated("#")).Returns( () => serialPortReturn); - var result = Assert.Throws(() => { SharedResources.Connect(deviceId, string.Empty); }); + var result = Assert.Throws(() => { SharedResources.Connect(deviceId, string.Empty, _traceLoggerMock.Object); }); Assert.That(result.Message, Is.EqualTo("Serial port is looping back data, something is wrong with the hardware.")); } @@ -251,7 +254,7 @@ namespace Meade.net.UnitTests _serialMock.Setup(x => x.Transmit(":GVP#")).Callback(() => { }); _serialMock.Setup(x => x.ReceiveTerminated("#")).Returns(() => throw new Exception("Testerror")); - var connectionResult = SharedResources.Connect(deviceId, string.Empty); + var connectionResult = SharedResources.Connect(deviceId, string.Empty, _traceLoggerMock.Object); try { @@ -301,7 +304,7 @@ namespace Meade.net.UnitTests _serialMock.Setup(x => x.Transmit(":GVN#")).Callback(() => { serialPortReturn = TelescopeList.Autostar497_43Eg; }); _serialMock.Setup(x => x.ReceiveTerminated("#")).Returns(() => serialPortReturn); - var connectionResult = SharedResources.Connect(deviceId, string.Empty); + var connectionResult = SharedResources.Connect(deviceId, string.Empty, _traceLoggerMock.Object); try { Assert.That(connectionResult.SameDevice, Is.EqualTo(1)); diff --git a/Meade.net.focuser/Focuser.cs b/Meade.net.focuser/Focuser.cs index e92e611..33ac3e4 100644 --- a/Meade.net.focuser/Focuser.cs +++ b/Meade.net.focuser/Focuser.cs @@ -187,7 +187,7 @@ namespace ASCOM.Meade.net try { ReadProfile(); - _sharedResourcesWrapper.Connect("Serial", DriverId); + _sharedResourcesWrapper.Connect("Serial", DriverId, _tl); try { IsConnected = true; diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index 5b5b23b..2d73b72 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -243,7 +243,7 @@ namespace ASCOM.Meade.net /// /// /// - public static ConnectionInfo Connect(string deviceId, string driverId) + public static ConnectionInfo Connect(string deviceId, string driverId, ITraceLogger traceLogger) { lock (LockObject) { @@ -273,14 +273,16 @@ namespace ASCOM.Meade.net ProductName = SendString(":GVP#"); FirmwareVersion = SendString(":GVN#"); } - catch (Exception) + catch (Exception ex) { + traceLogger.LogIssue("Connect", $"Error getting telescope information \"{ex.Message}\" setting to LX200 Classic mode."); ProductName = TelescopeList.LX200CLASSIC; FirmwareVersion = "Unknown"; } if (ProductName == ":GVP") { + traceLogger.LogIssue("Connect", "Serial port is looping back data, something is wrong with the hardware."); //This means that the serial port is looping back what's been sent, something is very wrong. SharedSerial.Connected = false; diff --git a/Meade.net/Wrapper/SharedResourcesWrapper.cs b/Meade.net/Wrapper/SharedResourcesWrapper.cs index 8220fbe..b9fa801 100644 --- a/Meade.net/Wrapper/SharedResourcesWrapper.cs +++ b/Meade.net/Wrapper/SharedResourcesWrapper.cs @@ -1,10 +1,11 @@ using System; +using ASCOM.Utilities.Interfaces; namespace ASCOM.Meade.net.Wrapper { public interface ISharedResourcesWrapper { - ConnectionInfo Connect(string deviceId, string driverId); + ConnectionInfo Connect(string deviceId, string driverId, ITraceLogger traceLogger); void Disconnect(string deviceId, string driverId); string ProductName { get; } @@ -29,9 +30,9 @@ namespace ASCOM.Meade.net.Wrapper public class SharedResourcesWrapper : ISharedResourcesWrapper { - public ConnectionInfo Connect(string deviceId, string driverId) + public ConnectionInfo Connect(string deviceId, string driverId, ITraceLogger traceLogger) { - return SharedResources.Connect(deviceId, driverId); + return SharedResources.Connect(deviceId, driverId, traceLogger); } public void Disconnect(string deviceId, string driverId) From 894b78d9f1646533dfb4d0af06a05ebc28126647 Mon Sep 17 00:00:00 2001 From: Colin Date: Sat, 23 May 2020 19:23:48 +0100 Subject: [PATCH 4/4] code inspections --- Meade.net.Telescope/Telescope.cs | 2 +- Meade.net/SharedResources.cs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index c366a9c..4cec2f4 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -134,7 +134,7 @@ namespace ASCOM.Meade.net } private double _guideRate; - private bool _isGuiding = false; + private bool _isGuiding; private void Initialise() { diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index 2d73b72..dbe28f5 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -243,6 +243,7 @@ namespace ASCOM.Meade.net /// /// /// + /// public static ConnectionInfo Connect(string deviceId, string driverId, ITraceLogger traceLogger) { lock (LockObject)