Started working on getting the basic communications with the scope working.

Working on routines to get and set the date and time in the handbox.
This commit is contained in:
2019-04-29 00:06:56 +01:00
parent f2f4b05911
commit da6b7ec55f
19 changed files with 746 additions and 79 deletions
+13 -7
View File
@@ -73,7 +73,7 @@ namespace ASCOM.MeadeAutostar497
/// <summary>
/// Driver description that displays in the ASCOM Chooser.
/// </summary>
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;
}
}
@@ -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; }
}
}
@@ -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();
}
}
}
}
+14 -3
View File
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -15,7 +15,7 @@
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>3.5</OldToolsVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<ApplicationIcon>ASCOM.ico</ApplicationIcon>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>ASCOMDriverTemplate.snk</AssemblyOriginatorKeyFile>
@@ -34,7 +34,8 @@
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -46,6 +47,7 @@
<WarningLevel>4</WarningLevel>
<RegisterForComInterop>true</RegisterForComInterop>
<PlatformTarget>AnyCPU</PlatformTarget>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@@ -56,6 +58,7 @@
<WarningLevel>4</WarningLevel>
<PlatformTarget>AnyCPU</PlatformTarget>
<RegisterForComInterop>false</RegisterForComInterop>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="ASCOM.Astrometry, Version=6.0.0.0, Culture=neutral, PublicKeyToken=565de7938946fba7, processorArchitecture=MSIL" />
@@ -66,6 +69,7 @@
<Reference Include="ASCOM.SettingsProvider, Version=6.0.0.0, Culture=neutral, PublicKeyToken=565de7938946fba7, processorArchitecture=MSIL" />
<Reference Include="ASCOM.Utilities, Version=6.0.0.0, Culture=neutral, PublicKeyToken=565de7938946fba7, processorArchitecture=MSIL" />
<Reference Include="ASCOM.Utilities.Video, Version=6.1.0.0, Culture=neutral, PublicKeyToken=565de7938946fba7, processorArchitecture=MSIL" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Configuration.Install" />
@@ -74,13 +78,20 @@
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.Transactions" />
<Reference Include="System.Windows" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="AscomClasses\Telescope.cs" />
<Compile Include="Controller\ITelescopeController.cs" />
<Compile Include="Controller\TelescopeController.cs" />
<Compile Include="StringExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
+5 -5
View File
@@ -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")]
+24 -37
View File
@@ -1,18 +1,17 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 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.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ASCOM.MeadeAutostar497.Properties
{
namespace ASCOM.MeadeAutostar497.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
@@ -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() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[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;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[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;
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
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));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>
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));
}
+10 -14
View File
@@ -1,28 +1,24 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 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.
// </auto-generated>
//------------------------------------------------------------------------------
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;
}
}
+16
View File
@@ -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);
}
}
}
+1 -1
View File
@@ -5,4 +5,4 @@
<section name="ASCOM.DeviceName.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</sectionGroup>
</configSections>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/></startup></configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/></startup></configuration>