Public Class Form_GOS

    Dim GOS As String
    Dim GOSlen As Integer

    Private Sub Form_GOS_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        ButtonRefresh.PerformClick()

    End Sub

  
    Private Sub ButtonRefresh_Click(sender As System.Object, e As System.EventArgs) Handles ButtonRefresh.Click
        Form1.AP_Command("MountOperatingStatus")
        GOS = Form1.GOSresp
        GOSlen = GOS.Length
        LabelGOS.Text = GOS

        ' Park Status
        Dim A As String = Mid(GOS, 1, 1)
        TextBoxA.Text = A
        Select Case A
            Case "P"
                TextBoxA2.Text = "parked"
            Case "0"
                TextBoxA2.Text = "not parked"
            Case "1"
                TextBoxA2.Text = "auto park - ON"
            Case Else
                TextBoxA2.Text = "invalid"
        End Select

        ' RA Tracking Status
        Dim B As String = Mid(GOS, 2, 1)
        TextBoxB.Text = B
        Select Case B
            Case "0"
                TextBoxB2.Text = "Lunar Rate"
            Case "1"
                TextBoxB2.Text = "Solar Rate"
            Case "2"
                TextBoxB2.Text = "Sidereal Rate"
            Case "9"
                TextBoxB2.Text = "Tracking Stopped"
            Case "C"
                TextBoxB2.Text = "Custom Rate"
            Case Else
                TextBoxB2.Text = "invalid"
        End Select

        ' Dec Tracking Status
        Dim C As String = Mid(GOS, 3, 1)
        TextBoxC.Text = C
        Select Case C
            Case "9"
                TextBoxC2.Text = "No Motion"
            Case "C"
                TextBoxC2.Text = "Custom Rate"
            Case Else
                TextBoxC2.Text = "invalid"
        End Select

        ' Slew Status
        Dim D As String = Mid(GOS, 4, 1)
        TextBoxD.Text = D
        Select Case D
            Case "S"
                TextBoxD2.Text = "Slewing"
            Case "0"
                TextBoxD2.Text = "Not slewing"
            Case Else
                TextBoxD2.Text = "invalid"
        End Select

        ' Moving RA Axis (via a Move command/Slew/ST4 Port signal)
        Dim E5 As String = Mid(GOS, 5, 1)
        TextBoxE.Text = E5
        Select Case E5
            Case "E"
                TextBoxE2.Text = "Moving East"
            Case "W"
                TextBoxE2.Text = "Moving West"
            Case "0"
                TextBoxE2.Text = "Not Moving"
            Case Else
                TextBoxE2.Text = "invalid"
        End Select

        ' Moving RA Axis (via a Move command/Slew/ST4 Port signal)
        Dim F As String = Mid(GOS, 6, 1)
        TextBoxF.Text = F
        Select Case F
            Case "N"
                TextBoxF2.Text = "Moving North"
            Case "S"
                TextBoxF2.Text = "Moving South"
            Case "0"
                TextBoxF2.Text = "Not Moving"
            Case Else
                TextBoxF2.Text = "invalid"
        End Select

        ' Guide Rate
        Dim G As String = Mid(GOS, 7, 1)
        TextBoxG.Text = G
        Select Case G
            Case "0"
                TextBoxG2.Text = "0.25x"
            Case "1"
                TextBoxG2.Text = "0.50x"
            Case "2"
                TextBoxG2.Text = "1.00x"
            Case Else
                TextBoxG2.Text = "invalid"
        End Select

        ' Center/Move Rate
        Dim H As String = Mid(GOS, 8, 1)
        TextBoxH.Text = H
        If GOS.Length > 14 Then
            Select Case H
                Case "0"
                    TextBoxH2.Text = "12x"
                Case "1"
                    TextBoxH2.Text = "64x"
                Case "2"
                    TextBoxH2.Text = "200x"
                Case "3"
                    TextBoxH2.Text = "600x"
                Case "4"
                    TextBoxH2.Text = "1200x"
                Case "5"
                    TextBoxH2.Text = "0.25x"
                Case "6"
                    TextBoxH2.Text = "0.5x"
                Case "7"
                    TextBoxH2.Text = "1.0x"
                Case "C"
                    TextBoxH2.Text = "Custom Rate"
                Case Else
                    TextBoxH2.Text = "invalid"
            End Select
        Else
            Select Case H
                Case "0"
                    TextBoxH2.Text = "12x"
                Case "1"
                    TextBoxH2.Text = "64x"
                Case "2"
                    TextBoxH2.Text = "600x"
                Case "3"
                    TextBoxH2.Text = "1200x"
                Case "C"
                    TextBoxH2.Text = "Custom Rate"
                Case Else
                    TextBoxH2.Text = "invalid"
            End Select
        End If

        ' Slew Rate
        Dim I As String = Mid(GOS, 9, 1)
        TextBoxI.Text = I
        Select Case I
            Case "0"
                TextBoxI2.Text = "600x"
            Case "1"
                TextBoxI2.Text = "900x"
            Case "2"
                TextBoxI2.Text = "1200x"
            Case "C"
                TextBoxI2.Text = "Custom Rate"
            Case Else
                TextBoxI2.Text = "invalid"
        End Select

        ' PEM
        Dim J As String = Mid(GOS, 10, 1)
        TextBoxJ.Text = J
        Select Case J
            Case "O"
                TextBoxJ2.Text = "Off"
            Case "P"
                TextBoxJ2.Text = "Playback"
            Case "R"
                TextBoxJ2.Text = "Recording"
            Case "E"
                TextBoxJ2.Text = "Encoder"
            Case Else
                TextBoxJ2.Text = "invalid"
        End Select

        ' Mount Status
        Dim K As String = Mid(GOS, 11, 1)
        TextBoxK.Text = K
        Select Case K
            Case "0"
                TextBoxK2.Text = "Normal"
            Case "1"
                TextBoxK2.Text = "Stalled"
            Case "2"
                TextBoxK2.Text = "Low Power Supply"
            Case "4"
                TextBoxK2.Text = "Servo fault / number probem"
            Case "8"
                TextBoxK2.Text = "Normal"
            Case "Z"
                TextBoxK2.Text = "Stalled"
            Case "Y"
                TextBoxK2.Text = "Low Power Supply"
            Case "X"
                TextBoxK2.Text = "Servo fault / number problem"
            Case "N"
                TextBoxK2.Text = "CCW Internal Dec Limit or AE Limit"
            Case "S"
                TextBoxK2.Text = "CW Internal Dec Limit or AE Limit"
            Case "E"
                TextBoxK2.Text = "Eest Internal RA Limit or AE Limit"
            Case "W"
                TextBoxK2.Text = "West Internal RA Limit or AE Limit"
            Case "z"
                TextBoxK2.Text = "Kill Function has been issued"
            Case Else
                TextBoxK2.Text = "invalid"
        End Select

        If GOS.Length > 14 Then
            ' E-W button reversal
            Dim L As String = Mid(GOS, 12, 1)
            TextBoxL.Text = L
            Select Case L
                Case "0"
                    TextBoxL2.Text = "Normal"
                Case "1"
                    TextBoxL2.Text = "Reversed"
                Case Else
                    TextBoxL2.Text = "invalid"
            End Select

            ' N-S button reversal
            Dim M As String = Mid(GOS, 13, 1)
            TextBoxM.Text = M
            Select Case M
                Case "0"
                    TextBoxM2.Text = "Normal"
                Case "1"
                    TextBoxM2.Text = "Reversed"
                Case Else
                    TextBoxM2.Text = "invalid"
            End Select

            ' Rate Table Index
            TextBoxN.Text = Mid(GOS, 14, 1)
            TextBoxN2.Text = "index"
        Else
            TextBoxL2.Text = ""
            TextBoxM2.Text = ""
            TextBoxN2.Text = ""
        End If

    End Sub
End Class