Implemented AbortSlew and did some code tidy up.

This commit is contained in:
2019-04-29 23:56:51 +01:00
parent dc2a24ad25
commit e339831f0c
7 changed files with 68 additions and 41 deletions
@@ -143,7 +143,7 @@ namespace MeadeAutostar497.UnitTests
} }
[Test] [Test]
public void SettingPortToInavalidPortFails() public void SettingPortToInvalidPortFails()
{ {
var exception = Assert.Throws<InvalidOperationException>(() => _telescopeController.Port = "COM5"); var exception = Assert.Throws<InvalidOperationException>(() => _telescopeController.Port = "COM5");
@@ -151,5 +151,17 @@ namespace MeadeAutostar497.UnitTests
Assert.That(_telescopeController.Port, Is.EqualTo("COM1")); //port hasn't changed Assert.That(_telescopeController.Port, Is.EqualTo("COM1")); //port hasn't changed
} }
[Test]
public void AbortSlewWorks()
{
_isConnected = true;
_telescopeController.Connected = true;
_telescopeController.AbortSlew();
serialMock.Verify(x => x.Command("#:Q#"), Times.Once);
}
} }
} }
+5 -9
View File
@@ -27,11 +27,7 @@
#define Telescope #define Telescope
using System; using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using ASCOM; using ASCOM;
using ASCOM.Astrometry; using ASCOM.Astrometry;
using ASCOM.Astrometry.AstroUtils; using ASCOM.Astrometry.AstroUtils;
@@ -293,8 +289,8 @@ namespace ASCOM.MeadeAutostar497
#region ITelescope Implementation #region ITelescope Implementation
public void AbortSlew() public void AbortSlew()
{ {
tl.LogMessage("AbortSlew", "Not implemented"); tl.LogMessage("AbortSlew", "Aborting slew");
throw new ASCOM.MethodNotImplementedException("AbortSlew"); _telescopeController.AbortSlew();
} }
public AlignmentModes AlignmentMode public AlignmentModes AlignmentMode
@@ -380,9 +376,9 @@ namespace ASCOM.MeadeAutostar497
tl.LogMessage("CanMoveAxis", "Get - " + Axis.ToString()); tl.LogMessage("CanMoveAxis", "Get - " + Axis.ToString());
switch (Axis) switch (Axis)
{ {
case TelescopeAxes.axisPrimary: return false; case TelescopeAxes.axisPrimary: return true; //RA or AZ
case TelescopeAxes.axisSecondary: return false; case TelescopeAxes.axisSecondary: return true; //Dev or Alt
case TelescopeAxes.axisTertiary: return false; case TelescopeAxes.axisTertiary: return false; //rotator / derotator
default: throw new InvalidValueException("CanMoveAxis", Axis.ToString(), "0 to 2"); default: throw new InvalidValueException("CanMoveAxis", Axis.ToString(), "0 to 2");
} }
} }
@@ -0,0 +1,26 @@
using System.IO.Ports;
using System.Runtime.InteropServices;
namespace ASCOM.MeadeAutostar497.Controller
{
[ComVisible(false)]
public interface ISerialProcessor
{
bool IsOpen { get; }
bool DtrEnable { get; set; }
bool RtsEnable { get; set; }
int BaudRate { get; set; }
int DataBits { get; set; }
StopBits StopBits { get; set; }
Parity Parity { get; set; }
string PortName { get; set; }
string[] GetPortNames();
void Open();
void Close();
string CommandTerminated(string command, string terminator);
char CommandChar(string command);
string ReadTerminated(string terminator);
void Command(string command);
}
}
@@ -1,15 +1,14 @@
using System; using System;
using System.IO.Ports;
namespace ASCOM.MeadeAutostar497.Controller namespace ASCOM.MeadeAutostar497.Controller
{ {
public interface ITelescopeController public interface ITelescopeController
{ {
ISerialProcessor SerialPort { get; set; }
string Port { get; set; } string Port { get; set; }
bool Connected { get; set; } bool Connected { get; set; }
bool Slewing { get; } bool Slewing { get; }
DateTime utcDate { get; set; } DateTime utcDate { get; set; }
void AbortSlew();
} }
} }
+13 -21
View File
@@ -1,31 +1,10 @@
using System; using System;
using System.IO.Ports; using System.IO.Ports;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System.Threading; using System.Threading;
namespace ASCOM.MeadeAutostar497.Controller namespace ASCOM.MeadeAutostar497.Controller
{ {
[ComVisible(false)]
public interface ISerialProcessor
{
bool IsOpen { get; }
bool DtrEnable { get; set; }
bool RtsEnable { get; set; }
int BaudRate { get; set; }
int DataBits { get; set; }
StopBits StopBits { get; set; }
Parity Parity { get; set; }
string PortName { get; set; }
string[] GetPortNames();
void Open();
void Close();
string CommandTerminated(string command, string terminator);
char CommandChar(string command);
string ReadTerminated(string terminator);
}
[ComVisible(false)] [ComVisible(false)]
public class SerialProcessor : ISerialProcessor public class SerialProcessor : ISerialProcessor
{ {
@@ -134,5 +113,18 @@ namespace ASCOM.MeadeAutostar497.Controller
serialMutex.ReleaseMutex(); serialMutex.ReleaseMutex();
} }
} }
public void Command(string command)
{
serialMutex.WaitOne();
try
{
_serialPort.Write(command);
}
finally
{
serialMutex.ReleaseMutex();
}
}
} }
} }
@@ -1,11 +1,6 @@
using System; using System;
using System.Configuration;
using System.Data;
using System.IO.Ports; using System.IO.Ports;
using System.Linq; using System.Linq;
using System.Threading;
using ASCOM.Utilities;
using ASCOM.Utilities.Interfaces;
namespace ASCOM.MeadeAutostar497.Controller namespace ASCOM.MeadeAutostar497.Controller
{ {
@@ -98,7 +93,7 @@ namespace ASCOM.MeadeAutostar497.Controller
private void TestConnectionActive() private void TestConnectionActive()
{ {
var firmwareVersionNumber = SerialPort.CommandTerminated(":GVN#", "#"); var firmwareVersionNumber = SerialPort.CommandTerminated("#:GVN#", "#");
if (string.IsNullOrEmpty(firmwareVersionNumber)) if (string.IsNullOrEmpty(firmwareVersionNumber))
{ {
throw new InvalidOperationException("Failed to communicate with telescope."); throw new InvalidOperationException("Failed to communicate with telescope.");
@@ -155,10 +150,16 @@ namespace ASCOM.MeadeAutostar497.Controller
throw new InvalidOperationException("Failed to set local time"); throw new InvalidOperationException("Failed to set local time");
} }
SerialPort.ReadTerminated("#"); //throwing away these two strings which represent
SerialPort.ReadTerminated("#"); SerialPort.ReadTerminated("#"); //Updating Planetary Data#
SerialPort.ReadTerminated("#"); // #
} }
} }
public void AbortSlew()
{
SerialPort.Command("#:Q#");
}
} }
} }
+1
View File
@@ -89,6 +89,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="AscomClasses\Telescope.cs" /> <Compile Include="AscomClasses\Telescope.cs" />
<Compile Include="Controller\ISerialProcessor.cs" />
<Compile Include="Controller\ITelescopeController.cs" /> <Compile Include="Controller\ITelescopeController.cs" />
<Compile Include="Controller\SerialProcessor.cs" /> <Compile Include="Controller\SerialProcessor.cs" />
<Compile Include="Controller\TelescopeController.cs" /> <Compile Include="Controller\TelescopeController.cs" />