@@ -78,15 +78,15 @@ Public Class Telescope
7878 Friend Shared latitude As Double
7979 Friend Shared longitude As Double
8080 Friend Shared elevation As Integer
81- ' Friend Shared PolarisRAJ2000 As Double = 0.0, PolarisRAJNow As Double = 0.0
81+ Friend Shared PolarisRAJNow As Double = 0.0
8282
8383
8484 Private connectedState As Boolean ' Private variable to hold the connected state
8585 Private utilities As Util ' Private variable to hold an ASCOM Utilities object
8686 Private astroUtilities As AstroUtils ' Private variable to hold an AstroUtils object to provide the Range method
8787 Private TL As TraceLogger ' Private variable to hold the trace logger object (creates a diagnostic log file with information that you specify)
8888 Private objSerial As ASCOM.Utilities.Serial
89- ' Private transform As ASCOM.Astrometry.Transform.Transform
89+ Private transform As ASCOM.Astrometry.Transform.Transform
9090
9191 Private isParked As Boolean = False , isTracking As Boolean = True
9292 Private targetRA As Double , targetDec As Double , targetRASet As Boolean = False , targetDecSet As Boolean = False
@@ -109,10 +109,12 @@ Public Class Telescope
109109
110110 'TODO: Implement your additional construction here
111111 mutexCommand = New Mutex( False , "CommMutex" )
112- ' transform = New Transform
113- 'PolarisRAJ2000 = utilities.HMSToHours("02:31:51.12")
114- 'transform.SetJ2000(PolarisRAJ2000, 90.0)
115- 'PolarisRAJNow = transform.RATopocentric
112+ transform = New Transform
113+ transform.SetJ2000(utilities.HMSToHours( "02:31:51.12" ), utilities.DMSToDegrees( "89:15:51.4" ))
114+ transform.SiteElevation = SiteElevation
115+ transform.SiteLatitude = SiteLatitude
116+ transform.SiteLongitude = SiteLongitude
117+ PolarisRAJNow = transform.RATopocentric
116118 TL.LogMessage( "Telescope" , "Completed initialisation" )
117119 End Sub
118120
@@ -146,7 +148,6 @@ Public Class Telescope
146148 Get
147149 Dim actionList As New ArrayList
148150 actionList.Add( "Telescope:getFirmwareVer" )
149- ' actionList.Add("Telescope:getPolJNow")
150151 TL.LogMessage( "SupportedActions Get" , "Returning arraylist of " + actionList.Count.ToString + " item(s)" )
151152 Return actionList
152153 End Get
@@ -160,8 +161,6 @@ Public Class Telescope
160161 Case "Telescope:getFirmwareVer"
161162 retVal = CommandString( ":GVP" ) ' Get firmware name
162163 retVal = retVal + " " + CommandString( ":GVN" ) ' Get firmware version number
163- 'Case "Telescope:getPolJNow"
164- ' retVal = utilities.HoursToHMS(PolarisRAJNow)
165164 End Select
166165 TL.LogMessage( "Action(" + ActionName + ", " + ActionParameters + ")" , retVal)
167166 Return retVal
@@ -190,10 +189,9 @@ Public Class Telescope
190189
191190 Public Function CommandBool( ByVal Command As String , Optional ByVal Raw As Boolean = False ) As Boolean _
192191 Implements ITelescopeV3.CommandBool
193- CheckConnected( "CommandBool" )
194- Dim ret As String = CommandString(Command, Raw)
192+ ' CheckConnected("CommandBool")
193+ ' Dim ret As String = CommandString(Command, Raw)
195194 ' TODO decode the return string and return true or false
196- ' or
197195 Throw New MethodNotImplementedException( "CommandBool" )
198196 End Function
199197
@@ -214,6 +212,8 @@ Public Class Telescope
214212 response = objSerial.ReceiveCounted( 1 )
215213 Case "M"
216214 response = objSerial.ReceiveCounted( 1 )
215+ Case "h"
216+ response = objSerial.ReceiveCounted( 1 )
217217 Case Else
218218 response = objSerial.ReceiveTerminated( "#" )
219219 response = response.Replace( "#" , "" )
@@ -251,7 +251,16 @@ Public Class Telescope
251251 Thread.Sleep( 2000 ) ' Disgusting hack to work around arduino resetting when connected.
252252 ' I don't know of any way to poll and see if the reset has completed
253253 CommandBlind( ":I" ) ' OAT's command for entering PC Control mode
254-
254+ If SiderealTime - PolarisRAJNow < 0 Then
255+ CommandString( ":SH" + utilities.HoursToHM( 24 + (SiderealTime - PolarisRAJNow)), False )
256+ Else
257+ CommandString( ":SH" + utilities.HoursToHM(SiderealTime - PolarisRAJNow), False )
258+ End If
259+ Dim sign As String = "+"
260+ If SiteLatitude < 0 Then
261+ sign = "-"
262+ End If
263+ CommandString( ":SY" + sign + utilities.DegreesToDMS( 90 , "*" , ":" , String .Empty) + "." + utilities.HoursToHMS(SiderealTime, ":" , ":" ), False )
255264 TL.LogMessage( "Connected Set" , "Connecting to port " + comPort)
256265
257266 Catch ex As Exception
@@ -379,16 +388,12 @@ Public Class Telescope
379388
380389 Public ReadOnly Property AtPark() As Boolean Implements ITelescopeV3.AtPark
381390 Get
382- 'Must be implemented, must not throw a PropertyNotImplementedException.
383- 'If the telescope cannot be parked, then AtPark must always return False.
384391 TL.LogMessage( "AtPark" , "Get - " & isParked.ToString())
385392 Return isParked ' Custom boolean we added to track parked state
386393 End Get
387394 End Property
388395
389396 Public Function AxisRates(Axis As TelescopeAxes) As IAxisRates Implements ITelescopeV3.AxisRates
390- 'Must be implemented, must not throw a MethodNotImplementedException.
391- 'See the description of MoveAxis(TelescopeAxes, Double) for more information. This method must return an empty collection if MoveAxis(TelescopeAxes, Double) is not supported.
392397 TL.LogMessage( "AxisRates" , "Get - " & Axis.ToString())
393398 Return New AxisRates(Axis)
394399 End Function
@@ -536,7 +541,7 @@ Public Class Telescope
536541 Public ReadOnly Property Declination() As Double Implements ITelescopeV3.Declination
537542 Get
538543 Dim declination__1 As Double = 0 . 0
539- Dim scopeDec As String = CommandString( ":GD" ) ' TODO : Change this to :GD once implemented in firmware
544+ Dim scopeDec As String = CommandString( ":GD" )
540545 TL.LogMessage( "Declination" , "Get - " & scopeDec)
541546 declination__1 = utilities.DMSToDegrees(scopeDec)
542547 Return declination__1
@@ -628,10 +633,20 @@ Public Class Telescope
628633 End Sub
629634
630635 Public Sub Park() Implements ITelescopeV3.Park
631- TL.LogMessage( "Park" , "Park requested" )
632- CommandBlind( ":hP" )
633- ' CommandBlind(":Q") -- TODO We need to be able to send this, but serial code is broke and disconnects. Issue #5 at ClutchplateDude/OpenAstroTracker
634- isParked = True
636+ If AtPark Then
637+ TL.LogMessage( "Park" , "Err : Mount already parked" )
638+ Throw New ASCOM.ParkedException( "Park" )
639+ Else
640+ Dim prkRet As String = CommandString( ":hP" , False )
641+ If prkRet = "1" Then
642+ isParked = True
643+ Else
644+ isParked = False
645+ Throw New ASCOM.DriverException( "Park failed" )
646+ End If
647+ TL.LogMessage( "Park" , "Park requested : " + prkRet)
648+ End If
649+
635650 End Sub
636651
637652 Public Sub PulseGuide(Direction As GuideDirections, Duration As Integer ) Implements ITelescopeV3.PulseGuide
@@ -642,8 +657,7 @@ Public Class Telescope
642657 Public ReadOnly Property RightAscension() As Double Implements ITelescopeV3.RightAscension
643658 Get
644659 Dim rightAscension__1 As Double = 0 . 0
645- Dim scopeRA As String = CommandString( ":GR" ) ' TODO : Change this to :GR once implemented in firmware
646- ' Minor change here just to recompile and test a theory w/ SGP
660+ Dim scopeRA As String = CommandString( ":GR" )
647661 TL.LogMessage( "RightAscension" , "Get: " + scopeRA)
648662 rightAscension__1 = utilities.HMSToHours(scopeRA)
649663 Return rightAscension__1
@@ -687,8 +701,6 @@ Public Class Telescope
687701 Return retVal
688702 End Get
689703 Set (value As PierSide)
690- ' TL.LogMessage("SideOfPier Set", value.ToString)
691- ' pierSide = value
692704 TL.LogMessage( "SideOfPier Set" , "Not Implemented" )
693705 Throw New ASCOM.PropertyNotImplementedException( "SideOfPier" , True )
694706 End Set
@@ -735,10 +747,7 @@ Public Class Telescope
735747 End Property
736748
737749 Public Property SiteLatitude() As Double Implements ITelescopeV3.SiteLatitude
738- ' ToDo Can we handle this entirely here, wihtout bothering the mount?
739750 Get
740- ' Used by SiderealTime
741- ' Throw New ASCOM.PropertyNotImplementedException("SiteLatitude", False)
742751 TL.LogMessage( "SiteLatitude Get" , latitude.ToString)
743752 Return latitude
744753 End Get
@@ -749,10 +758,7 @@ Public Class Telescope
749758 End Property
750759
751760 Public Property SiteLongitude() As Double Implements ITelescopeV3.SiteLongitude
752- ' ToDo Can we handle this entirely here, wihtout bothering the mount?
753761 Get
754- ' We should be able to not implment this, but SGP (any others?) breaks if we don't. Will confirm and log issue with MSS
755- ' Throw New ASCOM.PropertyNotImplementedException("SiteLongitude", False)
756762 TL.LogMessage( "SiteLongitude Get" , longitude.ToString)
757763 Return longitude
758764 End Get
@@ -828,12 +834,9 @@ Public Class Telescope
828834 Public Sub SlewToTargetAsync() Implements ITelescopeV3.SlewToTargetAsync
829835 TL.LogMessage( "SlewToTargetAsync" , TargetRightAscension.ToString + ", " + TargetDeclination.ToString)
830836 SlewToCoordinates(TargetRightAscension, TargetDeclination)
831-
832- ' Throw New ASCOM.MethodNotImplementedException("SlewToTargetAsync")
833837 End Sub
834838
835839 Public ReadOnly Property Slewing() As Boolean Implements ITelescopeV3.Slewing
836- 'ToDo - We need this, part of implementing Async Slewing
837840 Get
838841 TL.LogMessage( "Slewing Get" , "Not implemented" )
839842 Throw New ASCOM.PropertyNotImplementedException( "Slewing" , False )
@@ -864,11 +867,7 @@ Public Class Telescope
864867 TL.LogMessage( "TargetDeclination Get" , "Value not set" )
865868 Throw New ASCOM.ValueNotSetException( "TargetDeclination" )
866869 End If
867- 'Dim declination__t As Double = 0.0
868- 'Dim targetDec As String = CommandString(":Gd")
869- 'TL.LogMessage("TargetDeclination", "Get - " & targetDec)
870- 'declination__t = utilities.DMSToDegrees(targetDec)
871- 'Return declination__t
870+
872871 End Get
873872 Set (value As Double )
874873 If value >= - 90 And value <= 90 Then
@@ -879,8 +878,7 @@ Public Class Telescope
879878 TL.LogMessage( "TargetDeclination Set" , "Invalid Value " + value.ToString)
880879 Throw New ASCOM.InvalidValueException( "TargetDeclination" )
881880 End If
882- 'TL.LogMessage("TargetDeclination Set", "Not implemented")
883- 'Throw New ASCOM.PropertyNotImplementedException("TargetDeclination", True)
881+
884882 End Set
885883 End Property
886884
@@ -893,11 +891,7 @@ Public Class Telescope
893891 TL.LogMessage( "TargetRightAscension Get" , "Value not set" )
894892 Throw New ASCOM.ValueNotSetException( "TargetRightAscension" )
895893 End If
896- 'Dim rightAscension__t As Double = 0.0
897- 'Dim targetRA As String = CommandString(":Gr")
898- 'TL.LogMessage("TargetRightAscension", "Get - " + targetRA)
899- 'rightAscension__t = utilities.HMSToHours(targetRA)
900- 'Return rightAscension__t
894+
901895 End Get
902896 Set (value As Double )
903897 If value >= 0 And value <= 24 Then
@@ -908,27 +902,33 @@ Public Class Telescope
908902 TL.LogMessage( "TargetRightAscension Set" , "Invalid Value " + value.ToString)
909903 Throw New ASCOM.InvalidValueException( "TargetRightAscension" )
910904 End If
911- 'TL.LogMessage("TargetRightAscension Set", "Not implemented")
912- 'Throw New ASCOM.PropertyNotImplementedException("TargetRightAscension", True)
905+
913906 End Set
914907 End Property
915908
916909 Public Property Tracking() As Boolean Implements ITelescopeV3.Tracking
917- ' This is a shitty implementation fo this, just to see if it keeps SGP happy.
910+
918911 Get
919- If AtPark Or Not isTracking Then
912+ If CommandString( ":GIT" , False ) = "0" Then
913+ isTracking = False
920914 TL.LogMessage( "Tracking" , "Get - " & False .ToString())
921- Return False
922915 Else
916+ isTracking = True
923917 TL.LogMessage( "Tracking" , "Get - " & True .ToString())
924- Return True
925918 End If
919+ Return isTracking
926920 End Get
927921 Set (value As Boolean )
928- isTracking = value
929- TL.LogMessage( "Tracking Set" , value.ToString)
922+ If CommandString( ":MT" + Convert.ToInt32(value).ToString, False ) = "1" Then
923+ isTracking = value
924+ TL.LogMessage( "Tracking Set" , value.ToString)
925+ Else
926+ TL.LogMessage( "Tracking Set" , "Error" )
927+ Throw New ASCOM.DriverException( "Error setting tracking state" )
928+ End If
930929
931930 End Set
931+
932932 End Property
933933
934934 Public Property TrackingRate() As DriveRates Implements ITelescopeV3.TrackingRate
@@ -967,7 +967,14 @@ Public Class Telescope
967967 End Property
968968
969969 Public Sub Unpark() Implements ITelescopeV3.Unpark
970- TL.LogMessage( "Unpark" , "Unparked mount" )
970+ If Not AtPark Then
971+ TL.LogMessage( "Unpark" , "Err : Mount not parked" )
972+ Throw New ASCOM.DriverException( "Mount not parked" )
973+ End If
974+ Dim unprkRet As String = CommandString( ":hU" , False )
975+ If unprkRet = "1" Then
976+ TL.LogMessage( "Unpark" , "Unparked mount" )
977+ End If
971978 isParked = False
972979 End Sub
973980
0 commit comments