@@ -78,15 +78,15 @@ Public Class Telescope
78
78
Friend Shared latitude As Double
79
79
Friend Shared longitude As Double
80
80
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
82
82
83
83
84
84
Private connectedState As Boolean ' Private variable to hold the connected state
85
85
Private utilities As Util ' Private variable to hold an ASCOM Utilities object
86
86
Private astroUtilities As AstroUtils ' Private variable to hold an AstroUtils object to provide the Range method
87
87
Private TL As TraceLogger ' Private variable to hold the trace logger object (creates a diagnostic log file with information that you specify)
88
88
Private objSerial As ASCOM.Utilities.Serial
89
- ' Private transform As ASCOM.Astrometry.Transform.Transform
89
+ Private transform As ASCOM.Astrometry.Transform.Transform
90
90
91
91
Private isParked As Boolean = False , isTracking As Boolean = True
92
92
Private targetRA As Double , targetDec As Double , targetRASet As Boolean = False , targetDecSet As Boolean = False
@@ -109,10 +109,12 @@ Public Class Telescope
109
109
110
110
'TODO: Implement your additional construction here
111
111
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
116
118
TL.LogMessage( "Telescope" , "Completed initialisation" )
117
119
End Sub
118
120
@@ -146,7 +148,6 @@ Public Class Telescope
146
148
Get
147
149
Dim actionList As New ArrayList
148
150
actionList.Add( "Telescope:getFirmwareVer" )
149
- ' actionList.Add("Telescope:getPolJNow")
150
151
TL.LogMessage( "SupportedActions Get" , "Returning arraylist of " + actionList.Count.ToString + " item(s)" )
151
152
Return actionList
152
153
End Get
@@ -160,8 +161,6 @@ Public Class Telescope
160
161
Case "Telescope:getFirmwareVer"
161
162
retVal = CommandString( ":GVP" ) ' Get firmware name
162
163
retVal = retVal + " " + CommandString( ":GVN" ) ' Get firmware version number
163
- 'Case "Telescope:getPolJNow"
164
- ' retVal = utilities.HoursToHMS(PolarisRAJNow)
165
164
End Select
166
165
TL.LogMessage( "Action(" + ActionName + ", " + ActionParameters + ")" , retVal)
167
166
Return retVal
@@ -190,10 +189,9 @@ Public Class Telescope
190
189
191
190
Public Function CommandBool( ByVal Command As String , Optional ByVal Raw As Boolean = False ) As Boolean _
192
191
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)
195
194
' TODO decode the return string and return true or false
196
- ' or
197
195
Throw New MethodNotImplementedException( "CommandBool" )
198
196
End Function
199
197
@@ -214,6 +212,8 @@ Public Class Telescope
214
212
response = objSerial.ReceiveCounted( 1 )
215
213
Case "M"
216
214
response = objSerial.ReceiveCounted( 1 )
215
+ Case "h"
216
+ response = objSerial.ReceiveCounted( 1 )
217
217
Case Else
218
218
response = objSerial.ReceiveTerminated( "#" )
219
219
response = response.Replace( "#" , "" )
@@ -251,7 +251,16 @@ Public Class Telescope
251
251
Thread.Sleep( 2000 ) ' Disgusting hack to work around arduino resetting when connected.
252
252
' I don't know of any way to poll and see if the reset has completed
253
253
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 )
255
264
TL.LogMessage( "Connected Set" , "Connecting to port " + comPort)
256
265
257
266
Catch ex As Exception
@@ -379,16 +388,12 @@ Public Class Telescope
379
388
380
389
Public ReadOnly Property AtPark() As Boolean Implements ITelescopeV3.AtPark
381
390
Get
382
- 'Must be implemented, must not throw a PropertyNotImplementedException.
383
- 'If the telescope cannot be parked, then AtPark must always return False.
384
391
TL.LogMessage( "AtPark" , "Get - " & isParked.ToString())
385
392
Return isParked ' Custom boolean we added to track parked state
386
393
End Get
387
394
End Property
388
395
389
396
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.
392
397
TL.LogMessage( "AxisRates" , "Get - " & Axis.ToString())
393
398
Return New AxisRates(Axis)
394
399
End Function
@@ -536,7 +541,7 @@ Public Class Telescope
536
541
Public ReadOnly Property Declination() As Double Implements ITelescopeV3.Declination
537
542
Get
538
543
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" )
540
545
TL.LogMessage( "Declination" , "Get - " & scopeDec)
541
546
declination__1 = utilities.DMSToDegrees(scopeDec)
542
547
Return declination__1
@@ -628,10 +633,20 @@ Public Class Telescope
628
633
End Sub
629
634
630
635
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
+
635
650
End Sub
636
651
637
652
Public Sub PulseGuide(Direction As GuideDirections, Duration As Integer ) Implements ITelescopeV3.PulseGuide
@@ -642,8 +657,7 @@ Public Class Telescope
642
657
Public ReadOnly Property RightAscension() As Double Implements ITelescopeV3.RightAscension
643
658
Get
644
659
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" )
647
661
TL.LogMessage( "RightAscension" , "Get: " + scopeRA)
648
662
rightAscension__1 = utilities.HMSToHours(scopeRA)
649
663
Return rightAscension__1
@@ -687,8 +701,6 @@ Public Class Telescope
687
701
Return retVal
688
702
End Get
689
703
Set (value As PierSide)
690
- ' TL.LogMessage("SideOfPier Set", value.ToString)
691
- ' pierSide = value
692
704
TL.LogMessage( "SideOfPier Set" , "Not Implemented" )
693
705
Throw New ASCOM.PropertyNotImplementedException( "SideOfPier" , True )
694
706
End Set
@@ -735,10 +747,7 @@ Public Class Telescope
735
747
End Property
736
748
737
749
Public Property SiteLatitude() As Double Implements ITelescopeV3.SiteLatitude
738
- ' ToDo Can we handle this entirely here, wihtout bothering the mount?
739
750
Get
740
- ' Used by SiderealTime
741
- ' Throw New ASCOM.PropertyNotImplementedException("SiteLatitude", False)
742
751
TL.LogMessage( "SiteLatitude Get" , latitude.ToString)
743
752
Return latitude
744
753
End Get
@@ -749,10 +758,7 @@ Public Class Telescope
749
758
End Property
750
759
751
760
Public Property SiteLongitude() As Double Implements ITelescopeV3.SiteLongitude
752
- ' ToDo Can we handle this entirely here, wihtout bothering the mount?
753
761
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)
756
762
TL.LogMessage( "SiteLongitude Get" , longitude.ToString)
757
763
Return longitude
758
764
End Get
@@ -828,12 +834,9 @@ Public Class Telescope
828
834
Public Sub SlewToTargetAsync() Implements ITelescopeV3.SlewToTargetAsync
829
835
TL.LogMessage( "SlewToTargetAsync" , TargetRightAscension.ToString + ", " + TargetDeclination.ToString)
830
836
SlewToCoordinates(TargetRightAscension, TargetDeclination)
831
-
832
- ' Throw New ASCOM.MethodNotImplementedException("SlewToTargetAsync")
833
837
End Sub
834
838
835
839
Public ReadOnly Property Slewing() As Boolean Implements ITelescopeV3.Slewing
836
- 'ToDo - We need this, part of implementing Async Slewing
837
840
Get
838
841
TL.LogMessage( "Slewing Get" , "Not implemented" )
839
842
Throw New ASCOM.PropertyNotImplementedException( "Slewing" , False )
@@ -864,11 +867,7 @@ Public Class Telescope
864
867
TL.LogMessage( "TargetDeclination Get" , "Value not set" )
865
868
Throw New ASCOM.ValueNotSetException( "TargetDeclination" )
866
869
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
+
872
871
End Get
873
872
Set (value As Double )
874
873
If value >= - 90 And value <= 90 Then
@@ -879,8 +878,7 @@ Public Class Telescope
879
878
TL.LogMessage( "TargetDeclination Set" , "Invalid Value " + value.ToString)
880
879
Throw New ASCOM.InvalidValueException( "TargetDeclination" )
881
880
End If
882
- 'TL.LogMessage("TargetDeclination Set", "Not implemented")
883
- 'Throw New ASCOM.PropertyNotImplementedException("TargetDeclination", True)
881
+
884
882
End Set
885
883
End Property
886
884
@@ -893,11 +891,7 @@ Public Class Telescope
893
891
TL.LogMessage( "TargetRightAscension Get" , "Value not set" )
894
892
Throw New ASCOM.ValueNotSetException( "TargetRightAscension" )
895
893
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
+
901
895
End Get
902
896
Set (value As Double )
903
897
If value >= 0 And value <= 24 Then
@@ -908,27 +902,33 @@ Public Class Telescope
908
902
TL.LogMessage( "TargetRightAscension Set" , "Invalid Value " + value.ToString)
909
903
Throw New ASCOM.InvalidValueException( "TargetRightAscension" )
910
904
End If
911
- 'TL.LogMessage("TargetRightAscension Set", "Not implemented")
912
- 'Throw New ASCOM.PropertyNotImplementedException("TargetRightAscension", True)
905
+
913
906
End Set
914
907
End Property
915
908
916
909
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
+
918
911
Get
919
- If AtPark Or Not isTracking Then
912
+ If CommandString( ":GIT" , False ) = "0" Then
913
+ isTracking = False
920
914
TL.LogMessage( "Tracking" , "Get - " & False .ToString())
921
- Return False
922
915
Else
916
+ isTracking = True
923
917
TL.LogMessage( "Tracking" , "Get - " & True .ToString())
924
- Return True
925
918
End If
919
+ Return isTracking
926
920
End Get
927
921
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
930
929
931
930
End Set
931
+
932
932
End Property
933
933
934
934
Public Property TrackingRate() As DriveRates Implements ITelescopeV3.TrackingRate
@@ -967,7 +967,14 @@ Public Class Telescope
967
967
End Property
968
968
969
969
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
971
978
isParked = False
972
979
End Sub
973
980
0 commit comments