From 1b73a65a1b4e31958bfb98ed548072f96d312e7a Mon Sep 17 00:00:00 2001 From: Colin Date: Mon, 22 Feb 2021 11:47:43 +0000 Subject: [PATCH 1/3] Made local server compile for x86 only. --- LynxAstro.DewController/LynxAstro.DewController.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LynxAstro.DewController/LynxAstro.DewController.csproj b/LynxAstro.DewController/LynxAstro.DewController.csproj index ed3df9a..f620283 100644 --- a/LynxAstro.DewController/LynxAstro.DewController.csproj +++ b/LynxAstro.DewController/LynxAstro.DewController.csproj @@ -40,7 +40,7 @@ DEBUG;TRACE prompt 4 - AnyCPU + x86 MinimumRecommendedRules.ruleset false From a8ea4448f128704387491e743e2f372ba48c4b80 Mon Sep 17 00:00:00 2001 From: Colin Date: Mon, 22 Feb 2021 12:07:43 +0000 Subject: [PATCH 2/3] Let's see if this helps. --- LynxAstro.DewController.Switch/Switch.cs | 98 +------------- .../SharedResourcesUnitTests.cs | 7 +- LynxAstro.DewController/AscomDriverBase.cs | 120 ++++++++++++++++++ .../LynxAstro.DewController.csproj | 1 + 4 files changed, 127 insertions(+), 99 deletions(-) create mode 100644 LynxAstro.DewController/AscomDriverBase.cs diff --git a/LynxAstro.DewController.Switch/Switch.cs b/LynxAstro.DewController.Switch/Switch.cs index 624101f..68a72ed 100644 --- a/LynxAstro.DewController.Switch/Switch.cs +++ b/LynxAstro.DewController.Switch/Switch.cs @@ -28,7 +28,7 @@ namespace ASCOM.LynxAstro.DewController [ProgId("ASCOM.LynxAstro.DewController.Switch")] [ServedClassName("LynxAstro.DewController")] [ClassInterface(ClassInterfaceType.None)] - public class Switch : ISwitchV2 + public class Switch : AscomDriverBase, ISwitchV2 { /// /// ASCOM DeviceID (COM ProgID) for this driver. @@ -36,48 +36,21 @@ namespace ASCOM.LynxAstro.DewController /// internal static string DriverId = Marshal.GenerateProgIdForType(MethodBase.GetCurrentMethod().DeclaringType ?? throw new System.InvalidOperationException()); - /// - /// Driver description that displays in the ASCOM Chooser. - /// - private static string DriverDescription = "ASCOM Switch Driver for LynxAstro.DewController"; - - protected static string ComPort; // Variables to hold the currrent device configuration - protected static TraceLogger Tl; - - protected readonly ISharedResourcesWrapper SharedResourcesWrapper; - /// /// Initializes a new instance of the class. /// Must be public for COM registration. /// /// public Switch() - { - SharedResourcesWrapper = new SharedResourcesWrapper(); - + { Initialise(nameof(Switch)); } - public Switch(ISharedResourcesWrapper sharedResourcesWrapper) + public Switch(ISharedResourcesWrapper sharedResourcesWrapper) : base (sharedResourcesWrapper) { - SharedResourcesWrapper = sharedResourcesWrapper; - Initialise(nameof(Switch)); } - - - protected void Initialise(string className) - { - Tl = new TraceLogger("", $"LynxAstro.DewController.{className}"); - - ReadProfile(); // Read device configuration from the ASCOM Profile store - - IsConnected = false; // Initialise connected to false - - LogMessage(className, "Completed initialisation"); - LogMessage(className, $"Driver version: {DriverVersion}"); - } - + // // PUBLIC COM INTERFACE ISwitchV2 IMPLEMENTATION // @@ -196,36 +169,6 @@ namespace ASCOM.LynxAstro.DewController } } - public string Description - { - get - { - Tl.LogMessage("Description Get", DriverDescription); - return DriverDescription; - } - } - - public string DriverInfo - { - get - { - string driverInfo = $"{Description} .net driver. Version: {DriverVersion}"; - LogMessage("DriverInfo Get", driverInfo); - return driverInfo; - } - } - - public string DriverVersion - { - get - { - Version version = Assembly.GetExecutingAssembly().GetName().Version; - string driverVersion = $"{version.Major}.{version.Minor}.{version.Build}.{version.Revision}"; - LogMessage("DriverVersion Get", driverVersion); - return driverVersion; - } - } - public short InterfaceVersion { // set by the driver wizard @@ -638,8 +581,6 @@ namespace ASCOM.LynxAstro.DewController #endregion - protected bool IsConnected { get; set; } - /// /// Use this function to throw an exception if we aren't connected to the hardware /// @@ -651,24 +592,7 @@ namespace ASCOM.LynxAstro.DewController throw new ASCOM.NotConnectedException(message); } } - - /// - /// Read the device configuration from the ASCOM Profile store - /// - protected void ReadProfile() - { - var profileProperties = SharedResourcesWrapper.ReadProfile(); - Tl.Enabled = profileProperties.TraceLogger; - ComPort = profileProperties.ComPort; - - switchNames.Clear(); - switchNames.AddRange(profileProperties.SwitchNames); - - LogMessage("ReadProfile", $"Trace logger enabled: {Tl.Enabled}"); - LogMessage("ReadProfile", $"Com Port: {ComPort}"); - - } - + protected void WriteSwitchNames() { var profileProperties = SharedResourcesWrapper.ReadProfile(); @@ -678,18 +602,6 @@ namespace ASCOM.LynxAstro.DewController SharedResourcesWrapper.WriteProfile(profileProperties); } - - /// - /// Log helper function that takes formatted strings and arguments - /// - /// - /// - /// - internal void LogMessage(string identifier, string message, params object[] args) - { - var msg = string.Format(message, args); - Tl.LogMessage(identifier, msg); - } #endregion } } diff --git a/LynxAstro.DewController.UnitTests/SharedResourcesUnitTests.cs b/LynxAstro.DewController.UnitTests/SharedResourcesUnitTests.cs index db1d8ea..09eab88 100644 --- a/LynxAstro.DewController.UnitTests/SharedResourcesUnitTests.cs +++ b/LynxAstro.DewController.UnitTests/SharedResourcesUnitTests.cs @@ -130,12 +130,7 @@ namespace LynxAstro.DewController.UnitTests string ComPortDefault = "COM1"; string TraceStateDefault = "false"; - string GuideRateProfileNameDefault = "10.077939"; //67% of sidereal rate - string PrecisionDefault = "Unchanged"; - string GuidingStyleDefault = "Auto"; - string BacklashCompensationDefault = "3000"; - string ReverseFocuserDiectionDefault = "true"; - + Mock profileWrapperMock = new Mock(); profileWrapperMock.SetupAllProperties(); diff --git a/LynxAstro.DewController/AscomDriverBase.cs b/LynxAstro.DewController/AscomDriverBase.cs new file mode 100644 index 0000000..3330a33 --- /dev/null +++ b/LynxAstro.DewController/AscomDriverBase.cs @@ -0,0 +1,120 @@ +using System; +using System.Reflection; +using System.Runtime.InteropServices; +using ASCOM.Utilities; + +namespace ASCOM.LynxAstro.DewController +{ + [ComVisible(false)] + public class AscomDriverBase : ReferenceCountedObjectBase + { + /// + /// Variable to hold the trace logger object (creates a diagnostic log file with information that you specify) + /// + protected static TraceLogger Tl; + + /// + /// Driver description that displays in the ASCOM Chooser. + /// + protected static readonly string DriverDescription = "Meade Generic"; + + protected static string ComPort; // Variables to hold the currrent device configuration + + protected readonly ISharedResourcesWrapper SharedResourcesWrapper; + + public AscomDriverBase() + { + SharedResourcesWrapper = new SharedResourcesWrapper(); + } + + public AscomDriverBase(ISharedResourcesWrapper sharedResourcesWrapper) + { + SharedResourcesWrapper = sharedResourcesWrapper; + } + + protected void Initialise(string className) + { + Tl = new TraceLogger("", $"Meade.Generic.{className}"); + + ReadProfile(); // Read device configuration from the ASCOM Profile store + + IsConnected = false; // Initialise connected to false + + LogMessage(className, "Completed initialisation"); + LogMessage(className, $"Driver version: {DriverVersion}"); + } + + /// + /// Read the device configuration from the ASCOM Profile store + /// + protected void ReadProfile() + { + var profileProperties = SharedResourcesWrapper.ReadProfile(); + Tl.Enabled = profileProperties.TraceLogger; + ComPort = profileProperties.ComPort; + + LogMessage("ReadProfile", $"Trace logger enabled: {Tl.Enabled}"); + LogMessage("ReadProfile", $"Com Port: {ComPort}"); + } + + /// + /// Log helper function that takes formatted strings and arguments + /// + /// + /// + /// + public static void LogMessage(string identifier, string message, params object[] args) + { + var msg = string.Format(message, args); + Tl.LogMessage(identifier, msg); + } + + /// + /// Returns true if there is a valid connection to the driver hardware + /// + protected bool IsConnected { get; set; } + + public string Description + { + get + { + Tl.LogMessage("Description Get", DriverDescription); + return DriverDescription; + } + } + + public string DriverInfo + { + get + { + string driverInfo = $"{Description} .net driver. Version: {DriverVersion}"; + LogMessage("DriverInfo Get", driverInfo); + return driverInfo; + } + } + + public string DriverVersion + { + get + { + Version version = Assembly.GetExecutingAssembly().GetName().Version; + string driverVersion = $"{version.Major}.{version.Minor}.{version.Build}.{version.Revision}"; + LogMessage("DriverVersion Get", driverVersion); + return driverVersion; + } + } + + #region ASCOM Registration + + private static IProfileFactory _profileFactory; + + public static IProfileFactory ProfileFactory + { + get => _profileFactory ?? (_profileFactory = new ProfileFactory()); + set => _profileFactory = value; + } + + #endregion + + } +} \ No newline at end of file diff --git a/LynxAstro.DewController/LynxAstro.DewController.csproj b/LynxAstro.DewController/LynxAstro.DewController.csproj index f620283..7edc12e 100644 --- a/LynxAstro.DewController/LynxAstro.DewController.csproj +++ b/LynxAstro.DewController/LynxAstro.DewController.csproj @@ -116,6 +116,7 @@ + From 6937f779ec3930961f904b6ea11695f1844114d9 Mon Sep 17 00:00:00 2001 From: Colin Date: Mon, 22 Feb 2021 12:30:04 +0000 Subject: [PATCH 3/3] Changed the description to show the channel letter. --- .../Properties/AssemblyInfo.cs | 1 - LynxAstro.DewController.Switch/Switch.cs | 3 +-- LynxAstro.DewController.TestConsole/Program.cs | 3 --- LynxAstro.DewController.TestConsole/Properties/AssemblyInfo.cs | 1 - LynxAstro.DewController/SharedResources.cs | 1 - 5 files changed, 1 insertion(+), 8 deletions(-) diff --git a/LynxAstro.DewController.Switch.UnitTests/Properties/AssemblyInfo.cs b/LynxAstro.DewController.Switch.UnitTests/Properties/AssemblyInfo.cs index 1573b92..eb6eb6c 100644 --- a/LynxAstro.DewController.Switch.UnitTests/Properties/AssemblyInfo.cs +++ b/LynxAstro.DewController.Switch.UnitTests/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following diff --git a/LynxAstro.DewController.Switch/Switch.cs b/LynxAstro.DewController.Switch/Switch.cs index 68a72ed..35573e3 100644 --- a/LynxAstro.DewController.Switch/Switch.cs +++ b/LynxAstro.DewController.Switch/Switch.cs @@ -2,7 +2,6 @@ using System; using System.Runtime.InteropServices; -using ASCOM.Utilities; using ASCOM.DeviceInterface; using System.Collections; using System.Collections.Generic; @@ -260,7 +259,7 @@ namespace ASCOM.LynxAstro.DewController public string GetSwitchDescription(short id) { Validate("GetSwitchDescription", id); - return "Control Knob"; + return $"Channel {ChannelToLetter(id)}"; } /// diff --git a/LynxAstro.DewController.TestConsole/Program.cs b/LynxAstro.DewController.TestConsole/Program.cs index e7787a2..b0dc9f2 100644 --- a/LynxAstro.DewController.TestConsole/Program.cs +++ b/LynxAstro.DewController.TestConsole/Program.cs @@ -9,9 +9,6 @@ //#define UseChooser using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace ASCOM { diff --git a/LynxAstro.DewController.TestConsole/Properties/AssemblyInfo.cs b/LynxAstro.DewController.TestConsole/Properties/AssemblyInfo.cs index 3622a8c..ef157a8 100644 --- a/LynxAstro.DewController.TestConsole/Properties/AssemblyInfo.cs +++ b/LynxAstro.DewController.TestConsole/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following diff --git a/LynxAstro.DewController/SharedResources.cs b/LynxAstro.DewController/SharedResources.cs index a94085f..51cd224 100644 --- a/LynxAstro.DewController/SharedResources.cs +++ b/LynxAstro.DewController/SharedResources.cs @@ -19,7 +19,6 @@ using System.Collections.Generic; using System.Windows.Forms; using ASCOM.Utilities; using ASCOM.Utilities.Interfaces; -using JetBrains.Annotations; namespace ASCOM.LynxAstro.DewController {