mirror of
https://bitbucket.org/cjdskunkworks/lynxastrodewcontroller.git
synced 2026-05-03 17:28:52 +00:00
Let's see if this helps.
This commit is contained in:
@@ -28,7 +28,7 @@ namespace ASCOM.LynxAstro.DewController
|
|||||||
[ProgId("ASCOM.LynxAstro.DewController.Switch")]
|
[ProgId("ASCOM.LynxAstro.DewController.Switch")]
|
||||||
[ServedClassName("LynxAstro.DewController")]
|
[ServedClassName("LynxAstro.DewController")]
|
||||||
[ClassInterface(ClassInterfaceType.None)]
|
[ClassInterface(ClassInterfaceType.None)]
|
||||||
public class Switch : ISwitchV2
|
public class Switch : AscomDriverBase, ISwitchV2
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ASCOM DeviceID (COM ProgID) for this driver.
|
/// ASCOM DeviceID (COM ProgID) for this driver.
|
||||||
@@ -36,16 +36,6 @@ namespace ASCOM.LynxAstro.DewController
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal static string DriverId = Marshal.GenerateProgIdForType(MethodBase.GetCurrentMethod().DeclaringType ?? throw new System.InvalidOperationException());
|
internal static string DriverId = Marshal.GenerateProgIdForType(MethodBase.GetCurrentMethod().DeclaringType ?? throw new System.InvalidOperationException());
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Driver description that displays in the ASCOM Chooser.
|
|
||||||
/// </summary>
|
|
||||||
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;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="LynxAstro.DewController"/> class.
|
/// Initializes a new instance of the <see cref="LynxAstro.DewController"/> class.
|
||||||
/// Must be public for COM registration.
|
/// Must be public for COM registration.
|
||||||
@@ -53,31 +43,14 @@ namespace ASCOM.LynxAstro.DewController
|
|||||||
/// <param name="tl"></param>
|
/// <param name="tl"></param>
|
||||||
public Switch()
|
public Switch()
|
||||||
{
|
{
|
||||||
SharedResourcesWrapper = new SharedResourcesWrapper();
|
|
||||||
|
|
||||||
Initialise(nameof(Switch));
|
Initialise(nameof(Switch));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Switch(ISharedResourcesWrapper sharedResourcesWrapper)
|
public Switch(ISharedResourcesWrapper sharedResourcesWrapper) : base (sharedResourcesWrapper)
|
||||||
{
|
{
|
||||||
SharedResourcesWrapper = sharedResourcesWrapper;
|
|
||||||
|
|
||||||
Initialise(nameof(Switch));
|
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
|
// 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
|
public short InterfaceVersion
|
||||||
{
|
{
|
||||||
// set by the driver wizard
|
// set by the driver wizard
|
||||||
@@ -638,8 +581,6 @@ namespace ASCOM.LynxAstro.DewController
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
protected bool IsConnected { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Use this function to throw an exception if we aren't connected to the hardware
|
/// Use this function to throw an exception if we aren't connected to the hardware
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -652,23 +593,6 @@ namespace ASCOM.LynxAstro.DewController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Read the device configuration from the ASCOM Profile store
|
|
||||||
/// </summary>
|
|
||||||
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()
|
protected void WriteSwitchNames()
|
||||||
{
|
{
|
||||||
var profileProperties = SharedResourcesWrapper.ReadProfile();
|
var profileProperties = SharedResourcesWrapper.ReadProfile();
|
||||||
@@ -678,18 +602,6 @@ namespace ASCOM.LynxAstro.DewController
|
|||||||
|
|
||||||
SharedResourcesWrapper.WriteProfile(profileProperties);
|
SharedResourcesWrapper.WriteProfile(profileProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Log helper function that takes formatted strings and arguments
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="identifier"></param>
|
|
||||||
/// <param name="message"></param>
|
|
||||||
/// <param name="args"></param>
|
|
||||||
internal void LogMessage(string identifier, string message, params object[] args)
|
|
||||||
{
|
|
||||||
var msg = string.Format(message, args);
|
|
||||||
Tl.LogMessage(identifier, msg);
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -130,11 +130,6 @@ namespace LynxAstro.DewController.UnitTests
|
|||||||
|
|
||||||
string ComPortDefault = "COM1";
|
string ComPortDefault = "COM1";
|
||||||
string TraceStateDefault = "false";
|
string TraceStateDefault = "false";
|
||||||
string GuideRateProfileNameDefault = "10.077939"; //67% of sidereal rate
|
|
||||||
string PrecisionDefault = "Unchanged";
|
|
||||||
string GuidingStyleDefault = "Auto";
|
|
||||||
string BacklashCompensationDefault = "3000";
|
|
||||||
string ReverseFocuserDiectionDefault = "true";
|
|
||||||
|
|
||||||
Mock<IProfileWrapper> profileWrapperMock = new Mock<IProfileWrapper>();
|
Mock<IProfileWrapper> profileWrapperMock = new Mock<IProfileWrapper>();
|
||||||
profileWrapperMock.SetupAllProperties();
|
profileWrapperMock.SetupAllProperties();
|
||||||
|
|||||||
@@ -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
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Variable to hold the trace logger object (creates a diagnostic log file with information that you specify)
|
||||||
|
/// </summary>
|
||||||
|
protected static TraceLogger Tl;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Driver description that displays in the ASCOM Chooser.
|
||||||
|
/// </summary>
|
||||||
|
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}");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Read the device configuration from the ASCOM Profile store
|
||||||
|
/// </summary>
|
||||||
|
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}");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Log helper function that takes formatted strings and arguments
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="identifier"></param>
|
||||||
|
/// <param name="message"></param>
|
||||||
|
/// <param name="args"></param>
|
||||||
|
public static void LogMessage(string identifier, string message, params object[] args)
|
||||||
|
{
|
||||||
|
var msg = string.Format(message, args);
|
||||||
|
Tl.LogMessage(identifier, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true if there is a valid connection to the driver hardware
|
||||||
|
/// </summary>
|
||||||
|
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
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -116,6 +116,7 @@
|
|||||||
<Compile Include="IProfileWrapper.cs" />
|
<Compile Include="IProfileWrapper.cs" />
|
||||||
<Compile Include="ISharedResourcesWrapper.cs" />
|
<Compile Include="ISharedResourcesWrapper.cs" />
|
||||||
<Compile Include="LocalServer.cs" />
|
<Compile Include="LocalServer.cs" />
|
||||||
|
<Compile Include="AscomDriverBase.cs" />
|
||||||
<Compile Include="ProfileFactory.cs" />
|
<Compile Include="ProfileFactory.cs" />
|
||||||
<Compile Include="ProfileProperties.cs" />
|
<Compile Include="ProfileProperties.cs" />
|
||||||
<Compile Include="ProfileWrapper.cs" />
|
<Compile Include="ProfileWrapper.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user