Quantcast
Channel: Main Sequence Software - Latest posts
Viewing all articles
Browse latest Browse all 52138

JOLO Focuser problem

$
0
0

This might help

Private Shared lockObj As New Object

Public Function CommandString(ByVal Command As String, Optional ByVal Raw As Boolean = False) As String Implements IFocuserV2.CommandString
    CheckConnected("CommandString")
    Dim commandToSend As String = Command
    If Not (Raw) Then
        commandToSend = Command + Constants.vbLf
    End If

    Dim answer As String
    SyncLock lockObj
        Try
            ComPort.Write(commandToSend)
            answer = ComPort.ReadTo(Constants.vbLf)
        Catch ex As System.TimeoutException
            Throw New ASCOM.DriverException("Serial port timeout for command " + Command)
        Catch ex As System.InvalidOperationException
            Throw New ASCOM.DriverException("Serial port is not opened")
        End Try
        Return answer.Trim(Constants.vbLf)
    End SyncLock
End Function

The SyncLock structure should prevent a second call to CommandString sending a message to the hardware before the first one has finished.

I'd also add a considerable amount of logging to the driver, it makes it far easier to find out what is going on.

Chris

PS this is totally untested, no errors at edit time but that's it, not even compiled.


Viewing all articles
Browse latest Browse all 52138

Trending Articles