mirror of
https://bitbucket.org/cjdskunkworks/lynxastrodewcontroller.git
synced 2026-05-04 01:38:52 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a71397a2a1 | |||
| 7e19f47246 | |||
| 774bc2eef0 | |||
| a13c6e8f1e | |||
| 927ca03aba | |||
| 6937f779ec | |||
| a8ea4448f1 | |||
| 1b73a65a1b |
@@ -13,7 +13,7 @@
|
||||
|
||||
<?define InstallName = "ASCOM LynxAstro.DewController" ?>
|
||||
<?define Manufacturer = "cjdawson.com" ?>
|
||||
<?define UpgradeCode = "{57597bb6-f207-4998-97f4-8a041950d062}" ?>
|
||||
<?define UpgradeCode = "{AAD4DF96-1AFB-4F80-97B5-34AA7B0FDB57}" ?>
|
||||
<?define INSTALLFOLDER = "$(var.InstallName)" ?>
|
||||
|
||||
<?define LocalServerAppId = "{5EBBCD3B-3FC9-4D9F-868D-E0C2D085A58B}" ?>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using ASCOM.Utilities;
|
||||
using ASCOM.DeviceInterface;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@@ -28,7 +27,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
|
||||
{
|
||||
/// <summary>
|
||||
/// ASCOM DeviceID (COM ProgID) for this driver.
|
||||
@@ -36,16 +35,6 @@ namespace ASCOM.LynxAstro.DewController
|
||||
/// </summary>
|
||||
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>
|
||||
/// Initializes a new instance of the <see cref="LynxAstro.DewController"/> class.
|
||||
/// Must be public for COM registration.
|
||||
@@ -53,31 +42,14 @@ namespace ASCOM.LynxAstro.DewController
|
||||
/// <param name="tl"></param>
|
||||
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
|
||||
//
|
||||
@@ -102,7 +74,7 @@ namespace ASCOM.LynxAstro.DewController
|
||||
{
|
||||
get
|
||||
{
|
||||
Tl.LogMessage("SupportedActions Get", "Returning empty arraylist");
|
||||
LogMessage("SupportedActions Get", "Returning empty arraylist");
|
||||
return new ArrayList();
|
||||
}
|
||||
}
|
||||
@@ -196,36 +168,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
|
||||
@@ -241,7 +183,7 @@ namespace ASCOM.LynxAstro.DewController
|
||||
get
|
||||
{
|
||||
string name = "LynxAstro.DewController";
|
||||
Tl.LogMessage("Name Get", name);
|
||||
LogMessage("Name Get", name);
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -271,7 +213,7 @@ namespace ASCOM.LynxAstro.DewController
|
||||
//Purpose: Get the device type, i.e.the number of channels the dew controller has.
|
||||
//Response: :GDX# where X is either 1 or 4 depending on the number of channels this device has
|
||||
|
||||
Tl.LogMessage("MaxSwitch Get", numSwitch.ToString());
|
||||
LogMessage("MaxSwitch Get", numSwitch.ToString());
|
||||
return this.numSwitch;
|
||||
}
|
||||
}
|
||||
@@ -288,7 +230,10 @@ namespace ASCOM.LynxAstro.DewController
|
||||
Validate("GetSwitchName", id);
|
||||
ReadProfile();
|
||||
|
||||
return switchNames.Count > id ? switchNames[id] : string.Empty;
|
||||
var switchName = switchNames.Count > id ? switchNames[id] : string.Empty;
|
||||
|
||||
LogMessage("GetSwitchName", $"{id}: {switchName}");
|
||||
return switchName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -304,6 +249,8 @@ namespace ASCOM.LynxAstro.DewController
|
||||
while (id > switchNames.Count)
|
||||
switchNames.Add(string.Empty);
|
||||
|
||||
|
||||
LogMessage("SetSwitchName", $"{id}: \"{switchNames[id]}\" to \"{name}\"");
|
||||
switchNames[id] = name;
|
||||
|
||||
WriteSwitchNames();
|
||||
@@ -317,7 +264,11 @@ namespace ASCOM.LynxAstro.DewController
|
||||
public string GetSwitchDescription(short id)
|
||||
{
|
||||
Validate("GetSwitchDescription", id);
|
||||
return "Control Knob";
|
||||
|
||||
var channel= $"Channel {ChannelToLetter(id)}";
|
||||
|
||||
LogMessage("GetSwitchDescription", channel);
|
||||
return channel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -334,7 +285,8 @@ namespace ASCOM.LynxAstro.DewController
|
||||
{
|
||||
Validate("CanWrite", id);
|
||||
// default behavour is to report true
|
||||
Tl.LogMessage("CanWrite", string.Format("CanWrite({0}) - default true", id));
|
||||
|
||||
LogMessage("CanWrite", $"CanWrite({id}) - default true");
|
||||
return true;
|
||||
// implementation should report the correct behaviour
|
||||
//tl.LogMessage("CanWrite", string.Format("CanWrite({0}) - not implemented", id));
|
||||
@@ -354,7 +306,11 @@ namespace ASCOM.LynxAstro.DewController
|
||||
public bool GetSwitch(short id)
|
||||
{
|
||||
var value = GetSwitchValue(id);
|
||||
return value > 0;
|
||||
|
||||
var switchIsOn = value > 0;
|
||||
|
||||
LogMessage("GetSwitch", $"{id}: {switchIsOn} ({value})");
|
||||
return switchIsOn;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -374,7 +330,11 @@ namespace ASCOM.LynxAstro.DewController
|
||||
Tl.LogMessage("SetSwitch", str);
|
||||
throw new MethodNotImplementedException(str);
|
||||
}
|
||||
SetSwitchValue(id, state ? 1023 : 0);
|
||||
|
||||
var switchIsOn = state ? 1023 : 0;
|
||||
|
||||
LogMessage("SetSwitch", $"{id}: {state} ({switchIsOn})");
|
||||
SetSwitchValue(id, switchIsOn);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -447,6 +407,8 @@ namespace ASCOM.LynxAstro.DewController
|
||||
var encoded = SharedResourcesWrapper.SendString($":GC{channel}#");
|
||||
var decoded = DecodeResult(":GC", encoded);
|
||||
|
||||
LogMessage("GetSwitchValue", $"{id}: {channel} - {decoded}");
|
||||
|
||||
return double.Parse(decoded.TrimStart(channel));
|
||||
//Command: :GCX# where X is the channel A, B, C or D to retrieve.
|
||||
//Purpose: Get the current power setting for a specific channel.
|
||||
@@ -490,7 +452,9 @@ namespace ASCOM.LynxAstro.DewController
|
||||
//:ER4# = Not enough data received - make sure you zero pad the power level.
|
||||
//:ER5# = Channel or power level out of range, e.g. channel B on a 1 channel device or power above 1023.
|
||||
|
||||
var channel = ChannelToLetter(id);
|
||||
var channel = ChannelToLetter(id);
|
||||
|
||||
LogMessage("SetSwitchValue", $"{id}: {channel} - {value}");
|
||||
|
||||
var encoded = SharedResourcesWrapper.SendString($":SC{channel}{value:0000}#");
|
||||
var decoded = DecodeResult(":SC", encoded);
|
||||
@@ -499,6 +463,7 @@ namespace ASCOM.LynxAstro.DewController
|
||||
{
|
||||
throw new InvalidValueException($"Unable to set switch {{id}} to value {value}");
|
||||
}
|
||||
|
||||
//return double.Parse(decoded.TrimStart(channel));
|
||||
}
|
||||
|
||||
@@ -638,8 +603,6 @@ namespace ASCOM.LynxAstro.DewController
|
||||
|
||||
#endregion
|
||||
|
||||
protected bool IsConnected { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Use this function to throw an exception if we aren't connected to the hardware
|
||||
/// </summary>
|
||||
@@ -652,23 +615,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()
|
||||
{
|
||||
var profileProperties = SharedResourcesWrapper.ReadProfile();
|
||||
@@ -678,18 +624,6 @@ namespace ASCOM.LynxAstro.DewController
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,6 @@
|
||||
//#define UseChooser
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace ASCOM
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -130,11 +130,6 @@ 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<IProfileWrapper> profileWrapperMock = new Mock<IProfileWrapper>();
|
||||
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 = "LynxAstro.DewController";
|
||||
|
||||
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("", $"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}");
|
||||
}
|
||||
|
||||
/// <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
|
||||
{
|
||||
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
|
||||
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
@@ -116,6 +116,7 @@
|
||||
<Compile Include="IProfileWrapper.cs" />
|
||||
<Compile Include="ISharedResourcesWrapper.cs" />
|
||||
<Compile Include="LocalServer.cs" />
|
||||
<Compile Include="AscomDriverBase.cs" />
|
||||
<Compile Include="ProfileFactory.cs" />
|
||||
<Compile Include="ProfileProperties.cs" />
|
||||
<Compile Include="ProfileWrapper.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
|
||||
{
|
||||
@@ -148,6 +147,8 @@ namespace ASCOM.LynxAstro.DewController
|
||||
driverProfile.DeviceType = "Switch";
|
||||
driverProfile.WriteValue(DriverId, TraceStateProfileName, profileProperties.TraceLogger.ToString());
|
||||
driverProfile.WriteValue(DriverId, ComPortProfileName, profileProperties.ComPort);
|
||||
|
||||
//todo write the switch names
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user