diff --git a/MeadeAutostar497.UnitTests/BootstrapAscomProfileStore.ps1 b/MeadeAutostar497.UnitTests/BootstrapAscomProfileStore.ps1
new file mode 100644
index 0000000..213c64d
--- /dev/null
+++ b/MeadeAutostar497.UnitTests/BootstrapAscomProfileStore.ps1
@@ -0,0 +1,36 @@
+<#
+This script initializes a bare minimum set of registry entries required for ASCOM.Utilities.Profile to work
+without throwing any exceptions. When building on a build server, or on a computer without the ASCOM Platform installed,
+it may be useful to execute this script as a build step prior to running any unit tests, or calling any code that relies on
+ASCOM.Utilities.Profile. The alternative is to install the ASCOM Platform on the build agent.
+
+NOTE: This script equires elevated permissions because it creates registry keys in the LocalMachine hive.
+#>
+
+$wow = Test-Path HKLM:\SOFTWARE\Wow6432Node
+if ($wow)
+ {
+ $root = "HKLM:\SOFTWARE\Wow6432Node"
+ }
+else
+ {
+ $root = "HKLM:\SOFTWARE"
+ }
+$ascomRoot = $root + "\ASCOM"
+
+if (Test-Path $ascomRoot)
+ {
+ <# Don't upset an already-existing ASCOM registry #>
+ exit
+ }
+
+<# Create the ASCOM root key and set it's ACL to allow all users read/write access #>
+New-Item -Path $root -Name ASCOM –Force
+$ascomAcl = Get-Acl $ascomRoot
+$aclRule = New-Object System.Security.AccessControl.RegistryAccessRule ("Users","FullControl","Allow")
+$ascomAcl.SetAccessRule($aclRule)
+$ascomAcl | Set-Acl -Path $ascomRoot
+
+<# Now create the bare minimum keys required so that ASCOM.Utilities.Profile doesn't crash and burn #>
+New-ItemProperty -Path $ascomRoot -Name PlatformVersion -Value "6.1" -PropertyType String –Force
+New-ItemProperty -Path $ascomRoot -Name SerTraceFile -Value "C:\SerialTraceAuto.txt" -PropertyType String –Force
diff --git a/MeadeAutostar497.UnitTests/MeadeAutostar497.UnitTests.csproj b/MeadeAutostar497.UnitTests/MeadeAutostar497.UnitTests.csproj
new file mode 100644
index 0000000..e49ccdc
--- /dev/null
+++ b/MeadeAutostar497.UnitTests/MeadeAutostar497.UnitTests.csproj
@@ -0,0 +1,125 @@
+
+
+
+
+
+ Debug
+ AnyCPU
+ {9638DA27-77C7-4B30-A730-6E7159A4A09F}
+ Library
+ Properties
+ MeadeAutostar497.UnitTests
+ MeadeAutostar497.UnitTests
+ v4.6.2
+ 512
+ true
+
+
+
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+ false
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+ false
+
+
+
+ ..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.Astrometry.dll
+
+
+ ..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.Attributes.dll
+
+
+ ..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.Cache.dll
+
+
+ ..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.Controls.dll
+
+
+ ..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.DeviceInterfaces.dll
+
+
+ ..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.DriverAccess.dll
+
+
+ ..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.Exceptions.dll
+
+
+ ..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.Internal.Extensions.dll
+
+
+ ..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.SettingsProvider.dll
+
+
+ ..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.Utilities.dll
+
+
+ ..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.Utilities.Video.dll
+
+
+ ..\packages\Castle.Core.4.3.1\lib\net45\Castle.Core.dll
+
+
+ ..\packages\Moq.4.10.1\lib\net45\Moq.dll
+
+
+ ..\packages\NUnit.3.11.0\lib\net45\nunit.framework.dll
+
+
+
+
+
+
+ ..\packages\System.Runtime.CompilerServices.Unsafe.4.5.0\lib\netstandard1.0\System.Runtime.CompilerServices.Unsafe.dll
+
+
+
+
+ ..\packages\System.Threading.Tasks.Extensions.4.5.1\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {64308775-bd4a-469c-bcab-3ed830b811af}
+ MeadeAutostar497
+
+
+
+
+
+
+
+
+
+ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
+
+
+
+
\ No newline at end of file
diff --git a/MeadeAutostar497.UnitTests/Properties/AssemblyInfo.cs b/MeadeAutostar497.UnitTests/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..ef108f2
--- /dev/null
+++ b/MeadeAutostar497.UnitTests/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("MeadeAutostar497.UnitTests")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("MeadeAutostar497.UnitTests")]
+[assembly: AssemblyCopyright("Copyright © 2019")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("9638da27-77c7-4b30-a730-6e7159a4a09f")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/MeadeAutostar497.UnitTests/TelescopeControllerUnitTests.cs b/MeadeAutostar497.UnitTests/TelescopeControllerUnitTests.cs
new file mode 100644
index 0000000..247c1b8
--- /dev/null
+++ b/MeadeAutostar497.UnitTests/TelescopeControllerUnitTests.cs
@@ -0,0 +1,151 @@
+using System.Collections.Generic;
+using ASCOM;
+using ASCOM.MeadeAutostar497.Controller;
+using ASCOM.Utilities;
+using ASCOM.Utilities.Interfaces;
+using Moq;
+using NUnit.Framework;
+
+namespace MeadeAutostar497.UnitTests
+{
+ [TestFixture]
+ public class TelescopeControllerUnitTests
+ {
+ private Mock serialMock;
+
+ private readonly List _availableComPorts = new List { "COM1", "COM2", "COM3" };
+ private TelescopeController _telescopeController;
+
+ private string transmittedString;
+ private string stringToRecieve;
+
+ [SetUp]
+ public void Setup()
+ {
+ transmittedString = string.Empty;
+ stringToRecieve = string.Empty;
+
+ serialMock = new Mock();
+ serialMock.SetupAllProperties();
+
+ serialMock.Setup(x => x.AvailableComPorts).Returns( () => _availableComPorts.ToArray());
+ serialMock.Setup(X => X.Transmit(It.IsAny())).Callback(str => { transmittedString = str; });
+ serialMock.Setup(X => X.Receive()).Returns(() => stringToRecieve);
+
+ _telescopeController = TelescopeController.Instance;
+ _telescopeController.SerialPort = serialMock.Object;
+ }
+
+ [TearDown]
+ public void TearDown()
+ {
+ _telescopeController.Connected = false;
+ _telescopeController.Port = "COM1";
+ }
+
+ [Test]
+ public void ImplementsExpectedInterfaces()
+ {
+ Assert.That(_telescopeController, Is.Not.Null);
+ Assert.That(_telescopeController, Is.AssignableTo());
+ }
+
+ [Test]
+ public void NotConnectedByDefault()
+ {
+ Assert.That(_telescopeController.Connected, Is.False);
+ }
+
+ [Test]
+ public void ConnectedCanBeSetTrue()
+ {
+ stringToRecieve = "test#";
+
+ _telescopeController.Connected = true;
+ Assert.That(_telescopeController.Connected, Is.True);
+ }
+
+ [Test]
+ public void EnsureThatTheSerialCommunicationsAreSetCorrectly()
+ {
+ Assert.That(serialMock.Object.Connected, Is.False);
+
+ stringToRecieve = "test#";
+
+ _telescopeController.Connected = true;
+ Assert.That(_telescopeController.Connected, Is.True);
+
+ Assert.That(serialMock.Object.DTREnable, Is.False);
+ Assert.That(serialMock.Object.RTSEnable, Is.False);
+ Assert.That(serialMock.Object.Speed, Is.EqualTo(SerialSpeed.ps9600));
+ Assert.That(serialMock.Object.DataBits, Is.EqualTo(8));
+ Assert.That(serialMock.Object.StopBits, Is.EqualTo(SerialStopBits.One));
+ Assert.That(serialMock.Object.Parity, Is.EqualTo(SerialParity.None));
+ Assert.That(serialMock.Object.PortName, Is.EqualTo(_telescopeController.Port));
+ Assert.That(serialMock.Object.Connected, Is.True);
+ }
+
+ [Test]
+ public void WhenOpensComPortToNonAutostarThrowException()
+ {
+ Assert.That(serialMock.Object.Connected, Is.False);
+ var exception = Assert.Throws(() => { _telescopeController.Connected = true; });
+
+ Assert.That(exception.Message, Is.EqualTo("Failed to communicate with telescope."));
+
+ Assert.That(_telescopeController.Connected, Is.False);
+ }
+
+ [Test]
+ public void CannotChangeSerialPortObjectWhenConnected()
+ {
+ stringToRecieve = "test#";
+
+ _telescopeController.Connected = true;
+
+ Mock newSerialMock = new Mock();
+
+ var exception = Assert.Throws( () => { _telescopeController.SerialPort = newSerialMock.Object; });
+
+ Assert.That(exception, Is.Not.Null);
+ Assert.That(exception.Message, Is.EqualTo("Please disconnect before changing the serial engine."));
+ }
+
+ [Test]
+ public void PortIsSetToCom1ByDefault()
+ {
+ Assert.That(_telescopeController.Port, Is.EqualTo("COM1"));
+ }
+
+ [Test]
+ public void SettingPortToValidPortAllowed()
+ {
+ _telescopeController.Port = "COM2";
+
+ Assert.That(_telescopeController.Port, Is.EqualTo("COM2"));
+ }
+
+ [Test]
+ public void SettingPortToValidPortWhenConnectedFails()
+ {
+ stringToRecieve = "test#";
+
+ _telescopeController.Connected = true;
+ var exception = Assert.Throws( () => _telescopeController.Port = "COM2");
+
+ Assert.That(exception.Message, Is.EqualTo("Please disconnect from the scope before changing port."));
+
+ Assert.That(_telescopeController.Port, Is.EqualTo("COM1")); //port hasn't changed
+ }
+
+ [Test]
+ public void SettingPortToInavalidPortFails()
+ {
+ var exception = Assert.Throws(() => _telescopeController.Port = "COM5");
+
+ Assert.That(exception.Message, Is.EqualTo("Unable to select port COM5 as it does not exist."));
+
+ Assert.That(_telescopeController.Port, Is.EqualTo("COM1")); //port hasn't changed
+ }
+ }
+}
diff --git a/MeadeAutostar497.UnitTests/packages.config b/MeadeAutostar497.UnitTests/packages.config
new file mode 100644
index 0000000..e7172db
--- /dev/null
+++ b/MeadeAutostar497.UnitTests/packages.config
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/MeadeAutostar497.sln b/MeadeAutostar497.sln
index d98a188..69570e9 100644
--- a/MeadeAutostar497.sln
+++ b/MeadeAutostar497.sln
@@ -5,16 +5,40 @@ VisualStudioVersion = 15.0.28307.136
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MeadeAutostar497", "MeadeAutostar497\MeadeAutostar497.csproj", "{64308775-BD4A-469C-BCAB-3ED830B811AF}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MeadeAutostar497.UnitTests", "MeadeAutostar497.UnitTests\MeadeAutostar497.UnitTests.csproj", "{9638DA27-77C7-4B30-A730-6E7159A4A09F}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestConsole", "TestConsole\TestConsole.csproj", "{D5207217-61C7-4E94-8097-91DBACE57D2A}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
+ Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
+ Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{64308775-BD4A-469C-BCAB-3ED830B811AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{64308775-BD4A-469C-BCAB-3ED830B811AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {64308775-BD4A-469C-BCAB-3ED830B811AF}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {64308775-BD4A-469C-BCAB-3ED830B811AF}.Debug|x86.Build.0 = Debug|Any CPU
{64308775-BD4A-469C-BCAB-3ED830B811AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{64308775-BD4A-469C-BCAB-3ED830B811AF}.Release|Any CPU.Build.0 = Release|Any CPU
+ {64308775-BD4A-469C-BCAB-3ED830B811AF}.Release|x86.ActiveCfg = Release|Any CPU
+ {64308775-BD4A-469C-BCAB-3ED830B811AF}.Release|x86.Build.0 = Release|Any CPU
+ {9638DA27-77C7-4B30-A730-6E7159A4A09F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {9638DA27-77C7-4B30-A730-6E7159A4A09F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {9638DA27-77C7-4B30-A730-6E7159A4A09F}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {9638DA27-77C7-4B30-A730-6E7159A4A09F}.Debug|x86.Build.0 = Debug|Any CPU
+ {9638DA27-77C7-4B30-A730-6E7159A4A09F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {9638DA27-77C7-4B30-A730-6E7159A4A09F}.Release|Any CPU.Build.0 = Release|Any CPU
+ {9638DA27-77C7-4B30-A730-6E7159A4A09F}.Release|x86.ActiveCfg = Release|Any CPU
+ {9638DA27-77C7-4B30-A730-6E7159A4A09F}.Release|x86.Build.0 = Release|Any CPU
+ {D5207217-61C7-4E94-8097-91DBACE57D2A}.Debug|Any CPU.ActiveCfg = Debug|x86
+ {D5207217-61C7-4E94-8097-91DBACE57D2A}.Debug|x86.ActiveCfg = Debug|x86
+ {D5207217-61C7-4E94-8097-91DBACE57D2A}.Debug|x86.Build.0 = Debug|x86
+ {D5207217-61C7-4E94-8097-91DBACE57D2A}.Release|Any CPU.ActiveCfg = Release|x86
+ {D5207217-61C7-4E94-8097-91DBACE57D2A}.Release|x86.ActiveCfg = Release|x86
+ {D5207217-61C7-4E94-8097-91DBACE57D2A}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/MeadeAutostar497/AscomClasses/Telescope.cs b/MeadeAutostar497/AscomClasses/Telescope.cs
index e7e60c2..264f601 100644
--- a/MeadeAutostar497/AscomClasses/Telescope.cs
+++ b/MeadeAutostar497/AscomClasses/Telescope.cs
@@ -73,7 +73,7 @@ namespace ASCOM.MeadeAutostar497
///
/// Driver description that displays in the ASCOM Chooser.
///
- private static string driverDescription = "ASCOM Telescope Driver for Meade Autostar 497 based telescopes.";
+ private static string driverDescription = "Meade Autostar 497 .net";
internal static string comPortProfileName = "COM Port"; // Constants used for Profile persistence
internal static string comPortDefault = "COM1";
@@ -221,6 +221,7 @@ namespace ASCOM.MeadeAutostar497
if (value)
{
LogMessage("Connected Set", "Connecting to port {0}", comPort);
+ _telescopeController.Port = comPort;
_telescopeController.Connected = true;
}
else
@@ -810,8 +811,10 @@ namespace ASCOM.MeadeAutostar497
{
get
{
- tl.LogMessage("Slewing Get", "Not implemented");
- throw new ASCOM.PropertyNotImplementedException("Slewing", false);
+ tl.LogMessage("Slewing Get", "Started");
+ var result = _telescopeController.Slewing;
+ tl.LogMessage("Slewing Get", $"Result = {result}");
+ return result;
}
}
@@ -908,14 +911,17 @@ namespace ASCOM.MeadeAutostar497
{
get
{
- DateTime utcDate = DateTime.UtcNow;
- tl.LogMessage("TrackingRates", "Get - " + Format("MM/dd/yy HH:mm:ss", utcDate));
+ tl.LogMessage("UTCDate", "Get started");
+
+ var utcDate = _telescopeController.utcDate;
+ tl.LogMessage("UTCDate", "Get - " + Format("MM/dd/yy HH:mm:ss", utcDate));
return utcDate;
}
set
{
- tl.LogMessage("UTCDate Set", "Not implemented");
- throw new ASCOM.PropertyNotImplementedException("UTCDate", true);
+ tl.LogMessage("UTCDate", "Set - " + Format("MM/dd/yy HH:mm:ss", value));
+ _telescopeController.utcDate = value;
+
}
}
diff --git a/MeadeAutostar497/Controller/ITelescopeController.cs b/MeadeAutostar497/Controller/ITelescopeController.cs
index 2cbea84..6663772 100644
--- a/MeadeAutostar497/Controller/ITelescopeController.cs
+++ b/MeadeAutostar497/Controller/ITelescopeController.cs
@@ -1,4 +1,5 @@
-using ASCOM.Utilities.Interfaces;
+using System;
+using ASCOM.Utilities.Interfaces;
namespace ASCOM.MeadeAutostar497.Controller
{
@@ -9,5 +10,7 @@ namespace ASCOM.MeadeAutostar497.Controller
bool Connected { get; set; }
string CommandString(string command, bool raw);
+ bool Slewing { get; }
+ DateTime utcDate { get; set; }
}
}
\ No newline at end of file
diff --git a/MeadeAutostar497/Controller/TelescopeController.cs b/MeadeAutostar497/Controller/TelescopeController.cs
index 891111d..fe6dc4c 100644
--- a/MeadeAutostar497/Controller/TelescopeController.cs
+++ b/MeadeAutostar497/Controller/TelescopeController.cs
@@ -1,4 +1,8 @@
using System;
+using System.Configuration;
+using System.Data;
+using System.Linq;
+using System.Threading;
using ASCOM.Utilities;
using ASCOM.Utilities.Interfaces;
@@ -10,6 +14,8 @@ namespace ASCOM.MeadeAutostar497.Controller
public static TelescopeController Instance => lazy.Value;
+ private Mutex serialMutex = new Mutex();
+
private ISerial _serialPort;
public ISerial SerialPort
{
@@ -22,7 +28,7 @@ namespace ASCOM.MeadeAutostar497.Controller
if (_serialPort != null)
{
if (_serialPort.Connected)
- throw new InvalidOperationException("Please disconnect before changing the port.");
+ throw new InvalidOperationException("Please disconnect before changing the serial engine.");
}
_serialPort = value;
@@ -40,10 +46,18 @@ namespace ASCOM.MeadeAutostar497.Controller
if (Connected)
throw new InvalidOperationException("Please disconnect from the scope before changing port.");
+ if (!ValidPort(value))
+ throw new InvalidOperationException($"Unable to select port {value} as it does not exist.");
+
_port = value;
}
}
+ private bool ValidPort(string value)
+ {
+ return SerialPort.AvailableComPorts.Contains(value);
+ }
+
public bool Connected
{
get => SerialPort.Connected;
@@ -55,16 +69,24 @@ namespace ASCOM.MeadeAutostar497.Controller
if (value)
{
//Connecting
- SerialPort.DTREnable = false;
- SerialPort.RTSEnable = false;
- SerialPort.Speed = SerialSpeed.ps9600;
- SerialPort.DataBits = 8;
- SerialPort.StopBits = SerialStopBits.One;
- SerialPort.Parity = SerialParity.None;
- SerialPort.PortName = Port;
- SerialPort.Connected = true;
+ try
+ {
+ SerialPort.DTREnable = false;
+ SerialPort.RTSEnable = false;
+ SerialPort.Speed = SerialSpeed.ps9600;
+ SerialPort.DataBits = 8;
+ SerialPort.StopBits = SerialStopBits.One;
+ SerialPort.Parity = SerialParity.None;
+ SerialPort.PortName = Port;
+ SerialPort.Connected = true;
- //todo perform test to ensure that connection has been made correctly.
+ TestConnectionActive();
+ }
+ catch (Exception)
+ {
+ SerialPort.Connected = false;
+ throw;
+ }
}
else
{
@@ -74,13 +96,100 @@ namespace ASCOM.MeadeAutostar497.Controller
}
}
+ private void TestConnectionActive()
+ {
+ var firmwareVersionNumber = CommandString("GVN");
+ if (string.IsNullOrEmpty(firmwareVersionNumber))
+ {
+ throw new InvalidOperationException("Failed to communicate with telescope.");
+ }
+ }
+
+ public string CommandString(string command)
+ {
+ return CommandString($"#:{command}#", false);
+ }
+
public string CommandString(string command, bool raw)
{
// 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 SerialCommand(command, true);
+ }
- throw new ASCOM.MethodNotImplementedException("CommandString");
+ public bool Slewing
+ {
+ get
+ {
+ if (!Connected) return false;
+
+ var result = CommandString("D");
+ return result != string.Empty;
+ }
+ }
+
+ public DateTime utcDate
+ {
+ get
+ {
+ string telescopeDate = CommandString("GC");
+ string telescopeTime = CommandString("GL");
+
+ int month = telescopeDate.Substring(0, 2).ToInteger();
+ int day = telescopeDate.Substring(3, 2).ToInteger();
+ int year = telescopeDate.Substring(6, 2).ToInteger();
+
+ if (year < 2000) //This is a hack that will work until the end of the century
+ {
+ year = year + 2000;
+ }
+
+ int hour = telescopeTime.Substring(0, 2).ToInteger();
+ int minute = telescopeTime.Substring(3, 2).ToInteger();
+ int second = telescopeTime.Substring(6, 2).ToInteger();
+
+ var newDate = new DateTime(year, month, day, hour, minute, second, DateTimeKind.Utc);
+
+ return newDate;
+ }
+ set
+ {
+ //var result = SerialCommand(":SLHH:MM:SS#", true);
+ var timeResult = SerialCommand($"#:SL{value:hh:mm:ss}#", true);
+ if (timeResult != "1")
+ {
+ throw new InvalidOperationException("Failed to set local time");
+ }
+
+ var dateResult = SerialCommand($"#:SC{value:MM/dd/yy}#", true);
+ if (dateResult.Substring(0,1) != "1")
+ {
+ throw new InvalidOperationException("Failed to set local time");
+ }
+ }
+
+ }
+
+ private string SerialCommand(string command, bool expectsResult )
+ {
+ serialMutex.WaitOne();
+ try
+ {
+ SerialPort.Transmit(command);
+ if (expectsResult)
+ {
+ string result = SerialPort.ReceiveTerminated("#");
+
+ return result;
+ }
+ return string.Empty;
+ }
+ finally
+ {
+ SerialPort.ClearBuffers();
+ serialMutex.ReleaseMutex();
+ }
}
}
}
diff --git a/MeadeAutostar497/MeadeAutostar497.csproj b/MeadeAutostar497/MeadeAutostar497.csproj
index 2be7529..940afa9 100644
--- a/MeadeAutostar497/MeadeAutostar497.csproj
+++ b/MeadeAutostar497/MeadeAutostar497.csproj
@@ -1,5 +1,5 @@
-
+
Debug
AnyCPU
@@ -15,7 +15,7 @@
3.5
- v4.0
+ v4.6.2
ASCOM.ico
true
ASCOMDriverTemplate.snk
@@ -34,7 +34,8 @@
false
false
true
- Client
+
+
true
@@ -46,6 +47,7 @@
4
true
AnyCPU
+ false
pdbonly
@@ -56,6 +58,7 @@
4
AnyCPU
false
+ false
@@ -66,6 +69,7 @@
+
@@ -74,13 +78,20 @@
+
+
+
+
+
+
+
True
diff --git a/MeadeAutostar497/Properties/AssemblyInfo.cs b/MeadeAutostar497/Properties/AssemblyInfo.cs
index 848df7f..2a06abf 100644
--- a/MeadeAutostar497/Properties/AssemblyInfo.cs
+++ b/MeadeAutostar497/Properties/AssemblyInfo.cs
@@ -8,11 +8,11 @@ using System.Runtime.InteropServices;
//
// TODO - Add your authorship information here
[assembly: AssemblyTitle("ASCOM.MeadeAutostar497.Telescope")]
-[assembly: AssemblyDescription("ASCOM Telescope driver for MeadeAutostar497")]
+[assembly: AssemblyDescription("ASCOM MeadeAutostar497 .net")]
[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("The ASCOM Initiative")]
+[assembly: AssemblyCompany("Cjdawson.com")]
[assembly: AssemblyProduct("ASCOM Telescope driver for MeadeAutostar497")]
-[assembly: AssemblyCopyright("Copyright © 2019 The ASCOM Initiative")]
+[assembly: AssemblyCopyright("Copyright © 2019 cjdawson.com")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -35,5 +35,5 @@ using System.Runtime.InteropServices;
// by using the '*' as shown below:
//
// TODO - Set your driver's version here
-[assembly: AssemblyVersion("6.4.0.0")]
-[assembly: AssemblyFileVersion("6.4.0.0")]
+[assembly: AssemblyVersion("0.0.0.0")]
+[assembly: AssemblyFileVersion("0.0.0.0")]
diff --git a/MeadeAutostar497/Properties/Resources.Designer.cs b/MeadeAutostar497/Properties/Resources.Designer.cs
index c18564b..9d71803 100644
--- a/MeadeAutostar497/Properties/Resources.Designer.cs
+++ b/MeadeAutostar497/Properties/Resources.Designer.cs
@@ -1,18 +1,17 @@
//------------------------------------------------------------------------------
//
// This code was generated by a tool.
-// Runtime Version:4.0.30319.18052
+// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
//------------------------------------------------------------------------------
-namespace ASCOM.MeadeAutostar497.Properties
-{
+namespace ASCOM.MeadeAutostar497.Properties {
using System;
-
-
+
+
///
/// A strongly-typed resource class, for looking up localized strings, etc.
///
@@ -20,74 +19,62 @@ namespace ASCOM.MeadeAutostar497.Properties
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- internal class Resources
- {
-
+ internal class Resources {
+
private static global::System.Resources.ResourceManager resourceMan;
-
+
private static global::System.Globalization.CultureInfo resourceCulture;
-
+
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
- internal Resources()
- {
+ internal Resources() {
}
-
+
///
/// Returns the cached ResourceManager instance used by this class.
///
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Resources.ResourceManager ResourceManager
- {
- get
- {
- if (object.ReferenceEquals(resourceMan, null))
- {
+ internal static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ASCOM.MeadeAutostar497.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
-
+
///
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
///
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Globalization.CultureInfo Culture
- {
- get
- {
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
return resourceCulture;
}
- set
- {
+ set {
resourceCulture = value;
}
}
-
+
///
/// Looks up a localized resource of type System.Drawing.Bitmap.
///
- internal static System.Drawing.Bitmap ASCOM
- {
- get
- {
+ internal static System.Drawing.Bitmap ASCOM {
+ get {
object obj = ResourceManager.GetObject("ASCOM", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
-
+
///
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
///
- internal static System.Drawing.Icon DefaultIcon
- {
- get
- {
+ internal static System.Drawing.Icon DefaultIcon {
+ get {
object obj = ResourceManager.GetObject("DefaultIcon", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
diff --git a/MeadeAutostar497/Properties/Settings.Designer.cs b/MeadeAutostar497/Properties/Settings.Designer.cs
index 4e629ed..a2bb372 100644
--- a/MeadeAutostar497/Properties/Settings.Designer.cs
+++ b/MeadeAutostar497/Properties/Settings.Designer.cs
@@ -1,28 +1,24 @@
//------------------------------------------------------------------------------
//
// This code was generated by a tool.
-// Runtime Version:4.0.30319.18052
+// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
//------------------------------------------------------------------------------
-namespace ASCOM.MeadeAutostar497.Properties
-{
-
-
+namespace ASCOM.MeadeAutostar497.Properties {
+
+
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
- internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
- {
-
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")]
+ internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
+
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
-
- public static Settings Default
- {
- get
- {
+
+ public static Settings Default {
+ get {
return defaultInstance;
}
}
diff --git a/MeadeAutostar497/StringExtensions.cs b/MeadeAutostar497/StringExtensions.cs
new file mode 100644
index 0000000..e6a2cd1
--- /dev/null
+++ b/MeadeAutostar497/StringExtensions.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ASCOM.MeadeAutostar497
+{
+ public static class StringExtensions
+ {
+ public static int ToInteger(this string str)
+ {
+ return int.Parse(str);
+ }
+ }
+}
diff --git a/MeadeAutostar497/app.config b/MeadeAutostar497/app.config
index e4eb090..dd30df1 100644
--- a/MeadeAutostar497/app.config
+++ b/MeadeAutostar497/app.config
@@ -5,4 +5,4 @@
-
+
diff --git a/TestConsole/Program.cs b/TestConsole/Program.cs
new file mode 100644
index 0000000..b2ef23b
--- /dev/null
+++ b/TestConsole/Program.cs
@@ -0,0 +1,55 @@
+// This implements a console application that can be used to test an ASCOM driver
+//
+
+// This is used to define code in the template that is specific to one class implementation
+// unused code can be deleted and this definition removed.
+
+#define Telescope
+// remove this to bypass the code that uses the chooser to select the driver
+#define UseChooser
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace ASCOM
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ // Uncomment the code that's required
+#if UseChooser
+ // choose the device
+ string id = ASCOM.DriverAccess.Telescope.Choose("ASCOM.MeadeAutostar497.Telescope");
+ if (string.IsNullOrEmpty(id))
+ return;
+ // create this device
+ ASCOM.DriverAccess.Telescope device = new ASCOM.DriverAccess.Telescope(id);
+#else
+ // this can be replaced by this code, it avoids the chooser and creates the driver class directly.
+ ASCOM.DriverAccess.Telescope device = new ASCOM.DriverAccess.Telescope("ASCOM.MeadeAutostar497.Telescope");
+#endif
+ // now run some tests, adding code to your driver so that the tests will pass.
+ // these first tests are common to all drivers.
+ Console.WriteLine("name " + device.Name);
+ Console.WriteLine("description " + device.Description);
+ Console.WriteLine("DriverInfo " + device.DriverInfo);
+ Console.WriteLine("driverVersion " + device.DriverVersion);
+
+ // TODO add more code to test the driver.
+ device.Connected = true;
+
+ //Console.WriteLine(device.Slewing);
+
+ device.UTCDate = DateTime.UtcNow;
+
+ Console.WriteLine(device.UTCDate);
+
+ device.Connected = false;
+ Console.WriteLine("Press Enter to finish");
+ Console.ReadLine();
+ }
+ }
+}
diff --git a/TestConsole/Properties/AssemblyInfo.cs b/TestConsole/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..86599a1
--- /dev/null
+++ b/TestConsole/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("q Test Application")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("ASCOM Initiative")]
+[assembly: AssemblyProduct("q")]
+[assembly: AssemblyCopyright("Copyright © ASCOM Initiative 2014")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("c7008f94-e3b9-4481-b720-3b56557860c6")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+
+[assembly: AssemblyVersion("6.4.0.0")]
+[assembly: AssemblyFileVersion("6.4.0.0")]
diff --git a/TestConsole/TestConsole.csproj b/TestConsole/TestConsole.csproj
new file mode 100644
index 0000000..9631e67
--- /dev/null
+++ b/TestConsole/TestConsole.csproj
@@ -0,0 +1,64 @@
+
+
+
+ Debug
+ x86
+ 8.0.30703
+ 2.0
+ {D5207217-61C7-4E94-8097-91DBACE57D2A}
+ Exe
+ Properties
+ TestConsole
+ TestConsole
+ v4.6
+
+
+ 512
+
+
+ x86
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+ false
+
+
+ x86
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/TestConsole/app.config b/TestConsole/app.config
new file mode 100644
index 0000000..8935d57
--- /dev/null
+++ b/TestConsole/app.config
@@ -0,0 +1,3 @@
+
+
+