Skip to content

Commit cbe3cfd

Browse files
committed
Closes #18, Closes #19
1 parent 7477d0b commit cbe3cfd

File tree

1 file changed

+97
-20
lines changed
  • Software/OpenAstroTracker ASCOM/OpenAstroTracker ASCOM

1 file changed

+97
-20
lines changed

Software/OpenAstroTracker ASCOM/OpenAstroTracker ASCOM/Driver.vb

Lines changed: 97 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,6 @@ Public Class Telescope
508508
End Property
509509

510510
Public ReadOnly Property CanSlewAsync() As Boolean Implements ITelescopeV3.CanSlewAsync
511-
' TODO - Async Slewing
512511
Get
513512
TL.LogMessage("CanSlewAsync", "Get - " & True.ToString())
514513
Return True
@@ -517,8 +516,8 @@ Public Class Telescope
517516

518517
Public ReadOnly Property CanSync() As Boolean Implements ITelescopeV3.CanSync
519518
Get
520-
TL.LogMessage("CanSync", "Get - " & False.ToString())
521-
Return False
519+
TL.LogMessage("CanSync", "Get - " & True.ToString())
520+
Return True
522521
End Get
523522
End Property
524523

@@ -635,14 +634,10 @@ Public Class Telescope
635634
TL.LogMessage("Park", "Err : Mount already parked")
636635
Throw New ASCOM.ParkedException("Park")
637636
Else
638-
Dim prkRet As String = CommandString(":hP", False)
639-
If prkRet = "1" Then
640-
isParked = True
641-
Else
642-
isParked = False
643-
Throw New ASCOM.DriverException("Park failed")
644-
End If
645-
TL.LogMessage("Park", "Park requested : " + prkRet)
637+
CommandString(":hP", False)
638+
PollUntilZero(":GIS")
639+
isParked = True
640+
TL.LogMessage("Park", "Parked mount")
646641
End If
647642

648643
End Sub
@@ -789,6 +784,7 @@ Public Class Telescope
789784
End Sub
790785

791786
Public Sub SlewToCoordinates(RightAscension As Double, Declination As Double) Implements ITelescopeV3.SlewToCoordinates
787+
' Synchronous slew to given coordinates. Uses PollUntilZero to wait for slew to finish
792788
If RightAscension <= 24 And RightAscension >= 0 And Declination >= -90 And Declination <= 90 Then
793789

794790
If Not AtPark Then
@@ -804,6 +800,7 @@ Public Class Telescope
804800
If CommandString(strRAcmd) = "1" Then
805801
If CommandString(strDeccmd) = "1" Then
806802
CommandString(":MS")
803+
PollUntilZero(":GIS")
807804
End If
808805

809806
End If
@@ -818,25 +815,51 @@ Public Class Telescope
818815
End Sub
819816

820817
Public Sub SlewToCoordinatesAsync(RightAscension As Double, Declination As Double) Implements ITelescopeV3.SlewToCoordinatesAsync
821-
TL.LogMessage("SlewToCoordinatesAsync", RightAscension.ToString + ", " + Declination.ToString)
822-
SlewToCoordinates(RightAscension, Declination)
818+
' ASynchronous slew to coordinates. Returns immediately after receiving response from :MS that command was accepted
819+
If RightAscension <= 24 And RightAscension >= 0 And Declination >= -90 And Declination <= 90 Then
823820

821+
If Not AtPark Then
822+
TL.LogMessage("SlewToCoordinatesAsync", "RA " + RightAscension.ToString + ", Dec " + Declination.ToString)
823+
Dim strRAcmd = ":Sr" + utilities.HoursToHMS(RightAscension, ":", ":")
824+
Dim strDeccmd = utilities.DegreesToDMS(Declination, "*", ":", "")
825+
If Declination >= 0 Then
826+
strDeccmd = "+" + strDeccmd
827+
End If
828+
strDeccmd = ":Sd" + strDeccmd
829+
TL.LogMessage("SlewToCoordinatesAsyncRACmd", strRAcmd)
830+
TL.LogMessage("SlewToCoordinatesAsyncDecCmd", strDeccmd)
831+
If CommandString(strRAcmd) = "1" Then
832+
If CommandString(strDeccmd) = "1" Then
833+
CommandString(":MS")
834+
End If
835+
836+
End If
837+
Else
838+
TL.LogMessage("SlewToCoordinatesAsync", "Parked")
839+
Throw New ASCOM.ParkedException("SlewToCoordinatesAsync")
840+
End If
841+
Else
842+
TL.LogMessage("SlewToCoordinatesAsync", "Invalid coordinates RA: " + RightAscension.ToString + ", Dec: " + Declination.ToString)
843+
Throw New ASCOM.InvalidValueException("SlewToCoordinatesAsync")
844+
End If
824845

825846
End Sub
826847

827848
Public Sub SlewToTarget() Implements ITelescopeV3.SlewToTarget
849+
TL.LogMessage("SlewToTarget", TargetRightAscension.ToString + ", " + TargetDeclination.ToString)
828850
SlewToCoordinates(TargetRightAscension, TargetDeclination)
829851
End Sub
830852

