using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using ASCOM.Astrometry.AstroUtils;
using ASCOM.DeviceInterface;
using System.Globalization;
using System.Collections;
namespace ASCOM.ArduinoDriverEQ
[Guid("0df5f57d-ec0f-44ff-a539-48bebd21be30")]
[ClassInterface(ClassInterfaceType.None)]
public class Telescope : ITelescopeV3
internal static string driverID = "ASCOM.ArduinoDriverEQ.Telescope";
private static string driverDescription = "ASCOM Telescope Driver for ArduinoDriverEQ.";
internal static string comPortProfileName = "COM Port";
internal static string comPortDefault = "COM5";
internal static string traceStateProfileName = "Trace Level";
internal static string traceStateDefault = "false";
internal static string comPort;
internal static bool traceState;
private bool connectedState;
private AstroUtils astroUtilities;
internal static TraceLogger tl;
private Serial serialPort;
private bool isSlewing = false;
tl = new TraceLogger("", "ArduinoDriverEQ");
tl.LogMessage("Telescope", "Starting initialisation");
astroUtilities = new AstroUtils();
tl.LogMessage("Telescope", "Completed initialisation");
#region Common properties and methods.
public void SetupDialog()
System.Windows.Forms.MessageBox.Show("Already connected, just press OK");
using (SetupDialogForm F = new SetupDialogForm())
var result = F.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
public ArrayList SupportedActions
tl.LogMessage("SupportedActions Get", "Returning empty arraylist");
public string Action(string actionName, string actionParameters)
LogMessage("", "Action {0}, parameters {1} not implemented", actionName, actionParameters);
throw new ASCOM.ActionNotImplementedException("Action " + actionName + " is not implemented by this driver");
public void CommandBlind(string command, bool raw)
throw new ASCOM.MethodNotImplementedException("CommandBlind");
public bool CommandBool(string command, bool raw)
throw new ASCOM.MethodNotImplementedException("CommandBool");
public string CommandString(string command, bool raw)
CheckConnected("CommandString");
throw new ASCOM.MethodNotImplementedException("CommandString");
astroUtilities.Dispose();
tl.LogMessage("Connected Get", IsConnected.ToString());
tl.LogMessage("Connected Set", value.ToString());
if (value == IsConnected)
serialPort = new Serial();
serialPort.PortName = comPort;
serialPort.Speed = SerialSpeed.ps57600;
serialPort.Connected = true;
tl.LogMessage("Connected Set", "Connecting to port " + comPort);
throw new ASCOM.NotConnectedException("Serial port connection error", ex);
tl.LogMessage("Connected Set", "Disconnecting from port " + comPort);
if (serialPort != null && serialPort.Connected)
serialPort.Connected = false;
public string Description
tl.LogMessage("Description Get", driverDescription);
return driverDescription;
Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
string driverInfo = "Arduino EQ2Mount. Version: " + String.Format(CultureInfo.InvariantCulture, "{0}.{1}", version.Major, version.Minor);
tl.LogMessage("DriverInfo Get", driverInfo);
public string DriverVersion
Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
string driverVersion = String.Format(CultureInfo.InvariantCulture, "{0}.{1}", version.Major, version.Minor);
tl.LogMessage("DriverVersion Get", driverVersion);
public short InterfaceVersion
LogMessage("InterfaceVersion Get", "3");
return Convert.ToInt16("3");
tl.LogMessage("Name Get", name);
#region ITelescope Implementation
serialPort.Transmit("H#");
public AlignmentModes AlignmentMode
tl.LogMessage("AlignmentMode Get", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("AlignmentMode", false);
tl.LogMessage("Altitude", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("Altitude", false);
public double ApertureArea
tl.LogMessage("ApertureArea Get", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("ApertureArea", false);
public double ApertureDiameter
tl.LogMessage("ApertureDiameter Get", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("ApertureDiameter", false);
tl.LogMessage("AtHome", "Get - " + false.ToString());
tl.LogMessage("AtPark", "Get - " + false.ToString());
public IAxisRates AxisRates(TelescopeAxes Axis)
tl.LogMessage("AxisRates", "Get - " + Axis.ToString());
return new AxisRates(Axis);
tl.LogMessage("Azimuth Get", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("Azimuth", false);
tl.LogMessage("CanFindHome", "Get - " + false.ToString());
public bool CanMoveAxis(TelescopeAxes Axis)
tl.LogMessage("CanMoveAxis", "Get - " + Axis.ToString());
case TelescopeAxes.axisPrimary: return false;
case TelescopeAxes.axisSecondary: return false;
case TelescopeAxes.axisTertiary: return false;
default: throw new InvalidValueException("CanMoveAxis", Axis.ToString(), "0 to 2");
tl.LogMessage("CanPark", "Get - " + false.ToString());
public bool CanPulseGuide
tl.LogMessage("CanPulseGuide", "Get - " + true.ToString());
public bool CanSetDeclinationRate
tl.LogMessage("CanSetDeclinationRate", "Get - " + false.ToString());
public bool CanSetGuideRates
tl.LogMessage("CanSetGuideRates", "Get - " + false.ToString());
tl.LogMessage("CanSetPark", "Get - " + false.ToString());
public bool CanSetPierSide
tl.LogMessage("CanSetPierSide", "Get - " + false.ToString());
public bool CanSetRightAscensionRate
tl.LogMessage("CanSetRightAscensionRate", "Get - " + false.ToString());
public bool CanSetTracking
tl.LogMessage("CanSetTracking", "Get - " + false.ToString());
tl.LogMessage("CanSlew", "Get - " + false.ToString());
tl.LogMessage("CanSlewAltAz", "Get - " + false.ToString());
public bool CanSlewAltAzAsync
tl.LogMessage("CanSlewAltAzAsync", "Get - " + false.ToString());
tl.LogMessage("CanSlewAsync", "Get - " + false.ToString());
tl.LogMessage("CanSync", "Get - " + false.ToString());
tl.LogMessage("CanSyncAltAz", "Get - " + false.ToString());
tl.LogMessage("CanUnpark", "Get - " + false.ToString());
public double Declination
double declination = 0.0;
tl.LogMessage("Declination", "Get - " + utilities.DegreesToDMS(declination, ":", ":"));
public double DeclinationRate
double declination = 0.0;
tl.LogMessage("DeclinationRate", "Get - " + declination.ToString());
tl.LogMessage("DeclinationRate Set", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("DeclinationRate", true);
public PierSide DestinationSideOfPier(double RightAscension, double Declination)
tl.LogMessage("DestinationSideOfPier Get", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("DestinationSideOfPier", false);
public bool DoesRefraction
tl.LogMessage("DoesRefraction Get", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("DoesRefraction", false);
tl.LogMessage("DoesRefraction Set", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("DoesRefraction", true);
public EquatorialCoordinateType EquatorialSystem
EquatorialCoordinateType equatorialSystem = EquatorialCoordinateType.equLocalTopocentric;
tl.LogMessage("DeclinationRate", "Get - " + equatorialSystem.ToString());
tl.LogMessage("FindHome", "Not implemented");
throw new ASCOM.MethodNotImplementedException("FindHome");
public double FocalLength
tl.LogMessage("FocalLength Get", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("FocalLength", false);
public double GuideRateDeclination
tl.LogMessage("GuideRateDeclination Get", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("GuideRateDeclination", false);
tl.LogMessage("GuideRateDeclination Set", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("GuideRateDeclination", true);
public double GuideRateRightAscension
tl.LogMessage("GuideRateRightAscension Get", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("GuideRateRightAscension", false);
tl.LogMessage("GuideRateRightAscension Set", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("GuideRateRightAscension", true);
public bool IsPulseGuiding
serialPort.Transmit("I#");
s = serialPort.ReceiveTerminated("#");
bool ret = s.Equals("FALSE", StringComparison.Ordinal);
tl.LogMessage("IsPulseGuiding Get - ", ret.ToString());
public void MoveAxis(TelescopeAxes Axis, double Rate)
tl.LogMessage("MoveAxis", "Not implemented");
throw new ASCOM.MethodNotImplementedException("MoveAxis");
tl.LogMessage("Park", "Not implemented");
throw new ASCOM.MethodNotImplementedException("Park");
public void PulseGuide(GuideDirections Direction, int Duration)
if (Direction == GuideDirections.guideEast)
serialPort.Transmit("E#" + Duration.ToString() + "#");
else if (Direction == GuideDirections.guideWest)
serialPort.Transmit("W#" + Duration.ToString() + "#");
else if (Direction == GuideDirections.guideNorth)
serialPort.Transmit("N#" + Duration.ToString() + "#");
else if (Direction == GuideDirections.guideSouth)
serialPort.Transmit("S#" + Duration.ToString() + "#");
public double RightAscension
double rightAscension = 0.0;
tl.LogMessage("RightAscension", "Get - " + utilities.HoursToHMS(rightAscension));
public double RightAscensionRate
double rightAscensionRate = 0.0;
tl.LogMessage("RightAscensionRate", "Get - " + rightAscensionRate.ToString());
return rightAscensionRate;
tl.LogMessage("RightAscensionRate Set", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("RightAscensionRate", true);
tl.LogMessage("SetPark", "Not implemented");
throw new ASCOM.MethodNotImplementedException("SetPark");
public PierSide SideOfPier
tl.LogMessage("SideOfPier Get", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("SideOfPier", false);
tl.LogMessage("SideOfPier Set", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("SideOfPier", true);
public double SiderealTime
double siderealTime = (18.697374558 + 24.065709824419081 * (utilities.DateUTCToJulian(DateTime.UtcNow) - 2451545.0))% 24;
tl.LogMessage("SiderealTime", "Get - " + siderealTime.ToString());
public double SiteElevation
tl.LogMessage("SiteElevation Get", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("SiteElevation", false);
tl.LogMessage("SiteElevation Set", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("SiteElevation", true);
public double SiteLatitude
tl.LogMessage("SiteLatitude Get", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("SiteLatitude", false);
tl.LogMessage("SiteLatitude Set", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("SiteLatitude", true);
public double SiteLongitude
tl.LogMessage("SiteLongitude Get", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("SiteLongitude", false);
tl.LogMessage("SiteLongitude Set", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("SiteLongitude", true);
public short SlewSettleTime
tl.LogMessage("SlewSettleTime Get", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("SlewSettleTime", false);
tl.LogMessage("SlewSettleTime Set", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("SlewSettleTime", true);
public void SlewToAltAz(double Azimuth, double Altitude)
tl.LogMessage("SlewToAltAz", "Not implemented");
throw new ASCOM.MethodNotImplementedException("SlewToAltAz");
public void SlewToAltAzAsync(double Azimuth, double Altitude)
tl.LogMessage("SlewToAltAzAsync", "Not implemented");
throw new ASCOM.MethodNotImplementedException("SlewToAltAzAsync");
public void SlewToCoordinates(double RightAscension, double Declination)
tl.LogMessage("SlewToCoordinates", "Not implemented");
throw new ASCOM.MethodNotImplementedException("SlewToCoordinates");
public void SlewToCoordinatesAsync(double RightAscension, double Declination)
tl.LogMessage("SlewToCoordinatesAsync", "Not implemented");
throw new ASCOM.MethodNotImplementedException("SlewToCoordinatesAsync");
public void SlewToTarget()
tl.LogMessage("SlewToTarget", "Not implemented");
throw new ASCOM.MethodNotImplementedException("SlewToTarget");
public void SlewToTargetAsync()
tl.LogMessage("SlewToTargetAsync", "Not implemented");
throw new ASCOM.MethodNotImplementedException("SlewToTargetAsync");
get { return this.isSlewing; }
public void SyncToAltAz(double Azimuth, double Altitude)
tl.LogMessage("SyncToAltAz", "Not implemented");
throw new ASCOM.MethodNotImplementedException("SyncToAltAz");
public void SyncToCoordinates(double RightAscension, double Declination)
tl.LogMessage("SyncToCoordinates", "Not implemented");
throw new ASCOM.MethodNotImplementedException("SyncToCoordinates");
public void SyncToTarget()
tl.LogMessage("SyncToTarget", "Not implemented");
throw new ASCOM.MethodNotImplementedException("SyncToTarget");
public double TargetDeclination
tl.LogMessage("TargetDeclination Get", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("TargetDeclination", false);
tl.LogMessage("TargetDeclination Set", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("TargetDeclination", true);
public double TargetRightAscension
tl.LogMessage("TargetRightAscension Get", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("TargetRightAscension", false);
tl.LogMessage("TargetRightAscension Set", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("TargetRightAscension", true);
tl.LogMessage("Tracking", "Get - " + tracking.ToString());
tl.LogMessage("Tracking Set", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("Tracking", true);
public DriveRates TrackingRate
tl.LogMessage("TrackingRate Get", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("TrackingRate", false);
tl.LogMessage("TrackingRate Set", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("TrackingRate", true);
public ITrackingRates TrackingRates
ITrackingRates trackingRates = new TrackingRates();
tl.LogMessage("TrackingRates", "Get - ");
foreach (DriveRates driveRate in trackingRates)
tl.LogMessage("TrackingRates", "Get - " + driveRate.ToString());
DateTime utcDate = DateTime.UtcNow;
tl.LogMessage("TrackingRates", "Get - " + String.Format("MM/dd/yy HH:mm:ss", utcDate));
tl.LogMessage("UTCDate Set", "Not implemented");
throw new ASCOM.PropertyNotImplementedException("UTCDate", true);
tl.LogMessage("Unpark", "Not implemented");
throw new ASCOM.MethodNotImplementedException("Unpark");
#region Private properties and methods
#region ASCOM Registration
private static void RegUnregASCOM(bool bRegister)
using (var P = new ASCOM.Utilities.Profile())
P.DeviceType = "Telescope";
P.Register(driverID, driverDescription);
public static void RegisterASCOM(Type t)
public static void UnregisterASCOM(Type t)
private void CheckConnected(string message)
throw new ASCOM.NotConnectedException(message);
internal void ReadProfile()
using (Profile driverProfile = new Profile())
driverProfile.DeviceType = "Telescope";
tl.Enabled = Convert.ToBoolean(driverProfile.GetValue(driverID, traceStateProfileName, string.Empty, traceStateDefault));
comPort = driverProfile.GetValue(driverID, comPortProfileName, string.Empty, comPortDefault);
internal void WriteProfile()
using (Profile driverProfile = new Profile())
driverProfile.DeviceType = "Telescope";
driverProfile.WriteValue(driverID, traceStateProfileName, tl.Enabled.ToString());
driverProfile.WriteValue(driverID, comPortProfileName, comPort.ToString());
internal static void LogMessage(string identifier, string message, params object[] args)
var msg = string.Format(message, args);
tl.LogMessage(identifier, msg);