From 51bf99cb8c10883dea64f93b337484929106fd85 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Fri, 9 Apr 2021 12:54:25 +0100 Subject: [PATCH 01/28] Started adding full serial port settings, so that people can do crazy things at their own risk. --- Meade.net/SetupDialogForm.cs | 27 ++ Meade.net/SetupDialogForm.designer.cs | 99 +++++++ Meade.net/SetupDialogForm.resx | 393 ++++++++++++++++++++++---- 3 files changed, 462 insertions(+), 57 deletions(-) diff --git a/Meade.net/SetupDialogForm.cs b/Meade.net/SetupDialogForm.cs index d56b963..42e7be1 100644 --- a/Meade.net/SetupDialogForm.cs +++ b/Meade.net/SetupDialogForm.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.ComponentModel; using System.Diagnostics; using System.Globalization; @@ -7,6 +8,7 @@ using System.Linq; using System.Runtime.InteropServices; using System.Windows.Forms; using ASCOM.Meade.net.Properties; +using ASCOM.Utilities; namespace ASCOM.Meade.net { @@ -20,6 +22,31 @@ namespace ASCOM.Meade.net var assemblyInfo = new AssemblyInfo(); Text = string.Format(Resources.SetupDialogForm_SetupDialogForm__0__Settings___1__, assemblyInfo.Product, assemblyInfo.AssemblyVersion); + + SetItemsFromEnum(cboStopBits.Items, typeof(SerialStopBits)); + SetItemsFromEnum(cboParity.Items, typeof(SerialParity)); + SetItemsFromEnumValues(cboSpeed.Items, typeof(SerialSpeed)); + SetItemsFromEnum(cboHandShake.Items, typeof(SerialHandshake)); + } + + private void SetItemsFromEnum(IList items, Type enumItems) + { + items.Clear(); + + foreach (var item in Enum.GetNames(enumItems)) + { + items.Add(item); + } + } + + private void SetItemsFromEnumValues(IList items, Type enumItems) + { + items.Clear(); + + foreach (int item in Enum.GetValues(enumItems)) + { + items.Add(item); + } } public sealed override string Text diff --git a/Meade.net/SetupDialogForm.designer.cs b/Meade.net/SetupDialogForm.designer.cs index d0858bd..e049e87 100644 --- a/Meade.net/SetupDialogForm.designer.cs +++ b/Meade.net/SetupDialogForm.designer.cs @@ -64,8 +64,20 @@ namespace ASCOM.Meade.net this.label14 = new System.Windows.Forms.Label(); this.nudSettleTime = new System.Windows.Forms.NumericUpDown(); this.label15 = new System.Windows.Forms.Label(); + this.label16 = new System.Windows.Forms.Label(); + this.cboStopBits = new System.Windows.Forms.ComboBox(); + this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); + this.cboParity = new System.Windows.Forms.ComboBox(); + this.cboSpeed = new System.Windows.Forms.ComboBox(); + this.cboHandShake = new System.Windows.Forms.ComboBox(); + this.label17 = new System.Windows.Forms.Label(); + this.label18 = new System.Windows.Forms.Label(); + this.label19 = new System.Windows.Forms.Label(); + this.label20 = new System.Windows.Forms.Label(); + this.label21 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.picASCOM)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nudSettleTime)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); this.SuspendLayout(); // // cmdOK @@ -255,10 +267,85 @@ namespace ASCOM.Meade.net resources.ApplyResources(this.label15, "label15"); this.label15.Name = "label15"; // + // label16 + // + resources.ApplyResources(this.label16, "label16"); + this.label16.Name = "label16"; + // + // cboStopBits + // + this.cboStopBits.FormattingEnabled = true; + resources.ApplyResources(this.cboStopBits, "cboStopBits"); + this.cboStopBits.Name = "cboStopBits"; + // + // numericUpDown1 + // + resources.ApplyResources(this.numericUpDown1, "numericUpDown1"); + this.numericUpDown1.Maximum = new decimal(new int[] { + 32767, + 0, + 0, + 0}); + this.numericUpDown1.Name = "numericUpDown1"; + // + // cboParity + // + this.cboParity.FormattingEnabled = true; + resources.ApplyResources(this.cboParity, "cboParity"); + this.cboParity.Name = "cboParity"; + // + // cboSpeed + // + this.cboSpeed.FormattingEnabled = true; + resources.ApplyResources(this.cboSpeed, "cboSpeed"); + this.cboSpeed.Name = "cboSpeed"; + // + // cboHandShake + // + this.cboHandShake.FormattingEnabled = true; + resources.ApplyResources(this.cboHandShake, "cboHandShake"); + this.cboHandShake.Name = "cboHandShake"; + // + // label17 + // + resources.ApplyResources(this.label17, "label17"); + this.label17.Name = "label17"; + // + // label18 + // + resources.ApplyResources(this.label18, "label18"); + this.label18.Name = "label18"; + // + // label19 + // + resources.ApplyResources(this.label19, "label19"); + this.label19.Name = "label19"; + // + // label20 + // + resources.ApplyResources(this.label20, "label20"); + this.label20.Name = "label20"; + // + // label21 + // + resources.ApplyResources(this.label21, "label21"); + this.label21.Name = "label21"; + // // SetupDialogForm // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.label21); + this.Controls.Add(this.label20); + this.Controls.Add(this.label19); + this.Controls.Add(this.label18); + this.Controls.Add(this.label17); + this.Controls.Add(this.cboHandShake); + this.Controls.Add(this.cboSpeed); + this.Controls.Add(this.cboParity); + this.Controls.Add(this.numericUpDown1); + this.Controls.Add(this.cboStopBits); + this.Controls.Add(this.label16); this.Controls.Add(this.label15); this.Controls.Add(this.nudSettleTime); this.Controls.Add(this.label14); @@ -298,6 +385,7 @@ namespace ASCOM.Meade.net this.Shown += new System.EventHandler(this.SetupDialogForm_Shown); ((System.ComponentModel.ISupportInitialize)(this.picASCOM)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.nudSettleTime)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -336,5 +424,16 @@ namespace ASCOM.Meade.net private Label label14; private NumericUpDown nudSettleTime; private Label label15; + private Label label16; + private ComboBox cboStopBits; + private NumericUpDown numericUpDown1; + private ComboBox cboParity; + private ComboBox cboSpeed; + private ComboBox cboHandShake; + private Label label17; + private Label label18; + private Label label19; + private Label label20; + private Label label21; } } \ No newline at end of file diff --git a/Meade.net/SetupDialogForm.resx b/Meade.net/SetupDialogForm.resx index 73de650..7500694 100644 --- a/Meade.net/SetupDialogForm.resx +++ b/Meade.net/SetupDialogForm.resx @@ -123,7 +123,7 @@ - 281, 457 + 557, 391 59, 24 @@ -145,13 +145,13 @@ $this - 29 + 40 Bottom, Right - 281, 487 + 557, 421 59, 25 @@ -172,7 +172,7 @@ $this - 28 + 39 12, 9 @@ -196,13 +196,13 @@ $this - 27 + 38 Top, Right - 292, 9 + 568, 9 48, 56 @@ -223,7 +223,7 @@ $this - 26 + 37 True @@ -250,22 +250,22 @@ $this - 25 + 36 True - 97, 137 + 97, 305 - 69, 17 + 90, 17 2 - Trace on + Trace Log on chkTrace @@ -277,7 +277,7 @@ $this - 24 + 35 97, 87 @@ -298,13 +298,13 @@ $this - 23 + 34 True - 12, 278 + 290, 169 61, 13 @@ -325,10 +325,10 @@ $this - 22 + 33 - 97, 275 + 375, 166 46, 20 @@ -349,13 +349,13 @@ $this - 21 + 32 True - 149, 278 + 427, 169 122, 13 @@ -376,13 +376,13 @@ $this - 20 + 31 True - 149, 291 + 427, 182 105, 13 @@ -403,13 +403,13 @@ $this - 19 + 30 True - 12, 310 + 290, 201 50, 13 @@ -430,7 +430,7 @@ $this - 18 + 29 Unchanged @@ -442,7 +442,7 @@ High - 97, 307 + 375, 198 90, 21 @@ -460,7 +460,7 @@ $this - 17 + 28 True @@ -469,7 +469,7 @@ NoControl - 12, 337 + 290, 228 67, 13 @@ -490,7 +490,7 @@ $this - 16 + 27 Auto @@ -502,7 +502,7 @@ Pulse guiding - 97, 334 + 375, 225 90, 21 @@ -520,7 +520,7 @@ $this - 15 + 26 True @@ -529,7 +529,7 @@ Microsoft Sans Serif, 8.25pt, style=Bold - 12, 176 + 290, 67 66, 13 @@ -550,7 +550,7 @@ $this - 14 + 25 True @@ -562,7 +562,7 @@ NoControl - 12, 393 + 290, 284 52, 13 @@ -583,10 +583,10 @@ $this - 13 + 24 - 97, 411 + 375, 302 46, 20 @@ -607,7 +607,7 @@ $this - 11 + 22 True @@ -616,7 +616,7 @@ NoControl - 12, 414 + 290, 305 79, 13 @@ -637,7 +637,7 @@ $this - 12 + 23 True @@ -646,7 +646,7 @@ NoControl - 149, 414 + 427, 305 20, 13 @@ -667,7 +667,7 @@ $this - 10 + 21 True @@ -700,13 +700,13 @@ $this - 9 + 20 True - 97, 437 + 375, 328 109, 17 @@ -727,13 +727,13 @@ $this - 8 + 19 True - 97, 460 + 375, 351 112, 17 @@ -754,7 +754,7 @@ $this - 7 + 18 17, 17 @@ -790,7 +790,7 @@ $this - 6 + 17 17, 17 @@ -799,7 +799,7 @@ True - 12, 205 + 290, 96 72, 13 @@ -820,10 +820,10 @@ $this - 5 + 16 - 97, 202 + 375, 93 100, 20 @@ -841,13 +841,13 @@ $this - 4 + 15 True - 203, 205 + 481, 96 38, 13 @@ -868,13 +868,13 @@ $this - 3 + 14 True - 12, 236 + 290, 127 56, 13 @@ -895,10 +895,10 @@ $this - 2 + 13 - 97, 234 + 375, 125 120, 20 @@ -916,13 +916,13 @@ $this - 1 + 12 True - 223, 236 + 501, 127 47, 13 @@ -943,16 +943,295 @@ $this + 11 + + + True + + + 15, 139 + + + 49, 13 + + + 29 + + + Data bits + + + label16 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 10 + + + 97, 163 + + + 119, 21 + + + 30 + + + cboStopBits + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 9 + + + 97, 137 + + + 120, 20 + + + 31 + + + numericUpDown1 + + + System.Windows.Forms.NumericUpDown, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 8 + + + 97, 190 + + + 119, 21 + + + 32 + + + cboParity + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 7 + + + 97, 217 + + + 119, 21 + + + 33 + + + cboSpeed + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 6 + + + 97, 244 + + + 121, 21 + + + 34 + + + cboHandShake + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 5 + + + True + + + 15, 166 + + + 49, 13 + + + 35 + + + Stop Bits + + + label17 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 4 + + + True + + + 15, 193 + + + 33, 13 + + + 36 + + + Parity + + + label18 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 3 + + + True + + + 15, 220 + + + 38, 13 + + + 37 + + + Speed + + + label19 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 2 + + + True + + + 15, 247 + + + 62, 13 + + + 38 + + + Handshake + + + label20 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 1 + + + True + + + Microsoft Sans Serif, 8.25pt, style=Bold + + + NoControl + + + 15, 284 + + + 73, 13 + + + 39 + + + Diagnostics + + + label21 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + 0 True + + 25 + 6, 13 - 350, 520 + 626, 454 + + + NoControl CenterScreen From bf6203d901e4ae0c02998e16c435b46d15943430 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Fri, 9 Apr 2021 19:57:43 +0100 Subject: [PATCH 02/28] Added support for setting all serial properties. --- Meade.net/ProfileProperties.cs | 5 +++ Meade.net/SetupDialogForm.cs | 45 +++++++++++++++++++++++++++ Meade.net/SetupDialogForm.designer.cs | 18 +++++------ Meade.net/SetupDialogForm.resx | 28 +++++++---------- Meade.net/SharedResources.cs | 32 ++++++++++++++++--- 5 files changed, 97 insertions(+), 31 deletions(-) diff --git a/Meade.net/ProfileProperties.cs b/Meade.net/ProfileProperties.cs index b4f11cc..391c31d 100644 --- a/Meade.net/ProfileProperties.cs +++ b/Meade.net/ProfileProperties.cs @@ -14,5 +14,10 @@ namespace ASCOM.Meade.net public bool RtsDtrEnabled { get; set; } public double SiteElevation { get; set; } public short SettleTime { get; set; } + public int DataBits { get; set; } + public string StopBits { get; set; } + public string Parity { get; set; } + public int Speed { get; set; } + public string Handshake { get; set; } } } \ No newline at end of file diff --git a/Meade.net/SetupDialogForm.cs b/Meade.net/SetupDialogForm.cs index 42e7be1..82fac95 100644 --- a/Meade.net/SetupDialogForm.cs +++ b/Meade.net/SetupDialogForm.cs @@ -110,6 +110,46 @@ namespace ASCOM.Meade.net cboGuidingStyle.SelectedItem = "Auto"; } + numDatabits.Value = profileProperties.DataBits; + + try + { + cboStopBits.SelectedItem = profileProperties.StopBits; + } + catch (Exception) + { + cboStopBits.SelectedItem = "One"; + } + + + try + { + cboParity.SelectedItem = profileProperties.Parity; + } + catch (Exception) + { + cboParity.SelectedItem = "None"; + } + + try + { + cboSpeed.SelectedItem = profileProperties.Speed; + } + catch (Exception) + { + cboParity.SelectedItem = "9600"; + } + + + try + { + cboHandShake.SelectedItem = profileProperties.Handshake; + } + catch (Exception) + { + cboHandShake.SelectedItem = "None"; + } + txtBacklashSteps.Text = profileProperties.BacklashCompensation.ToString(CultureInfo.CurrentCulture); txtElevation.Text = profileProperties.SiteElevation.ToString(CultureInfo.CurrentCulture); @@ -125,6 +165,11 @@ namespace ASCOM.Meade.net TraceLogger = chkTrace.Checked, ComPort = comboBoxComPort.SelectedItem.ToString(), RtsDtrEnabled = cbxRtsDtr.Checked, + DataBits = Convert.ToInt32(numDatabits.Value), + StopBits = cboStopBits.SelectedItem.ToString(), + Parity = cboParity.SelectedItem.ToString(), + Speed = Convert.ToInt32(cboSpeed.SelectedItem), + Handshake = cboHandShake.SelectedItem.ToString(), GuideRateArcSecondsPerSecond = double.Parse(txtGuideRate.Text.Trim()), Precision = cboPrecision.SelectedItem.ToString(), GuidingStyle = cboGuidingStyle.SelectedItem.ToString(), diff --git a/Meade.net/SetupDialogForm.designer.cs b/Meade.net/SetupDialogForm.designer.cs index e049e87..74b44f7 100644 --- a/Meade.net/SetupDialogForm.designer.cs +++ b/Meade.net/SetupDialogForm.designer.cs @@ -66,7 +66,7 @@ namespace ASCOM.Meade.net this.label15 = new System.Windows.Forms.Label(); this.label16 = new System.Windows.Forms.Label(); this.cboStopBits = new System.Windows.Forms.ComboBox(); - this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); + this.numDatabits = new System.Windows.Forms.NumericUpDown(); this.cboParity = new System.Windows.Forms.ComboBox(); this.cboSpeed = new System.Windows.Forms.ComboBox(); this.cboHandShake = new System.Windows.Forms.ComboBox(); @@ -77,7 +77,7 @@ namespace ASCOM.Meade.net this.label21 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.picASCOM)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nudSettleTime)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numDatabits)).BeginInit(); this.SuspendLayout(); // // cmdOK @@ -278,15 +278,15 @@ namespace ASCOM.Meade.net resources.ApplyResources(this.cboStopBits, "cboStopBits"); this.cboStopBits.Name = "cboStopBits"; // - // numericUpDown1 + // numDatabits // - resources.ApplyResources(this.numericUpDown1, "numericUpDown1"); - this.numericUpDown1.Maximum = new decimal(new int[] { + resources.ApplyResources(this.numDatabits, "numDatabits"); + this.numDatabits.Maximum = new decimal(new int[] { 32767, 0, 0, 0}); - this.numericUpDown1.Name = "numericUpDown1"; + this.numDatabits.Name = "numDatabits"; // // cboParity // @@ -343,7 +343,7 @@ namespace ASCOM.Meade.net this.Controls.Add(this.cboHandShake); this.Controls.Add(this.cboSpeed); this.Controls.Add(this.cboParity); - this.Controls.Add(this.numericUpDown1); + this.Controls.Add(this.numDatabits); this.Controls.Add(this.cboStopBits); this.Controls.Add(this.label16); this.Controls.Add(this.label15); @@ -385,7 +385,7 @@ namespace ASCOM.Meade.net this.Shown += new System.EventHandler(this.SetupDialogForm_Shown); ((System.ComponentModel.ISupportInitialize)(this.picASCOM)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.nudSettleTime)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numDatabits)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -426,7 +426,7 @@ namespace ASCOM.Meade.net private Label label15; private Label label16; private ComboBox cboStopBits; - private NumericUpDown numericUpDown1; + private NumericUpDown numDatabits; private ComboBox cboParity; private ComboBox cboSpeed; private ComboBox cboHandShake; diff --git a/Meade.net/SetupDialogForm.resx b/Meade.net/SetupDialogForm.resx index 7500694..ca8813c 100644 --- a/Meade.net/SetupDialogForm.resx +++ b/Meade.net/SetupDialogForm.resx @@ -756,9 +756,6 @@ 18 - - 17, 17 - True @@ -777,6 +774,9 @@ Enable RTS/DTR + + 17, 17 + Useful for Meade LS scopes @@ -792,9 +792,6 @@ 17 - - 17, 17 - True @@ -993,25 +990,25 @@ 9 - + 97, 137 - + 120, 20 - + 31 - - numericUpDown1 + + numDatabits - + System.Windows.Forms.NumericUpDown, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + $this - + 8 @@ -1230,9 +1227,6 @@ 626, 454 - - NoControl - CenterScreen diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index 1aae39b..af84be1 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -148,6 +148,12 @@ namespace ASCOM.Meade.net private const string SiteElevationName = "Site Elevation"; private const string SettleTimeName = "Settle Time"; + private const string SpeedName = "Speed"; + private const string DataBitsName = "8"; + private const string StopBitsName = "Stop Bits"; + private const string HandShakeName = "Hand Shake"; + private const string ParityName = "Parity"; + public static void WriteProfile(ProfileProperties profileProperties) { lock (LockObject) @@ -158,6 +164,11 @@ namespace ASCOM.Meade.net driverProfile.WriteValue(DriverId, TraceStateProfileName, profileProperties.TraceLogger.ToString()); driverProfile.WriteValue(DriverId, ComPortProfileName, profileProperties.ComPort); driverProfile.WriteValue(DriverId, RtsDtrProfileName, profileProperties.RtsDtrEnabled.ToString()); + driverProfile.WriteValue(DriverId, SpeedName, profileProperties.Speed.ToString(CultureInfo.InvariantCulture)); + driverProfile.WriteValue(DriverId, DataBitsName, profileProperties.DataBits.ToString(CultureInfo.InvariantCulture)); + driverProfile.WriteValue(DriverId, StopBitsName, profileProperties.StopBits); + driverProfile.WriteValue(DriverId, HandShakeName, profileProperties.Handshake); + driverProfile.WriteValue(DriverId, ParityName, profileProperties.Parity); driverProfile.WriteValue(DriverId, GuideRateProfileName, profileProperties.GuideRateArcSecondsPerSecond.ToString(CultureInfo.InvariantCulture)); driverProfile.WriteValue(DriverId, PrecisionProfileName, profileProperties.Precision); driverProfile.WriteValue(DriverId, GuidingStyleProfileName, profileProperties.GuidingStyle); @@ -181,6 +192,11 @@ namespace ASCOM.Meade.net private const string DynamicBreakingDefault = "true"; private const string SiteElevationDefault = "0"; private const string SettleTimeDefault = "2"; + private const string SpeedDefault = "9600"; + private const string DataBitsDefault = "8"; + private const string StopBitsDefault = "One"; + private const string HandShakeDefault = "None"; + private const string ParityDefault = "None"; public static ProfileProperties ReadProfile() { @@ -201,6 +217,12 @@ namespace ASCOM.Meade.net 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)); + profileProperties.StopBits = driverProfile.GetValue(DriverId, StopBitsName, string.Empty, StopBitsDefault); + profileProperties.DataBits = Convert.ToInt32(driverProfile.GetValue(DriverId, DataBitsName, string.Empty, DataBitsDefault)); + profileProperties.Handshake = driverProfile.GetValue(DriverId, HandShakeName, string.Empty, HandShakeDefault); + profileProperties.Speed = Convert.ToInt32(driverProfile.GetValue(DriverId, SpeedName, string.Empty, SpeedDefault)); + profileProperties.Parity = driverProfile.GetValue(DriverId, ParityName, string.Empty, ParityDefault); + } return profileProperties; @@ -286,11 +308,11 @@ namespace ASCOM.Meade.net SharedSerial.PortName = profileProperties.ComPort; SharedSerial.DTREnable = profileProperties.RtsDtrEnabled; SharedSerial.RTSEnable = profileProperties.RtsDtrEnabled; - SharedSerial.DataBits = 8; - SharedSerial.StopBits = SerialStopBits.One; - SharedSerial.Parity = SerialParity.None; - SharedSerial.Speed = SerialSpeed.ps9600; - SharedSerial.Handshake = SerialHandshake.None; + SharedSerial.DataBits = profileProperties.DataBits; + SharedSerial.StopBits = (SerialStopBits)Enum.Parse(typeof(SerialStopBits), profileProperties.StopBits ); + SharedSerial.Parity = (SerialParity)Enum.Parse(typeof(SerialParity), profileProperties.Parity); + SharedSerial.Speed = (SerialSpeed)profileProperties.Speed; + SharedSerial.Handshake = (SerialHandshake)Enum.Parse(typeof(SerialHandshake), profileProperties.Handshake); SharedSerial.Connected = true; try From 0835431e765272ac824a3394dfa1af7a43ff7f25 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Fri, 9 Apr 2021 20:07:52 +0100 Subject: [PATCH 03/28] Added new profile settings to the unit tests --- Meade.net.Focuser.UnitTests/FocuserUnitTests.cs | 6 ++++++ Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs b/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs index 2ba4e76..ca09d30 100644 --- a/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs +++ b/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs @@ -27,6 +27,12 @@ namespace Meade.net.Focuser.UnitTests { TraceLogger = false, ComPort = "TestCom1", + Speed = 9600, + Parity = "None", + Handshake = "None", + StopBits = "One", + DataBits = 8, + GuideRateArcSecondsPerSecond = 1.23, Precision = "Unchanged", GuidingStyle = "Auto" diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 16b330d..21dcaba 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -35,6 +35,12 @@ namespace Meade.net.Telescope.UnitTests { TraceLogger = false, ComPort = "TestCom1", + Speed = 9600, + Parity = "None", + Handshake = "None", + StopBits = "One", + DataBits = 8, + GuideRateArcSecondsPerSecond = 1.23, Precision = "Unchanged", GuidingStyle = "Auto" From 178ef8b11dd93c56575d0d65df1b37abbcbd5a3c Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Fri, 9 Apr 2021 20:43:12 +0100 Subject: [PATCH 04/28] Fixed the dataBits profile name, and upgraded the sharedresources unit tests for the new comport settings. --- .../SharedResourcesUnitTests.cs | 211 +++++++++++++++--- Meade.net/SharedResources.cs | 2 +- 2 files changed, 181 insertions(+), 32 deletions(-) diff --git a/Meade.net.UnitTests/SharedResourcesUnitTests.cs b/Meade.net.UnitTests/SharedResourcesUnitTests.cs index 025bfb5..976f3c6 100644 --- a/Meade.net.UnitTests/SharedResourcesUnitTests.cs +++ b/Meade.net.UnitTests/SharedResourcesUnitTests.cs @@ -123,10 +123,19 @@ namespace Meade.net.UnitTests Assert.That(profeWrapper.DeviceType, Is.EqualTo("Telescope")); profileWrapperMock.Verify( x => x.WriteValue(DriverId, "Trace Level", profileProperties.TraceLogger.ToString()), Times.Once); + profileWrapperMock.Verify(x => x.WriteValue(DriverId, "COM Port", profileProperties.ComPort), Times.Once); + profileWrapperMock.Verify(x => x.WriteValue(DriverId, "Speed", profileProperties.Speed.ToString()), Times.Once); + profileWrapperMock.Verify(x => x.WriteValue(DriverId, "Data Bits", profileProperties.DataBits.ToString()), Times.Once); + profileWrapperMock.Verify(x => x.WriteValue(DriverId, "Stop Bits", profileProperties.StopBits), Times.Once); + profileWrapperMock.Verify(x => x.WriteValue(DriverId, "Hand Shake", profileProperties.Handshake), Times.Once); + profileWrapperMock.Verify(x => x.WriteValue(DriverId, "Parity", profileProperties.Parity), Times.Once); + profileWrapperMock.Verify(x => x.WriteValue(DriverId, "Rts / Dtr", profileProperties.RtsDtrEnabled.ToString()), 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); + profileWrapperMock.Verify(x => x.WriteValue(DriverId, "Backlash Compensation", profileProperties.BacklashCompensation.ToString(CultureInfo.CurrentCulture)), Times.Once); profileWrapperMock.Verify(x => x.WriteValue(DriverId, "Reverse Focuser Direction", profileProperties.ReverseFocusDirection.ToString()), Times.Once); } @@ -136,13 +145,22 @@ namespace Meade.net.UnitTests { string DriverId = "ASCOM.MeadeGeneric.Telescope"; - string ComPortDefault = "COM1"; string TraceStateDefault = "false"; + + string ComPortDefault = "COM1"; + string SpeedDefault = "9600"; + string DataBitsDefault = "8"; + string StopBitsDefault = "One"; + string HandshakeDefault = "None"; + string ParityDefault = "None"; + string RtsDtrEnabledDefault = "false"; + string GuideRateProfileNameDefault = "10.077939"; //67% of sidereal rate string PrecisionDefault = "Unchanged"; string GuidingStyleDefault = "Auto"; + string BacklashCompensationDefault = "3000"; - string ReverseFocuserDiectionDefault = "true"; + string ReverseFocuserDiectionDefault = "true"; Mock profileWrapperMock = new Mock(); profileWrapperMock.SetupAllProperties(); @@ -165,6 +183,24 @@ namespace Meade.net.UnitTests profileWrapperMock.Setup(x => x.GetValue(DriverId, "Reverse Focuser Direction", string.Empty, ReverseFocuserDiectionDefault)) .Returns(() => ReverseFocuserDiectionDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Speed", string.Empty, SpeedDefault)) + .Returns(() => SpeedDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Data Bits", string.Empty, DataBitsDefault)) + .Returns(() => DataBitsDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Stop Bits", string.Empty, StopBitsDefault)) + .Returns(() => StopBitsDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Hand Shake", string.Empty, HandshakeDefault)) + .Returns(() => HandshakeDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Parity", string.Empty, ParityDefault)) + .Returns(() => ParityDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Rts / Dtr", string.Empty, RtsDtrEnabledDefault)) + .Returns(() => RtsDtrEnabledDefault); IProfileWrapper profeWrapper = profileWrapperMock.Object; @@ -174,16 +210,27 @@ namespace Meade.net.UnitTests SharedResources.ProfileFactory = profileFactoryMock.Object; var profileProperties = SharedResources.ReadProfile(); - + Assert.That(profeWrapper.DeviceType, Is.EqualTo("Telescope")); - Assert.That(profileProperties.ComPort, Is.EqualTo(ComPortDefault)); - Assert.That(profileProperties.GuideRateArcSecondsPerSecond, - Is.EqualTo(double.Parse(GuideRateProfileNameDefault))); + Assert.That(profileProperties.TraceLogger, Is.EqualTo(bool.Parse(TraceStateDefault))); + + Assert.That(profileProperties.ComPort, Is.EqualTo(ComPortDefault)); + + Assert.That(profileProperties.GuideRateArcSecondsPerSecond, + Is.EqualTo(double.Parse(GuideRateProfileNameDefault))); Assert.That(profileProperties.Precision, Is.EqualTo(PrecisionDefault)); Assert.That(profileProperties.GuidingStyle, Is.EqualTo(GuidingStyleDefault)); + Assert.That(profileProperties.BacklashCompensation, Is.EqualTo(int.Parse(BacklashCompensationDefault))); Assert.That(profileProperties.ReverseFocusDirection, Is.EqualTo(bool.Parse(ReverseFocuserDiectionDefault))); + + Assert.That(profileProperties.Speed, Is.EqualTo(int.Parse(SpeedDefault))); + Assert.That(profileProperties.DataBits, Is.EqualTo(int.Parse(DataBitsDefault))); + Assert.That(profileProperties.StopBits, Is.EqualTo(StopBitsDefault)); + Assert.That(profileProperties.Handshake, Is.EqualTo(HandshakeDefault)); + Assert.That(profileProperties.Parity, Is.EqualTo(ParityDefault)); + Assert.That(profileProperties.RtsDtrEnabled, Is.EqualTo(bool.Parse(RtsDtrEnabledDefault))); } [TestCase("TCP")] @@ -199,10 +246,16 @@ namespace Meade.net.UnitTests public void Connect_WhenDeviceIdIsSerialButGVPEchos_ThenThrowsException() { string deviceId = "Serial"; - - string driverDriverId = "ASCOM.MeadeGeneric.Telescope"; + string DriverId = "ASCOM.MeadeGeneric.Telescope"; string ComPortDefault = "COM1"; + string SpeedDefault = "9600"; + string DataBitsDefault = "8"; + string StopBitsDefault = "One"; + string HandshakeDefault = "None"; + string ParityDefault = "None"; + string RtsDtrEnabledDefault = "false"; + string TraceStateDefault = "false"; string GuideRateProfileNameDefault = "10.077939"; //67% of sidereal rate string PrecisionDefault = "Unchanged"; @@ -210,14 +263,33 @@ namespace Meade.net.UnitTests Mock profileWrapperMock = new Mock(); profileWrapperMock.SetupAllProperties(); - profileWrapperMock.Setup(x => x.GetValue(driverDriverId, "Trace Level", string.Empty, TraceStateDefault)) + profileWrapperMock.Setup(x => x.GetValue(DriverId, "Trace Level", string.Empty, TraceStateDefault)) .Returns(TraceStateDefault); - profileWrapperMock.Setup(x => x.GetValue(driverDriverId, "COM Port", string.Empty, ComPortDefault)) + profileWrapperMock.Setup(x => x.GetValue(DriverId, "COM Port", string.Empty, ComPortDefault)) .Returns(ComPortDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Speed", string.Empty, SpeedDefault)) + .Returns(() => SpeedDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Data Bits", string.Empty, DataBitsDefault)) + .Returns(() => DataBitsDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Stop Bits", string.Empty, StopBitsDefault)) + .Returns(() => StopBitsDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Hand Shake", string.Empty, HandshakeDefault)) + .Returns(() => HandshakeDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Parity", string.Empty, ParityDefault)) + .Returns(() => ParityDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Rts / Dtr", string.Empty, RtsDtrEnabledDefault)) + .Returns(() => RtsDtrEnabledDefault); + profileWrapperMock - .Setup(x => x.GetValue(driverDriverId, "Guide Rate Arc Seconds Per Second", string.Empty, + .Setup(x => x.GetValue(DriverId, "Guide Rate Arc Seconds Per Second", string.Empty, GuideRateProfileNameDefault)).Returns(GuideRateProfileNameDefault); - profileWrapperMock.Setup(x => x.GetValue(driverDriverId, "Precision", string.Empty, PrecisionDefault)) + profileWrapperMock.Setup(x => x.GetValue(DriverId, "Precision", string.Empty, PrecisionDefault)) .Returns(PrecisionDefault); Mock profileFactoryMock = new Mock(); @@ -239,26 +311,51 @@ namespace Meade.net.UnitTests public void Connect_WhenDeviceIdIsSerialButGVPNotSupported_ThenConnectsAndSetsProductToLX200Classic() { string deviceId = "Serial"; + string DriverId = "ASCOM.MeadeGeneric.Telescope"; - string driverDriverId = "ASCOM.MeadeGeneric.Telescope"; + string TraceStateDefault = "false"; string ComPortDefault = "COM1"; - string TraceStateDefault = "false"; + string SpeedDefault = "9600"; + string DataBitsDefault = "8"; + string StopBitsDefault = "One"; + string HandshakeDefault = "None"; + string ParityDefault = "None"; + string RtsDtrEnabledDefault = "false"; + string GuideRateProfileNameDefault = "10.077939"; //67% of sidereal rate string PrecisionDefault = "Unchanged"; - + Mock profileWrapperMock = new Mock(); profileWrapperMock.SetupAllProperties(); - profileWrapperMock.Setup(x => x.GetValue(driverDriverId, "Trace Level", string.Empty, TraceStateDefault)) + profileWrapperMock.Setup(x => x.GetValue(DriverId, "Trace Level", string.Empty, TraceStateDefault)) .Returns(TraceStateDefault); - profileWrapperMock.Setup(x => x.GetValue(driverDriverId, "COM Port", string.Empty, ComPortDefault)) + profileWrapperMock.Setup(x => x.GetValue(DriverId, "COM Port", string.Empty, ComPortDefault)) .Returns(ComPortDefault); profileWrapperMock - .Setup(x => x.GetValue(driverDriverId, "Guide Rate Arc Seconds Per Second", string.Empty, + .Setup(x => x.GetValue(DriverId, "Guide Rate Arc Seconds Per Second", string.Empty, GuideRateProfileNameDefault)).Returns(GuideRateProfileNameDefault); - profileWrapperMock.Setup(x => x.GetValue(driverDriverId, "Precision", string.Empty, PrecisionDefault)) + profileWrapperMock.Setup(x => x.GetValue(DriverId, "Precision", string.Empty, PrecisionDefault)) .Returns(PrecisionDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Speed", string.Empty, SpeedDefault)) + .Returns(() => SpeedDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Data Bits", string.Empty, DataBitsDefault)) + .Returns(() => DataBitsDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Stop Bits", string.Empty, StopBitsDefault)) + .Returns(() => StopBitsDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Hand Shake", string.Empty, HandshakeDefault)) + .Returns(() => HandshakeDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Parity", string.Empty, ParityDefault)) + .Returns(() => ParityDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Rts / Dtr", string.Empty, RtsDtrEnabledDefault)) + .Returns(() => RtsDtrEnabledDefault); Mock profileFactoryMock = new Mock(); profileFactoryMock.Setup(x => x.Create()).Returns(profileWrapperMock.Object); @@ -293,25 +390,51 @@ namespace Meade.net.UnitTests { string deviceId = "Serial"; - string driverDriverId = "ASCOM.MeadeGeneric.Telescope"; + string DriverId = "ASCOM.MeadeGeneric.Telescope"; + + string TraceStateDefault = "false"; string ComPortDefault = "COM1"; - string TraceStateDefault = "false"; + string SpeedDefault = "9600"; + string DataBitsDefault = "8"; + string StopBitsDefault = "One"; + string HandshakeDefault = "None"; + string ParityDefault = "None"; + string RtsDtrEnabledDefault = "false"; + string GuideRateProfileNameDefault = "10.077939"; //67% of sidereal rate string PrecisionDefault = "Unchanged"; Mock profileWrapperMock = new Mock(); profileWrapperMock.SetupAllProperties(); - profileWrapperMock.Setup(x => x.GetValue(driverDriverId, "Trace Level", string.Empty, TraceStateDefault)) + profileWrapperMock.Setup(x => x.GetValue(DriverId, "Trace Level", string.Empty, TraceStateDefault)) .Returns(TraceStateDefault); - profileWrapperMock.Setup(x => x.GetValue(driverDriverId, "COM Port", string.Empty, ComPortDefault)) + profileWrapperMock.Setup(x => x.GetValue(DriverId, "COM Port", string.Empty, ComPortDefault)) .Returns(ComPortDefault); profileWrapperMock - .Setup(x => x.GetValue(driverDriverId, "Guide Rate Arc Seconds Per Second", string.Empty, + .Setup(x => x.GetValue(DriverId, "Guide Rate Arc Seconds Per Second", string.Empty, GuideRateProfileNameDefault)).Returns(GuideRateProfileNameDefault); - profileWrapperMock.Setup(x => x.GetValue(driverDriverId, "Precision", string.Empty, PrecisionDefault)) + profileWrapperMock.Setup(x => x.GetValue(DriverId, "Precision", string.Empty, PrecisionDefault)) .Returns(PrecisionDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Speed", string.Empty, SpeedDefault)) + .Returns(() => SpeedDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Data Bits", string.Empty, DataBitsDefault)) + .Returns(() => DataBitsDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Stop Bits", string.Empty, StopBitsDefault)) + .Returns(() => StopBitsDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Hand Shake", string.Empty, HandshakeDefault)) + .Returns(() => HandshakeDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Parity", string.Empty, ParityDefault)) + .Returns(() => ParityDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Rts / Dtr", string.Empty, RtsDtrEnabledDefault)) + .Returns(() => RtsDtrEnabledDefault); Mock profileFactoryMock = new Mock(); profileFactoryMock.Setup(x => x.Create()).Returns(profileWrapperMock.Object); @@ -343,25 +466,51 @@ namespace Meade.net.UnitTests { string deviceId = "Serial"; - string driverDriverId = "ASCOM.MeadeGeneric.Telescope"; + string DriverId = "ASCOM.MeadeGeneric.Telescope"; + + string TraceStateDefault = "false"; string ComPortDefault = "COM1"; - string TraceStateDefault = "false"; + string SpeedDefault = "9600"; + string DataBitsDefault = "8"; + string StopBitsDefault = "One"; + string HandshakeDefault = "None"; + string ParityDefault = "None"; + string RtsDtrEnabledDefault = "false"; + string GuideRateProfileNameDefault = "10.077939"; //67% of sidereal rate string PrecisionDefault = "Unchanged"; Mock profileWrapperMock = new Mock(); profileWrapperMock.SetupAllProperties(); - profileWrapperMock.Setup(x => x.GetValue(driverDriverId, "Trace Level", string.Empty, TraceStateDefault)) + profileWrapperMock.Setup(x => x.GetValue(DriverId, "Trace Level", string.Empty, TraceStateDefault)) .Returns(TraceStateDefault); - profileWrapperMock.Setup(x => x.GetValue(driverDriverId, "COM Port", string.Empty, ComPortDefault)) + profileWrapperMock.Setup(x => x.GetValue(DriverId, "COM Port", string.Empty, ComPortDefault)) .Returns(ComPortDefault); profileWrapperMock - .Setup(x => x.GetValue(driverDriverId, "Guide Rate Arc Seconds Per Second", string.Empty, + .Setup(x => x.GetValue(DriverId, "Guide Rate Arc Seconds Per Second", string.Empty, GuideRateProfileNameDefault)).Returns(GuideRateProfileNameDefault); - profileWrapperMock.Setup(x => x.GetValue(driverDriverId, "Precision", string.Empty, PrecisionDefault)) + profileWrapperMock.Setup(x => x.GetValue(DriverId, "Precision", string.Empty, PrecisionDefault)) .Returns(PrecisionDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Speed", string.Empty, SpeedDefault)) + .Returns(() => SpeedDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Data Bits", string.Empty, DataBitsDefault)) + .Returns(() => DataBitsDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Stop Bits", string.Empty, StopBitsDefault)) + .Returns(() => StopBitsDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Hand Shake", string.Empty, HandshakeDefault)) + .Returns(() => HandshakeDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Parity", string.Empty, ParityDefault)) + .Returns(() => ParityDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Rts / Dtr", string.Empty, RtsDtrEnabledDefault)) + .Returns(() => RtsDtrEnabledDefault); Mock profileFactoryMock = new Mock(); profileFactoryMock.Setup(x => x.Create()).Returns(profileWrapperMock.Object); diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index af84be1..cb1e747 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -149,7 +149,7 @@ namespace ASCOM.Meade.net private const string SettleTimeName = "Settle Time"; private const string SpeedName = "Speed"; - private const string DataBitsName = "8"; + private const string DataBitsName = "Data Bits"; private const string StopBitsName = "Stop Bits"; private const string HandShakeName = "Hand Shake"; private const string ParityName = "Parity"; From d0f12a604ac0bf560adaf18ef93316a8a7d64f6c Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Fri, 9 Apr 2021 21:35:19 +0100 Subject: [PATCH 05/28] Made the new serial options dropdownLists to help avoid ID10T errors. --- Meade.net/SetupDialogForm.designer.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Meade.net/SetupDialogForm.designer.cs b/Meade.net/SetupDialogForm.designer.cs index 74b44f7..701c5be 100644 --- a/Meade.net/SetupDialogForm.designer.cs +++ b/Meade.net/SetupDialogForm.designer.cs @@ -274,6 +274,7 @@ namespace ASCOM.Meade.net // // cboStopBits // + this.cboStopBits.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cboStopBits.FormattingEnabled = true; resources.ApplyResources(this.cboStopBits, "cboStopBits"); this.cboStopBits.Name = "cboStopBits"; @@ -290,18 +291,21 @@ namespace ASCOM.Meade.net // // cboParity // + this.cboParity.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cboParity.FormattingEnabled = true; resources.ApplyResources(this.cboParity, "cboParity"); this.cboParity.Name = "cboParity"; // // cboSpeed // + this.cboSpeed.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cboSpeed.FormattingEnabled = true; resources.ApplyResources(this.cboSpeed, "cboSpeed"); this.cboSpeed.Name = "cboSpeed"; // // cboHandShake // + this.cboHandShake.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cboHandShake.FormattingEnabled = true; resources.ApplyResources(this.cboHandShake, "cboHandShake"); this.cboHandShake.Name = "cboHandShake"; From e4af93dd0753590640e82106c3f52a8fa3beea75 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Wed, 21 Apr 2021 20:17:00 +0100 Subject: [PATCH 06/28] Added ability to skip the prompts initial connect, and added ability to send the date and time on initial connect --- Meade.net.Telescope/Telescope.cs | 27 +++ .../SharedResourcesUnitTests.cs | 24 ++- Meade.net/MeadeTelescopeBase.cs | 6 + Meade.net/ProfileProperties.cs | 2 + Meade.net/SetupDialogForm.cs | 9 +- Meade.net/SetupDialogForm.designer.cs | 21 +++ Meade.net/SetupDialogForm.resx | 163 +++++++++++++----- Meade.net/SharedResources.cs | 9 +- 8 files changed, 207 insertions(+), 54 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index ada8098..aa23f75 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -418,6 +418,9 @@ namespace ASCOM.Meade.net } SetTelescopePrecision("Connect"); + + ApplySkipAutoStarPrompts("Connect"); + SendCurrentDateTime("Connect"); } else { @@ -447,6 +450,30 @@ namespace ASCOM.Meade.net } } + private void SendCurrentDateTime(string connect) + { + if (SendDateTime) + { + UTCDate = DateTime.UtcNow; + } + } + + private void ApplySkipAutoStarPrompts(string connect) + { + if (SkipAutoStarPrompts) + { + var displayText = Action("Handbox", "readdisplay"); + if (displayText.Contains("Daylight")) + { + for(var i = 0; i < 3; i++) + { + Action("Handbox", "enter"); + _utilities.WaitForMilliseconds(2000); + } + } + } + } + private void SetTelescopePrecision(string propertyName) { switch (Precision.ToLower()) diff --git a/Meade.net.UnitTests/SharedResourcesUnitTests.cs b/Meade.net.UnitTests/SharedResourcesUnitTests.cs index 976f3c6..414d327 100644 --- a/Meade.net.UnitTests/SharedResourcesUnitTests.cs +++ b/Meade.net.UnitTests/SharedResourcesUnitTests.cs @@ -153,14 +153,17 @@ namespace Meade.net.UnitTests string StopBitsDefault = "One"; string HandshakeDefault = "None"; string ParityDefault = "None"; - string RtsDtrEnabledDefault = "false"; + string RtsDtrEnabledDefault = "true"; string GuideRateProfileNameDefault = "10.077939"; //67% of sidereal rate string PrecisionDefault = "Unchanged"; string GuidingStyleDefault = "Auto"; string BacklashCompensationDefault = "3000"; - string ReverseFocuserDiectionDefault = "true"; + string ReverseFocuserDiectionDefault = "true"; + + string SendDateTimeDefault = "true"; + string SkipPromptsDefault = "true"; Mock profileWrapperMock = new Mock(); profileWrapperMock.SetupAllProperties(); @@ -181,7 +184,7 @@ namespace Meade.net.UnitTests x.GetValue(DriverId, "Backlash Compensation", string.Empty, BacklashCompensationDefault)) .Returns(BacklashCompensationDefault); profileWrapperMock.Setup(x => - x.GetValue(DriverId, "Reverse Focuser Direction", string.Empty, ReverseFocuserDiectionDefault)) + x.GetValue(DriverId, "Reverse Focuser Direction", string.Empty, "true")) .Returns(() => ReverseFocuserDiectionDefault); profileWrapperMock.Setup(x => x.GetValue(DriverId, "Speed", string.Empty, SpeedDefault)) @@ -199,9 +202,19 @@ namespace Meade.net.UnitTests x.GetValue(DriverId, "Parity", string.Empty, ParityDefault)) .Returns(() => ParityDefault); profileWrapperMock.Setup(x => - x.GetValue(DriverId, "Rts / Dtr", string.Empty, RtsDtrEnabledDefault)) + x.GetValue(DriverId, "Rts / Dtr", string.Empty, "false")) .Returns(() => RtsDtrEnabledDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Send Date and time on connect", string.Empty, "false")) + .Returns(() => SendDateTimeDefault); + + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Skip date prompts on connect", string.Empty, "false")) + .Returns(() => SkipPromptsDefault); + + + IProfileWrapper profeWrapper = profileWrapperMock.Object; Mock profileFactoryMock = new Mock(); @@ -231,6 +244,9 @@ namespace Meade.net.UnitTests Assert.That(profileProperties.Handshake, Is.EqualTo(HandshakeDefault)); Assert.That(profileProperties.Parity, Is.EqualTo(ParityDefault)); Assert.That(profileProperties.RtsDtrEnabled, Is.EqualTo(bool.Parse(RtsDtrEnabledDefault))); + + Assert.That(profileProperties.SendDateTime, Is.EqualTo(bool.Parse(SendDateTimeDefault))); + Assert.That(profileProperties.SkipPrompts, Is.EqualTo(bool.Parse(SkipPromptsDefault))); } [TestCase("TCP")] diff --git a/Meade.net/MeadeTelescopeBase.cs b/Meade.net/MeadeTelescopeBase.cs index 51e0892..3e79993 100644 --- a/Meade.net/MeadeTelescopeBase.cs +++ b/Meade.net/MeadeTelescopeBase.cs @@ -28,6 +28,8 @@ namespace ASCOM.Meade.net protected string GuidingStyle; protected double SiteElevation; protected short ProfileSettleTime; + protected bool SkipAutoStarPrompts; + protected bool SendDateTime; protected readonly ISharedResourcesWrapper SharedResourcesWrapper; @@ -69,6 +71,8 @@ namespace ASCOM.Meade.net GuidingStyle = profileProperties.GuidingStyle.ToLower(); SiteElevation = profileProperties.SiteElevation; ProfileSettleTime = profileProperties.SettleTime; + SkipAutoStarPrompts = profileProperties.SkipPrompts; + SendDateTime = profileProperties.SendDateTime; LogMessage("ReadProfile", $"Trace logger enabled: {Tl.Enabled}"); LogMessage("ReadProfile", $"Com Port: {ComPort}"); @@ -79,6 +83,8 @@ namespace ASCOM.Meade.net LogMessage("ReadProfile", $"Guiding Style: {GuidingStyle}"); LogMessage("ReadProfile", $"Site Elevation: {SiteElevation}"); LogMessage("ReadProfile", $"Settle Time after slew: {ProfileSettleTime}"); + LogMessage("ReadProfile", $"Skip Autostar startup prompts: {SkipAutoStarPrompts}"); + LogMessage("ReadProfile", $"Send date and time on connect: {SendDateTime}"); } /// diff --git a/Meade.net/ProfileProperties.cs b/Meade.net/ProfileProperties.cs index 391c31d..9c03728 100644 --- a/Meade.net/ProfileProperties.cs +++ b/Meade.net/ProfileProperties.cs @@ -19,5 +19,7 @@ namespace ASCOM.Meade.net public string Parity { get; set; } public int Speed { get; set; } public string Handshake { get; set; } + public bool SendDateTime { get; set; } + public bool SkipPrompts { get; set; } } } \ No newline at end of file diff --git a/Meade.net/SetupDialogForm.cs b/Meade.net/SetupDialogForm.cs index 82fac95..40c753b 100644 --- a/Meade.net/SetupDialogForm.cs +++ b/Meade.net/SetupDialogForm.cs @@ -156,6 +156,9 @@ namespace ASCOM.Meade.net cbxReverseDirection.Checked = profileProperties.ReverseFocusDirection; cbxDynamicBreaking.Checked = profileProperties.DynamicBreaking; nudSettleTime.Value = profileProperties.SettleTime; + + cbxSendDateTime.Checked = profileProperties.SendDateTime; + cbxSkipPrompts.Checked = profileProperties.SkipPrompts; } public ProfileProperties GetProfile() @@ -177,8 +180,10 @@ namespace ASCOM.Meade.net ReverseFocusDirection = cbxReverseDirection.Checked, DynamicBreaking = cbxDynamicBreaking.Checked, SiteElevation = double.Parse(txtElevation.Text), - SettleTime = Convert.ToInt16(nudSettleTime.Value) - }; + SettleTime = Convert.ToInt16(nudSettleTime.Value), + SendDateTime = cbxSendDateTime.Checked, + SkipPrompts = cbxSkipPrompts.Checked + }; return profileProperties; } diff --git a/Meade.net/SetupDialogForm.designer.cs b/Meade.net/SetupDialogForm.designer.cs index 701c5be..2f9e0b7 100644 --- a/Meade.net/SetupDialogForm.designer.cs +++ b/Meade.net/SetupDialogForm.designer.cs @@ -75,6 +75,8 @@ namespace ASCOM.Meade.net this.label19 = new System.Windows.Forms.Label(); this.label20 = new System.Windows.Forms.Label(); this.label21 = new System.Windows.Forms.Label(); + this.cbxSkipPrompts = new System.Windows.Forms.CheckBox(); + this.cbxSendDateTime = new System.Windows.Forms.CheckBox(); ((System.ComponentModel.ISupportInitialize)(this.picASCOM)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nudSettleTime)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numDatabits)).BeginInit(); @@ -137,6 +139,7 @@ namespace ASCOM.Meade.net // resources.ApplyResources(this.txtGuideRate, "txtGuideRate"); this.txtGuideRate.Name = "txtGuideRate"; + this.toolTip1.SetToolTip(this.txtGuideRate, resources.GetString("txtGuideRate.ToolTip")); this.txtGuideRate.TextChanged += new System.EventHandler(this.TextBox1_TextChanged); // // label4 @@ -335,10 +338,26 @@ namespace ASCOM.Meade.net resources.ApplyResources(this.label21, "label21"); this.label21.Name = "label21"; // + // cbxSkipPrompts + // + resources.ApplyResources(this.cbxSkipPrompts, "cbxSkipPrompts"); + this.cbxSkipPrompts.Name = "cbxSkipPrompts"; + this.toolTip1.SetToolTip(this.cbxSkipPrompts, resources.GetString("cbxSkipPrompts.ToolTip")); + this.cbxSkipPrompts.UseVisualStyleBackColor = true; + // + // cbxSendDateTime + // + resources.ApplyResources(this.cbxSendDateTime, "cbxSendDateTime"); + this.cbxSendDateTime.Name = "cbxSendDateTime"; + this.toolTip1.SetToolTip(this.cbxSendDateTime, resources.GetString("cbxSendDateTime.ToolTip")); + this.cbxSendDateTime.UseVisualStyleBackColor = true; + // // SetupDialogForm // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.cbxSendDateTime); + this.Controls.Add(this.cbxSkipPrompts); this.Controls.Add(this.label21); this.Controls.Add(this.label20); this.Controls.Add(this.label19); @@ -439,5 +458,7 @@ namespace ASCOM.Meade.net private Label label19; private Label label20; private Label label21; + private CheckBox cbxSkipPrompts; + private CheckBox cbxSendDateTime; } } \ No newline at end of file diff --git a/Meade.net/SetupDialogForm.resx b/Meade.net/SetupDialogForm.resx index ca8813c..6103062 100644 --- a/Meade.net/SetupDialogForm.resx +++ b/Meade.net/SetupDialogForm.resx @@ -123,7 +123,7 @@ - 557, 391 + 715, 391 59, 24 @@ -145,13 +145,13 @@ $this - 40 + 42 Bottom, Right - 557, 421 + 715, 421 59, 25 @@ -172,7 +172,7 @@ $this - 39 + 41 12, 9 @@ -196,13 +196,13 @@ $this - 38 + 40 Top, Right - 568, 9 + 726, 9 48, 56 @@ -223,7 +223,7 @@ $this - 37 + 39 True @@ -250,7 +250,7 @@ $this - 36 + 38 True @@ -277,7 +277,7 @@ $this - 35 + 37 97, 87 @@ -298,7 +298,7 @@ $this - 34 + 36 True @@ -325,7 +325,7 @@ $this - 33 + 35 375, 166 @@ -339,6 +339,12 @@ 10.0 + + 17, 17 + + + LX-200GPS only + txtGuideRate @@ -349,7 +355,7 @@ $this - 32 + 34 True @@ -376,7 +382,7 @@ $this - 31 + 33 True @@ -403,7 +409,7 @@ $this - 30 + 32 True @@ -430,7 +436,7 @@ $this - 29 + 31 Unchanged @@ -460,7 +466,7 @@ $this - 28 + 30 True @@ -490,7 +496,7 @@ $this - 27 + 29 Auto @@ -520,7 +526,7 @@ $this - 26 + 28 True @@ -550,7 +556,7 @@ $this - 25 + 27 True @@ -583,7 +589,7 @@ $this - 24 + 26 375, 302 @@ -607,7 +613,7 @@ $this - 22 + 24 True @@ -637,7 +643,7 @@ $this - 23 + 25 True @@ -667,7 +673,7 @@ $this - 21 + 23 True @@ -700,7 +706,7 @@ $this - 20 + 22 True @@ -727,7 +733,7 @@ $this - 19 + 21 True @@ -754,7 +760,7 @@ $this - 18 + 20 True @@ -774,9 +780,6 @@ Enable RTS/DTR - - 17, 17 - Useful for Meade LS scopes @@ -790,7 +793,7 @@ $this - 17 + 19 True @@ -817,7 +820,7 @@ $this - 16 + 18 375, 93 @@ -838,7 +841,7 @@ $this - 15 + 17 True @@ -865,7 +868,7 @@ $this - 14 + 16 True @@ -892,7 +895,7 @@ $this - 13 + 15 375, 125 @@ -913,7 +916,7 @@ $this - 12 + 14 True @@ -940,7 +943,7 @@ $this - 11 + 13 True @@ -967,7 +970,7 @@ $this - 10 + 12 97, 163 @@ -988,7 +991,7 @@ $this - 9 + 11 97, 137 @@ -1009,7 +1012,7 @@ $this - 8 + 10 97, 190 @@ -1030,7 +1033,7 @@ $this - 7 + 9 97, 217 @@ -1051,7 +1054,7 @@ $this - 6 + 8 97, 244 @@ -1072,7 +1075,7 @@ $this - 5 + 7 True @@ -1099,7 +1102,7 @@ $this - 4 + 6 True @@ -1126,7 +1129,7 @@ $this - 3 + 5 True @@ -1153,7 +1156,7 @@ $this - 2 + 4 True @@ -1180,7 +1183,7 @@ $this - 1 + 3 True @@ -1213,6 +1216,72 @@ $this + 2 + + + True + + + NoControl + + + 615, 96 + + + 113, 17 + + + 40 + + + Skip Date prompts + + + driver will attempt to skip past the date prompts when a connection to the Autostar is made + + + cbxSkipPrompts + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 1 + + + True + + + NoControl + + + 615, 123 + + + 145, 17 + + + 41 + + + Set current date and time + + + Send Current Date and Time + + + cbxSendDateTime + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + 0 @@ -1225,7 +1294,7 @@ 6, 13 - 626, 454 + 784, 454 CenterScreen diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index cb1e747..1d07e15 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -153,6 +153,8 @@ namespace ASCOM.Meade.net private const string StopBitsName = "Stop Bits"; private const string HandShakeName = "Hand Shake"; private const string ParityName = "Parity"; + private const string SkipPromptsName = "Skip date prompts on connect"; + private const string SendDateTimeName = "Send Date and time on connect"; public static void WriteProfile(ProfileProperties profileProperties) { @@ -177,6 +179,8 @@ namespace ASCOM.Meade.net driverProfile.WriteValue(DriverId, DynamicBreakingName, profileProperties.DynamicBreaking.ToString()); driverProfile.WriteValue(DriverId, SiteElevationName, profileProperties.SiteElevation.ToString(CultureInfo.InvariantCulture)); driverProfile.WriteValue(DriverId, SettleTimeName, profileProperties.SettleTime.ToString()); + driverProfile.WriteValue(DriverId, SkipPromptsName, profileProperties.SkipPrompts.ToString()); + driverProfile.WriteValue(DriverId, SendDateTimeName, profileProperties.SendDateTime.ToString()); } } } @@ -197,6 +201,8 @@ namespace ASCOM.Meade.net private const string StopBitsDefault = "One"; private const string HandShakeDefault = "None"; private const string ParityDefault = "None"; + private const string SendDateTimeDefault = "false"; + private const string SkipPromptsDefault = "false"; public static ProfileProperties ReadProfile() { @@ -222,7 +228,8 @@ namespace ASCOM.Meade.net profileProperties.Handshake = driverProfile.GetValue(DriverId, HandShakeName, string.Empty, HandShakeDefault); profileProperties.Speed = Convert.ToInt32(driverProfile.GetValue(DriverId, SpeedName, string.Empty, SpeedDefault)); profileProperties.Parity = driverProfile.GetValue(DriverId, ParityName, string.Empty, ParityDefault); - + profileProperties.SendDateTime = Convert.ToBoolean(driverProfile.GetValue(DriverId, SendDateTimeName, string.Empty, SendDateTimeDefault)); + profileProperties.SkipPrompts = Convert.ToBoolean(driverProfile.GetValue(DriverId, SkipPromptsName, string.Empty, SkipPromptsDefault)); } return profileProperties; From ed84313c2e4f2717d325a2f537406ff61e7fd59a Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Thu, 22 Apr 2021 21:40:07 +0100 Subject: [PATCH 07/28] Added initial display values bypass for the Autostar 497 --- Meade.net.Telescope/Telescope.cs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index aa23f75..d3dda39 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -462,13 +462,28 @@ namespace ASCOM.Meade.net { if (SkipAutoStarPrompts) { - var displayText = Action("Handbox", "readdisplay"); - if (displayText.Contains("Daylight")) + if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) { - for(var i = 0; i < 3; i++) + var displayText = Action("Handbox", "readdisplay"); + if (displayText.Contains("Daylight")) { - Action("Handbox", "enter"); - _utilities.WaitForMilliseconds(2000); + for (var i = 0; i < 3; i++) + { + Action("Handbox", "enter"); + _utilities.WaitForMilliseconds(2000); + } + } + } + else if (SharedResourcesWrapper.ProductName == TelescopeList.Autostar497) + { + var displayText = Action("Handbox", "readdisplay"); + if (displayText.Contains("€Press 0 to Alignor MODE for Menu")) + { + for (var i = 0; i < 4; i++) + { + Action("Handbox", "mode"); + _utilities.WaitForMilliseconds(500); + } } } } From a15bf2278512a221432c2ba313cc6fa8e582adb6 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Fri, 23 Apr 2021 15:00:03 +0100 Subject: [PATCH 08/28] Switched the order of the setting of the date and time, then skipping the prompts. --- Meade.net.Telescope/Telescope.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index d3dda39..26c4f41 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -418,9 +418,9 @@ namespace ASCOM.Meade.net } SetTelescopePrecision("Connect"); - - ApplySkipAutoStarPrompts("Connect"); + SendCurrentDateTime("Connect"); + ApplySkipAutoStarPrompts("Connect"); } else { From e7c81aba241bca151e900fb6be7e0a466729d63f Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Fri, 23 Apr 2021 16:51:05 +0100 Subject: [PATCH 09/28] Added code to force the date time to happen after the display bypass for autostar 497's --- Meade.net.Telescope/Telescope.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 26c4f41..1ac6a91 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -418,9 +418,15 @@ namespace ASCOM.Meade.net } SetTelescopePrecision("Connect"); + + bool setTimeBeforeDisplayBypass = SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS; + if (setTimeBeforeDisplayBypass) + SendCurrentDateTime("Connect"); - SendCurrentDateTime("Connect"); ApplySkipAutoStarPrompts("Connect"); + if (!setTimeBeforeDisplayBypass) + SendCurrentDateTime("Connect"); + } else { From fc3c91b975f252c0b4b82878bcf736c3e84d87f4 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Fri, 23 Apr 2021 17:14:33 +0100 Subject: [PATCH 10/28] Added extra logging to get slewing --- Meade.net.Telescope/Telescope.cs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 1ac6a91..9ff99e6 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -2055,13 +2055,23 @@ namespace ASCOM.Meade.net private bool GetSlewing() { - if (!Connected) return false; + var result = false; + try + { + if (Connected) + { + if (!MovingAxis()) + result = IsSlewingToTarget(); + result = true; + } + } + finally + { + LogMessage("GetSlewing", $"Result = {result}"); + } - if (MovingAxis()) - return true; - - return IsSlewingToTarget(); + return result; } private bool IsSlewingToTarget() From 2776b469c8f3a3f4a5695b74034597ecd7ce0b8e Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Fri, 23 Apr 2021 18:26:49 +0100 Subject: [PATCH 11/28] Fixed broken logic, and fixed broken unit tests. --- .../TelescopeUnitTests.cs | 197 ++++++------------ Meade.net.Telescope/Telescope.cs | 8 +- 2 files changed, 66 insertions(+), 139 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 21dcaba..6cc6980 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -14,6 +14,12 @@ using InvalidOperationException = ASCOM.InvalidOperationException; namespace Meade.net.Telescope.UnitTests { + public class TestProperties + { + internal string telescopeRaResult = "HH:MM:SS"; + internal double rightAscension = 1.2; //todo rename to RightAscension; + } + [TestFixture] public class TelescopeUnitTests { @@ -28,9 +34,13 @@ namespace Meade.net.Telescope.UnitTests private ProfileProperties _profileProperties; private ConnectionInfo _connectionInfo; + private TestProperties _testProperties; + [SetUp] public void Setup() { + _testProperties = new TestProperties(); + _profileProperties = new ProfileProperties { TraceLogger = false, @@ -79,6 +89,9 @@ namespace Meade.net.Telescope.UnitTests private void ConnectTelescope(string productName = TelescopeList.Autostar497, string firmwareVersion = TelescopeList.Autostar497_31Ee) { + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(_testProperties.telescopeRaResult); + _utilMock.Setup(x => x.HMSToHours(_testProperties.telescopeRaResult)).Returns(_testProperties.rightAscension); + _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => productName); _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => firmwareVersion); _telescope.Connected = true; @@ -432,12 +445,6 @@ namespace Meade.net.Telescope.UnitTests [Test] public void Connected_Set_SettingFalseWhenTrue_ThenDisconnects() { - var telescopeRaResult = "HH:MM:SS"; - var hmsResult = 1.2; - - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); - _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(hmsResult); - ConnectTelescope(); _sharedResourcesWrapperMock.Verify(x => x.Connect(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); @@ -996,13 +1003,9 @@ namespace Meade.net.Telescope.UnitTests { 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); ConnectTelescope(); @@ -1324,12 +1327,6 @@ namespace Meade.net.Telescope.UnitTests [TestCase(GuideDirections.guideSouth)] public void PulseGuide_WhenConnectedAndNewerPulseGuidingAvailable_ThenSendsNewCommandsAndWaits(GuideDirections direction) { - var telescopeRaResult = "HH:MM:SS"; - var hmsResult = 1.2; - - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); - _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(hmsResult); - var duration = 0; ConnectTelescope(); @@ -1398,13 +1395,11 @@ namespace Meade.net.Telescope.UnitTests { var telescopeDecResult = "s12*34’56"; var dmsResult = 1.2; - var telescopeRaResult = "HH:MM:SS"; - var hmsResult = 1.3; + + _testProperties.rightAscension = 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); @@ -1416,7 +1411,7 @@ namespace Meade.net.Telescope.UnitTests isSlewing = _telescope.Slewing; }); - _telescope.Connected = true; + ConnectTelescope(); _telescope.PulseGuide(direction, duration); @@ -1431,18 +1426,12 @@ namespace Meade.net.Telescope.UnitTests { var telescopeDecResult = "s12*34’56"; var dmsResult = 1.2; - var telescopeRaResult = "HH:MM:SS"; - var hmsResult = 1.3; + var duration = 0; _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; + ConnectTelescope(TelescopeList.Autostar497, TelescopeList.Autostar497_30Ee); _telescope.PulseGuide(direction, duration); @@ -1478,21 +1467,14 @@ namespace Meade.net.Telescope.UnitTests short slewSettleTime = 10; _profileProperties.SettleTime = slewSettleTime; + var duration = 0; 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; + _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); + + ConnectTelescope(TelescopeList.Autostar497, TelescopeList.Autostar497_30Ee); _telescope.PulseGuide(direction, duration); @@ -1522,16 +1504,8 @@ namespace Meade.net.Telescope.UnitTests [TestCase(GuideDirections.guideSouth)] public void PulseGuide_WhenConnectedAndNewerPulseGuidingAvailableButDurationTooLong_ThenSendsOldCommandsAndWaits(GuideDirections direction) { - var telescopeRaResult = "HH:MM:SS"; - var hmsResult = 1.2; - - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); - _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(hmsResult); - var duration = 10000; - _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.Autostar497); - _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => TelescopeList.Autostar497_30Ee); - _telescope.Connected = true; + ConnectTelescope(TelescopeList.Autostar497, TelescopeList.Autostar497_30Ee); _telescope.PulseGuide(direction, duration); @@ -1572,20 +1546,11 @@ namespace Meade.net.Telescope.UnitTests [Test] public void RightAscension_Get_WhenConnected_ThenReturnsExpectedResult() { - var telescopeRaResult = "HH:MM:SS"; - var hmsResult = 1.2; - - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); - _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(hmsResult); - ConnectTelescope(); var result = _telescope.RightAscension; - _sharedResourcesWrapperMock.Verify( x => x.SendString(":GR#"), Times.Exactly(2)); - _utilMock.Verify( x => x.HMSToHours(telescopeRaResult), Times.Exactly(2)); - - Assert.That(result,Is.EqualTo(hmsResult)); + Assert.That(result,Is.EqualTo(_testProperties.rightAscension)); } [Test] @@ -1935,12 +1900,6 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SyncToTarget_WhenSyncToTargetWorks_ThennoExceptionThrown() { - var telescopeRaResult = "HH:MM:SS"; - var hmsResult = 1.2; - - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); - _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(hmsResult); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":CM#")).Returns(" M31 EX GAL MAG 3.5 SZ178.0'#"); ConnectTelescope(); @@ -2315,28 +2274,25 @@ namespace Meade.net.Telescope.UnitTests public void SyncToCoordinates_WhenConnected_ThenReturnsExpectedResult() { var telescopeDecResult = "s12*34’56"; - var telescopeRaResult = "HH:MM:SS"; - //var hmsResult = 1.2; - double rightAscension = 5.5; string hms = "05:30:00"; + _testProperties.rightAscension = 5.5; double declination = -30.5; string dec = "-30*30:00"; var digitsRA = 2; - _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sr{telescopeRaResult}#")).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sr{_testProperties.telescopeRaResult}#")).Returns("1"); - _utilMock.Setup(x => x.HoursToHMS(rightAscension, ":", ":", ":", digitsRA)).Returns(telescopeRaResult); - _utilMock.Setup(x => x.HMSToHours(hms)).Returns(rightAscension); + _utilMock.Setup(x => x.HoursToHMS(_testProperties.rightAscension, ":", ":", ":", digitsRA)).Returns(_testProperties.telescopeRaResult); + _utilMock.Setup(x => x.HMSToHours(hms)).Returns(_testProperties.rightAscension); _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", digitsRA)).Returns(telescopeDecResult); _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(declination); - - //_utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(hmsResult); + _utilMock.Setup(x => x.DMSToDegrees(dec)).Returns(declination); - _utilMock.Setup(x => x.HoursToHMS(rightAscension, ":", ":", ":", 2)).Returns(hms); + _utilMock.Setup(x => x.HoursToHMS(_testProperties.rightAscension, ":", ":", ":", 2)).Returns(hms); _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", digitsRA)).Returns(dec); _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sr{hms}#")).Returns("1"); _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sd{dec}#")).Returns("1"); @@ -2344,16 +2300,13 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Setup(x => x.SendString($":CM#")).Returns("M31 EX GAL MAG 3.5 SZ178.0'#"); _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(telescopeDecResult); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); - - _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(rightAscension); ConnectTelescope(); - - _telescope.SyncToCoordinates(rightAscension, declination); - _sharedResourcesWrapperMock.Verify( x => x.SendString(":CM#"), Times.Once); - Assert.That(_telescope.TargetRightAscension, Is.EqualTo(rightAscension)); + _telescope.SyncToCoordinates(_testProperties.rightAscension, declination); + + _sharedResourcesWrapperMock.Verify(x => x.SendString(":CM#"), Times.Once); + Assert.That(_telescope.TargetRightAscension, Is.EqualTo(_testProperties.rightAscension)); Assert.That(_telescope.TargetDeclination, Is.EqualTo(declination)); } @@ -2460,11 +2413,6 @@ namespace Meade.net.Telescope.UnitTests [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, "", false)] public void Slewing_WhenTelescopeNotSlewing_ThenReturnsFalse(string productName, string firmwareVersion, string response, bool isSlewing) { - var telescopeRaResult = "HH:MM:SS"; - var hmsResult = 1.2; - - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); - _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(hmsResult); _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#")).Returns(response); ConnectTelescope(productName, firmwareVersion); @@ -2693,19 +2641,17 @@ namespace Meade.net.Telescope.UnitTests { var digitsRA = 2; - var rightAscension = 1; + _testProperties.rightAscension = 1; + var declination = 2; - var telescopeRaResult = "HH:MM:SS"; var telescopeDecResult = "s12*34’56"; _sharedResourcesWrapperMock.Setup(x => x.SendChar(":MS#")).Returns("0"); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sr{telescopeRaResult}#")).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sr{_testProperties.telescopeRaResult}#")).Returns("1"); _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(telescopeDecResult); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); - _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(rightAscension); - _utilMock.Setup(x => x.HoursToHMS(rightAscension, ":", ":", ":", digitsRA)).Returns(telescopeRaResult); + _utilMock.Setup(x => x.HoursToHMS(_testProperties.rightAscension, ":", ":", ":", digitsRA)).Returns(_testProperties.telescopeRaResult); _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(declination); _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", digitsRA)).Returns(telescopeDecResult); @@ -2723,10 +2669,10 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); - _telescope.SlewToCoordinatesAsync(rightAscension, declination); + _telescope.SlewToCoordinatesAsync(_testProperties.rightAscension, declination); //_utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny()), Times.Exactly(iterations)); - Assert.That(_telescope.TargetRightAscension, Is.EqualTo(rightAscension)); + Assert.That(_telescope.TargetRightAscension, Is.EqualTo(_testProperties.rightAscension)); Assert.That(_telescope.TargetDeclination, Is.EqualTo(declination)); _sharedResourcesWrapperMock.Verify( x => x.SendChar(":MS#"), Times.Once); } @@ -2741,26 +2687,20 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SlewToCoordinates_WhenCalled_ThenSetsTargetAndSlews() { - var rightAscension = 1; + _testProperties.rightAscension = 1; var declination = 2; var telescopeDecResult = "s12*34’56"; var dmsResult = 1.2; - var telescopeRaResult = "HH:MM:SS"; - var hmsResult = 1.3; var digitsRA = 2; _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(telescopeDecResult); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sr{telescopeRaResult}#")).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sr{_testProperties.telescopeRaResult}#")).Returns("1"); - _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(hmsResult); - _utilMock.Setup(x => x.HoursToHMS(rightAscension, ":", ":", ":", digitsRA)).Returns(telescopeRaResult); - _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(rightAscension); + _utilMock.Setup(x => x.HoursToHMS(_testProperties.rightAscension, ":", ":", ":", digitsRA)).Returns(_testProperties.telescopeRaResult); _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", digitsRA)).Returns(telescopeDecResult); - _sharedResourcesWrapperMock.Setup(x => x.SendChar(":MS#")).Returns("0"); var slewCounter = 0; @@ -2775,8 +2715,8 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); - _telescope.SlewToCoordinates(rightAscension, declination); - Assert.That(_telescope.TargetRightAscension, Is.EqualTo(rightAscension)); + _telescope.SlewToCoordinates(_testProperties.rightAscension, declination); + Assert.That(_telescope.TargetRightAscension, Is.EqualTo(_testProperties.rightAscension)); Assert.That(_telescope.TargetDeclination, Is.EqualTo(dmsResult)); _sharedResourcesWrapperMock.Verify(x => x.SendChar(":MS#"), Times.Once); @@ -2829,9 +2769,10 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SlewToAltAzAsync_WhenAltAndAzValid_ThenConvertsToRADec() { + _testProperties.rightAscension = 20; + var altitude = 30; var azimuth = 45; - var rightAscension = 20; var declination = 10; _sharedResourcesWrapperMock.Setup(x => x.SendString(":GC#")).Returns("10/15/20"); @@ -2840,7 +2781,7 @@ namespace Meade.net.Telescope.UnitTests _astroMathsMock .Setup(x => x.ConvertHozToEq(It.IsAny(), It.IsAny(), It.IsAny(), - It.IsAny())).Returns(new EquatorialCoordinates { Declination = declination, RightAscension = rightAscension }); + It.IsAny())).Returns(new EquatorialCoordinates { Declination = declination, RightAscension = _testProperties.rightAscension }); _sharedResourcesWrapperMock.Setup(x => x.SendChar(":MS#")).Returns("0"); @@ -2850,8 +2791,8 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sr{telescopeRaResult}#")).Returns("1"); - _utilMock.Setup(x => x.HoursToHMS(rightAscension, ":", ":", ":", digitsRA)).Returns(telescopeRaResult); - _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(rightAscension); + _utilMock.Setup(x => x.HoursToHMS(_testProperties.rightAscension, ":", ":", ":", digitsRA)).Returns(telescopeRaResult); + _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(_testProperties.rightAscension); _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", digitsRA)).Returns(telescopeDecResult); _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(declination); @@ -2859,7 +2800,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.SlewToAltAzAsync(azimuth, altitude); - Assert.That(_telescope.TargetRightAscension, Is.EqualTo(rightAscension)); + Assert.That(_telescope.TargetRightAscension, Is.EqualTo(_testProperties.rightAscension)); Assert.That(_telescope.TargetDeclination, Is.EqualTo(declination)); _sharedResourcesWrapperMock.Verify(x => x.SendChar(":MS#"), Times.Once); } @@ -2874,20 +2815,14 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SlewToAltAz_WhenCalled_ThenSetsTargetAndSlews() { - var rightAscension = 10.0; + _testProperties.rightAscension = 10.0; var declination = 20; var azimuth = 30; var altitude = 40; - var telescopeRaResult = "HH:MM:SS"; - var hmsResult = 10.0; - - _utilMock.Setup(x => x.HoursToHMS(rightAscension, ":", ":", ":", 2)).Returns(telescopeRaResult); - _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", 2)).Returns(telescopeRaResult); - _utilMock.Setup(x => x.DMSToDegrees(telescopeRaResult)).Returns(declination); - - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); - _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(hmsResult); + _utilMock.Setup(x => x.HoursToHMS(_testProperties.rightAscension, ":", ":", ":", 2)).Returns(_testProperties.telescopeRaResult); + _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", 2)).Returns(_testProperties.telescopeRaResult); + _utilMock.Setup(x => x.DMSToDegrees(_testProperties.telescopeRaResult)).Returns(declination); _sharedResourcesWrapperMock.Setup(x => x.SendString(":GC#")).Returns("10/15/20"); _sharedResourcesWrapperMock.Setup(x => x.SendString(":GL#")).Returns("20:15:10"); @@ -2896,7 +2831,7 @@ namespace Meade.net.Telescope.UnitTests _astroMathsMock .Setup(x => x.ConvertHozToEq(It.IsAny(), It.IsAny(), It.IsAny(), - It.IsAny())).Returns(new EquatorialCoordinates { Declination = declination, RightAscension = rightAscension }); + It.IsAny())).Returns(new EquatorialCoordinates { Declination = declination, RightAscension = _testProperties.rightAscension }); _sharedResourcesWrapperMock.Setup(x => x.SendChar(":MS#")).Returns("0"); @@ -2914,7 +2849,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.SlewToAltAz( azimuth, altitude); - Assert.That(_telescope.TargetRightAscension, Is.EqualTo(rightAscension)); + Assert.That(_telescope.TargetRightAscension, Is.EqualTo(_testProperties.rightAscension)); Assert.That(_telescope.TargetDeclination, Is.EqualTo(declination)); _sharedResourcesWrapperMock.Verify(x => x.SendChar(":MS#"), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny()), Times.Exactly(iterations)); @@ -2938,10 +2873,7 @@ namespace Meade.net.Telescope.UnitTests var telescopeLongitude = "350"; var telescopeLongitudeValue = 350; - - var telescopeLatitude = "HH:MM:SS"; - var telescopeLatitudeValue = 1.2; - + var mockHourAngle = 3; _sharedResourcesWrapperMock.Setup(x => x.SendString(":GC#")).Returns("10/15/20"); @@ -2950,10 +2882,7 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Setup(x => x.SendString(":Gg#")).Returns(telescopeLongitude); _utilMock.Setup(x => x.DMSToDegrees(telescopeLongitude)).Returns(telescopeLongitudeValue); - - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeLatitude); - _utilMock.Setup(x => x.HMSToHours(telescopeLatitude)).Returns(telescopeLatitudeValue); - + _astroMathsMock.Setup(x => x.RightAscensionToHourAngle(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockHourAngle); _astroMathsMock.Setup(x => x.ConvertEqToHoz(mockHourAngle, It.IsAny(), It.IsAny())).Returns(new HorizonCoordinates { Altitude = 45, Azimuth = expectedAzimuth }); @@ -2984,9 +2913,6 @@ namespace Meade.net.Telescope.UnitTests var telescopeLongitude = "350"; var telescopeLongitudeValue = 350; - var telescopeLatitude = "HH:MM:SS"; - var telescopeLatitudeValue = 1.2; - var mockHourAngle = 3; _sharedResourcesWrapperMock.Setup(x => x.SendString(":GC#")).Returns("10/15/20"); @@ -2996,9 +2922,6 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Setup(x => x.SendString(":Gg#")).Returns(telescopeLongitude); _utilMock.Setup(x => x.DMSToDegrees(telescopeLongitude)).Returns(telescopeLongitudeValue); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeLatitude); - _utilMock.Setup(x => x.HMSToHours(telescopeLatitude)).Returns(telescopeLatitudeValue); - _astroMathsMock.Setup(x => x.RightAscensionToHourAngle(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockHourAngle); _astroMathsMock.Setup(x => x.ConvertEqToHoz(mockHourAngle, It.IsAny(), It.IsAny())).Returns(new HorizonCoordinates { Altitude = expectedAltitude, Azimuth = 200 }); diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 9ff99e6..f4fc0c9 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -2061,9 +2061,13 @@ namespace ASCOM.Meade.net if (Connected) { if (!MovingAxis()) + { result = IsSlewingToTarget(); - - result = true; + } + else + { + result = true; + } } } finally From b27adf264983fa431fcc44dcf8e80f07e6de4f75 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Fri, 23 Apr 2021 18:58:14 +0100 Subject: [PATCH 12/28] Added check that returns [7F] when slewing --- Meade.net.Telescope/Telescope.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index f4fc0c9..4a13778 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -2107,6 +2107,12 @@ namespace ASCOM.Meade.net return isSlewing; } + if (result.Contains("[7F]")) + { + isSlewing = true; + return isSlewing; + } + ////classic LX200 return bar with 32 chars. FF is contained from left to right when slewing //byte[] ba = Encoding.Default.GetBytes(result); ////replace fill chars not belonging to a slew bar. Are there others? The bar character is a FF in hex. From 384deecc3f2930ee17e28e4c0bacdc46b26406be Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Fri, 23 Apr 2021 19:11:45 +0100 Subject: [PATCH 13/28] More attempts to detect the slewing character --- Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs | 2 ++ Meade.net.Telescope/Telescope.cs | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 6cc6980..04e538a 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -2410,6 +2410,8 @@ namespace Meade.net.Telescope.UnitTests [TestCase(TelescopeList.LX200CLASSIC, "", "[FF][FF][FF][FF][FF][FF][FF][FF][FF][FF][FF][FF][FF][FF] [FF][FF][FF][FF][FF][FF]", false)] //The test case below is this same string encoded to return exactly what the telescope will return. [TestCase(TelescopeList.LX200CLASSIC, "", "\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff \x00ff\x00ff\x00ff\x00ff\x00ff\x00ff", false)] [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, "|", true)] + [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, "[7F]", true)] + [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, "\x00ff", true)] [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, "", false)] public void Slewing_WhenTelescopeNotSlewing_ThenReturnsFalse(string productName, string firmwareVersion, string response, bool isSlewing) { diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 4a13778..5183e95 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -2107,12 +2107,18 @@ namespace ASCOM.Meade.net return isSlewing; } - if (result.Contains("[7F]")) + if (result.Equals("[7F]")) { isSlewing = true; return isSlewing; } - + + if (result.Equals("\x00ff")) + { + isSlewing = true; + return isSlewing; + } + ////classic LX200 return bar with 32 chars. FF is contained from left to right when slewing //byte[] ba = Encoding.Default.GetBytes(result); ////replace fill chars not belonging to a slew bar. Are there others? The bar character is a FF in hex. From aca01de4eeb356cbbe3f8526da2fe355a89bb499 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Fri, 23 Apr 2021 19:45:10 +0100 Subject: [PATCH 14/28] Added a # prefix before the commands. --- .../FocuserUnitTests.cs | 4 +- .../TelescopeUnitTests.cs | 140 +++++++++--------- Meade.net.Telescope/Telescope.cs | 18 +-- .../SharedResourcesUnitTests.cs | 9 +- Meade.net/SharedResources.cs | 15 +- Meade.net/Wrapper/SharedResourcesWrapper.cs | 6 +- 6 files changed, 92 insertions(+), 100 deletions(-) diff --git a/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs b/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs index ca09d30..9f945d2 100644 --- a/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs +++ b/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs @@ -159,11 +159,11 @@ namespace Meade.net.Focuser.UnitTests ConnectFocuser(); - _sharedResourcesWrapperMock.Setup(x => x.SendString(sendMessage)).Returns(() => expectedMessage); + _sharedResourcesWrapperMock.Setup(x => x.SendString(sendMessage, true)).Returns(() => expectedMessage); var actualMessage = _focuser.CommandString(sendMessage, true); - _sharedResourcesWrapperMock.Verify(x => x.SendString(sendMessage), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(sendMessage, true), Times.Once); Assert.That(actualMessage, Is.EqualTo(expectedMessage)); } diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 04e538a..1a2c74a 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -61,7 +61,7 @@ namespace Meade.net.Telescope.UnitTests _astroUtilsMock = new Mock(); _sharedResourcesWrapperMock = new Mock(); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#")).Returns("DDD*MM’SS"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#", true)).Returns("DDD*MM’SS"); _sharedResourcesWrapperMock.Setup(x => x.ReadProfile()).Returns(() =>_profileProperties); _sharedResourcesWrapperMock.Setup(x => x.Lock(It.IsAny())).Callback(action => { action(); }); @@ -89,7 +89,7 @@ namespace Meade.net.Telescope.UnitTests private void ConnectTelescope(string productName = TelescopeList.Autostar497, string firmwareVersion = TelescopeList.Autostar497_31Ee) { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(_testProperties.telescopeRaResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#", true)).Returns(_testProperties.telescopeRaResult); _utilMock.Setup(x => x.HMSToHours(_testProperties.telescopeRaResult)).Returns(_testProperties.rightAscension); _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => productName); @@ -145,14 +145,14 @@ namespace Meade.net.Telescope.UnitTests public void Action_Handbox_ReadDisplay() { string expectedResult = "test result string"; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":ED#")).Returns(expectedResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":ED#", true)).Returns(expectedResult); _telescope.Connected = true; var actualResult = _telescope.Action("handbox", "readdisplay"); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":ED#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(":ED#", true), Times.Once); Assert.That(actualResult, Is.EqualTo(expectedResult)); } @@ -216,14 +216,14 @@ namespace Meade.net.Telescope.UnitTests [TestCase("4", ":GP#", "Parents")] public void Action_Site_GetName_WhenCallingWithValidValues_ThenSelectsCorrectSite(string site, string telescopeCommand, string siteName) { - _sharedResourcesWrapperMock.Setup(x => x.SendString(telescopeCommand)).Returns(siteName); + _sharedResourcesWrapperMock.Setup(x => x.SendString(telescopeCommand, true)).Returns(siteName); ConnectTelescope(); string parameters = $"GetName {site}"; var result = _telescope.Action("site", parameters); - _sharedResourcesWrapperMock.Verify(x => x.SendString(telescopeCommand), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(telescopeCommand, true), Times.Once); Assert.That(result, Is.EqualTo(siteName)); } @@ -370,13 +370,13 @@ namespace Meade.net.Telescope.UnitTests string expectedMessage = "expected result message"; string sendMessage = "test blind Message"; - _sharedResourcesWrapperMock.Setup(x => x.SendString(sendMessage)).Returns(() => expectedMessage); + _sharedResourcesWrapperMock.Setup(x => x.SendString(sendMessage, true)).Returns(() => expectedMessage); ConnectTelescope(); var actualMessage = _telescope.CommandString(sendMessage, true); - _sharedResourcesWrapperMock.Verify(x => x.SendString(sendMessage), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(sendMessage, true), Times.Once); Assert.That(actualMessage, Is.EqualTo(expectedMessage)); } @@ -392,7 +392,7 @@ namespace Meade.net.Telescope.UnitTests if (expectedConnected) { - _sharedResourcesWrapperMock.Verify(x => x.SendString(":GZ#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(":GZ#", true), Times.Once); _sharedResourcesWrapperMock.Verify(x => x.SendBlind($":Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}#"), Times.Never); } } @@ -408,7 +408,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.Connected = true; _sharedResourcesWrapperMock.Verify( x => x.Connect("Serial", It.IsAny(), It.IsAny()), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":GZ#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(":GZ#", true), Times.Once); _sharedResourcesWrapperMock.Verify(x => x.SendBlind($":Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}#"),Times.Once); } @@ -424,7 +424,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.Connected = true; _sharedResourcesWrapperMock.Verify(x => x.Connect("Serial", It.IsAny(), It.IsAny()), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":GZ#"), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendString(":GZ#", true), Times.Never); _sharedResourcesWrapperMock.Verify(x => x.SendBlind($":Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}#"), Times.Never); } @@ -461,7 +461,7 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.Autostar497); _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => TelescopeList.Autostar497_31Ee); - _sharedResourcesWrapperMock.Setup(x => x.SendString(It.IsAny())).Throws(new Exception("TestFailed")); + _sharedResourcesWrapperMock.Setup(x => x.SendString(It.IsAny(), It.IsAny())).Throws(new Exception("TestFailed")); //act _telescope.Connected = true; @@ -496,7 +496,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SetLongFormatFalse_WhenTelescopeReturnsShortFormat_ThenDoesNothing() { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#")).Returns("DDD*MM"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#", true)).Returns("DDD*MM"); _telescope.SetLongFormat(false); _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":U#"),Times.Never); @@ -505,7 +505,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SetLongFormatFalse_WhenTelescopeReturnsLongFormat_ThenTogglesPrecision() { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#")).Returns("DDD*MM’SS"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#", true)).Returns("DDD*MM’SS"); _telescope.SetLongFormat(false); _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":U#"), Times.Once); @@ -514,7 +514,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SetLongFormatTrue_WhenTelescopeReturnsLongFormat_ThenDoesNothing() { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#")).Returns("DDD*MM’SS"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#", true)).Returns("DDD*MM’SS"); _telescope.SetLongFormat(true); _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":U#"), Times.Never); @@ -523,7 +523,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SetLongFormatTrue_WhenTelescopeReturnsShortFormat_ThenTogglesPrecision() { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#")).Returns("DDD*MM"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#", true)).Returns("DDD*MM"); _telescope.SetLongFormat(true); _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":U#"), Times.Once); @@ -838,7 +838,7 @@ namespace Meade.net.Telescope.UnitTests { _telescope.Connected = true; - _sharedResourcesWrapperMock.Verify( x => x.SendString(":P#"), Times.Never); + _sharedResourcesWrapperMock.Verify( x => x.SendString(":P#", true), Times.Never); } [TestCase("High", false, true)] @@ -989,7 +989,7 @@ namespace Meade.net.Telescope.UnitTests public void Declination_Get_WhenConnected_ThenReadsValueFromScope(string declincationString) { var expectedResult = 12.34; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(declincationString); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#", true)).Returns(declincationString); _utilMock.Setup(x => x.DMSToDegrees(declincationString)).Returns(expectedResult); ConnectTelescope(); @@ -1004,14 +1004,14 @@ namespace Meade.net.Telescope.UnitTests var telescopeDecResult = "s12*34’56"; var dmsResult = 1.2; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#", true)).Returns(telescopeDecResult); _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); ConnectTelescope(); var result = _telescope.Declination; - _sharedResourcesWrapperMock.Verify(x => x.SendString(":GD#"), Times.Exactly(2)); + _sharedResourcesWrapperMock.Verify(x => x.SendString(":GD#", true), Times.Exactly(2)); _utilMock.Verify(x => x.DMSToDegrees(telescopeDecResult), Times.Exactly(2)); Assert.That(result, Is.EqualTo(dmsResult)); @@ -1359,7 +1359,7 @@ namespace Meade.net.Telescope.UnitTests [TestCase(GuideDirections.guideSouth)] public void PulseGuide_WhenSlewingAndPulseGuideAttempted_ThenThrowsExpectedException(GuideDirections direction) { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#")).Returns("|"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#", true)).Returns("|"); var duration = 0; ConnectTelescope(); @@ -1375,7 +1375,7 @@ namespace Meade.net.Telescope.UnitTests [TestCase(GuideDirections.guideSouth, TelescopeAxes.axisSecondary)] public void PulseGuide_WhenMovingAxisAndPulseGuideAttempted_ThenThrowsExpectedException(GuideDirections direction, TelescopeAxes axes) { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#")).Returns(""); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#", true)).Returns(""); var duration = 0; ConnectTelescope(); @@ -1398,7 +1398,7 @@ namespace Meade.net.Telescope.UnitTests _testProperties.rightAscension = 1.3; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#", true)).Returns(telescopeDecResult); _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); var duration = 0; @@ -1428,7 +1428,7 @@ namespace Meade.net.Telescope.UnitTests var dmsResult = 1.2; var duration = 0; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#", true)).Returns(telescopeDecResult); _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); ConnectTelescope(TelescopeList.Autostar497, TelescopeList.Autostar497_30Ee); @@ -1471,7 +1471,7 @@ namespace Meade.net.Telescope.UnitTests var telescopeDecResult = "s12*34’56"; var dmsResult = 1.2; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#", true)).Returns(telescopeDecResult); _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); ConnectTelescope(TelescopeList.Autostar497, TelescopeList.Autostar497_30Ee); @@ -1725,14 +1725,14 @@ namespace Meade.net.Telescope.UnitTests var siteLatitudeString = "testLatString"; var siteLatitudeValue = 123.45; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":Gt#")).Returns(siteLatitudeString); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":Gt#", true)).Returns(siteLatitudeString); _utilMock.Setup(x => x.DMSToDegrees(siteLatitudeString)).Returns(siteLatitudeValue); ConnectTelescope(); var result = _telescope.SiteLatitude; - _sharedResourcesWrapperMock.Verify( x => x.SendString(":Gt#"), Times.Once); + _sharedResourcesWrapperMock.Verify( x => x.SendString(":Gt#", true), Times.Once); Assert.That(result,Is.EqualTo(siteLatitudeValue)); } @@ -1808,7 +1808,7 @@ namespace Meade.net.Telescope.UnitTests { var telescopeLongitude = "testLongitude"; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":Gg#")).Returns(telescopeLongitude); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":Gg#", true)).Returns(telescopeLongitude); _utilMock.Setup(x => x.DMSToDegrees(telescopeLongitude)).Returns(telescopeLongitudeValue); ConnectTelescope(); @@ -1887,26 +1887,26 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SyncToTarget_WhenSyncToTargetFails_ThenThrowsException() { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":CM#")).Returns(string.Empty); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":CM#", true)).Returns(string.Empty); ConnectTelescope(); var exception = Assert.Throws(() => { _telescope.SyncToTarget(); } ); Assert.That(exception.Message, Is.EqualTo("Unable to perform sync")); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":CM#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(":CM#", true), Times.Once); } [Test] public void SyncToTarget_WhenSyncToTargetWorks_ThennoExceptionThrown() { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":CM#")).Returns(" M31 EX GAL MAG 3.5 SZ178.0'#"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":CM#", true)).Returns(" M31 EX GAL MAG 3.5 SZ178.0'#"); ConnectTelescope(); Assert.DoesNotThrow(() => { _telescope.SyncToTarget(); }); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":CM#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(":CM#", true), Times.Once); } [Test] @@ -2169,9 +2169,9 @@ namespace Meade.net.Telescope.UnitTests public void UTCDate_Get_WhenConnected_ThenReturnsUTCDateTime(string telescopeDate, string telescopeTime, string telescopeUtcCorrection, int year, int month, int day, int hour, int min, int second) { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GC#")).Returns(telescopeDate); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GL#")).Returns(telescopeTime); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#")).Returns(telescopeUtcCorrection); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GC#", true)).Returns(telescopeDate); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GL#", true)).Returns(telescopeTime); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns(telescopeUtcCorrection); ConnectTelescope(); @@ -2204,7 +2204,7 @@ namespace Meade.net.Telescope.UnitTests var newDate = new DateTime(year, month, day, hour, min, second, DateTimeKind.Local) + utcCorrection; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#")).Returns(telescopeUtcCorrection); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns(telescopeUtcCorrection); _sharedResourcesWrapperMock.Setup(x => x.SendChar($":SL{telescopeTime}#")).Returns("0"); ConnectTelescope(); @@ -2223,7 +2223,7 @@ namespace Meade.net.Telescope.UnitTests var newDate = new DateTime(year, month, day, hour, min, second, DateTimeKind.Local) + utcCorrection; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#")).Returns(telescopeUtcCorrection); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns(telescopeUtcCorrection); _sharedResourcesWrapperMock.Setup(x => x.SendChar($":SL{telescopeTime}#")).Returns("1"); _sharedResourcesWrapperMock.Setup(x => x.SendChar($":SC{newDate:MM/dd/yy}#")).Returns("0"); @@ -2245,7 +2245,7 @@ namespace Meade.net.Telescope.UnitTests var newDate = new DateTime(year, month, day, hour, min, second, DateTimeKind.Local) + utcCorrection; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#")).Returns(telescopeUtcCorrection); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns(telescopeUtcCorrection); _sharedResourcesWrapperMock.Setup(x => x.SendChar($":SL{telescopeTime}#")).Returns("1"); _sharedResourcesWrapperMock.Setup(x => x.SendChar($":SC{telescopeDate}#")).Returns("1"); @@ -2297,15 +2297,15 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sr{hms}#")).Returns("1"); _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sd{dec}#")).Returns("1"); - _sharedResourcesWrapperMock.Setup(x => x.SendString($":CM#")).Returns("M31 EX GAL MAG 3.5 SZ178.0'#"); + _sharedResourcesWrapperMock.Setup(x => x.SendString($":CM#", true)).Returns("M31 EX GAL MAG 3.5 SZ178.0'#"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#", true)).Returns(telescopeDecResult); ConnectTelescope(); _telescope.SyncToCoordinates(_testProperties.rightAscension, declination); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":CM#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(":CM#", true), Times.Once); Assert.That(_telescope.TargetRightAscension, Is.EqualTo(_testProperties.rightAscension)); Assert.That(_telescope.TargetDeclination, Is.EqualTo(declination)); } @@ -2317,7 +2317,7 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.False); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#"), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#", true), Times.Never); } [Test] @@ -2329,13 +2329,13 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.False); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#", true), Times.Once); } [Test] public void Slewing_WhenTelescopeIsSlewing_ThenReturnsTrue() { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#")).Returns("|"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#", true)).Returns("|"); ConnectTelescope(); @@ -2343,7 +2343,7 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.True); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#"),Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#", true),Times.Once); } [TestCase(0, 0, "2021-10-03T20:36:00", "2021-10-03T20:36:01", false)] @@ -2381,7 +2381,7 @@ namespace Meade.net.Telescope.UnitTests var slewingText = "|"; var notSlewingText = String.Empty; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#")).Returns( () => + _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#", true)).Returns( () => { if (timescalled == 0) { @@ -2410,12 +2410,10 @@ namespace Meade.net.Telescope.UnitTests [TestCase(TelescopeList.LX200CLASSIC, "", "[FF][FF][FF][FF][FF][FF][FF][FF][FF][FF][FF][FF][FF][FF] [FF][FF][FF][FF][FF][FF]", false)] //The test case below is this same string encoded to return exactly what the telescope will return. [TestCase(TelescopeList.LX200CLASSIC, "", "\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff \x00ff\x00ff\x00ff\x00ff\x00ff\x00ff", false)] [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, "|", true)] - [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, "[7F]", true)] - [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, "\x00ff", true)] [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, "", false)] public void Slewing_WhenTelescopeNotSlewing_ThenReturnsFalse(string productName, string firmwareVersion, string response, bool isSlewing) { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#")).Returns(response); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#", true)).Returns(response); ConnectTelescope(productName, firmwareVersion); @@ -2423,7 +2421,7 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.EqualTo(isSlewing)); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#", true), Times.Once); } [TestCase(1, TelescopeAxes.axisPrimary)] @@ -2439,7 +2437,7 @@ namespace Meade.net.Telescope.UnitTests var result = _telescope.Slewing; Assert.That(result, Is.True); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#"), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#", true), Times.Never); } [TestCase(1, TelescopeAxes.axisPrimary, 0, 0, false, false)] @@ -2613,7 +2611,7 @@ namespace Meade.net.Telescope.UnitTests var slewCounter = 0; var iterations = 10; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#")).Returns(() => + _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#", true)).Returns(() => { slewCounter++; if (slewCounter <= iterations) @@ -2652,7 +2650,7 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Setup(x => x.SendChar(":MS#")).Returns("0"); _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sr{_testProperties.telescopeRaResult}#")).Returns("1"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#", true)).Returns(telescopeDecResult); _utilMock.Setup(x => x.HoursToHMS(_testProperties.rightAscension, ":", ":", ":", digitsRA)).Returns(_testProperties.telescopeRaResult); _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(declination); @@ -2696,7 +2694,7 @@ namespace Meade.net.Telescope.UnitTests var dmsResult = 1.2; var digitsRA = 2; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#", true)).Returns(telescopeDecResult); _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sr{_testProperties.telescopeRaResult}#")).Returns("1"); _utilMock.Setup(x => x.HoursToHMS(_testProperties.rightAscension, ":", ":", ":", digitsRA)).Returns(_testProperties.telescopeRaResult); @@ -2707,7 +2705,7 @@ namespace Meade.net.Telescope.UnitTests var slewCounter = 0; var iterations = 10; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#")).Returns(() => + _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#", true)).Returns(() => { slewCounter++; if (slewCounter <= iterations) @@ -2777,9 +2775,9 @@ namespace Meade.net.Telescope.UnitTests var azimuth = 45; var declination = 10; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GC#")).Returns("10/15/20"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GL#")).Returns("20:15:10"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#")).Returns("-1.0"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GC#", true)).Returns("10/15/20"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GL#", true)).Returns("20:15:10"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns("-1.0"); _astroMathsMock .Setup(x => x.ConvertHozToEq(It.IsAny(), It.IsAny(), It.IsAny(), @@ -2826,9 +2824,9 @@ namespace Meade.net.Telescope.UnitTests _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", 2)).Returns(_testProperties.telescopeRaResult); _utilMock.Setup(x => x.DMSToDegrees(_testProperties.telescopeRaResult)).Returns(declination); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GC#")).Returns("10/15/20"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GL#")).Returns("20:15:10"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#")).Returns("-1.0"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GC#", true)).Returns("10/15/20"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GL#", true)).Returns("20:15:10"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns("-1.0"); _sharedResourcesWrapperMock.Setup(x => x.SendChar(":Sd+HH:MM:SS#")).Returns("1"); _astroMathsMock @@ -2839,7 +2837,7 @@ namespace Meade.net.Telescope.UnitTests var slewCounter = 0; var iterations = 10; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#")).Returns(() => + _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#", true)).Returns(() => { slewCounter++; if (slewCounter <= iterations) @@ -2878,11 +2876,11 @@ namespace Meade.net.Telescope.UnitTests var mockHourAngle = 3; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GC#")).Returns("10/15/20"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GL#")).Returns("20:15:10"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#")).Returns("-1.0"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GC#", true)).Returns("10/15/20"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GL#", true)).Returns("20:15:10"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns("-1.0"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":Gg#")).Returns(telescopeLongitude); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":Gg#", true)).Returns(telescopeLongitude); _utilMock.Setup(x => x.DMSToDegrees(telescopeLongitude)).Returns(telescopeLongitudeValue); _astroMathsMock.Setup(x => x.RightAscensionToHourAngle(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockHourAngle); @@ -2917,11 +2915,11 @@ namespace Meade.net.Telescope.UnitTests var mockHourAngle = 3; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GC#")).Returns("10/15/20"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GL#")).Returns("20:15:10"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#")).Returns("-1.0"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GC#", true)).Returns("10/15/20"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GL#", true)).Returns("20:15:10"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns("-1.0"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":Gg#")).Returns(telescopeLongitude); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":Gg#", true)).Returns(telescopeLongitude); _utilMock.Setup(x => x.DMSToDegrees(telescopeLongitude)).Returns(telescopeLongitudeValue); _astroMathsMock.Setup(x => x.RightAscensionToHourAngle(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockHourAngle); @@ -2954,7 +2952,7 @@ namespace Meade.net.Telescope.UnitTests var isSloSlewing = _telescope.Slewing; Assert.That(isSloSlewing, Is.False); - _sharedResourcesWrapperMock.Verify( x => x.SendString(":D#"), Times.Once); + _sharedResourcesWrapperMock.Verify( x => x.SendString(":D#", true), Times.Once); } } } \ No newline at end of file diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 5183e95..1cb7ec9 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -357,7 +357,7 @@ namespace ASCOM.Meade.net // it's a good idea to put all the low level communication with the device here, // then all communication calls this function // you need something to ensure that only one command is in progress at a time - return SharedResourcesWrapper.SendString(command); + return SharedResourcesWrapper.SendString(command, raw); //throw new ASCOM.MethodNotImplementedException("CommandString"); } @@ -2107,18 +2107,6 @@ namespace ASCOM.Meade.net return isSlewing; } - if (result.Equals("[7F]")) - { - isSlewing = true; - return isSlewing; - } - - if (result.Equals("\x00ff")) - { - isSlewing = true; - return isSlewing; - } - ////classic LX200 return bar with 32 chars. FF is contained from left to right when slewing //byte[] ba = Encoding.Default.GetBytes(result); ////replace fill chars not belonging to a slew bar. Are there others? The bar character is a FF in hex. @@ -2134,13 +2122,13 @@ namespace ASCOM.Meade.net ////a 0 movement will solved that lock if the target coordinates are set to the current coordinates. //if (IsTargetCoordinateInitRequired()) // InitTargetCoordinates(); - - return isSlewing; } finally { LogMessage("IsSlewingToTarget", $"IsSlewing = {isSlewing} : result = {result ?? ""}"); } + + return isSlewing; } public void SyncToAltAz(double azimuth, double altitude) diff --git a/Meade.net.UnitTests/SharedResourcesUnitTests.cs b/Meade.net.UnitTests/SharedResourcesUnitTests.cs index 414d327..ec88158 100644 --- a/Meade.net.UnitTests/SharedResourcesUnitTests.cs +++ b/Meade.net.UnitTests/SharedResourcesUnitTests.cs @@ -59,15 +59,16 @@ namespace Meade.net.UnitTests Assert.That(result, Is.EqualTo(expectedResult)); } - [Test] - public void SendString_WhenCalled_ThenSendsMessageAndReadsResultUntilTerminatorFound() + [TestCase(false, "Test")] + [TestCase(true, "#Test")] + public void SendString_WhenCalled_ThenSendsMessageAndReadsResultUntilTerminatorFound(bool includePrefix, string expectedMessage) { - var expectedMessage = "Test"; + var transmitMessage = "Test"; var expectedResult = "TestMessage#"; _serialMock.Setup(x => x.ReceiveTerminated("#")).Returns(expectedResult); - var result = SharedResources.SendString(expectedMessage); + var result = SharedResources.SendString(transmitMessage, includePrefix); _serialMock.Verify(x => x.ClearBuffers(), Times.Once); _serialMock.Verify(x => x.Transmit(expectedMessage), Times.Once); diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index 1d07e15..f84a243 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -93,12 +93,17 @@ namespace ASCOM.Meade.net /// /// /// - public static string SendString(string message) + public static string SendString(string message, bool includePrefix = true) { lock (LockObject) { SharedSerial.ClearBuffers(); - SharedSerial.Transmit(message); + + if (includePrefix) + SharedSerial.Transmit( $"#{message}"); + else + SharedSerial.Transmit(message); + return SharedSerial.ReceiveTerminated("#").TrimEnd('#'); } } @@ -324,8 +329,8 @@ namespace ASCOM.Meade.net try { - ProductName = SendString("#:GVP#"); - FirmwareVersion = SendString("#:GVN#"); + ProductName = SendString(":GVP#"); + FirmwareVersion = SendString(":GVN#"); } catch (Exception ex) { @@ -345,7 +350,7 @@ namespace ASCOM.Meade.net try { - string utcOffSet = SendString("#:GG#"); + string utcOffSet = SendString(":GG#"); //:GG# Get UTC offset time //Returns: sHH# or sHH.H# //The number of decimal hours to add to local time to convert it to UTC. If the number is a whole number the diff --git a/Meade.net/Wrapper/SharedResourcesWrapper.cs b/Meade.net/Wrapper/SharedResourcesWrapper.cs index b9fa801..82e24e0 100644 --- a/Meade.net/Wrapper/SharedResourcesWrapper.cs +++ b/Meade.net/Wrapper/SharedResourcesWrapper.cs @@ -15,7 +15,7 @@ namespace ASCOM.Meade.net.Wrapper void Lock(Action action); T Lock(Func func); - string SendString(string message); + string SendString(string message, bool includePrefix = true); void SendBlind(string message); string SendChar(string message); @@ -54,9 +54,9 @@ namespace ASCOM.Meade.net.Wrapper return SharedResources.Lock(func); } - public string SendString(string message) + public string SendString(string message, bool includePrefix = true) { - return SharedResources.SendString(message); + return SharedResources.SendString(message, includePrefix); } public void SendBlind(string message) From ad40eb8b9ae8b9f13b959678b3e2a70d8347e499 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Fri, 23 Apr 2021 20:45:48 +0100 Subject: [PATCH 15/28] Fixed problem with Autostar not returning the correct value for IsSlewing --- Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs | 1 + Meade.net.Telescope/Telescope.cs | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 1a2c74a..ae762b7 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -2410,6 +2410,7 @@ namespace Meade.net.Telescope.UnitTests [TestCase(TelescopeList.LX200CLASSIC, "", "[FF][FF][FF][FF][FF][FF][FF][FF][FF][FF][FF][FF][FF][FF] [FF][FF][FF][FF][FF][FF]", false)] //The test case below is this same string encoded to return exactly what the telescope will return. [TestCase(TelescopeList.LX200CLASSIC, "", "\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff \x00ff\x00ff\x00ff\x00ff\x00ff\x00ff", false)] [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, "|", true)] + [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, "\u007f", true)] [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, "", false)] public void Slewing_WhenTelescopeNotSlewing_ThenReturnsFalse(string productName, string firmwareVersion, string response, bool isSlewing) { diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 1cb7ec9..a6e8271 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -483,7 +483,7 @@ namespace ASCOM.Meade.net else if (SharedResourcesWrapper.ProductName == TelescopeList.Autostar497) { var displayText = Action("Handbox", "readdisplay"); - if (displayText.Contains("€Press 0 to Alignor MODE for Menu")) + if (displayText.Contains("Press 0 to Alignor MODE for Menu")) { for (var i = 0; i < 4; i++) { @@ -2107,6 +2107,12 @@ namespace ASCOM.Meade.net return isSlewing; } + if (result.Contains("\u007f")) + { + isSlewing = true; + return isSlewing; + } + ////classic LX200 return bar with 32 chars. FF is contained from left to right when slewing //byte[] ba = Encoding.Default.GetBytes(result); ////replace fill chars not belonging to a slew bar. Are there others? The bar character is a FF in hex. From 9c5620edee0e0f7a15385b35ee8c34656f414a15 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Fri, 23 Apr 2021 21:13:46 +0100 Subject: [PATCH 16/28] Going to try the proper command for bypassing the date entry for AutostarII --- Meade.net.Telescope/Telescope.cs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index a6e8271..fdb427d 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -421,12 +421,16 @@ namespace ASCOM.Meade.net bool setTimeBeforeDisplayBypass = SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS; if (setTimeBeforeDisplayBypass) - SendCurrentDateTime("Connect"); - - ApplySkipAutoStarPrompts("Connect"); - if (!setTimeBeforeDisplayBypass) - SendCurrentDateTime("Connect"); - + { + BypassHandboxEntryForAutostarII(); + //SendCurrentDateTime("Connect"); + } + else + { + ApplySkipAutoStarPrompts("Connect"); + if (!setTimeBeforeDisplayBypass) + SendCurrentDateTime("Connect"); + } } else { @@ -2502,6 +2506,13 @@ namespace ASCOM.Meade.net //:I# LX200 GPS Only - Causes the telescope to cease current operations and restart at its power on initialization. //Returns: X once the handset restart has completed + BypassHandboxEntryForAutostarII(); + + AtPark = false; + } + + private void BypassHandboxEntryForAutostarII() + { var utcCorrection = GetUtcCorrection(); var localDateTime = DateTime.UtcNow - utcCorrection; @@ -2512,8 +2523,6 @@ namespace ASCOM.Meade.net //intended to allow use of the Autostar II from permanent installations where GPS reception is not possible, such as within //metal domes. This command must be issued while the telescope is waiting at the initial daylight savings prompt. //Returns: 1 – if command was accepted. - - AtPark = false; } #endregion From 6ac80c408cec1d6dcde3b139ec2a6c8e899b8a92 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Sat, 24 Apr 2021 13:07:42 +0100 Subject: [PATCH 17/28] Fixed problem with changing the modifying the profile on the fly! --- Meade.net.Telescope/Telescope.cs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index fdb427d..919fa51 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -2619,14 +2619,19 @@ namespace ASCOM.Meade.net private void WriteProfile() { - var profileProperties = new ProfileProperties - { - TraceLogger = Tl.Enabled, - ComPort = ComPort, - GuideRateArcSecondsPerSecond = GuideRate - }; + var changed = false; - SharedResourcesWrapper.WriteProfile(profileProperties); + var profileProperties = SharedResourcesWrapper.ReadProfile(); + + + if (Math.Abs(profileProperties.GuideRateArcSecondsPerSecond - GuideRate) > 0.0000001) + { + changed = true; + profileProperties.GuideRateArcSecondsPerSecond = GuideRate; + } + + if (changed) + SharedResourcesWrapper.WriteProfile(profileProperties); } #endregion } From eaeae4d66b3e763ae6fdfac66c76463b369d410e Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Sat, 24 Apr 2021 13:16:08 +0100 Subject: [PATCH 18/28] Combined the skip prompts and set date time code, to just one check box. --- Meade.net.Telescope/Telescope.cs | 61 +++--- .../SharedResourcesUnitTests.cs | 1 - Meade.net/MeadeTelescopeBase.cs | 3 - Meade.net/ProfileProperties.cs | 1 - Meade.net/SetupDialogForm.cs | 4 +- Meade.net/SetupDialogForm.designer.cs | 26 +-- Meade.net/SetupDialogForm.resx | 179 +++++++----------- Meade.net/SharedResources.cs | 4 - 8 files changed, 111 insertions(+), 168 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 919fa51..08e8dfd 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -419,17 +419,17 @@ namespace ASCOM.Meade.net SetTelescopePrecision("Connect"); - bool setTimeBeforeDisplayBypass = SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS; - if (setTimeBeforeDisplayBypass) + if (SendDateTime) { - BypassHandboxEntryForAutostarII(); - //SendCurrentDateTime("Connect"); - } - else - { - ApplySkipAutoStarPrompts("Connect"); - if (!setTimeBeforeDisplayBypass) + if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) + { + BypassHandboxEntryForAutostarII(); + } + else + { + ApplySkipAutoStarPrompts("Connect"); SendCurrentDateTime("Connect"); + } } } else @@ -470,33 +470,30 @@ namespace ASCOM.Meade.net private void ApplySkipAutoStarPrompts(string connect) { - if (SkipAutoStarPrompts) + //if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) + //{ + // var displayText = Action("Handbox", "readdisplay"); + // if (displayText.Contains("Daylight")) + // { + // for (var i = 0; i < 3; i++) + // { + // Action("Handbox", "enter"); + // _utilities.WaitForMilliseconds(2000); + // } + // } + //} + //else if (SharedResourcesWrapper.ProductName == TelescopeList.Autostar497) + //{ + var displayText = Action("Handbox", "readdisplay"); + if (displayText.Contains("Press 0 to Alignor MODE for Menu")) { - if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) + for (var i = 0; i < 4; i++) { - var displayText = Action("Handbox", "readdisplay"); - if (displayText.Contains("Daylight")) - { - for (var i = 0; i < 3; i++) - { - Action("Handbox", "enter"); - _utilities.WaitForMilliseconds(2000); - } - } - } - else if (SharedResourcesWrapper.ProductName == TelescopeList.Autostar497) - { - var displayText = Action("Handbox", "readdisplay"); - if (displayText.Contains("Press 0 to Alignor MODE for Menu")) - { - for (var i = 0; i < 4; i++) - { - Action("Handbox", "mode"); - _utilities.WaitForMilliseconds(500); - } - } + Action("Handbox", "mode"); + _utilities.WaitForMilliseconds(500); } } + //} } private void SetTelescopePrecision(string propertyName) diff --git a/Meade.net.UnitTests/SharedResourcesUnitTests.cs b/Meade.net.UnitTests/SharedResourcesUnitTests.cs index ec88158..d6888e6 100644 --- a/Meade.net.UnitTests/SharedResourcesUnitTests.cs +++ b/Meade.net.UnitTests/SharedResourcesUnitTests.cs @@ -247,7 +247,6 @@ namespace Meade.net.UnitTests Assert.That(profileProperties.RtsDtrEnabled, Is.EqualTo(bool.Parse(RtsDtrEnabledDefault))); Assert.That(profileProperties.SendDateTime, Is.EqualTo(bool.Parse(SendDateTimeDefault))); - Assert.That(profileProperties.SkipPrompts, Is.EqualTo(bool.Parse(SkipPromptsDefault))); } [TestCase("TCP")] diff --git a/Meade.net/MeadeTelescopeBase.cs b/Meade.net/MeadeTelescopeBase.cs index 3e79993..a923a2a 100644 --- a/Meade.net/MeadeTelescopeBase.cs +++ b/Meade.net/MeadeTelescopeBase.cs @@ -28,7 +28,6 @@ namespace ASCOM.Meade.net protected string GuidingStyle; protected double SiteElevation; protected short ProfileSettleTime; - protected bool SkipAutoStarPrompts; protected bool SendDateTime; protected readonly ISharedResourcesWrapper SharedResourcesWrapper; @@ -71,7 +70,6 @@ namespace ASCOM.Meade.net GuidingStyle = profileProperties.GuidingStyle.ToLower(); SiteElevation = profileProperties.SiteElevation; ProfileSettleTime = profileProperties.SettleTime; - SkipAutoStarPrompts = profileProperties.SkipPrompts; SendDateTime = profileProperties.SendDateTime; LogMessage("ReadProfile", $"Trace logger enabled: {Tl.Enabled}"); @@ -83,7 +81,6 @@ namespace ASCOM.Meade.net LogMessage("ReadProfile", $"Guiding Style: {GuidingStyle}"); LogMessage("ReadProfile", $"Site Elevation: {SiteElevation}"); LogMessage("ReadProfile", $"Settle Time after slew: {ProfileSettleTime}"); - LogMessage("ReadProfile", $"Skip Autostar startup prompts: {SkipAutoStarPrompts}"); LogMessage("ReadProfile", $"Send date and time on connect: {SendDateTime}"); } diff --git a/Meade.net/ProfileProperties.cs b/Meade.net/ProfileProperties.cs index 9c03728..e95c707 100644 --- a/Meade.net/ProfileProperties.cs +++ b/Meade.net/ProfileProperties.cs @@ -20,6 +20,5 @@ namespace ASCOM.Meade.net public int Speed { get; set; } public string Handshake { get; set; } public bool SendDateTime { get; set; } - public bool SkipPrompts { get; set; } } } \ No newline at end of file diff --git a/Meade.net/SetupDialogForm.cs b/Meade.net/SetupDialogForm.cs index 40c753b..af0db74 100644 --- a/Meade.net/SetupDialogForm.cs +++ b/Meade.net/SetupDialogForm.cs @@ -158,7 +158,6 @@ namespace ASCOM.Meade.net nudSettleTime.Value = profileProperties.SettleTime; cbxSendDateTime.Checked = profileProperties.SendDateTime; - cbxSkipPrompts.Checked = profileProperties.SkipPrompts; } public ProfileProperties GetProfile() @@ -181,8 +180,7 @@ namespace ASCOM.Meade.net DynamicBreaking = cbxDynamicBreaking.Checked, SiteElevation = double.Parse(txtElevation.Text), SettleTime = Convert.ToInt16(nudSettleTime.Value), - SendDateTime = cbxSendDateTime.Checked, - SkipPrompts = cbxSkipPrompts.Checked + SendDateTime = cbxSendDateTime.Checked }; return profileProperties; diff --git a/Meade.net/SetupDialogForm.designer.cs b/Meade.net/SetupDialogForm.designer.cs index 2f9e0b7..3e9a255 100644 --- a/Meade.net/SetupDialogForm.designer.cs +++ b/Meade.net/SetupDialogForm.designer.cs @@ -58,6 +58,7 @@ namespace ASCOM.Meade.net this.cbxDynamicBreaking = new System.Windows.Forms.CheckBox(); this.cbxRtsDtr = new System.Windows.Forms.CheckBox(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); + this.cbxSendDateTime = new System.Windows.Forms.CheckBox(); this.label12 = new System.Windows.Forms.Label(); this.txtElevation = new System.Windows.Forms.TextBox(); this.label13 = new System.Windows.Forms.Label(); @@ -75,8 +76,6 @@ namespace ASCOM.Meade.net this.label19 = new System.Windows.Forms.Label(); this.label20 = new System.Windows.Forms.Label(); this.label21 = new System.Windows.Forms.Label(); - this.cbxSkipPrompts = new System.Windows.Forms.CheckBox(); - this.cbxSendDateTime = new System.Windows.Forms.CheckBox(); ((System.ComponentModel.ISupportInitialize)(this.picASCOM)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nudSettleTime)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numDatabits)).BeginInit(); @@ -234,6 +233,13 @@ namespace ASCOM.Meade.net this.toolTip1.SetToolTip(this.cbxRtsDtr, resources.GetString("cbxRtsDtr.ToolTip")); this.cbxRtsDtr.UseVisualStyleBackColor = true; // + // cbxSendDateTime + // + resources.ApplyResources(this.cbxSendDateTime, "cbxSendDateTime"); + this.cbxSendDateTime.Name = "cbxSendDateTime"; + this.toolTip1.SetToolTip(this.cbxSendDateTime, resources.GetString("cbxSendDateTime.ToolTip")); + this.cbxSendDateTime.UseVisualStyleBackColor = true; + // // label12 // resources.ApplyResources(this.label12, "label12"); @@ -338,26 +344,11 @@ namespace ASCOM.Meade.net resources.ApplyResources(this.label21, "label21"); this.label21.Name = "label21"; // - // cbxSkipPrompts - // - resources.ApplyResources(this.cbxSkipPrompts, "cbxSkipPrompts"); - this.cbxSkipPrompts.Name = "cbxSkipPrompts"; - this.toolTip1.SetToolTip(this.cbxSkipPrompts, resources.GetString("cbxSkipPrompts.ToolTip")); - this.cbxSkipPrompts.UseVisualStyleBackColor = true; - // - // cbxSendDateTime - // - resources.ApplyResources(this.cbxSendDateTime, "cbxSendDateTime"); - this.cbxSendDateTime.Name = "cbxSendDateTime"; - this.toolTip1.SetToolTip(this.cbxSendDateTime, resources.GetString("cbxSendDateTime.ToolTip")); - this.cbxSendDateTime.UseVisualStyleBackColor = true; - // // SetupDialogForm // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.Controls.Add(this.cbxSendDateTime); - this.Controls.Add(this.cbxSkipPrompts); this.Controls.Add(this.label21); this.Controls.Add(this.label20); this.Controls.Add(this.label19); @@ -458,7 +449,6 @@ namespace ASCOM.Meade.net private Label label19; private Label label20; private Label label21; - private CheckBox cbxSkipPrompts; private CheckBox cbxSendDateTime; } } \ No newline at end of file diff --git a/Meade.net/SetupDialogForm.resx b/Meade.net/SetupDialogForm.resx index 6103062..726e548 100644 --- a/Meade.net/SetupDialogForm.resx +++ b/Meade.net/SetupDialogForm.resx @@ -145,7 +145,7 @@ $this - 42 + 41 Bottom, Right @@ -172,7 +172,7 @@ $this - 41 + 40 12, 9 @@ -196,7 +196,7 @@ $this - 40 + 39 Top, Right @@ -223,7 +223,7 @@ $this - 39 + 38 True @@ -250,7 +250,7 @@ $this - 38 + 37 True @@ -277,7 +277,7 @@ $this - 37 + 36 97, 87 @@ -298,7 +298,7 @@ $this - 36 + 35 True @@ -325,7 +325,7 @@ $this - 35 + 34 375, 166 @@ -355,7 +355,7 @@ $this - 34 + 33 True @@ -382,7 +382,7 @@ $this - 33 + 32 True @@ -409,7 +409,7 @@ $this - 32 + 31 True @@ -436,7 +436,7 @@ $this - 31 + 30 Unchanged @@ -466,7 +466,7 @@ $this - 30 + 29 True @@ -496,7 +496,7 @@ $this - 29 + 28 Auto @@ -526,7 +526,7 @@ $this - 28 + 27 True @@ -556,7 +556,7 @@ $this - 27 + 26 True @@ -589,7 +589,7 @@ $this - 26 + 25 375, 302 @@ -613,7 +613,7 @@ $this - 24 + 23 True @@ -643,7 +643,7 @@ $this - 25 + 24 True @@ -673,7 +673,7 @@ $this - 23 + 22 True @@ -706,7 +706,7 @@ $this - 22 + 21 True @@ -733,7 +733,7 @@ $this - 21 + 20 True @@ -760,7 +760,7 @@ $this - 20 + 19 True @@ -793,7 +793,40 @@ $this - 19 + 18 + + + True + + + NoControl + + + 627, 95 + + + 145, 17 + + + 41 + + + Set current date and time + + + Send Current Date and Time (will also skip the opening dialogs on the LX200GPS) + + + cbxSendDateTime + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 0 True @@ -820,7 +853,7 @@ $this - 18 + 17 375, 93 @@ -841,7 +874,7 @@ $this - 17 + 16 True @@ -868,7 +901,7 @@ $this - 16 + 15 True @@ -895,7 +928,7 @@ $this - 15 + 14 375, 125 @@ -916,7 +949,7 @@ $this - 14 + 13 True @@ -943,7 +976,7 @@ $this - 13 + 12 True @@ -970,7 +1003,7 @@ $this - 12 + 11 97, 163 @@ -991,7 +1024,7 @@ $this - 11 + 10 97, 137 @@ -1012,7 +1045,7 @@ $this - 10 + 9 97, 190 @@ -1033,7 +1066,7 @@ $this - 9 + 8 97, 217 @@ -1054,7 +1087,7 @@ $this - 8 + 7 97, 244 @@ -1075,7 +1108,7 @@ $this - 7 + 6 True @@ -1102,7 +1135,7 @@ $this - 6 + 5 True @@ -1129,7 +1162,7 @@ $this - 5 + 4 True @@ -1156,7 +1189,7 @@ $this - 4 + 3 True @@ -1183,7 +1216,7 @@ $this - 3 + 2 True @@ -1216,74 +1249,8 @@ $this - 2 - - - True - - - NoControl - - - 615, 96 - - - 113, 17 - - - 40 - - - Skip Date prompts - - - driver will attempt to skip past the date prompts when a connection to the Autostar is made - - - cbxSkipPrompts - - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - 1 - - True - - - NoControl - - - 615, 123 - - - 145, 17 - - - 41 - - - Set current date and time - - - Send Current Date and Time - - - cbxSendDateTime - - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 0 - True diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index f84a243..ebcc48c 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -158,7 +158,6 @@ namespace ASCOM.Meade.net private const string StopBitsName = "Stop Bits"; private const string HandShakeName = "Hand Shake"; private const string ParityName = "Parity"; - private const string SkipPromptsName = "Skip date prompts on connect"; private const string SendDateTimeName = "Send Date and time on connect"; public static void WriteProfile(ProfileProperties profileProperties) @@ -184,7 +183,6 @@ namespace ASCOM.Meade.net driverProfile.WriteValue(DriverId, DynamicBreakingName, profileProperties.DynamicBreaking.ToString()); driverProfile.WriteValue(DriverId, SiteElevationName, profileProperties.SiteElevation.ToString(CultureInfo.InvariantCulture)); driverProfile.WriteValue(DriverId, SettleTimeName, profileProperties.SettleTime.ToString()); - driverProfile.WriteValue(DriverId, SkipPromptsName, profileProperties.SkipPrompts.ToString()); driverProfile.WriteValue(DriverId, SendDateTimeName, profileProperties.SendDateTime.ToString()); } } @@ -207,7 +205,6 @@ namespace ASCOM.Meade.net private const string HandShakeDefault = "None"; private const string ParityDefault = "None"; private const string SendDateTimeDefault = "false"; - private const string SkipPromptsDefault = "false"; public static ProfileProperties ReadProfile() { @@ -234,7 +231,6 @@ namespace ASCOM.Meade.net profileProperties.Speed = Convert.ToInt32(driverProfile.GetValue(DriverId, SpeedName, string.Empty, SpeedDefault)); profileProperties.Parity = driverProfile.GetValue(DriverId, ParityName, string.Empty, ParityDefault); profileProperties.SendDateTime = Convert.ToBoolean(driverProfile.GetValue(DriverId, SendDateTimeName, string.Empty, SendDateTimeDefault)); - profileProperties.SkipPrompts = Convert.ToBoolean(driverProfile.GetValue(DriverId, SkipPromptsName, string.Empty, SkipPromptsDefault)); } return profileProperties; From fdd008fcfbc52fd8c8fe4599d86baf4cc5b76778 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Sat, 24 Apr 2021 19:16:36 +0100 Subject: [PATCH 19/28] Adding support for sending co-ordinates when scope is parked. --- Meade.net.Telescope/Telescope.cs | 11 +- .../SharedResourcesUnitTests.cs | 71 ++++- Meade.net/EnumExtensionMethods.cs | 39 +++ Meade.net/Meade.net.csproj | 2 + Meade.net/MeadeTelescopeBase.cs | 11 +- Meade.net/ParkedBehaviour.cs | 14 + Meade.net/ProfileProperties.cs | 3 + Meade.net/SetupDialogForm.cs | 73 ++++- Meade.net/SetupDialogForm.designer.cs | 57 ++++ Meade.net/SetupDialogForm.resx | 254 ++++++++++++++---- Meade.net/SharedResources.cs | 13 + 11 files changed, 492 insertions(+), 56 deletions(-) create mode 100644 Meade.net/EnumExtensionMethods.cs create mode 100644 Meade.net/ParkedBehaviour.cs diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 08e8dfd..0210715 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -423,7 +423,16 @@ namespace ASCOM.Meade.net { if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) { - BypassHandboxEntryForAutostarII(); + var displayText = Action("Handbox", "readdisplay"); + if (displayText.Contains("Daylight")) + { + BypassHandboxEntryForAutostarII(); + } + else + { + SendCurrentDateTime("Connect"); + } + } else { diff --git a/Meade.net.UnitTests/SharedResourcesUnitTests.cs b/Meade.net.UnitTests/SharedResourcesUnitTests.cs index d6888e6..634c33e 100644 --- a/Meade.net.UnitTests/SharedResourcesUnitTests.cs +++ b/Meade.net.UnitTests/SharedResourcesUnitTests.cs @@ -166,6 +166,10 @@ namespace Meade.net.UnitTests string SendDateTimeDefault = "true"; string SkipPromptsDefault = "true"; + string ParkedBehaviourDefault = "No Coordinates"; + string ParkedAltDefault = "0"; + string ParkedAzimuthDefault = "180"; + Mock profileWrapperMock = new Mock(); profileWrapperMock.SetupAllProperties(); @@ -206,6 +210,16 @@ namespace Meade.net.UnitTests x.GetValue(DriverId, "Rts / Dtr", string.Empty, "false")) .Returns(() => RtsDtrEnabledDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Parked Behaviour", string.Empty, ParkedBehaviourDefault)) + .Returns(() => ParityDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Parked Altitude", string.Empty, ParkedAltDefault)) + .Returns(() => ParkedAltDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Parked Azimuth", string.Empty, ParkedAzimuthDefault)) + .Returns(() => ParkedAzimuthDefault); + profileWrapperMock.Setup(x => x.GetValue(DriverId, "Send Date and time on connect", string.Empty, "false")) .Returns(() => SendDateTimeDefault); @@ -276,6 +290,10 @@ namespace Meade.net.UnitTests string GuideRateProfileNameDefault = "10.077939"; //67% of sidereal rate string PrecisionDefault = "Unchanged"; + string ParkedBehaviourDefault = "No Coordinates"; + string ParkedAltDefault = "0"; + string ParkedAzimuthDefault = "180"; + Mock profileWrapperMock = new Mock(); profileWrapperMock.SetupAllProperties(); @@ -308,6 +326,16 @@ namespace Meade.net.UnitTests profileWrapperMock.Setup(x => x.GetValue(DriverId, "Precision", string.Empty, PrecisionDefault)) .Returns(PrecisionDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Parked Behaviour", string.Empty, ParkedBehaviourDefault)) + .Returns(() => ParityDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Parked Altitude", string.Empty, ParkedAltDefault)) + .Returns(() => ParkedAltDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Parked Azimuth", string.Empty, ParkedAzimuthDefault)) + .Returns(() => ParkedAzimuthDefault); + Mock profileFactoryMock = new Mock(); profileFactoryMock.Setup(x => x.Create()).Returns(profileWrapperMock.Object); @@ -341,7 +369,11 @@ namespace Meade.net.UnitTests string GuideRateProfileNameDefault = "10.077939"; //67% of sidereal rate string PrecisionDefault = "Unchanged"; - + + string ParkedBehaviourDefault = "No Coordinates"; + string ParkedAltDefault = "0"; + string ParkedAzimuthDefault = "180"; + Mock profileWrapperMock = new Mock(); profileWrapperMock.SetupAllProperties(); @@ -373,6 +405,16 @@ namespace Meade.net.UnitTests x.GetValue(DriverId, "Rts / Dtr", string.Empty, RtsDtrEnabledDefault)) .Returns(() => RtsDtrEnabledDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Parked Behaviour", string.Empty, ParkedBehaviourDefault)) + .Returns(() => ParityDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Parked Altitude", string.Empty, ParkedAltDefault)) + .Returns(() => ParkedAltDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Parked Azimuth", string.Empty, ParkedAzimuthDefault)) + .Returns(() => ParkedAzimuthDefault); + Mock profileFactoryMock = new Mock(); profileFactoryMock.Setup(x => x.Create()).Returns(profileWrapperMock.Object); @@ -421,6 +463,10 @@ namespace Meade.net.UnitTests string GuideRateProfileNameDefault = "10.077939"; //67% of sidereal rate string PrecisionDefault = "Unchanged"; + string ParkedBehaviourDefault = "No Coordinates"; + string ParkedAltDefault = "0"; + string ParkedAzimuthDefault = "180"; + Mock profileWrapperMock = new Mock(); profileWrapperMock.SetupAllProperties(); @@ -452,6 +498,16 @@ namespace Meade.net.UnitTests x.GetValue(DriverId, "Rts / Dtr", string.Empty, RtsDtrEnabledDefault)) .Returns(() => RtsDtrEnabledDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Parked Behaviour", string.Empty, ParkedBehaviourDefault)) + .Returns(() => ParityDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Parked Altitude", string.Empty, ParkedAltDefault)) + .Returns(() => ParkedAltDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Parked Azimuth", string.Empty, ParkedAzimuthDefault)) + .Returns(() => ParkedAzimuthDefault); + Mock profileFactoryMock = new Mock(); profileFactoryMock.Setup(x => x.Create()).Returns(profileWrapperMock.Object); @@ -497,6 +553,10 @@ namespace Meade.net.UnitTests string GuideRateProfileNameDefault = "10.077939"; //67% of sidereal rate string PrecisionDefault = "Unchanged"; + string ParkedBehaviourDefault = "No Coordinates"; + string ParkedAltDefault = "0"; + string ParkedAzimuthDefault = "180"; + Mock profileWrapperMock = new Mock(); profileWrapperMock.SetupAllProperties(); @@ -527,6 +587,15 @@ namespace Meade.net.UnitTests profileWrapperMock.Setup(x => x.GetValue(DriverId, "Rts / Dtr", string.Empty, RtsDtrEnabledDefault)) .Returns(() => RtsDtrEnabledDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Parked Behaviour", string.Empty, ParkedBehaviourDefault)) + .Returns(() => ParityDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Parked Altitude", string.Empty, ParkedAltDefault)) + .Returns(() => ParkedAltDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Parked Azimuth", string.Empty, ParkedAzimuthDefault)) + .Returns(() => ParkedAzimuthDefault); Mock profileFactoryMock = new Mock(); profileFactoryMock.Setup(x => x.Create()).Returns(profileWrapperMock.Object); diff --git a/Meade.net/EnumExtensionMethods.cs b/Meade.net/EnumExtensionMethods.cs new file mode 100644 index 0000000..82b834a --- /dev/null +++ b/Meade.net/EnumExtensionMethods.cs @@ -0,0 +1,39 @@ +using System; +using System.Linq; +using System.Reflection; + +namespace ASCOM.Meade.net +{ + public static class EnumExtensionMethods + { + public static string GetDescription(this Enum GenericEnum) + { + Type genericEnumType = GenericEnum.GetType(); + MemberInfo[] memberInfo = genericEnumType.GetMember(GenericEnum.ToString()); + if ((memberInfo != null && memberInfo.Length > 0)) + { + var _Attribs = memberInfo[0] + .GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false); + if ((_Attribs != null && _Attribs.Count() > 0)) + { + return ((System.ComponentModel.DescriptionAttribute) _Attribs.ElementAt(0)).Description; + } + } + + return GenericEnum.ToString(); + } + + public static T GetValueFromDescription( string description) where T : Enum + { + foreach (T value in Enum.GetValues(typeof(T))) + { + if (value.GetDescription() == description) + { + return value; + } + } + + return default; + } + } +} \ No newline at end of file diff --git a/Meade.net/Meade.net.csproj b/Meade.net/Meade.net.csproj index eb6b45c..366e8e0 100644 --- a/Meade.net/Meade.net.csproj +++ b/Meade.net/Meade.net.csproj @@ -129,6 +129,7 @@ + Form @@ -138,6 +139,7 @@ + diff --git a/Meade.net/MeadeTelescopeBase.cs b/Meade.net/MeadeTelescopeBase.cs index a923a2a..a84f993 100644 --- a/Meade.net/MeadeTelescopeBase.cs +++ b/Meade.net/MeadeTelescopeBase.cs @@ -29,7 +29,10 @@ namespace ASCOM.Meade.net protected double SiteElevation; protected short ProfileSettleTime; protected bool SendDateTime; - + protected ParkedBehaviour ParkedBehaviour; + protected double ParkedAzimuth; + protected double ParkedAlt; + protected readonly ISharedResourcesWrapper SharedResourcesWrapper; public MeadeTelescopeBase() @@ -71,6 +74,9 @@ namespace ASCOM.Meade.net SiteElevation = profileProperties.SiteElevation; ProfileSettleTime = profileProperties.SettleTime; SendDateTime = profileProperties.SendDateTime; + ParkedBehaviour = profileProperties.ParkedBehaviour; + ParkedAlt = profileProperties.ParkedAlt; + ParkedAzimuth = profileProperties.ParkedAz; LogMessage("ReadProfile", $"Trace logger enabled: {Tl.Enabled}"); LogMessage("ReadProfile", $"Com Port: {ComPort}"); @@ -82,6 +88,9 @@ namespace ASCOM.Meade.net LogMessage("ReadProfile", $"Site Elevation: {SiteElevation}"); LogMessage("ReadProfile", $"Settle Time after slew: {ProfileSettleTime}"); LogMessage("ReadProfile", $"Send date and time on connect: {SendDateTime}"); + LogMessage("ReadProfile", $"Parked Behaviour: {ParkedBehaviour}"); + LogMessage("ReadProfile", $"Parked Alt: {ParkedAlt}"); + LogMessage("ReadProfile", $"Parked Az: {ParkedAzimuth}"); } /// diff --git a/Meade.net/ParkedBehaviour.cs b/Meade.net/ParkedBehaviour.cs new file mode 100644 index 0000000..e67945f --- /dev/null +++ b/Meade.net/ParkedBehaviour.cs @@ -0,0 +1,14 @@ +using System.ComponentModel; + +namespace ASCOM.Meade.net +{ + public enum ParkedBehaviour + { + [Description("No Coordinates")] + NoCoordinates, + [Description("Last Good Position")] + LastGoodPosition, + [Description("Report coordinates as")] + ReportCoordinates + } +} \ No newline at end of file diff --git a/Meade.net/ProfileProperties.cs b/Meade.net/ProfileProperties.cs index e95c707..8cd29c5 100644 --- a/Meade.net/ProfileProperties.cs +++ b/Meade.net/ProfileProperties.cs @@ -20,5 +20,8 @@ namespace ASCOM.Meade.net public int Speed { get; set; } public string Handshake { get; set; } public bool SendDateTime { get; set; } + public ParkedBehaviour ParkedBehaviour { get; set; } + public double ParkedAlt { get; set; } + public double ParkedAz { get; set; } } } \ No newline at end of file diff --git a/Meade.net/SetupDialogForm.cs b/Meade.net/SetupDialogForm.cs index af0db74..3b7b039 100644 --- a/Meade.net/SetupDialogForm.cs +++ b/Meade.net/SetupDialogForm.cs @@ -27,15 +27,17 @@ namespace ASCOM.Meade.net SetItemsFromEnum(cboParity.Items, typeof(SerialParity)); SetItemsFromEnumValues(cboSpeed.Items, typeof(SerialSpeed)); SetItemsFromEnum(cboHandShake.Items, typeof(SerialHandshake)); + SetItemsFromEnum(cboParkedBehaviour.Items, typeof(ParkedBehaviour)); } private void SetItemsFromEnum(IList items, Type enumItems) { items.Clear(); - foreach (var item in Enum.GetNames(enumItems)) + foreach (var value in Enum.GetValues(enumItems) ) { - items.Add(item); + var val = value as Enum; + items.Add(val.GetDescription()); } } @@ -158,6 +160,35 @@ namespace ASCOM.Meade.net nudSettleTime.Value = profileProperties.SettleTime; cbxSendDateTime.Checked = profileProperties.SendDateTime; + + try + { + cboParkedBehaviour.SelectedItem = profileProperties.ParkedBehaviour.GetDescription(); + } + catch (Exception) + { + cboParkedBehaviour.SelectedItem = ParkedBehaviour.NoCoordinates.GetDescription(); + } + + try + { + txtParkedAlt.Text = profileProperties.ParkedAlt.ToString(CultureInfo.CurrentCulture); + } + catch (Exception) + { + txtParkedAlt.Text = "0"; + } + + try + { + txtParkedAz.Text = profileProperties.ParkedAz.ToString(CultureInfo.CurrentCulture); + } + catch (Exception) + { + txtParkedAz.Text = "180"; + } + + UpdateParkedItemsEnabled(); } public ProfileProperties GetProfile() @@ -180,7 +211,10 @@ namespace ASCOM.Meade.net DynamicBreaking = cbxDynamicBreaking.Checked, SiteElevation = double.Parse(txtElevation.Text), SettleTime = Convert.ToInt16(nudSettleTime.Value), - SendDateTime = cbxSendDateTime.Checked + SendDateTime = cbxSendDateTime.Checked, + ParkedBehaviour = EnumExtensionMethods.GetValueFromDescription(cboParkedBehaviour.SelectedItem.ToString()), + ParkedAlt = double.Parse(txtParkedAlt.Text), + ParkedAz = double.Parse(txtParkedAz.Text) }; return profileProperties; @@ -257,5 +291,36 @@ namespace ASCOM.Meade.net txtBacklashSteps.Text = txtElevation.Text.Remove(txtBacklashSteps.Text.Length - 1); } } + + private void cboParkedBehaviour_SelectionChangeCommitted(object sender, EventArgs e) + { + UpdateParkedItemsEnabled(); + } + + private void UpdateParkedItemsEnabled() + { + txtParkedAlt.Enabled = cboParkedBehaviour.SelectedItem?.ToString() == "Report coordinates as"; + txtParkedAz.Enabled = txtParkedAlt.Enabled; + } + + private void txtParkedAlt_TextChanged(object sender, EventArgs e) + { + if (System.Text.RegularExpressions.Regex.IsMatch(txtParkedAlt.Text, "[^0-9]")) + { + MessageBox.Show(Resources.SetupDialogForm_txtElevation_TextChanged_1_Please_enter_only_numbers_); + txtParkedAlt.Text = txtParkedAlt.Text.Remove(txtParkedAlt.Text.Length - 1); + } + } + + private void txtParkedAz_TextChanged(object sender, EventArgs e) + { + if (System.Text.RegularExpressions.Regex.IsMatch(txtParkedAz.Text, "[^0-9]")) + { + MessageBox.Show(Resources.SetupDialogForm_txtElevation_TextChanged_1_Please_enter_only_numbers_); + txtParkedAz.Text = txtParkedAz.Text.Remove(txtParkedAz.Text.Length - 1); + } + } } -} \ No newline at end of file +} + + diff --git a/Meade.net/SetupDialogForm.designer.cs b/Meade.net/SetupDialogForm.designer.cs index 3e9a255..b401604 100644 --- a/Meade.net/SetupDialogForm.designer.cs +++ b/Meade.net/SetupDialogForm.designer.cs @@ -76,6 +76,12 @@ namespace ASCOM.Meade.net this.label19 = new System.Windows.Forms.Label(); this.label20 = new System.Windows.Forms.Label(); this.label21 = new System.Windows.Forms.Label(); + this.cboParkedBehaviour = new System.Windows.Forms.ComboBox(); + this.label22 = new System.Windows.Forms.Label(); + this.label23 = new System.Windows.Forms.Label(); + this.label24 = new System.Windows.Forms.Label(); + this.txtParkedAlt = new System.Windows.Forms.TextBox(); + this.txtParkedAz = new System.Windows.Forms.TextBox(); ((System.ComponentModel.ISupportInitialize)(this.picASCOM)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nudSettleTime)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numDatabits)).BeginInit(); @@ -344,10 +350,55 @@ namespace ASCOM.Meade.net resources.ApplyResources(this.label21, "label21"); this.label21.Name = "label21"; // + // cboParkedBehaviour + // + this.cboParkedBehaviour.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.cboParkedBehaviour.FormattingEnabled = true; + this.cboParkedBehaviour.Items.AddRange(new object[] { + resources.GetString("cboParkedBehaviour.Items"), + resources.GetString("cboParkedBehaviour.Items1"), + resources.GetString("cboParkedBehaviour.Items2")}); + resources.ApplyResources(this.cboParkedBehaviour, "cboParkedBehaviour"); + this.cboParkedBehaviour.Name = "cboParkedBehaviour"; + this.cboParkedBehaviour.SelectionChangeCommitted += new System.EventHandler(this.cboParkedBehaviour_SelectionChangeCommitted); + // + // label22 + // + resources.ApplyResources(this.label22, "label22"); + this.label22.Name = "label22"; + // + // label23 + // + resources.ApplyResources(this.label23, "label23"); + this.label23.Name = "label23"; + // + // label24 + // + resources.ApplyResources(this.label24, "label24"); + this.label24.Name = "label24"; + // + // txtParkedAlt + // + resources.ApplyResources(this.txtParkedAlt, "txtParkedAlt"); + this.txtParkedAlt.Name = "txtParkedAlt"; + this.txtParkedAlt.TextChanged += new System.EventHandler(this.txtParkedAlt_TextChanged); + // + // txtParkedAz + // + resources.ApplyResources(this.txtParkedAz, "txtParkedAz"); + this.txtParkedAz.Name = "txtParkedAz"; + this.txtParkedAz.TextChanged += new System.EventHandler(this.txtParkedAz_TextChanged); + // // SetupDialogForm // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.txtParkedAz); + this.Controls.Add(this.txtParkedAlt); + this.Controls.Add(this.label24); + this.Controls.Add(this.label23); + this.Controls.Add(this.label22); + this.Controls.Add(this.cboParkedBehaviour); this.Controls.Add(this.cbxSendDateTime); this.Controls.Add(this.label21); this.Controls.Add(this.label20); @@ -450,5 +501,11 @@ namespace ASCOM.Meade.net private Label label20; private Label label21; private CheckBox cbxSendDateTime; + private ComboBox cboParkedBehaviour; + private Label label22; + private Label label23; + private Label label24; + private TextBox txtParkedAlt; + private TextBox txtParkedAz; } } \ No newline at end of file diff --git a/Meade.net/SetupDialogForm.resx b/Meade.net/SetupDialogForm.resx index 726e548..2e52c51 100644 --- a/Meade.net/SetupDialogForm.resx +++ b/Meade.net/SetupDialogForm.resx @@ -123,7 +123,7 @@ - 715, 391 + 765, 391 59, 24 @@ -145,13 +145,13 @@ $this - 41 + 47 Bottom, Right - 715, 421 + 765, 421 59, 25 @@ -172,7 +172,7 @@ $this - 40 + 46 12, 9 @@ -196,13 +196,13 @@ $this - 39 + 45 Top, Right - 726, 9 + 776, 9 48, 56 @@ -223,7 +223,7 @@ $this - 38 + 44 True @@ -250,7 +250,7 @@ $this - 37 + 43 True @@ -277,7 +277,7 @@ $this - 36 + 42 97, 87 @@ -298,7 +298,7 @@ $this - 35 + 41 True @@ -325,8 +325,11 @@ $this - 34 + 40 + + 17, 17 + 375, 166 @@ -339,9 +342,6 @@ 10.0 - - 17, 17 - LX-200GPS only @@ -355,7 +355,7 @@ $this - 33 + 39 True @@ -382,7 +382,7 @@ $this - 32 + 38 True @@ -409,7 +409,7 @@ $this - 31 + 37 True @@ -436,7 +436,7 @@ $this - 30 + 36 Unchanged @@ -466,7 +466,7 @@ $this - 29 + 35 True @@ -496,7 +496,7 @@ $this - 28 + 34 Auto @@ -526,7 +526,7 @@ $this - 27 + 33 True @@ -556,7 +556,7 @@ $this - 26 + 32 True @@ -589,7 +589,7 @@ $this - 25 + 31 375, 302 @@ -613,7 +613,7 @@ $this - 23 + 29 True @@ -643,7 +643,7 @@ $this - 24 + 30 True @@ -673,7 +673,7 @@ $this - 22 + 28 True @@ -706,7 +706,7 @@ $this - 21 + 27 True @@ -733,7 +733,7 @@ $this - 20 + 26 True @@ -760,7 +760,7 @@ $this - 19 + 25 True @@ -793,8 +793,11 @@ $this - 18 + 24 + + 17, 17 + True @@ -802,7 +805,7 @@ NoControl - 627, 95 + 671, 96 145, 17 @@ -826,7 +829,7 @@ $this - 0 + 6 True @@ -853,7 +856,7 @@ $this - 17 + 23 375, 93 @@ -874,7 +877,7 @@ $this - 16 + 22 True @@ -901,7 +904,7 @@ $this - 15 + 21 True @@ -928,7 +931,7 @@ $this - 14 + 20 375, 125 @@ -949,7 +952,7 @@ $this - 13 + 19 True @@ -976,7 +979,7 @@ $this - 12 + 18 True @@ -1003,7 +1006,7 @@ $this - 11 + 17 97, 163 @@ -1024,7 +1027,7 @@ $this - 10 + 16 97, 137 @@ -1045,7 +1048,7 @@ $this - 9 + 15 97, 190 @@ -1066,7 +1069,7 @@ $this - 8 + 14 97, 217 @@ -1087,7 +1090,7 @@ $this - 7 + 13 97, 244 @@ -1108,7 +1111,7 @@ $this - 6 + 12 True @@ -1135,7 +1138,7 @@ $this - 5 + 11 True @@ -1162,7 +1165,7 @@ $this - 4 + 10 True @@ -1189,7 +1192,7 @@ $this - 3 + 9 True @@ -1216,7 +1219,7 @@ $this - 2 + 8 True @@ -1249,8 +1252,161 @@ $this + 7 + + + No Coordinates + + + Last Good Position + + + Report coordinates as + + + 671, 124 + + + 126, 21 + + + 42 + + + cboParkedBehaviour + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 5 + + + True + + + 574, 127 + + + 91, 13 + + + 43 + + + Parked behaviour + + + label22 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 4 + + + True + + + 668, 154 + + + 19, 13 + + + 44 + + + Alt + + + label23 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 3 + + + True + + + 668, 180 + + + 19, 13 + + + 45 + + + Az + + + label24 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 2 + + + 697, 151 + + + 100, 20 + + + 46 + + + txtParkedAlt + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + 1 + + 697, 177 + + + 100, 20 + + + 47 + + + txtParkedAz + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 0 + True @@ -1261,7 +1417,7 @@ 6, 13 - 784, 454 + 834, 454 CenterScreen diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index ebcc48c..70afea1 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -159,6 +159,9 @@ namespace ASCOM.Meade.net private const string HandShakeName = "Hand Shake"; private const string ParityName = "Parity"; private const string SendDateTimeName = "Send Date and time on connect"; + private const string ParkedBehaviourName = "Parked Behaviour"; + private const string ParkedAltName = "Parked Altitude"; + private const string ParkedAzimuthName = "Parked Azimuth"; public static void WriteProfile(ProfileProperties profileProperties) { @@ -184,6 +187,9 @@ namespace ASCOM.Meade.net driverProfile.WriteValue(DriverId, SiteElevationName, profileProperties.SiteElevation.ToString(CultureInfo.InvariantCulture)); driverProfile.WriteValue(DriverId, SettleTimeName, profileProperties.SettleTime.ToString()); driverProfile.WriteValue(DriverId, SendDateTimeName, profileProperties.SendDateTime.ToString()); + driverProfile.WriteValue(DriverId, ParkedBehaviourName, profileProperties.ParkedBehaviour.GetDescription()); + driverProfile.WriteValue(DriverId, ParkedAltName, profileProperties.ParkedAlt.ToString(CultureInfo.InvariantCulture)); + driverProfile.WriteValue(DriverId, ParkedAzimuthName, profileProperties.ParkedAz.ToString(CultureInfo.InvariantCulture)); } } } @@ -205,6 +211,9 @@ namespace ASCOM.Meade.net private const string HandShakeDefault = "None"; private const string ParityDefault = "None"; private const string SendDateTimeDefault = "false"; + private static string ParkedBehaviourDefault = "No Coordinates"; + private const string ParkedAltDefault = "0"; + private const string ParkedAzimuthDefault = "180"; public static ProfileProperties ReadProfile() { @@ -231,6 +240,10 @@ namespace ASCOM.Meade.net profileProperties.Speed = Convert.ToInt32(driverProfile.GetValue(DriverId, SpeedName, string.Empty, SpeedDefault)); profileProperties.Parity = driverProfile.GetValue(DriverId, ParityName, string.Empty, ParityDefault); profileProperties.SendDateTime = Convert.ToBoolean(driverProfile.GetValue(DriverId, SendDateTimeName, string.Empty, SendDateTimeDefault)); + + profileProperties.ParkedBehaviour = EnumExtensionMethods.GetValueFromDescription(driverProfile.GetValue(DriverId, ParkedBehaviourName, string.Empty, ParkedBehaviourDefault)); + profileProperties.ParkedAlt = double.Parse(driverProfile.GetValue(DriverId, ParkedAltName, string.Empty, ParkedAltDefault), NumberFormatInfo.InvariantInfo); + profileProperties.ParkedAz = double.Parse(driverProfile.GetValue(DriverId, ParkedAzimuthName, string.Empty, ParkedAzimuthDefault), NumberFormatInfo.InvariantInfo); } return profileProperties; From 53abdba374ec0d035ef93ed714c82de032e4363d Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Sat, 24 Apr 2021 19:20:05 +0100 Subject: [PATCH 20/28] Added extra logging. --- Meade.net.Telescope/Telescope.cs | 47 ++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 0210715..fbb1bd4 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -419,23 +419,30 @@ namespace ASCOM.Meade.net SetTelescopePrecision("Connect"); + LogMessage("Connected Set", $"SendDateTime: {SendDateTime}"); if (SendDateTime) { if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) { + LogMessage("Connected Set", $"LX200GPS Detecting if daylight savings message on screen: {SendDateTime}"); var displayText = Action("Handbox", "readdisplay"); if (displayText.Contains("Daylight")) { + LogMessage("Connected Set", $"LX200GPS Setting Date time and bypassing settings screens: {SendDateTime}"); BypassHandboxEntryForAutostarII(); } else { + LogMessage("Connected Set", $"LX200GPS Sending current date and time: {SendDateTime}"); SendCurrentDateTime("Connect"); + LogMessage("Connected Set", $"LX200GPS Attempting manual bypass of prompts: {SendDateTime}"); + ApplySkipAutoStarPrompts("Connect"); } } else { + LogMessage("Connected Set", $"Autostar Attempting manual bypass of prompts"); ApplySkipAutoStarPrompts("Connect"); SendCurrentDateTime("Connect"); } @@ -479,30 +486,30 @@ namespace ASCOM.Meade.net private void ApplySkipAutoStarPrompts(string connect) { - //if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) - //{ - // var displayText = Action("Handbox", "readdisplay"); - // if (displayText.Contains("Daylight")) - // { - // for (var i = 0; i < 3; i++) - // { - // Action("Handbox", "enter"); - // _utilities.WaitForMilliseconds(2000); - // } - // } - //} - //else if (SharedResourcesWrapper.ProductName == TelescopeList.Autostar497) - //{ - var displayText = Action("Handbox", "readdisplay"); - if (displayText.Contains("Press 0 to Alignor MODE for Menu")) + if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) { - for (var i = 0; i < 4; i++) + var displayText = Action("Handbox", "readdisplay"); + if (displayText.Contains("Daylight")) { - Action("Handbox", "mode"); - _utilities.WaitForMilliseconds(500); + for (var i = 0; i < 3; i++) + { + Action("Handbox", "enter"); + _utilities.WaitForMilliseconds(2000); + } + } + } + else if (SharedResourcesWrapper.ProductName == TelescopeList.Autostar497) + { + var displayText = Action("Handbox", "readdisplay"); + if (displayText.Contains("Press 0 to Alignor MODE for Menu")) + { + for (var i = 0; i < 4; i++) + { + Action("Handbox", "mode"); + _utilities.WaitForMilliseconds(500); + } } } - //} } private void SetTelescopePrecision(string propertyName) From f4eafa668d860fc8e6b0849651267f7cf5808d4d Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Sat, 24 Apr 2021 19:30:46 +0100 Subject: [PATCH 21/28] Added a log for the display output --- Meade.net.Telescope/Telescope.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index fbb1bd4..3c891ef 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -426,6 +426,7 @@ namespace ASCOM.Meade.net { LogMessage("Connected Set", $"LX200GPS Detecting if daylight savings message on screen: {SendDateTime}"); var displayText = Action("Handbox", "readdisplay"); + LogMessage("Connected Set", $"Current Handset display: {displayText}"); if (displayText.Contains("Daylight")) { LogMessage("Connected Set", $"LX200GPS Setting Date time and bypassing settings screens: {SendDateTime}"); @@ -489,6 +490,7 @@ namespace ASCOM.Meade.net if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) { var displayText = Action("Handbox", "readdisplay"); + if (displayText.Contains("Daylight")) { for (var i = 0; i < 3; i++) From 18ea52c9721ebcf27dff4ca7d089a1a02ce9962e Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Sat, 24 Apr 2021 20:52:21 +0100 Subject: [PATCH 22/28] Impemented the code changes to return co-ordinated when the telescope is parked. Also added loads of checks for if the telescope is parked. --- .../AstroMath.UnitTests.csproj | 4 + .../Meade.net.Telescope.csproj | 1 - Meade.net.Telescope/Telescope.cs | 95 +++++++++++++++---- .../AstroMaths/HorizonCoordinates.cs | 0 Meade.net/Meade.net.csproj | 2 + Meade.net/MeadeTelescopeBase.cs | 20 ++-- 6 files changed, 97 insertions(+), 25 deletions(-) rename {Meade.net.Telescope => Meade.net}/AstroMaths/HorizonCoordinates.cs (100%) diff --git a/AstroMath.UnitTests/AstroMath.UnitTests.csproj b/AstroMath.UnitTests/AstroMath.UnitTests.csproj index 9457f57..cffc483 100644 --- a/AstroMath.UnitTests/AstroMath.UnitTests.csproj +++ b/AstroMath.UnitTests/AstroMath.UnitTests.csproj @@ -90,6 +90,10 @@ {64308775-bd4a-469c-bcab-3ed830b811af} Meade.net.Telescope + + {3689a2cb-94c5-4012-a5cf-7e7d1dd27143} + Meade.net + diff --git a/Meade.net.Telescope/Meade.net.Telescope.csproj b/Meade.net.Telescope/Meade.net.Telescope.csproj index cfae8a4..92ec7b9 100644 --- a/Meade.net.Telescope/Meade.net.Telescope.csproj +++ b/Meade.net.Telescope/Meade.net.Telescope.csproj @@ -122,7 +122,6 @@ - diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 3c891ef..2d33ae8 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -878,6 +878,7 @@ namespace ASCOM.Meade.net public void AbortSlew() { CheckConnected("AbortSlew"); + CheckParked(); LogMessage("AbortSlew", "Aborting slew"); SharedResourcesWrapper.SendBlind(":Q#"); @@ -889,6 +890,12 @@ namespace ASCOM.Meade.net SetSlewingMinEndTime(); } + private void CheckParked() + { + if (AtPark) + throw new ParkedException("Telescope is parked"); + } + public AlignmentModes AlignmentMode { get @@ -974,7 +981,7 @@ namespace ASCOM.Meade.net get { CheckConnected("Altitude Get"); - + var altAz = CalcAltAzFromTelescopeEqData(); LogMessage("Altitude", $"{altAz.Altitude}"); return altAz.Altitude; @@ -1247,21 +1254,41 @@ namespace ASCOM.Meade.net } } + private double _lastGoodDeclination; + public double Declination { get { CheckConnected("Declination Get"); + try + { + CheckParked(); - var result = SharedResourcesWrapper.SendString(":GD#"); - //:GD# Get Telescope Declination. - //Returns: sDD*MM# or sDD*MM’SS# - //Depending upon the current precision setting for the telescope. + var result = SharedResourcesWrapper.SendString(":GD#"); + //:GD# Get Telescope Declination. + //Returns: sDD*MM# or sDD*MM’SS# + //Depending upon the current precision setting for the telescope. - double declination = _utilities.DMSToDegrees(result); + double declination = _utilities.DMSToDegrees(result); - LogMessage("Declination", $"Get - {result} convert to {declination} {_utilitiesExtra.DegreesToDMS(declination, ":", ":")}"); - return declination; + LogMessage("Declination", $"Get - {result} convert to {declination} {_utilitiesExtra.DegreesToDMS(declination, ":", ":")}"); + _lastGoodDeclination = declination; + return declination; + } + catch (ParkedException) + { + switch (ParkedBehaviour) + { + case ParkedBehaviour.LastGoodPosition: + return _lastGoodDeclination; + case ParkedBehaviour.ReportCoordinates: + var raDec = _astroMaths.ConvertHozToEq(UTCDate, SiteLatitude, SiteLongitude, ParkedAltAz); + return raDec.Declination; + default: + throw; + } + } } } @@ -1413,6 +1440,7 @@ namespace ASCOM.Meade.net { LogMessage("MoveAxis", $"Axis={axis} rate={rate}"); CheckConnected("MoveAxis"); + CheckParked(); var absRate = Math.Abs(rate); @@ -1535,6 +1563,7 @@ namespace ASCOM.Meade.net try { CheckConnected("PulseGuide"); + CheckParked(); if (IsSlewingToTarget()) throw new InvalidOperationException("Unable to PulseGuide whilst slewing to target."); @@ -1644,21 +1673,43 @@ namespace ASCOM.Meade.net var hms = $"{token[0]}:{seconds}"; return _utilities.HMSToHours(hms); } + + double _lastGoodRightAsension; public double RightAscension { get { CheckConnected("RightAscension Get"); - var result = SharedResourcesWrapper.SendString(":GR#"); - //:GR# Get Telescope RA - //Returns: HH:MM.T# or HH:MM:SS# - //Depending which precision is set for the telescope + try + { + CheckParked(); - double rightAscension = HmToHours(result); + var result = SharedResourcesWrapper.SendString(":GR#"); + //:GR# Get Telescope RA + //Returns: HH:MM.T# or HH:MM:SS# + //Depending which precision is set for the telescope - LogMessage("RightAscension", $"Get - {result} convert to {rightAscension} {_utilitiesExtra.HoursToHMS(rightAscension)}"); - return rightAscension; + double rightAscension = HmToHours(result); + + LogMessage("RightAscension", $"Get - {result} convert to {rightAscension} {_utilitiesExtra.HoursToHMS(rightAscension)}"); + _lastGoodRightAsension = rightAscension; + return rightAscension; + } + catch (ParkedException) + { + switch (ParkedBehaviour) + { + case ParkedBehaviour.LastGoodPosition: + return _lastGoodRightAsension; + case ParkedBehaviour.ReportCoordinates: + var raDec = _astroMaths.ConvertHozToEq(UTCDate, SiteLatitude, SiteLongitude, ParkedAltAz); + return raDec.RightAscension; + default: + throw; + } + } + } } @@ -1870,6 +1921,7 @@ namespace ASCOM.Meade.net { LogMessage("SlewToAltAz", $"Az=~{azimuth} Alt={altitude}"); CheckConnected("SlewToAltAz"); + CheckParked(); SlewToAltAzAsync(azimuth, altitude); @@ -1882,6 +1934,7 @@ namespace ASCOM.Meade.net public void SlewToAltAzAsync(double azimuth, double altitude) { CheckConnected("SlewToAltAzAsync"); + CheckParked(); if (altitude > 90) throw new InvalidValueException("Altitude cannot be greater than 90."); @@ -1922,6 +1975,7 @@ namespace ASCOM.Meade.net private void DoSlewAsync(bool polar) { CheckConnected("DoSlewAsync"); + CheckParked(); SharedResourcesWrapper.Lock(() => { @@ -1986,6 +2040,7 @@ namespace ASCOM.Meade.net { LogMessage("SlewToCoordinates", $"Ra={rightAscension}, Dec={declination}"); CheckConnected("SlewToCoordinates"); + CheckParked(); SlewToCoordinatesAsync(rightAscension, declination); @@ -2001,6 +2056,7 @@ namespace ASCOM.Meade.net { LogMessage("SlewToCoordinatesAsync", $"Ra={rightAscension}, Dec={declination}"); CheckConnected("SlewToCoordinatesAsync"); + CheckParked(); SharedResourcesWrapper.Lock(() => { @@ -2016,6 +2072,7 @@ namespace ASCOM.Meade.net { LogMessage("SlewToTarget", "Executing"); CheckConnected("SlewToTarget"); + CheckParked(); SlewToTargetAsync(); while (Slewing) @@ -2029,6 +2086,7 @@ namespace ASCOM.Meade.net public void SlewToTargetAsync() { CheckConnected("SlewToTargetAsync"); + CheckParked(); if (TargetDeclination.Equals(InvalidParameter) || TargetRightAscension.Equals(InvalidParameter)) throw new InvalidOperationException("No target selected to slew to."); @@ -2167,6 +2225,7 @@ namespace ASCOM.Meade.net LogMessage("SyncToCoordinates", $"RA={rightAscension} Dec={declination}"); LogMessage("SyncToCoordinates", $"RA={_utilitiesExtra.HoursToHMS(rightAscension)} Dec={_utilitiesExtra.HoursToHMS(declination)}"); CheckConnected("SyncToCoordinates"); + CheckParked(); SharedResourcesWrapper.Lock(() => { @@ -2181,7 +2240,8 @@ namespace ASCOM.Meade.net { LogMessage("SyncToTarget", "Executing"); CheckConnected("SyncToTarget"); - + CheckParked(); + var result = SharedResourcesWrapper.SendString(":CM#"); //:CM# Synchronizes the telescope's position with the currently selected database object's coordinates. //Returns: @@ -2234,6 +2294,7 @@ namespace ASCOM.Meade.net LogMessage("TargetDeclination Set", $"{value}"); CheckConnected("TargetDeclination Set"); + CheckParked(); if (value > 90) throw new InvalidValueException("Declination cannot be greater than 90."); @@ -2289,6 +2350,7 @@ namespace ASCOM.Meade.net { LogMessage("TargetRightAscension Set", $"{value}"); CheckConnected("TargetRightAscension Set"); + CheckParked(); if (value < 0) throw new InvalidValueException("Right ascension value cannot be below 0"); @@ -2357,6 +2419,7 @@ namespace ASCOM.Meade.net { LogMessage("TrackingRate Set", $"{value}"); CheckConnected("TrackingRate Set"); + CheckParked(); switch (value) { diff --git a/Meade.net.Telescope/AstroMaths/HorizonCoordinates.cs b/Meade.net/AstroMaths/HorizonCoordinates.cs similarity index 100% rename from Meade.net.Telescope/AstroMaths/HorizonCoordinates.cs rename to Meade.net/AstroMaths/HorizonCoordinates.cs diff --git a/Meade.net/Meade.net.csproj b/Meade.net/Meade.net.csproj index 366e8e0..c30849a 100644 --- a/Meade.net/Meade.net.csproj +++ b/Meade.net/Meade.net.csproj @@ -137,6 +137,7 @@ frmMain.cs + @@ -201,6 +202,7 @@ true +