831853
Public Sub SlewToTargetAsync() Implements ITelescopeV3.SlewToTargetAsync
832854
TL.LogMessage("SlewToTargetAsync", TargetRightAscension.ToString + ", " + TargetDeclination.ToString)
833-
SlewToCoordinates(TargetRightAscension, TargetDeclination)
855+
SlewToCoordinatesAsync(TargetRightAscension, TargetDeclination)
834856
End Sub
835857

836858
Public ReadOnly Property Slewing() As Boolean Implements ITelescopeV3.Slewing
837859
Get
838-
TL.LogMessage("Slewing Get", "Not implemented")
839-
Throw New ASCOM.PropertyNotImplementedException("Slewing", False)
860+
Dim retVal As Boolean = Convert.ToBoolean(CInt(CommandString(":GIS")))
861+
TL.LogMessage("Slewing Get", retVal.ToString)
862+
Return retVal
840863
End Get
841864
End Property
842865

@@ -846,13 +869,53 @@ Public Class Telescope
846869
End Sub
847870

848871
Public Sub SyncToCoordinates(RightAscension As Double, Declination As Double) Implements ITelescopeV3.SyncToCoordinates
849-
TL.LogMessage("SyncToCoordinates", "Not implemented")
850-
Throw New ASCOM.MethodNotImplementedException("SyncToCoordinates")
872+
If RightAscension <= 24 And RightAscension >= 0 And Declination >= -90 And Declination <= 90 Then
873+
Dim sign As String = String.Empty
874+
If Declination >= 0 Then
875+
sign = "+"
876+
End If
877+
Dim success As String = CommandString(":SY" + sign + utilities.DegreesToDMS(Declination, "*", ":", String.Empty) + "." + utilities.HoursToHMS(RightAscension, ":", ":"), False)
878+
If success = "1" Then
879+
TL.LogMessage("SyncToCoordinates", "Synced to " + utilities.DegreesToDMS(Declination) + ", " + utilities.HoursToHMS(RightAscension))
880+
Else
881+
TL.LogMessage("SyncToCoordinates", "Failed to sync to " + utilities.DegreesToDMS(Declination) + ", " + utilities.HoursToHMS(RightAscension))
882+
Throw New ASCOM.DriverException("SyncToCoordinates")
883+
End If
884+
Else
885+
TL.LogMessage("SyncToCoordinates", "Invalid coordinates RA: " + RightAscension.ToString + ", Dec: " + Declination.ToString)
886+
Throw New ASCOM.InvalidValueException("SyncToCoordinates")
887+
End If
851888
End Sub
852889

853890
Public Sub SyncToTarget() Implements ITelescopeV3.SyncToTarget
854-
TL.LogMessage("SyncToTarget", "Not implemented")
855-
Throw New ASCOM.MethodNotImplementedException("SyncToTarget")
891+
If targetDecSet Then
892+
893+
If targetRASet Then
894+
895+
Dim sign As String = String.Empty
896+
If TargetDeclination >= 0 Then
897+
sign = "+"
898+
End If
899+
Dim success As String = CommandString(":SY" + sign + utilities.DegreesToDMS(TargetDeclination, "*", ":", String.Empty) + "." + utilities.HoursToHMS(TargetRightAscension, ":", ":"), False)
900+
If success = "1" Then
901+
TL.LogMessage("SyncToTarget", "Synced to " + utilities.DegreesToDMS(TargetDeclination) + ", " + utilities.HoursToHMS(TargetRightAscension))
902+
Else
903+
TL.LogMessage("SyncToTarget", "Failed to sync to " + utilities.DegreesToDMS(TargetDeclination) + ", " + utilities.HoursToHMS(TargetRightAscension))
904+
Throw New ASCOM.DriverException("SyncToTarget")
905+
End If
906+
907+
Else
908+
909+
Throw New ASCOM.ValueNotSetException("TargetRightAscension")
910+
911+
End If
912+
913+
Else
914+
915+
Throw New ASCOM.ValueNotSetException("TargetDeclination")
916+
917+
End If
918+
856919
End Sub
857920

858921
Public Property TargetDeclination() As Double Implements ITelescopeV3.TargetDeclination
@@ -1062,4 +1125,18 @@ Public Class Telescope
10621125

10631126
#End Region
10641127

1128+
#Region "Helper Functions"
1129+
1130+
Private Function PollUntilZero(ByVal command As String) As Integer
1131+
' Takes a command to be sent via CommandString, and resends every 1000ms until a 0 is returned. Returns 0 only when complete.
1132+
Dim retVal As String = ""
1133+
Do Until retVal = "0"
1134+
retVal = CommandString(command, False)
1135+
Thread.Sleep(1000)
1136+
Loop
1137+
Return CInt(retVal)
1138+
End Function
1139+
1140+
#End Region
1141+
10651142
End Class

0 commit comments

Comments
 (0)