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.